Commit 66e87900 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch 'preload-environments-for-ci-cd-variables' into 'master'

Clear Environment Search in CI/CD Variables

See merge request gitlab-org/gitlab!54626
parents 0afccd2a 1d823270
...@@ -20,7 +20,7 @@ export default { ...@@ -20,7 +20,7 @@ export default {
}, },
data() { data() {
return { return {
searchTerm: this.value || '', searchTerm: '',
}; };
}, },
computed: { computed: {
...@@ -38,11 +38,6 @@ export default { ...@@ -38,11 +38,6 @@ export default {
); );
}, },
}, },
watch: {
value(newVal) {
this.searchTerm = newVal;
},
},
methods: { methods: {
selectEnvironment(selected) { selectEnvironment(selected) {
this.$emit('selectEnvironment', selected); this.$emit('selectEnvironment', selected);
...@@ -55,11 +50,14 @@ export default { ...@@ -55,11 +50,14 @@ export default {
isSelected(env) { isSelected(env) {
return this.value === env; return this.value === env;
}, },
clearSearch() {
this.searchTerm = '';
},
}, },
}; };
</script> </script>
<template> <template>
<gl-dropdown :text="value"> <gl-dropdown :text="value" @show="clearSearch">
<gl-search-box-by-type v-model.trim="searchTerm" data-testid="ci-environment-search" /> <gl-search-box-by-type v-model.trim="searchTerm" data-testid="ci-environment-search" />
<gl-dropdown-item <gl-dropdown-item
v-for="environment in filteredResults" v-for="environment in filteredResults"
......
---
title: Clear Environment Search in CI/CD Variables
merge_request: 54626
author:
type: changed
...@@ -24,7 +24,6 @@ RSpec.describe 'Project variables', :js do ...@@ -24,7 +24,6 @@ RSpec.describe 'Project variables', :js do
find('[data-qa-selector="ci_variable_key_field"] input').set('akey') find('[data-qa-selector="ci_variable_key_field"] input').set('akey')
find('#ci-variable-value').set('akey_value') find('#ci-variable-value').set('akey_value')
find('[data-testid="environment-scope"]').click find('[data-testid="environment-scope"]').click
find_button('clear').click
find('[data-testid="ci-environment-search"]').set('review/*') find('[data-testid="ci-environment-search"]').set('review/*')
find('[data-testid="create-wildcard-button"]').click find('[data-testid="create-wildcard-button"]').click
......
import { GlDropdownItem, GlIcon } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem, GlIcon } from '@gitlab/ui';
import { mount, createLocalVue } from '@vue/test-utils'; import { mount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import CiEnvironmentsDropdown from '~/ci_variable_list/components/ci_environments_dropdown.vue'; import CiEnvironmentsDropdown from '~/ci_variable_list/components/ci_environments_dropdown.vue';
...@@ -10,6 +10,9 @@ describe('Ci environments dropdown', () => { ...@@ -10,6 +10,9 @@ describe('Ci environments dropdown', () => {
let wrapper; let wrapper;
let store; let store;
const enterSearchTerm = (value) =>
wrapper.find('[data-testid="ci-environment-search"]').setValue(value);
const createComponent = (term) => { const createComponent = (term) => {
store = new Vuex.Store({ store = new Vuex.Store({
getters: { getters: {
...@@ -24,11 +27,12 @@ describe('Ci environments dropdown', () => { ...@@ -24,11 +27,12 @@ describe('Ci environments dropdown', () => {
value: term, value: term,
}, },
}); });
enterSearchTerm(term);
}; };
const findAllDropdownItems = () => wrapper.findAll(GlDropdownItem); const findAllDropdownItems = () => wrapper.findAllComponents(GlDropdownItem);
const findDropdownItemByIndex = (index) => wrapper.findAll(GlDropdownItem).at(index); const findDropdownItemByIndex = (index) => wrapper.findAllComponents(GlDropdownItem).at(index);
const findActiveIconByIndex = (index) => findDropdownItemByIndex(index).find(GlIcon); const findActiveIconByIndex = (index) => findDropdownItemByIndex(index).findComponent(GlIcon);
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
...@@ -68,8 +72,9 @@ describe('Ci environments dropdown', () => { ...@@ -68,8 +72,9 @@ describe('Ci environments dropdown', () => {
}); });
describe('Environments found', () => { describe('Environments found', () => {
beforeEach(() => { beforeEach(async () => {
createComponent('prod'); createComponent('prod');
await wrapper.vm.$nextTick();
}); });
it('renders only the environment searched for', () => { it('renders only the environment searched for', () => {
...@@ -84,21 +89,29 @@ describe('Ci environments dropdown', () => { ...@@ -84,21 +89,29 @@ describe('Ci environments dropdown', () => {
}); });
it('should not display empty results message', () => { it('should not display empty results message', () => {
expect(wrapper.find({ ref: 'noMatchingResults' }).exists()).toBe(false); expect(wrapper.findComponent({ ref: 'noMatchingResults' }).exists()).toBe(false);
}); });
it('should display active checkmark if active', () => { it('should display active checkmark if active', () => {
expect(findActiveIconByIndex(0).classes('gl-visibility-hidden')).toBe(false); expect(findActiveIconByIndex(0).classes('gl-visibility-hidden')).toBe(false);
}); });
it('should clear the search term when showing the dropdown', () => {
wrapper.findComponent(GlDropdown).trigger('click');
expect(wrapper.find('[data-testid="ci-environment-search"]').text()).toBe('');
});
describe('Custom events', () => { describe('Custom events', () => {
it('should emit selectEnvironment if an environment is clicked', () => { it('should emit selectEnvironment if an environment is clicked', () => {
findDropdownItemByIndex(0).vm.$emit('click'); findDropdownItemByIndex(0).vm.$emit('click');
expect(wrapper.emitted('selectEnvironment')).toEqual([['prod']]); expect(wrapper.emitted('selectEnvironment')).toEqual([['prod']]);
}); });
it('should emit createClicked if an environment is clicked', () => { it('should emit createClicked if an environment is clicked', async () => {
createComponent('newscope'); createComponent('newscope');
await wrapper.vm.$nextTick();
findDropdownItemByIndex(1).vm.$emit('click'); findDropdownItemByIndex(1).vm.$emit('click');
expect(wrapper.emitted('createClicked')).toEqual([['newscope']]); expect(wrapper.emitted('createClicked')).toEqual([['newscope']]);
}); });
......
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