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,17 +10,16 @@ import table from './modules/table/index'; ...@@ -10,17 +10,16 @@ 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, mutations,
mutations, modules: {
modules: { filters,
filters, charts,
charts, table,
table, },
}, });
});
export default createStore(); export default () => new Vuex.Store(getStoreConfig());
...@@ -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