From b76ae638462ab0f673e5915986070518dd3f9ad3 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 19 Aug 2021 09:08:42 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-2-stable-ee --- spec/frontend/search/topbar/components/app_spec.js | 19 ++++++++---- .../search/topbar/components/group_filter_spec.js | 34 ++++++++++++++++++++-- .../topbar/components/project_filter_spec.js | 34 ++++++++++++++++++++-- 3 files changed, 76 insertions(+), 11 deletions(-) (limited to 'spec/frontend/search/topbar/components') diff --git a/spec/frontend/search/topbar/components/app_spec.js b/spec/frontend/search/topbar/components/app_spec.js index fb953f2ed1b..7ce5efb3c52 100644 --- a/spec/frontend/search/topbar/components/app_spec.js +++ b/spec/frontend/search/topbar/components/app_spec.js @@ -1,13 +1,13 @@ import { GlForm, GlSearchBoxByType, GlButton } from '@gitlab/ui'; -import { createLocalVue, shallowMount } from '@vue/test-utils'; +import { shallowMount } from '@vue/test-utils'; +import Vue from 'vue'; import Vuex from 'vuex'; import { MOCK_QUERY } from 'jest/search/mock_data'; import GlobalSearchTopbar from '~/search/topbar/components/app.vue'; import GroupFilter from '~/search/topbar/components/group_filter.vue'; import ProjectFilter from '~/search/topbar/components/project_filter.vue'; -const localVue = createLocalVue(); -localVue.use(Vuex); +Vue.use(Vuex); describe('GlobalSearchTopbar', () => { let wrapper; @@ -15,6 +15,7 @@ describe('GlobalSearchTopbar', () => { const actionSpies = { applyQuery: jest.fn(), setQuery: jest.fn(), + preloadStoredFrequentItems: jest.fn(), }; const createComponent = (initialState) => { @@ -27,14 +28,12 @@ describe('GlobalSearchTopbar', () => { }); wrapper = shallowMount(GlobalSearchTopbar, { - localVue, store, }); }; afterEach(() => { wrapper.destroy(); - wrapper = null; }); const findTopbarForm = () => wrapper.find(GlForm); @@ -110,4 +109,14 @@ describe('GlobalSearchTopbar', () => { expect(actionSpies.applyQuery).toHaveBeenCalled(); }); }); + + describe('onCreate', () => { + beforeEach(() => { + createComponent(); + }); + + it('calls preloadStoredFrequentItems', () => { + expect(actionSpies.preloadStoredFrequentItems).toHaveBeenCalled(); + }); + }); }); diff --git a/spec/frontend/search/topbar/components/group_filter_spec.js b/spec/frontend/search/topbar/components/group_filter_spec.js index fbd7ad6bb57..bd173791fee 100644 --- a/spec/frontend/search/topbar/components/group_filter_spec.js +++ b/spec/frontend/search/topbar/components/group_filter_spec.js @@ -51,7 +51,6 @@ describe('GroupFilter', () => { afterEach(() => { wrapper.destroy(); - wrapper = null; }); const findSearchableDropdown = () => wrapper.find(SearchableDropdown); @@ -89,10 +88,11 @@ describe('GroupFilter', () => { findSearchableDropdown().vm.$emit('change', ANY_OPTION); }); - it('calls setUrlParams with group null, project id null, and then calls visitUrl', () => { + it('calls setUrlParams with group null, project id null, nav_source null, and then calls visitUrl', () => { expect(setUrlParams).toHaveBeenCalledWith({ [GROUP_DATA.queryParam]: null, [PROJECT_DATA.queryParam]: null, + nav_source: null, }); expect(visitUrl).toHaveBeenCalled(); @@ -108,10 +108,11 @@ describe('GroupFilter', () => { findSearchableDropdown().vm.$emit('change', MOCK_GROUP); }); - it('calls setUrlParams with group id, project id null, and then calls visitUrl', () => { + it('calls setUrlParams with group id, project id null, nav_source null, and then calls visitUrl', () => { expect(setUrlParams).toHaveBeenCalledWith({ [GROUP_DATA.queryParam]: MOCK_GROUP.id, [PROJECT_DATA.queryParam]: null, + nav_source: null, }); expect(visitUrl).toHaveBeenCalled(); @@ -156,4 +157,31 @@ describe('GroupFilter', () => { }); }); }); + + describe.each` + navSource | initialData | callMethod + ${null} | ${null} | ${false} + ${null} | ${MOCK_GROUP} | ${false} + ${'navbar'} | ${null} | ${false} + ${'navbar'} | ${MOCK_GROUP} | ${true} + `('onCreate', ({ navSource, initialData, callMethod }) => { + describe(`when nav_source is ${navSource} and ${ + initialData ? 'has' : 'does not have' + } an initial group`, () => { + beforeEach(() => { + createComponent({ query: { ...MOCK_QUERY, nav_source: navSource } }, { initialData }); + }); + + it(`${callMethod ? 'does' : 'does not'} call setFrequentGroup`, () => { + if (callMethod) { + expect(actionSpies.setFrequentGroup).toHaveBeenCalledWith( + expect.any(Object), + initialData, + ); + } else { + expect(actionSpies.setFrequentGroup).not.toHaveBeenCalled(); + } + }); + }); + }); }); diff --git a/spec/frontend/search/topbar/components/project_filter_spec.js b/spec/frontend/search/topbar/components/project_filter_spec.js index 63b0f882ca4..5afcd281d0c 100644 --- a/spec/frontend/search/topbar/components/project_filter_spec.js +++ b/spec/frontend/search/topbar/components/project_filter_spec.js @@ -51,7 +51,6 @@ describe('ProjectFilter', () => { afterEach(() => { wrapper.destroy(); - wrapper = null; }); const findSearchableDropdown = () => wrapper.find(SearchableDropdown); @@ -89,9 +88,10 @@ describe('ProjectFilter', () => { findSearchableDropdown().vm.$emit('change', ANY_OPTION); }); - it('calls setUrlParams with null, no group id, then calls visitUrl', () => { + it('calls setUrlParams with null, no group id, nav_source null, then calls visitUrl', () => { expect(setUrlParams).toHaveBeenCalledWith({ [PROJECT_DATA.queryParam]: null, + nav_source: null, }); expect(visitUrl).toHaveBeenCalled(); }); @@ -106,10 +106,11 @@ describe('ProjectFilter', () => { findSearchableDropdown().vm.$emit('change', MOCK_PROJECT); }); - it('calls setUrlParams with project id, group id, then calls visitUrl', () => { + it('calls setUrlParams with project id, group id, nav_source null, then calls visitUrl', () => { expect(setUrlParams).toHaveBeenCalledWith({ [GROUP_DATA.queryParam]: MOCK_PROJECT.namespace.id, [PROJECT_DATA.queryParam]: MOCK_PROJECT.id, + nav_source: null, }); expect(visitUrl).toHaveBeenCalled(); }); @@ -157,4 +158,31 @@ describe('ProjectFilter', () => { }); }); }); + + describe.each` + navSource | initialData | callMethod + ${null} | ${null} | ${false} + ${null} | ${MOCK_PROJECT} | ${false} + ${'navbar'} | ${null} | ${false} + ${'navbar'} | ${MOCK_PROJECT} | ${true} + `('onCreate', ({ navSource, initialData, callMethod }) => { + describe(`when nav_source is ${navSource} and ${ + initialData ? 'has' : 'does not have' + } an initial project`, () => { + beforeEach(() => { + createComponent({ query: { ...MOCK_QUERY, nav_source: navSource } }, { initialData }); + }); + + it(`${callMethod ? 'does' : 'does not'} call setFrequentProject`, () => { + if (callMethod) { + expect(actionSpies.setFrequentProject).toHaveBeenCalledWith( + expect.any(Object), + initialData, + ); + } else { + expect(actionSpies.setFrequentProject).not.toHaveBeenCalled(); + } + }); + }); + }); }); -- cgit v1.2.1