Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-05 09:09:25 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-05 09:09:25 +0300
commit962fbcfb94b13668632de822e3f7a74fb5ecaf68 (patch)
tree51bebd0983aa06a72af75f7b85c05debd5169037 /spec/frontend/search
parent24fca3804098db8d0083d35db1975d198467e9b8 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/search')
-rw-r--r--spec/frontend/search/mock_data.js15
-rw-r--r--spec/frontend/search/store/actions_spec.js79
-rw-r--r--spec/frontend/search/store/utils_spec.js86
-rw-r--r--spec/frontend/search/topbar/components/app_spec.js19
-rw-r--r--spec/frontend/search/topbar/components/group_filter_spec.js34
-rw-r--r--spec/frontend/search/topbar/components/project_filter_spec.js34
6 files changed, 194 insertions, 73 deletions
diff --git a/spec/frontend/search/mock_data.js b/spec/frontend/search/mock_data.js
index 24ce45e8a09..0542e96c77c 100644
--- a/spec/frontend/search/mock_data.js
+++ b/spec/frontend/search/mock_data.js
@@ -86,18 +86,21 @@ export const STALE_STORED_DATA = [
export const MOCK_FRESH_DATA_RES = { name: 'fresh' };
-export const PROMISE_ALL_EXPECTED_MUTATIONS = {
- initGroups: {
+export const PRELOAD_EXPECTED_MUTATIONS = [
+ {
type: types.LOAD_FREQUENT_ITEMS,
payload: { key: GROUPS_LOCAL_STORAGE_KEY, data: FRESH_STORED_DATA },
},
- resGroups: {
+ {
type: types.LOAD_FREQUENT_ITEMS,
- payload: { key: GROUPS_LOCAL_STORAGE_KEY, data: [MOCK_FRESH_DATA_RES, MOCK_FRESH_DATA_RES] },
+ payload: { key: PROJECTS_LOCAL_STORAGE_KEY, data: FRESH_STORED_DATA },
},
- initProjects: {
+];
+
+export const PROMISE_ALL_EXPECTED_MUTATIONS = {
+ resGroups: {
type: types.LOAD_FREQUENT_ITEMS,
- payload: { key: PROJECTS_LOCAL_STORAGE_KEY, data: FRESH_STORED_DATA },
+ payload: { key: GROUPS_LOCAL_STORAGE_KEY, data: [MOCK_FRESH_DATA_RES, MOCK_FRESH_DATA_RES] },
},
resProjects: {
type: types.LOAD_FREQUENT_ITEMS,
diff --git a/spec/frontend/search/store/actions_spec.js b/spec/frontend/search/store/actions_spec.js
index 3755f8ffae7..9f8c83f2873 100644
--- a/spec/frontend/search/store/actions_spec.js
+++ b/spec/frontend/search/store/actions_spec.js
@@ -17,6 +17,7 @@ import {
MOCK_GROUP,
FRESH_STORED_DATA,
MOCK_FRESH_DATA_RES,
+ PRELOAD_EXPECTED_MUTATIONS,
PROMISE_ALL_EXPECTED_MUTATIONS,
} from '../mock_data';
@@ -68,31 +69,31 @@ describe('Global Search Store Actions', () => {
});
describe.each`
- action | axiosMock | type | expectedMutations | flashCallCount | lsKey
- ${actions.loadFrequentGroups} | ${{ method: 'onGet', code: 200 }} | ${'success'} | ${[PROMISE_ALL_EXPECTED_MUTATIONS.initGroups, PROMISE_ALL_EXPECTED_MUTATIONS.resGroups]} | ${0} | ${GROUPS_LOCAL_STORAGE_KEY}
- ${actions.loadFrequentGroups} | ${{ method: 'onGet', code: 500 }} | ${'error'} | ${[PROMISE_ALL_EXPECTED_MUTATIONS.initGroups]} | ${1} | ${GROUPS_LOCAL_STORAGE_KEY}
- ${actions.loadFrequentProjects} | ${{ method: 'onGet', code: 200 }} | ${'success'} | ${[PROMISE_ALL_EXPECTED_MUTATIONS.initProjects, PROMISE_ALL_EXPECTED_MUTATIONS.resProjects]} | ${0} | ${PROJECTS_LOCAL_STORAGE_KEY}
- ${actions.loadFrequentProjects} | ${{ method: 'onGet', code: 500 }} | ${'error'} | ${[PROMISE_ALL_EXPECTED_MUTATIONS.initProjects]} | ${1} | ${PROJECTS_LOCAL_STORAGE_KEY}
- `(
- 'Promise.all calls',
- ({ action, axiosMock, type, expectedMutations, flashCallCount, lsKey }) => {
- describe(action.name, () => {
- describe(`on ${type}`, () => {
- beforeEach(() => {
- storeUtils.loadDataFromLS = jest.fn().mockReturnValue(FRESH_STORED_DATA);
- mock[axiosMock.method]().reply(axiosMock.code, MOCK_FRESH_DATA_RES);
- });
+ action | axiosMock | type | expectedMutations | flashCallCount
+ ${actions.loadFrequentGroups} | ${{ method: 'onGet', code: 200 }} | ${'success'} | ${[PROMISE_ALL_EXPECTED_MUTATIONS.resGroups]} | ${0}
+ ${actions.loadFrequentGroups} | ${{ method: 'onGet', code: 500 }} | ${'error'} | ${[]} | ${1}
+ ${actions.loadFrequentProjects} | ${{ method: 'onGet', code: 200 }} | ${'success'} | ${[PROMISE_ALL_EXPECTED_MUTATIONS.resProjects]} | ${0}
+ ${actions.loadFrequentProjects} | ${{ method: 'onGet', code: 500 }} | ${'error'} | ${[]} | ${1}
+ `('Promise.all calls', ({ action, axiosMock, type, expectedMutations, flashCallCount }) => {
+ describe(action.name, () => {
+ describe(`on ${type}`, () => {
+ beforeEach(() => {
+ state.frequentItems = {
+ [GROUPS_LOCAL_STORAGE_KEY]: FRESH_STORED_DATA,
+ [PROJECTS_LOCAL_STORAGE_KEY]: FRESH_STORED_DATA,
+ };
+
+ mock[axiosMock.method]().reply(axiosMock.code, MOCK_FRESH_DATA_RES);
+ });
- it(`should dispatch the correct mutations`, () => {
- return testAction({ action, state, expectedMutations }).then(() => {
- expect(storeUtils.loadDataFromLS).toHaveBeenCalledWith(lsKey);
- flashCallback(flashCallCount);
- });
+ it(`should dispatch the correct mutations`, () => {
+ return testAction({ action, state, expectedMutations }).then(() => {
+ flashCallback(flashCallCount);
});
});
});
- },
- );
+ });
+ });
describe('getGroupsData', () => {
const mockCommit = () => {};
@@ -182,14 +183,38 @@ describe('Global Search Store Actions', () => {
});
});
+ describe('preloadStoredFrequentItems', () => {
+ beforeEach(() => {
+ storeUtils.loadDataFromLS = jest.fn().mockReturnValue(FRESH_STORED_DATA);
+ });
+
+ it('calls preloadStoredFrequentItems for both groups and projects and commits LOAD_FREQUENT_ITEMS', async () => {
+ await testAction({
+ action: actions.preloadStoredFrequentItems,
+ state,
+ expectedMutations: PRELOAD_EXPECTED_MUTATIONS,
+ });
+
+ expect(storeUtils.loadDataFromLS).toHaveBeenCalledTimes(2);
+ expect(storeUtils.loadDataFromLS).toHaveBeenCalledWith(GROUPS_LOCAL_STORAGE_KEY);
+ expect(storeUtils.loadDataFromLS).toHaveBeenCalledWith(PROJECTS_LOCAL_STORAGE_KEY);
+ });
+ });
+
describe('setFrequentGroup', () => {
beforeEach(() => {
- storeUtils.setFrequentItemToLS = jest.fn();
+ storeUtils.setFrequentItemToLS = jest.fn().mockReturnValue(FRESH_STORED_DATA);
});
- it(`calls setFrequentItemToLS with ${GROUPS_LOCAL_STORAGE_KEY} and item data`, async () => {
+ it(`calls setFrequentItemToLS with ${GROUPS_LOCAL_STORAGE_KEY} and item data then commits LOAD_FREQUENT_ITEMS`, async () => {
await testAction({
action: actions.setFrequentGroup,
+ expectedMutations: [
+ {
+ type: types.LOAD_FREQUENT_ITEMS,
+ payload: { key: GROUPS_LOCAL_STORAGE_KEY, data: FRESH_STORED_DATA },
+ },
+ ],
payload: MOCK_GROUP,
state,
});
@@ -204,12 +229,18 @@ describe('Global Search Store Actions', () => {
describe('setFrequentProject', () => {
beforeEach(() => {
- storeUtils.setFrequentItemToLS = jest.fn();
+ storeUtils.setFrequentItemToLS = jest.fn().mockReturnValue(FRESH_STORED_DATA);
});
it(`calls setFrequentItemToLS with ${PROJECTS_LOCAL_STORAGE_KEY} and item data`, async () => {
await testAction({
action: actions.setFrequentProject,
+ expectedMutations: [
+ {
+ type: types.LOAD_FREQUENT_ITEMS,
+ payload: { key: PROJECTS_LOCAL_STORAGE_KEY, data: FRESH_STORED_DATA },
+ },
+ ],
payload: MOCK_PROJECT,
state,
});
diff --git a/spec/frontend/search/store/utils_spec.js b/spec/frontend/search/store/utils_spec.js
index 5055fa2cc3d..cd7f7dc3b5f 100644
--- a/spec/frontend/search/store/utils_spec.js
+++ b/spec/frontend/search/store/utils_spec.js
@@ -51,19 +51,25 @@ describe('Global Search Store Utils', () => {
describe('setFrequentItemToLS', () => {
const frequentItems = {};
+ let res;
describe('with existing data', () => {
describe(`when frequency is less than ${MAX_FREQUENCY}`, () => {
beforeEach(() => {
frequentItems[MOCK_LS_KEY] = [{ ...MOCK_GROUPS[0], frequency: 1, lastUsed: PREV_TIME }];
- setFrequentItemToLS(MOCK_LS_KEY, frequentItems, MOCK_GROUPS[0]);
+ res = setFrequentItemToLS(MOCK_LS_KEY, frequentItems, MOCK_GROUPS[0]);
});
- it('adds 1 to the frequency, tracks lastUsed, and calls localStorage.setItem', () => {
+ it('adds 1 to the frequency, tracks lastUsed, calls localStorage.setItem and returns the array', () => {
+ const updatedFrequentItems = [
+ { ...MOCK_GROUPS[0], frequency: 2, lastUsed: CURRENT_TIME },
+ ];
+
expect(localStorage.setItem).toHaveBeenCalledWith(
MOCK_LS_KEY,
- JSON.stringify([{ ...MOCK_GROUPS[0], frequency: 2, lastUsed: CURRENT_TIME }]),
+ JSON.stringify(updatedFrequentItems),
);
+ expect(res).toEqual(updatedFrequentItems);
});
});
@@ -72,16 +78,19 @@ describe('Global Search Store Utils', () => {
frequentItems[MOCK_LS_KEY] = [
{ ...MOCK_GROUPS[0], frequency: MAX_FREQUENCY, lastUsed: PREV_TIME },
];
- setFrequentItemToLS(MOCK_LS_KEY, frequentItems, MOCK_GROUPS[0]);
+ res = setFrequentItemToLS(MOCK_LS_KEY, frequentItems, MOCK_GROUPS[0]);
});
- it(`does not further increase frequency past ${MAX_FREQUENCY}, tracks lastUsed, and calls localStorage.setItem`, () => {
+ it(`does not further increase frequency past ${MAX_FREQUENCY}, tracks lastUsed, calls localStorage.setItem, and returns the array`, () => {
+ const updatedFrequentItems = [
+ { ...MOCK_GROUPS[0], frequency: MAX_FREQUENCY, lastUsed: CURRENT_TIME },
+ ];
+
expect(localStorage.setItem).toHaveBeenCalledWith(
MOCK_LS_KEY,
- JSON.stringify([
- { ...MOCK_GROUPS[0], frequency: MAX_FREQUENCY, lastUsed: CURRENT_TIME },
- ]),
+ JSON.stringify(updatedFrequentItems),
);
+ expect(res).toEqual(updatedFrequentItems);
});
});
});
@@ -89,14 +98,17 @@ describe('Global Search Store Utils', () => {
describe('with no existing data', () => {
beforeEach(() => {
frequentItems[MOCK_LS_KEY] = [];
- setFrequentItemToLS(MOCK_LS_KEY, frequentItems, MOCK_GROUPS[0]);
+ res = setFrequentItemToLS(MOCK_LS_KEY, frequentItems, MOCK_GROUPS[0]);
});
- it('adds a new entry with frequency 1, tracks lastUsed, and calls localStorage.setItem', () => {
+ it('adds a new entry with frequency 1, tracks lastUsed, calls localStorage.setItem, and returns the array', () => {
+ const updatedFrequentItems = [{ ...MOCK_GROUPS[0], frequency: 1, lastUsed: CURRENT_TIME }];
+
expect(localStorage.setItem).toHaveBeenCalledWith(
MOCK_LS_KEY,
- JSON.stringify([{ ...MOCK_GROUPS[0], frequency: 1, lastUsed: CURRENT_TIME }]),
+ JSON.stringify(updatedFrequentItems),
);
+ expect(res).toEqual(updatedFrequentItems);
});
});
@@ -107,18 +119,21 @@ describe('Global Search Store Utils', () => {
{ id: 2, frequency: 1, lastUsed: PREV_TIME },
{ id: 3, frequency: 1, lastUsed: PREV_TIME },
];
- setFrequentItemToLS(MOCK_LS_KEY, frequentItems, { id: 3 });
+ res = setFrequentItemToLS(MOCK_LS_KEY, frequentItems, { id: 3 });
});
- it('sorts the array by most frequent and lastUsed', () => {
+ it('sorts the array by most frequent and lastUsed and returns the array', () => {
+ const updatedFrequentItems = [
+ { id: 3, frequency: 2, lastUsed: CURRENT_TIME },
+ { id: 1, frequency: 2, lastUsed: PREV_TIME },
+ { id: 2, frequency: 1, lastUsed: PREV_TIME },
+ ];
+
expect(localStorage.setItem).toHaveBeenCalledWith(
MOCK_LS_KEY,
- JSON.stringify([
- { id: 3, frequency: 2, lastUsed: CURRENT_TIME },
- { id: 1, frequency: 2, lastUsed: PREV_TIME },
- { id: 2, frequency: 1, lastUsed: PREV_TIME },
- ]),
+ JSON.stringify(updatedFrequentItems),
);
+ expect(res).toEqual(updatedFrequentItems);
});
});
@@ -131,31 +146,35 @@ describe('Global Search Store Utils', () => {
{ id: 4, frequency: 2, lastUsed: PREV_TIME },
{ id: 5, frequency: 1, lastUsed: PREV_TIME },
];
- setFrequentItemToLS(MOCK_LS_KEY, frequentItems, { id: 6 });
+ res = setFrequentItemToLS(MOCK_LS_KEY, frequentItems, { id: 6 });
});
- it('removes the last item in the array', () => {
+ it('removes the last item in the array and returns the array', () => {
+ const updatedFrequentItems = [
+ { id: 1, frequency: 5, lastUsed: PREV_TIME },
+ { id: 2, frequency: 4, lastUsed: PREV_TIME },
+ { id: 3, frequency: 3, lastUsed: PREV_TIME },
+ { id: 4, frequency: 2, lastUsed: PREV_TIME },
+ { id: 6, frequency: 1, lastUsed: CURRENT_TIME },
+ ];
+
expect(localStorage.setItem).toHaveBeenCalledWith(
MOCK_LS_KEY,
- JSON.stringify([
- { id: 1, frequency: 5, lastUsed: PREV_TIME },
- { id: 2, frequency: 4, lastUsed: PREV_TIME },
- { id: 3, frequency: 3, lastUsed: PREV_TIME },
- { id: 4, frequency: 2, lastUsed: PREV_TIME },
- { id: 6, frequency: 1, lastUsed: CURRENT_TIME },
- ]),
+ JSON.stringify(updatedFrequentItems),
);
+ expect(res).toEqual(updatedFrequentItems);
});
});
describe('with null data loaded in', () => {
beforeEach(() => {
frequentItems[MOCK_LS_KEY] = null;
- setFrequentItemToLS(MOCK_LS_KEY, frequentItems, MOCK_GROUPS[0]);
+ res = setFrequentItemToLS(MOCK_LS_KEY, frequentItems, MOCK_GROUPS[0]);
});
- it('wipes local storage', () => {
+ it('wipes local storage and returns empty array', () => {
expect(localStorage.removeItem).toHaveBeenCalledWith(MOCK_LS_KEY);
+ expect(res).toEqual([]);
});
});
@@ -163,14 +182,17 @@ describe('Global Search Store Utils', () => {
beforeEach(() => {
const MOCK_ADDITIONAL_DATA_GROUP = { ...MOCK_GROUPS[0], extraData: 'test' };
frequentItems[MOCK_LS_KEY] = [];
- setFrequentItemToLS(MOCK_LS_KEY, frequentItems, MOCK_ADDITIONAL_DATA_GROUP);
+ res = setFrequentItemToLS(MOCK_LS_KEY, frequentItems, MOCK_ADDITIONAL_DATA_GROUP);
});
- it('parses out extra data for LS', () => {
+ it('parses out extra data for LS and returns the array', () => {
+ const updatedFrequentItems = [{ ...MOCK_GROUPS[0], frequency: 1, lastUsed: CURRENT_TIME }];
+
expect(localStorage.setItem).toHaveBeenCalledWith(
MOCK_LS_KEY,
- JSON.stringify([{ ...MOCK_GROUPS[0], frequency: 1, lastUsed: CURRENT_TIME }]),
+ JSON.stringify(updatedFrequentItems),
);
+ expect(res).toEqual(updatedFrequentItems);
});
});
});
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();
+ }
+ });
+ });
+ });
});