diff options
Diffstat (limited to 'spec/frontend/boards')
-rw-r--r-- | spec/frontend/boards/components/board_filtered_search_spec.js | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/spec/frontend/boards/components/board_filtered_search_spec.js b/spec/frontend/boards/components/board_filtered_search_spec.js index 64111cfb01a..5a976816f74 100644 --- a/spec/frontend/boards/components/board_filtered_search_spec.js +++ b/spec/frontend/boards/components/board_filtered_search_spec.js @@ -2,7 +2,7 @@ import { shallowMount } from '@vue/test-utils'; import Vue from 'vue'; import Vuex from 'vuex'; import BoardFilteredSearch from '~/boards/components/board_filtered_search.vue'; -import * as urlUtility from '~/lib/utils/url_utility'; +import { updateHistory } from '~/lib/utils/url_utility'; import { TOKEN_TITLE_AUTHOR, TOKEN_TITLE_LABEL, @@ -23,6 +23,12 @@ import { createStore } from '~/boards/stores'; Vue.use(Vuex); +jest.mock('~/lib/utils/url_utility', () => ({ + updateHistory: jest.fn(), + setUrlParams: jest.requireActual('~/lib/utils/url_utility').setUrlParams, + queryToObject: jest.requireActual('~/lib/utils/url_utility').queryToObject, +})); + describe('BoardFilteredSearch', () => { let wrapper; let store; @@ -88,10 +94,9 @@ describe('BoardFilteredSearch', () => { }); it('calls historyPushState', () => { - jest.spyOn(urlUtility, 'updateHistory'); findFilteredSearch().vm.$emit('onFilter', [{ value: { data: 'searchQuery' } }]); - expect(urlUtility.updateHistory).toHaveBeenCalledWith({ + expect(updateHistory).toHaveBeenCalledWith({ replace: true, title: '', url: 'http://test.host/', @@ -120,7 +125,7 @@ describe('BoardFilteredSearch', () => { beforeEach(() => { createComponent(); - jest.spyOn(wrapper.vm, 'performSearch').mockImplementation(); + jest.spyOn(store, 'dispatch').mockImplementation(); }); it('sets the url params to the correct results', () => { @@ -137,10 +142,11 @@ describe('BoardFilteredSearch', () => { { type: TOKEN_TYPE_HEALTH, value: { data: 'onTrack', operator: '=' } }, { type: TOKEN_TYPE_HEALTH, value: { data: 'atRisk', operator: '!=' } }, ]; - jest.spyOn(urlUtility, 'updateHistory'); + findFilteredSearch().vm.$emit('onFilter', mockFilters); - expect(urlUtility.updateHistory).toHaveBeenCalledWith({ + expect(store.dispatch).toHaveBeenCalledWith('performSearch'); + expect(updateHistory).toHaveBeenCalledWith({ title: '', replace: true, url: @@ -158,10 +164,10 @@ describe('BoardFilteredSearch', () => { const mockFilters = [ { type: TOKEN_TYPE_ASSIGNEE, value: { data: assigneeParam, operator: '=' } }, ]; - jest.spyOn(urlUtility, 'updateHistory'); + findFilteredSearch().vm.$emit('onFilter', mockFilters); - expect(urlUtility.updateHistory).toHaveBeenCalledWith({ + expect(updateHistory).toHaveBeenCalledWith({ title: '', replace: true, url: expected, @@ -175,8 +181,6 @@ describe('BoardFilteredSearch', () => { createComponent({ initialFilterParams: { authorUsername: 'root', labelName: ['label'], healthStatus: 'Any' }, }); - - jest.spyOn(store, 'dispatch'); }); it('passes the correct props to FilterSearchBar', () => { @@ -194,11 +198,9 @@ describe('BoardFilteredSearch', () => { }); it('emits setFilters and updates URL when onFilter is emitted', () => { - jest.spyOn(urlUtility, 'updateHistory'); - findFilteredSearch().vm.$emit('onFilter', [{ value: { data: '' } }]); - expect(urlUtility.updateHistory).toHaveBeenCalledWith({ + expect(updateHistory).toHaveBeenCalledWith({ title: '', replace: true, url: 'http://test.host/', |