diff options
Diffstat (limited to 'spec/frontend/vue_shared/components/filtered_search_bar')
3 files changed, 52 insertions, 18 deletions
diff --git a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/author_token_spec.js b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/author_token_spec.js index f50eafdbc52..951b050495c 100644 --- a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/author_token_spec.js +++ b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/author_token_spec.js @@ -46,6 +46,7 @@ function createComponent(options = {}) { active = false, stubs = defaultStubs, data = {}, + listeners = {}, } = options; return mount(AuthorToken, { propsData: { @@ -62,6 +63,7 @@ function createComponent(options = {}) { return { ...data }; }, stubs, + listeners, }); } @@ -258,6 +260,18 @@ describe('AuthorToken', () => { expect(suggestions.at(0).text()).toBe(DEFAULT_LABEL_ANY.text); }); + it('emits listeners in the base-token', () => { + const mockInput = jest.fn(); + wrapper = createComponent({ + listeners: { + input: mockInput, + }, + }); + wrapper.findComponent(BaseToken).vm.$emit('input', [{ data: 'mockData', operator: '=' }]); + + expect(mockInput).toHaveBeenLastCalledWith([{ data: 'mockData', operator: '=' }]); + }); + describe('when loading', () => { beforeEach(() => { wrapper = createComponent({ @@ -276,6 +290,14 @@ describe('AuthorToken', () => { expect(firstSuggestion).toContain('Administrator'); expect(firstSuggestion).toContain('@root'); }); + + it('does not show current user while searching', async () => { + wrapper.findComponent(BaseToken).vm.handleInput({ data: 'foo' }); + + await wrapper.vm.$nextTick(); + + expect(wrapper.findComponent(GlFilteredSearchSuggestion).exists()).toBe(false); + }); }); }); }); diff --git a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/base_token_spec.js b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/base_token_spec.js index 602864f4fa5..89c5cedc9b8 100644 --- a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/base_token_spec.js +++ b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/base_token_spec.js @@ -46,12 +46,11 @@ const defaultSlots = { }; const mockProps = { - tokenConfig: mockLabelToken, - tokenValue: { data: '' }, - tokenActive: false, - tokensListLoading: false, + config: mockLabelToken, + value: { data: '' }, + active: false, tokenValues: [], - fnActiveTokenValue: jest.fn(), + tokensListLoading: false, defaultTokenValues: DEFAULT_LABELS, recentTokenValuesStorageKey: mockStorageKey, fnCurrentTokenValue: jest.fn(), @@ -83,7 +82,7 @@ describe('BaseToken', () => { wrapper = createComponent({ props: { ...mockProps, - tokenValue: { data: `"${mockRegularLabel.title}"` }, + value: { data: `"${mockRegularLabel.title}"` }, tokenValues: mockLabels, }, }); @@ -112,17 +111,17 @@ describe('BaseToken', () => { describe('activeTokenValue', () => { it('calls `fnActiveTokenValue` when it is provided', async () => { + const mockFnActiveTokenValue = jest.fn(); + wrapper.setProps({ + fnActiveTokenValue: mockFnActiveTokenValue, fnCurrentTokenValue: undefined, }); await wrapper.vm.$nextTick(); - // We're disabling lint to trigger computed prop execution for this test. - // eslint-disable-next-line no-unused-vars - const { activeTokenValue } = wrapper.vm; - - expect(wrapper.vm.fnActiveTokenValue).toHaveBeenCalledWith( + expect(mockFnActiveTokenValue).toHaveBeenCalledTimes(1); + expect(mockFnActiveTokenValue).toHaveBeenCalledWith( mockLabels, `"${mockRegularLabel.title.toLowerCase()}"`, ); @@ -131,15 +130,15 @@ describe('BaseToken', () => { }); describe('watch', () => { - describe('tokenActive', () => { + describe('active', () => { let wrapperWithTokenActive; beforeEach(() => { wrapperWithTokenActive = createComponent({ props: { ...mockProps, - tokenActive: true, - tokenValue: { data: `"${mockRegularLabel.title}"` }, + value: { data: `"${mockRegularLabel.title}"` }, + active: true, }, }); }); @@ -150,7 +149,7 @@ describe('BaseToken', () => { it('emits `fetch-token-values` event on the component when value of this prop is changed to false and `tokenValues` array is empty', async () => { wrapperWithTokenActive.setProps({ - tokenActive: false, + active: false, }); await wrapperWithTokenActive.vm.$nextTick(); @@ -238,7 +237,7 @@ describe('BaseToken', () => { jest.runAllTimers(); expect(wrapperWithNoStubs.emitted('fetch-token-values')).toBeTruthy(); - expect(wrapperWithNoStubs.emitted('fetch-token-values')[1]).toEqual(['foo']); + expect(wrapperWithNoStubs.emitted('fetch-token-values')[2]).toEqual(['foo']); }); }); }); diff --git a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/label_token_spec.js b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/label_token_spec.js index dd1c61b92b8..cc40ff96b65 100644 --- a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/label_token_spec.js +++ b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/label_token_spec.js @@ -40,6 +40,7 @@ function createComponent(options = {}) { value = { data: '' }, active = false, stubs = defaultStubs, + listeners = {}, } = options; return mount(LabelToken, { propsData: { @@ -53,6 +54,7 @@ function createComponent(options = {}) { suggestionsListClass: 'custom-class', }, stubs, + listeners, }); } @@ -206,7 +208,7 @@ describe('LabelToken', () => { expect(wrapper.find(GlDropdownDivider).exists()).toBe(false); }); - it('renders `DEFAULT_LABELS` as default suggestions', async () => { + it('renders `DEFAULT_LABELS` as default suggestions', () => { wrapper = createComponent({ active: true, config: { ...mockLabelToken }, @@ -215,7 +217,6 @@ describe('LabelToken', () => { const tokenSegments = wrapper.findAll(GlFilteredSearchTokenSegment); const suggestionsSegment = tokenSegments.at(2); suggestionsSegment.vm.$emit('activate'); - await wrapper.vm.$nextTick(); const suggestions = wrapper.findAll(GlFilteredSearchSuggestion); @@ -224,5 +225,17 @@ describe('LabelToken', () => { expect(suggestions.at(index).text()).toBe(label.text); }); }); + + it('emits listeners in the base-token', () => { + const mockInput = jest.fn(); + wrapper = createComponent({ + listeners: { + input: mockInput, + }, + }); + wrapper.findComponent(BaseToken).vm.$emit('input', [{ data: 'mockData', operator: '=' }]); + + expect(mockInput).toHaveBeenLastCalledWith([{ data: 'mockData', operator: '=' }]); + }); }); }); |