Commit 758acba0 authored by Illya Klymov's avatar Illya Klymov Committed by Natalia Tepluhina

Remove deprecated `methods` from security_dashboard specs

`@vue/test-utils` deprecated `methods` option. Replaced with
stubbing store actions
parent 6e00773e
...@@ -12,17 +12,21 @@ import pipelineJobs from './modules/pipeline_jobs/index'; ...@@ -12,17 +12,21 @@ import pipelineJobs from './modules/pipeline_jobs/index';
Vue.use(Vuex); Vue.use(Vuex);
export const getStoreConfig = (dashboardType = DASHBOARD_TYPES.PROJECT) => ({
state: () => ({
dashboardType,
}),
modules: {
vulnerableProjects,
filters,
vulnerabilities,
unscannedProjects,
pipelineJobs,
},
});
export default ({ dashboardType = DASHBOARD_TYPES.PROJECT, plugins = [] } = {}) => export default ({ dashboardType = DASHBOARD_TYPES.PROJECT, plugins = [] } = {}) =>
new Vuex.Store({ new Vuex.Store({
state: () => ({ ...getStoreConfig(dashboardType),
dashboardType,
}),
modules: {
vulnerableProjects,
filters,
vulnerabilities,
unscannedProjects,
pipelineJobs,
},
plugins: [mediator, ...plugins], plugins: [mediator, ...plugins],
}); });
import { nextTick } from 'vue';
import Vuex from 'vuex';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import { merge } from 'lodash';
import Filters from 'ee/security_dashboard/components/filters.vue'; import Filters from 'ee/security_dashboard/components/filters.vue';
import LoadingError from 'ee/security_dashboard/components/loading_error.vue'; import LoadingError from 'ee/security_dashboard/components/loading_error.vue';
import SecurityDashboardLayout from 'ee/security_dashboard/components/security_dashboard_layout.vue'; import SecurityDashboardLayout from 'ee/security_dashboard/components/security_dashboard_layout.vue';
import SecurityDashboardTable from 'ee/security_dashboard/components/security_dashboard_table.vue'; import SecurityDashboardTable from 'ee/security_dashboard/components/security_dashboard_table.vue';
import SecurityDashboard from 'ee/security_dashboard/components/security_dashboard_vuex.vue'; import SecurityDashboard from 'ee/security_dashboard/components/security_dashboard_vuex.vue';
import createStore from 'ee/security_dashboard/store'; import { getStoreConfig } from 'ee/security_dashboard/store';
import IssueModal from 'ee/vue_shared/security_reports/components/modal.vue'; import IssueModal from 'ee/vue_shared/security_reports/components/modal.vue';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
...@@ -27,15 +29,24 @@ describe('Security Dashboard component', () => { ...@@ -27,15 +29,24 @@ describe('Security Dashboard component', () => {
let store; let store;
const createComponent = (props) => { const createComponent = (props) => {
setPipelineIdSpy = jest.fn();
fetchPipelineJobsSpy = jest.fn();
const { actions, ...storeConfig } = getStoreConfig();
store = new Vuex.Store(
merge(storeConfig, {
modules: {
vulnerabilities: { actions: { setPipelineId: setPipelineIdSpy } },
pipelineJobs: { actions: { fetchPipelineJobs: fetchPipelineJobsSpy } },
},
}),
);
wrapper = shallowMount(SecurityDashboard, { wrapper = shallowMount(SecurityDashboard, {
store, store,
stubs: { stubs: {
SecurityDashboardLayout, SecurityDashboardLayout,
}, },
methods: {
setPipelineId: setPipelineIdSpy,
fetchPipelineJobs: fetchPipelineJobsSpy,
},
propsData: { propsData: {
dashboardDocumentation: '', dashboardDocumentation: '',
vulnerabilitiesEndpoint, vulnerabilitiesEndpoint,
...@@ -47,16 +58,12 @@ describe('Security Dashboard component', () => { ...@@ -47,16 +58,12 @@ describe('Security Dashboard component', () => {
beforeEach(() => { beforeEach(() => {
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
setPipelineIdSpy = jest.fn();
fetchPipelineJobsSpy = jest.fn();
store = createStore();
}); });
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null; wrapper = null;
mock.restore(); mock.restore();
jest.clearAllMocks();
}); });
describe('default', () => { describe('default', () => {
...@@ -73,11 +80,11 @@ describe('Security Dashboard component', () => { ...@@ -73,11 +80,11 @@ describe('Security Dashboard component', () => {
}); });
it('sets the pipeline id', () => { it('sets the pipeline id', () => {
expect(setPipelineIdSpy).toHaveBeenCalledWith(pipelineId); expect(setPipelineIdSpy).toHaveBeenCalledWith(expect.any(Object), pipelineId);
}); });
it('fetchs the pipeline jobs', () => { it('fetchs the pipeline jobs', () => {
expect(fetchPipelineJobsSpy).toHaveBeenCalledWith(); expect(fetchPipelineJobsSpy).toHaveBeenCalledWith(expect.any(Object), undefined);
}); });
it('renders the issue modal', () => { it('renders the issue modal', () => {
...@@ -101,7 +108,7 @@ describe('Security Dashboard component', () => { ...@@ -101,7 +108,7 @@ describe('Security Dashboard component', () => {
`( `(
'dispatches the "$expectedDispatchedAction" action when the modal emits a "$emittedModalEvent" event', 'dispatches the "$expectedDispatchedAction" action when the modal emits a "$emittedModalEvent" event',
({ emittedModalEvent, eventPayload, expectedDispatchedAction, expectedActionPayload }) => { ({ emittedModalEvent, eventPayload, expectedDispatchedAction, expectedActionPayload }) => {
wrapper.vm.$store.state.vulnerabilities.modal.vulnerability = 'bar'; store.state.vulnerabilities.modal.vulnerability = 'bar';
jest.spyOn(store, 'dispatch').mockImplementation(); jest.spyOn(store, 'dispatch').mockImplementation();
wrapper.find(IssueModal).vm.$emit(emittedModalEvent, eventPayload); wrapper.find(IssueModal).vm.$emit(emittedModalEvent, eventPayload);
...@@ -126,10 +133,10 @@ describe('Security Dashboard component', () => { ...@@ -126,10 +133,10 @@ describe('Security Dashboard component', () => {
${{ isCreatingMergeRequest: true }} | ${expect.objectContaining({ isCreatingMergeRequest: true })} ${{ isCreatingMergeRequest: true }} | ${expect.objectContaining({ isCreatingMergeRequest: true })}
`( `(
'passes right props to issue modal with state $givenState', 'passes right props to issue modal with state $givenState',
({ givenState, expectedProps }) => { async ({ givenState, expectedProps }) => {
Object.assign(store.state.vulnerabilities, givenState);
createComponent(); createComponent();
Object.assign(store.state.vulnerabilities, givenState);
await nextTick();
expect(wrapper.find(IssueModal).props()).toStrictEqual(expectedProps); expect(wrapper.find(IssueModal).props()).toStrictEqual(expectedProps);
}, },
...@@ -141,18 +148,16 @@ describe('Security Dashboard component', () => { ...@@ -141,18 +148,16 @@ describe('Security Dashboard component', () => {
createComponent(); createComponent();
}); });
it.each([401, 403])('displays an error on error %s', (errorCode) => { it.each([401, 403])('displays an error on error %s', async (errorCode) => {
store.dispatch('vulnerabilities/receiveVulnerabilitiesError', errorCode); store.dispatch('vulnerabilities/receiveVulnerabilitiesError', errorCode);
return wrapper.vm.$nextTick().then(() => { await nextTick();
expect(wrapper.find(LoadingError).exists()).toBe(true); expect(wrapper.find(LoadingError).exists()).toBe(true);
});
}); });
it.each([404, 500])('does not display an error on error %s', (errorCode) => { it.each([404, 500])('does not display an error on error %s', async (errorCode) => {
store.dispatch('vulnerabilities/receiveVulnerabilitiesError', errorCode); store.dispatch('vulnerabilities/receiveVulnerabilitiesError', errorCode);
return wrapper.vm.$nextTick().then(() => { await nextTick();
expect(wrapper.find(LoadingError).exists()).toBe(false); expect(wrapper.find(LoadingError).exists()).toBe(false);
});
}); });
}); });
}); });
...@@ -45,7 +45,6 @@ describe('UnscannedProjects component', () => { ...@@ -45,7 +45,6 @@ describe('UnscannedProjects component', () => {
propsData: { ...defaultPropsData, ...propsData }, propsData: { ...defaultPropsData, ...propsData },
store, store,
localVue, localVue,
sync: false,
}); });
}; };
......
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