Commit 9a87720a authored by Michael Lunøe's avatar Michael Lunøe Committed by Sarah Groff Hennigh-Palermo

Refactor(Productivity Analytics): refactor methods

@vue/test-utils 1.x deprecated use of methods.
This MR removes usage of this option from
productivity analytics tests

See the following for details:
https://gitlab.com/groups/gitlab-org/-/epics/3856
https://gitlab.com/groups/gitlab-org/-/epics/4255
parent 63db21c1
...@@ -10,8 +10,7 @@ import table from './modules/table/index'; ...@@ -10,8 +10,7 @@ import table from './modules/table/index';
Vue.use(Vuex); Vue.use(Vuex);
const createStore = () => export const getStoreConfig = () => ({
new Vuex.Store({
state: state(), state: state(),
getters, getters,
actions, actions,
...@@ -21,6 +20,6 @@ const createStore = () => ...@@ -21,6 +20,6 @@ const createStore = () =>
charts, charts,
table, table,
}, },
}); });
export default createStore(); export default () => new Vuex.Store(getStoreConfig());
...@@ -5,7 +5,7 @@ import MockAdapter from 'axios-mock-adapter'; ...@@ -5,7 +5,7 @@ import MockAdapter from 'axios-mock-adapter';
import ProductivityApp from 'ee/analytics/productivity_analytics/components/app.vue'; import ProductivityApp from 'ee/analytics/productivity_analytics/components/app.vue';
import Scatterplot from 'ee/analytics/shared/components/scatterplot.vue'; import Scatterplot from 'ee/analytics/shared/components/scatterplot.vue';
import MergeRequestTable from 'ee/analytics/productivity_analytics/components/mr_table.vue'; import MergeRequestTable from 'ee/analytics/productivity_analytics/components/mr_table.vue';
import store from 'ee/analytics/productivity_analytics/store'; import { getStoreConfig } from 'ee/analytics/productivity_analytics/store';
import { chartKeys } from 'ee/analytics/productivity_analytics/constants'; import { chartKeys } from 'ee/analytics/productivity_analytics/constants';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import { import {
...@@ -28,45 +28,71 @@ localVue.use(Vuex); ...@@ -28,45 +28,71 @@ localVue.use(Vuex);
describe('ProductivityApp component', () => { describe('ProductivityApp component', () => {
let wrapper; let wrapper;
let mock; let mock;
let mockStore;
const propsData = { const propsData = {
emptyStateSvgPath: TEST_HOST, emptyStateSvgPath: TEST_HOST,
noAccessSvgPath: TEST_HOST, noAccessSvgPath: TEST_HOST,
}; };
const actionSpies = { const chartsActionSpies = {
resetMainChartSelection: jest.fn(),
};
const tableActionSpies = {
setSortField: jest.fn(), setSortField: jest.fn(),
setPage: jest.fn(), setPage: jest.fn(),
toggleSortOrder: jest.fn(), toggleSortOrder: jest.fn(),
setColumnMetric: jest.fn(), setColumnMetric: jest.fn(),
resetMainChartSelection: jest.fn(),
}; };
const mainChartData = { 1: 2, 2: 3 }; const mainChartData = { 1: 2, 2: 3 };
const createComponent = ({ props = {}, options = {}, scatterplotEnabled = true } = {}) => { const createComponent = ({ props = {}, options = {}, scatterplotEnabled = true } = {}) => {
const {
modules: { charts, table, ...modules },
...storeConfig
} = getStoreConfig();
mockStore = new Vuex.Store({
...storeConfig,
modules: {
charts: {
...charts,
actions: {
...charts.actions,
...chartsActionSpies,
},
},
table: {
...table,
actions: {
...table.actions,
...tableActionSpies,
},
},
...modules,
},
});
wrapper = shallowMount(ProductivityApp, { wrapper = shallowMount(ProductivityApp, {
localVue, localVue,
store, store: mockStore,
mixins: [UrlSyncMixin], mixins: [UrlSyncMixin],
propsData: { propsData: {
...propsData, ...propsData,
...props, ...props,
}, },
methods: {
...actionSpies,
},
provide: { provide: {
glFeatures: { productivityAnalyticsScatterplotEnabled: scatterplotEnabled }, glFeatures: { productivityAnalyticsScatterplotEnabled: scatterplotEnabled },
}, },
...options, ...options,
}); });
wrapper.vm.$store.dispatch('setEndpoint', TEST_HOST); mockStore.dispatch('setEndpoint', TEST_HOST);
}; };
beforeEach(() => { beforeEach(() => {
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
createComponent();
}); });
afterEach(() => { afterEach(() => {
...@@ -99,26 +125,26 @@ describe('ProductivityApp component', () => { ...@@ -99,26 +125,26 @@ describe('ProductivityApp component', () => {
describe('with a group being selected', () => { describe('with a group being selected', () => {
beforeEach(() => { beforeEach(() => {
wrapper.vm.$store.dispatch('filters/setInitialData', { mockStore.dispatch('filters/setInitialData', {
skipFetch: true, skipFetch: true,
data: { data: {
mergedAfter: new Date('2019-09-01'), mergedAfter: new Date('2019-09-01'),
mergedBefore: new Date('2019-09-02'), mergedBefore: new Date('2019-09-02'),
}, },
}); });
wrapper.vm.$store.dispatch('filters/setGroupNamespace', 'gitlab-org'); mockStore.dispatch('filters/setGroupNamespace', 'gitlab-org');
mock.onGet(wrapper.vm.$store.state.endpoint).replyOnce(200); mock.onGet(mockStore.state.endpoint).replyOnce(200);
}); });
describe('user has no access to the group', () => { describe('user has no access to the group', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
const error = { response: { status: 403 } }; const error = { response: { status: 403 } };
wrapper.vm.$store.dispatch('charts/receiveChartDataError', { mockStore.dispatch('charts/receiveChartDataError', {
chartKey: chartKeys.main, chartKey: chartKeys.main,
error, error,
}); });
wrapper.vm.$store.state.charts.charts[chartKeys.main].errorCode = 403; mockStore.state.charts.charts[chartKeys.main].errorCode = 403;
}); });
it('renders the no access illustration', () => { it('renders the no access illustration', () => {
...@@ -131,7 +157,7 @@ describe('ProductivityApp component', () => { ...@@ -131,7 +157,7 @@ describe('ProductivityApp component', () => {
describe('user has access to the group', () => { describe('user has access to the group', () => {
beforeEach(() => { beforeEach(() => {
wrapper.vm.$store.state.charts.charts[chartKeys.main].errorCode = null; mockStore.state.charts.charts[chartKeys.main].errorCode = null;
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
...@@ -139,7 +165,7 @@ describe('ProductivityApp component', () => { ...@@ -139,7 +165,7 @@ describe('ProductivityApp component', () => {
describe('when the main chart is loading', () => { describe('when the main chart is loading', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
wrapper.vm.$store.dispatch('charts/requestChartData', chartKeys.main); mockStore.dispatch('charts/requestChartData', chartKeys.main);
}); });
it('renders a metric chart component for the main chart', () => { it('renders a metric chart component for the main chart', () => {
...@@ -164,7 +190,7 @@ describe('ProductivityApp component', () => { ...@@ -164,7 +190,7 @@ describe('ProductivityApp component', () => {
describe('and has data', () => { describe('and has data', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
wrapper.vm.$store.dispatch('charts/receiveChartDataSuccess', { mockStore.dispatch('charts/receiveChartDataSuccess', {
chartKey: chartKeys.main, chartKey: chartKeys.main,
data: mainChartData, data: mainChartData,
}); });
...@@ -180,7 +206,7 @@ describe('ProductivityApp component', () => { ...@@ -180,7 +206,7 @@ describe('ProductivityApp component', () => {
describe('when an item on the chart is clicked', () => { describe('when an item on the chart is clicked', () => {
beforeEach(() => { beforeEach(() => {
jest.spyOn(store, 'dispatch'); jest.spyOn(mockStore, 'dispatch');
const data = { const data = {
chart: null, chart: null,
...@@ -197,7 +223,7 @@ describe('ProductivityApp component', () => { ...@@ -197,7 +223,7 @@ describe('ProductivityApp component', () => {
}); });
it('dispatches updateSelectedItems action', () => { it('dispatches updateSelectedItems action', () => {
expect(store.dispatch).toHaveBeenCalledWith('charts/updateSelectedItems', { expect(mockStore.dispatch).toHaveBeenCalledWith('charts/updateSelectedItems', {
chartKey: chartKeys.main, chartKey: chartKeys.main,
item: 0, item: 0,
}); });
...@@ -206,7 +232,7 @@ describe('ProductivityApp component', () => { ...@@ -206,7 +232,7 @@ describe('ProductivityApp component', () => {
describe('when the main chart has selected items', () => { describe('when the main chart has selected items', () => {
beforeEach(() => { beforeEach(() => {
wrapper.vm.$store.state.charts.charts[chartKeys.main].selected = [1]; mockStore.state.charts.charts[chartKeys.main].selected = [1];
}); });
it('renders the "Clear chart data" button', () => { it('renders the "Clear chart data" button', () => {
...@@ -216,7 +242,7 @@ describe('ProductivityApp component', () => { ...@@ -216,7 +242,7 @@ describe('ProductivityApp component', () => {
it('dispatches resetMainChartSelection action when the user clicks on the "Clear chart data" button', () => { it('dispatches resetMainChartSelection action when the user clicks on the "Clear chart data" button', () => {
findClearFilterButton().vm.$emit('click'); findClearFilterButton().vm.$emit('click');
expect(actionSpies.resetMainChartSelection).toHaveBeenCalled(); expect(chartsActionSpies.resetMainChartSelection).toHaveBeenCalled();
}); });
}); });
...@@ -228,7 +254,7 @@ describe('ProductivityApp component', () => { ...@@ -228,7 +254,7 @@ describe('ProductivityApp component', () => {
describe('when chart finished loading', () => { describe('when chart finished loading', () => {
describe('and the chart has data', () => { describe('and the chart has data', () => {
beforeEach(() => { beforeEach(() => {
wrapper.vm.$store.dispatch('charts/receiveChartDataSuccess', { mockStore.dispatch('charts/receiveChartDataSuccess', {
chartKey: chartKeys.timeBasedHistogram, chartKey: chartKeys.timeBasedHistogram,
data: { 1: 2, 2: 3 }, data: { 1: 2, 2: 3 },
}); });
...@@ -244,12 +270,12 @@ describe('ProductivityApp component', () => { ...@@ -244,12 +270,12 @@ describe('ProductivityApp component', () => {
describe('when the user changes the metric', () => { describe('when the user changes the metric', () => {
beforeEach(() => { beforeEach(() => {
jest.spyOn(store, 'dispatch'); jest.spyOn(mockStore, 'dispatch');
findTimeBasedMetricChart().vm.$emit('metricTypeChange', 'time_to_merge'); findTimeBasedMetricChart().vm.$emit('metricTypeChange', 'time_to_merge');
}); });
it('should call setMetricType when `metricTypeChange` is emitted on the metric chart', () => { it('should call setMetricType when `metricTypeChange` is emitted on the metric chart', () => {
expect(store.dispatch).toHaveBeenCalledWith('charts/setMetricType', { expect(mockStore.dispatch).toHaveBeenCalledWith('charts/setMetricType', {
metricType: 'time_to_merge', metricType: 'time_to_merge',
chartKey: chartKeys.timeBasedHistogram, chartKey: chartKeys.timeBasedHistogram,
}); });
...@@ -267,7 +293,7 @@ describe('ProductivityApp component', () => { ...@@ -267,7 +293,7 @@ describe('ProductivityApp component', () => {
describe('when chart finished loading', () => { describe('when chart finished loading', () => {
describe('and the chart has data', () => { describe('and the chart has data', () => {
beforeEach(() => { beforeEach(() => {
wrapper.vm.$store.dispatch('charts/receiveChartDataSuccess', { mockStore.dispatch('charts/receiveChartDataSuccess', {
chartKey: chartKeys.commitBasedHistogram, chartKey: chartKeys.commitBasedHistogram,
data: { 1: 2, 2: 3 }, data: { 1: 2, 2: 3 },
}); });
...@@ -283,13 +309,13 @@ describe('ProductivityApp component', () => { ...@@ -283,13 +309,13 @@ describe('ProductivityApp component', () => {
describe('when the user changes the metric', () => { describe('when the user changes the metric', () => {
beforeEach(() => { beforeEach(() => {
jest.spyOn(store, 'dispatch'); jest.spyOn(mockStore, 'dispatch');
findCommitBasedMetricChart().vm.$emit('metricTypeChange', 'loc_per_commit'); findCommitBasedMetricChart().vm.$emit('metricTypeChange', 'loc_per_commit');
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
it('should call setMetricType when `metricTypeChange` is emitted on the metric chart', () => { it('should call setMetricType when `metricTypeChange` is emitted on the metric chart', () => {
expect(store.dispatch).toHaveBeenCalledWith('charts/setMetricType', { expect(mockStore.dispatch).toHaveBeenCalledWith('charts/setMetricType', {
metricType: 'loc_per_commit', metricType: 'loc_per_commit',
chartKey: chartKeys.commitBasedHistogram, chartKey: chartKeys.commitBasedHistogram,
}); });
...@@ -317,7 +343,7 @@ describe('ProductivityApp component', () => { ...@@ -317,7 +343,7 @@ describe('ProductivityApp component', () => {
describe('when chart finished loading', () => { describe('when chart finished loading', () => {
describe('and the chart has data', () => { describe('and the chart has data', () => {
beforeEach(() => { beforeEach(() => {
wrapper.vm.$store.dispatch('charts/receiveChartDataSuccess', { mockStore.dispatch('charts/receiveChartDataSuccess', {
chartKey: chartKeys.scatterplot, chartKey: chartKeys.scatterplot,
data: { data: {
1: { metric: 2, merged_at: '2019-09-01T07:06:23.193Z' }, 1: { metric: 2, merged_at: '2019-09-01T07:06:23.193Z' },
...@@ -340,13 +366,13 @@ describe('ProductivityApp component', () => { ...@@ -340,13 +366,13 @@ describe('ProductivityApp component', () => {
describe('when the user changes the metric', () => { describe('when the user changes the metric', () => {
beforeEach(() => { beforeEach(() => {
jest.spyOn(store, 'dispatch'); jest.spyOn(mockStore, 'dispatch');
findScatterplotMetricChart().vm.$emit('metricTypeChange', 'loc_per_commit'); findScatterplotMetricChart().vm.$emit('metricTypeChange', 'loc_per_commit');
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
it('should call setMetricType when `metricTypeChange` is emitted on the metric chart', () => { it('should call setMetricType when `metricTypeChange` is emitted on the metric chart', () => {
expect(store.dispatch).toHaveBeenCalledWith('charts/setMetricType', { expect(mockStore.dispatch).toHaveBeenCalledWith('charts/setMetricType', {
metricType: 'loc_per_commit', metricType: 'loc_per_commit',
chartKey: chartKeys.scatterplot, chartKey: chartKeys.scatterplot,
}); });
...@@ -379,7 +405,7 @@ describe('ProductivityApp component', () => { ...@@ -379,7 +405,7 @@ describe('ProductivityApp component', () => {
describe('MR table', () => { describe('MR table', () => {
describe('when table is loading', () => { describe('when table is loading', () => {
beforeEach(() => { beforeEach(() => {
wrapper.vm.$store.dispatch('table/requestMergeRequests'); mockStore.dispatch('table/requestMergeRequests');
}); });
it('renders a loading indicator', () => { it('renders a loading indicator', () => {
...@@ -394,7 +420,7 @@ describe('ProductivityApp component', () => { ...@@ -394,7 +420,7 @@ describe('ProductivityApp component', () => {
describe('when table finished loading', () => { describe('when table finished loading', () => {
describe('and the table has data', () => { describe('and the table has data', () => {
beforeEach(() => { beforeEach(() => {
wrapper.vm.$store.dispatch('table/receiveMergeRequestsSuccess', { mockStore.dispatch('table/receiveMergeRequestsSuccess', {
headers: {}, headers: {},
data: [{ id: 1, title: 'This is a test MR' }], data: [{ id: 1, title: 'This is a test MR' }],
}); });
...@@ -412,17 +438,17 @@ describe('ProductivityApp component', () => { ...@@ -412,17 +438,17 @@ describe('ProductivityApp component', () => {
).toBe(false); ).toBe(false);
}); });
it('should change the column metric', () => { it('should change the column metric', async () => {
findMrTable().vm.$emit('columnMetricChange', 'time_to_first_comment'); findMrTable().vm.$emit('columnMetricChange', 'time_to_first_comment');
expect(actionSpies.setColumnMetric).toHaveBeenCalledWith( const { calls } = tableActionSpies.setColumnMetric.mock;
'time_to_first_comment', expect(calls[calls.length - 1][1]).toBe('time_to_first_comment');
);
}); });
it('should change the page', () => { it('should change the page', () => {
const page = 2; const page = 2;
findMrTable().vm.$emit('pageChange', page); findMrTable().vm.$emit('pageChange', page);
expect(actionSpies.setPage).toHaveBeenCalledWith(page); const { calls } = tableActionSpies.setPage.mock;
expect(calls[calls.length - 1][1]).toBe(page);
}); });
describe('sort controls', () => { describe('sort controls', () => {
...@@ -437,19 +463,19 @@ describe('ProductivityApp component', () => { ...@@ -437,19 +463,19 @@ describe('ProductivityApp component', () => {
.at(0) .at(0)
.vm.$emit('click'); .vm.$emit('click');
expect(actionSpies.setSortField).toHaveBeenCalled(); expect(tableActionSpies.setSortField).toHaveBeenCalled();
}); });
it('should toggle the sort order', () => { it('should toggle the sort order', () => {
findSortOrderToggle().vm.$emit('click'); findSortOrderToggle().vm.$emit('click');
expect(actionSpies.toggleSortOrder).toHaveBeenCalled(); expect(tableActionSpies.toggleSortOrder).toHaveBeenCalled();
}); });
}); });
}); });
describe("and the table doesn't have any data", () => { describe("and the table doesn't have any data", () => {
beforeEach(() => { beforeEach(() => {
wrapper.vm.$store.dispatch('table/receiveMergeRequestsSuccess', { mockStore.dispatch('table/receiveMergeRequestsSuccess', {
headers: {}, headers: {},
data: [], data: [],
}); });
...@@ -479,7 +505,7 @@ describe('ProductivityApp component', () => { ...@@ -479,7 +505,7 @@ describe('ProductivityApp component', () => {
describe('and has no data', () => { describe('and has no data', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
wrapper.vm.$store.dispatch('charts/receiveChartDataSuccess', { mockStore.dispatch('charts/receiveChartDataSuccess', {
chartKey: chartKeys.main, chartKey: chartKeys.main,
data: {}, data: {},
}); });
...@@ -512,7 +538,7 @@ describe('ProductivityApp component', () => { ...@@ -512,7 +538,7 @@ describe('ProductivityApp component', () => {
}, },
}, },
}); });
wrapper.vm.$store.dispatch('charts/receiveChartDataError', { mockStore.dispatch('charts/receiveChartDataError', {
chartKey: chartKeys.main, chartKey: chartKeys.main,
error: { response: { status: httpStatusCodes.INTERNAL_SERVER_ERROR } }, error: { response: { status: httpStatusCodes.INTERNAL_SERVER_ERROR } },
}); });
...@@ -570,7 +596,7 @@ describe('ProductivityApp component', () => { ...@@ -570,7 +596,7 @@ describe('ProductivityApp component', () => {
urlUtils.setUrlParams = jest.fn(); urlUtils.setUrlParams = jest.fn();
createComponent(); createComponent();
wrapper.vm.$store.dispatch('filters/setInitialData', { mockStore.dispatch('filters/setInitialData', {
skipFetch: true, skipFetch: true,
data: { data: {
mergedAfter: new Date('2019-09-01'), mergedAfter: new Date('2019-09-01'),
...@@ -589,7 +615,7 @@ describe('ProductivityApp component', () => { ...@@ -589,7 +615,7 @@ describe('ProductivityApp component', () => {
urlUtils.setUrlParams = jest.fn(); urlUtils.setUrlParams = jest.fn();
createComponent({ props: { hideGroupDropDown: true } }); createComponent({ props: { hideGroupDropDown: true } });
wrapper.vm.$store.dispatch('filters/setInitialData', { mockStore.dispatch('filters/setInitialData', {
skipFetch: true, skipFetch: true,
data: { data: {
mergedAfter: new Date('2019-09-01'), mergedAfter: new Date('2019-09-01'),
...@@ -597,7 +623,7 @@ describe('ProductivityApp component', () => { ...@@ -597,7 +623,7 @@ describe('ProductivityApp component', () => {
}, },
}); });
wrapper.vm.$store.dispatch('filters/setGroupNamespace', 'earth-special-forces'); mockStore.dispatch('filters/setGroupNamespace', 'earth-special-forces');
}); });
it('does not set the group_id', () => { it('does not set the group_id', () => {
...@@ -609,7 +635,7 @@ describe('ProductivityApp component', () => { ...@@ -609,7 +635,7 @@ describe('ProductivityApp component', () => {
describe('with a group selected', () => { describe('with a group selected', () => {
beforeEach(() => { beforeEach(() => {
wrapper.vm.$store.dispatch('filters/setGroupNamespace', 'earth-special-forces'); mockStore.dispatch('filters/setGroupNamespace', 'earth-special-forces');
}); });
it('sets the group_id', () => { it('sets the group_id', () => {
...@@ -622,7 +648,7 @@ describe('ProductivityApp component', () => { ...@@ -622,7 +648,7 @@ describe('ProductivityApp component', () => {
describe('with a project selected', () => { describe('with a project selected', () => {
beforeEach(() => { beforeEach(() => {
wrapper.vm.$store.dispatch('filters/setProjectPath', 'earth-special-forces/frieza-saga'); mockStore.dispatch('filters/setProjectPath', 'earth-special-forces/frieza-saga');
}); });
it('sets the project_id', () => { it('sets the project_id', () => {
...@@ -640,7 +666,7 @@ describe('ProductivityApp component', () => { ...@@ -640,7 +666,7 @@ describe('ProductivityApp component', () => {
${'label_name'} | ${'label_name[]'} | ${['who-will-win']} ${'label_name'} | ${'label_name[]'} | ${['who-will-win']}
`('with the $paramKey filter set', ({ paramKey, resultKey, value }) => { `('with the $paramKey filter set', ({ paramKey, resultKey, value }) => {
beforeEach(() => { beforeEach(() => {
wrapper.vm.$store.dispatch('filters/setFilters', { mockStore.dispatch('filters/setFilters', {
...defaultFilters, ...defaultFilters,
[paramKey]: value, [paramKey]: value,
}); });
......
...@@ -3,7 +3,7 @@ import Vuex from 'vuex'; ...@@ -3,7 +3,7 @@ import Vuex from 'vuex';
import FilterDropdowns from 'ee/analytics/productivity_analytics/components/filter_dropdowns.vue'; import FilterDropdowns from 'ee/analytics/productivity_analytics/components/filter_dropdowns.vue';
import GroupsDropdownFilter from 'ee/analytics/shared/components/groups_dropdown_filter.vue'; import GroupsDropdownFilter from 'ee/analytics/shared/components/groups_dropdown_filter.vue';
import ProjectsDropdownFilter from 'ee/analytics/shared/components/projects_dropdown_filter.vue'; import ProjectsDropdownFilter from 'ee/analytics/shared/components/projects_dropdown_filter.vue';
import store from 'ee/analytics/productivity_analytics/store'; import { getStoreConfig } from 'ee/analytics/productivity_analytics/store';
import resetStore from '../helpers'; import resetStore from '../helpers';
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -11,8 +11,9 @@ localVue.use(Vuex); ...@@ -11,8 +11,9 @@ localVue.use(Vuex);
describe('FilterDropdowns component', () => { describe('FilterDropdowns component', () => {
let wrapper; let wrapper;
let mockStore;
const actionSpies = { const filtersActionSpies = {
setGroupNamespace: jest.fn(), setGroupNamespace: jest.fn(),
setProjectPath: jest.fn(), setProjectPath: jest.fn(),
}; };
...@@ -23,19 +24,33 @@ describe('FilterDropdowns component', () => { ...@@ -23,19 +24,33 @@ describe('FilterDropdowns component', () => {
const projectId = 10; const projectId = 10;
beforeEach(() => { beforeEach(() => {
const {
modules: { filters, ...modules },
...storeConfig
} = getStoreConfig();
mockStore = new Vuex.Store({
...storeConfig,
modules: {
filters: {
...filters,
actions: {
...filters.actions,
...filtersActionSpies,
},
},
...modules,
},
});
wrapper = shallowMount(FilterDropdowns, { wrapper = shallowMount(FilterDropdowns, {
localVue, localVue,
store, store: mockStore,
propsData: {}, propsData: {},
methods: {
...actionSpies,
},
}); });
}); });
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
resetStore(store); resetStore(mockStore);
}); });
describe('template', () => { describe('template', () => {
...@@ -72,7 +87,8 @@ describe('FilterDropdowns component', () => { ...@@ -72,7 +87,8 @@ describe('FilterDropdowns component', () => {
it('updates the groupId and invokes setGroupNamespace action', () => { it('updates the groupId and invokes setGroupNamespace action', () => {
expect(wrapper.vm.groupId).toBe(1); expect(wrapper.vm.groupId).toBe(1);
expect(actionSpies.setGroupNamespace).toHaveBeenCalledWith(groupNamespace); const { calls } = filtersActionSpies.setGroupNamespace.mock;
expect(calls[calls.length - 1][1]).toBe(groupNamespace);
}); });
it('emits the "groupSelected" event', () => { it('emits the "groupSelected" event', () => {
...@@ -90,12 +106,13 @@ describe('FilterDropdowns component', () => { ...@@ -90,12 +106,13 @@ describe('FilterDropdowns component', () => {
describe('when the list of selected projects is not empty', () => { describe('when the list of selected projects is not empty', () => {
beforeEach(() => { beforeEach(() => {
store.state.filters.groupNamespace = groupNamespace; mockStore.state.filters.groupNamespace = groupNamespace;
wrapper.vm.onProjectsSelected([{ id: projectId, path_with_namespace: `${projectPath}` }]); wrapper.vm.onProjectsSelected([{ id: projectId, path_with_namespace: `${projectPath}` }]);
}); });
it('invokes setProjectPath action', () => { it('invokes setProjectPath action', () => {
expect(actionSpies.setProjectPath).toHaveBeenCalledWith(projectPath); const { calls } = filtersActionSpies.setProjectPath.mock;
expect(calls[calls.length - 1][1]).toBe(projectPath);
}); });
it('emits the "projectSelected" event', () => { it('emits the "projectSelected" event', () => {
...@@ -110,12 +127,13 @@ describe('FilterDropdowns component', () => { ...@@ -110,12 +127,13 @@ describe('FilterDropdowns component', () => {
describe('when the list of selected projects is empty', () => { describe('when the list of selected projects is empty', () => {
beforeEach(() => { beforeEach(() => {
store.state.filters.groupNamespace = groupNamespace; mockStore.state.filters.groupNamespace = groupNamespace;
wrapper.vm.onProjectsSelected([]); wrapper.vm.onProjectsSelected([]);
}); });
it('invokes setProjectPath action with null', () => { it('invokes setProjectPath action with null', () => {
expect(actionSpies.setProjectPath).toHaveBeenCalledWith(null); const { calls } = filtersActionSpies.setProjectPath.mock;
expect(calls[calls.length - 1][1]).toBe(null);
}); });
it('emits the "projectSelected" event', () => { it('emits the "projectSelected" event', () => {
......
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