Commit 633ae56b authored by Simon Knox's avatar Simon Knox

Merge branch...

Merge branch '356584-kubernetes-agent-registration-dialog-reloads-the-page-when-enter-is-pressed' into 'master'

Kubernetes Agent Registration dialog reloads the page when Enter is pressed

See merge request gitlab-org/gitlab!84225
parents 65535077 407fbace
...@@ -3,6 +3,7 @@ import { ...@@ -3,6 +3,7 @@ import {
GlDropdown, GlDropdown,
GlDropdownItem, GlDropdownItem,
GlDropdownDivider, GlDropdownDivider,
GlDropdownText,
GlSearchBoxByType, GlSearchBoxByType,
GlSprintf, GlSprintf,
} from '@gitlab/ui'; } from '@gitlab/ui';
...@@ -15,6 +16,7 @@ export default { ...@@ -15,6 +16,7 @@ export default {
GlDropdown, GlDropdown,
GlDropdownItem, GlDropdownItem,
GlDropdownDivider, GlDropdownDivider,
GlDropdownText,
GlSearchBoxByType, GlSearchBoxByType,
GlSprintf, GlSprintf,
}, },
...@@ -73,13 +75,24 @@ export default { ...@@ -73,13 +75,24 @@ export default {
this.clearSearch(); this.clearSearch();
this.focusSearch(); this.focusSearch();
}, },
onKeyEnter() {
if (!this.searchTerm?.length) {
return;
}
this.$refs.dropdown.hide();
this.selectAgent(this.searchTerm);
},
}, },
}; };
</script> </script>
<template> <template>
<gl-dropdown :text="dropdownText" :loading="isRegistering" @shown="handleShow"> <gl-dropdown ref="dropdown" :text="dropdownText" :loading="isRegistering" @shown="handleShow">
<template #header> <template #header>
<gl-search-box-by-type ref="searchInput" v-model.trim="searchTerm" /> <gl-search-box-by-type
ref="searchInput"
v-model.trim="searchTerm"
@keydown.enter.stop.prevent="onKeyEnter"
/>
</template> </template>
<gl-dropdown-item <gl-dropdown-item
v-for="agent in filteredResults" v-for="agent in filteredResults"
...@@ -90,9 +103,9 @@ export default { ...@@ -90,9 +103,9 @@ export default {
> >
{{ agent }} {{ agent }}
</gl-dropdown-item> </gl-dropdown-item>
<gl-dropdown-item v-if="!filteredResults.length" ref="noMatchingResults">{{ <gl-dropdown-text v-if="!filteredResults.length" ref="noMatchingResults">{{
$options.i18n.noResults $options.i18n.noResults
}}</gl-dropdown-item> }}</gl-dropdown-text>
<template v-if="shouldRenderCreateButton"> <template v-if="shouldRenderCreateButton">
<gl-dropdown-divider /> <gl-dropdown-divider />
<gl-dropdown-item data-testid="create-config-button" @click="selectAgent(searchTerm)"> <gl-dropdown-item data-testid="create-config-button" @click="selectAgent(searchTerm)">
......
import { GlDropdown, GlDropdownItem, GlSearchBoxByType } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem, GlSearchBoxByType } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { ENTER_KEY } from '~/lib/utils/keys';
import AvailableAgentsDropdown from '~/clusters_list/components/available_agents_dropdown.vue'; import AvailableAgentsDropdown from '~/clusters_list/components/available_agents_dropdown.vue';
import { I18N_AVAILABLE_AGENTS_DROPDOWN } from '~/clusters_list/constants'; import { I18N_AVAILABLE_AGENTS_DROPDOWN } from '~/clusters_list/constants';
...@@ -18,6 +19,7 @@ describe('AvailableAgentsDropdown', () => { ...@@ -18,6 +19,7 @@ describe('AvailableAgentsDropdown', () => {
propsData, propsData,
stubs: { GlDropdown }, stubs: { GlDropdown },
}); });
wrapper.vm.$refs.dropdown.hide = jest.fn();
}; };
afterEach(() => { afterEach(() => {
...@@ -96,6 +98,25 @@ describe('AvailableAgentsDropdown', () => { ...@@ -96,6 +98,25 @@ describe('AvailableAgentsDropdown', () => {
expect(findDropdown().props('text')).toBe('new-agent'); expect(findDropdown().props('text')).toBe('new-agent');
}); });
}); });
describe('click enter to register new agent without configuration', () => {
beforeEach(async () => {
await findSearchInput().vm.$emit('input', 'new-agent');
await findSearchInput().vm.$emit('keydown', new KeyboardEvent({ key: ENTER_KEY }));
});
it('emits agentSelected with the name of the clicked agent', () => {
expect(wrapper.emitted('agentSelected')).toEqual([['new-agent']]);
});
it('marks the clicked item as selected', () => {
expect(findDropdown().props('text')).toBe('new-agent');
});
it('closes the dropdown', () => {
expect(wrapper.vm.$refs.dropdown.hide).toHaveBeenCalledTimes(1);
});
});
}); });
describe('registration in progress', () => { describe('registration in progress', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment