Commit d90a33f4 authored by Alexander Turinske's avatar Alexander Turinske

Refactor security_dashboard store tests to be Jest

- moving Karma tests to Jest
parent 8d1fe49b
...@@ -441,11 +441,11 @@ export const receiveUndoDismissError = ({ commit }, { flashError }) => { ...@@ -441,11 +441,11 @@ export const receiveUndoDismissError = ({ commit }, { flashError }) => {
}; };
export const downloadPatch = ({ state }) => { export const downloadPatch = ({ state }) => {
/* /*
This action doesn't actually mutate the Vuex state and is a dirty This action doesn't actually mutate the Vuex state and is a dirty
workaround to modifying the dom. We do this because gl-split-button workaround to modifying the dom. We do this because gl-split-button
relies on a old version of vue-bootstrap and it doesn't allow us to relies on a old version of vue-bootstrap and it doesn't allow us to
set a href for a file download. set a href for a file download.
https://gitlab.com/gitlab-org/gitlab-ui/issues/188#note_165808493 https://gitlab.com/gitlab-org/gitlab-ui/issues/188#note_165808493
*/ */
......
import testAction from 'spec/helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import createState from 'ee/security_dashboard/store/modules/filters/state'; import createState from 'ee/security_dashboard/store/modules/filters/state';
import * as types from 'ee/security_dashboard/store/modules/filters/mutation_types'; import * as types from 'ee/security_dashboard/store/modules/filters/mutation_types';
import module, * as actions from 'ee/security_dashboard/store/modules/filters/actions'; import * as actions from 'ee/security_dashboard/store/modules/filters/actions';
import { ALL } from 'ee/security_dashboard/store/modules/filters/constants'; import { ALL } from 'ee/security_dashboard/store/modules/filters/constants';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import { getParameterValues } from '~/lib/utils/url_utility';
jest.mock('~/lib/utils/url_utility', () => ({
getParameterValues: jest.fn().mockReturnValue([]),
}));
describe('filters actions', () => { describe('filters actions', () => {
beforeEach(() => { beforeEach(() => {
spyOn(Tracking, 'event'); jest.spyOn(Tracking, 'event').mockImplementation(() => {});
}); });
describe('setFilter', () => { describe('setFilter', () => {
...@@ -85,7 +90,7 @@ describe('filters actions', () => { ...@@ -85,7 +90,7 @@ describe('filters actions', () => {
}, },
{ {
type: types.SET_FILTER, type: types.SET_FILTER,
payload: jasmine.objectContaining({ payload: expect.objectContaining({
filterId: 'project_id', filterId: 'project_id',
optionId: ALL, optionId: ALL,
}), }),
...@@ -164,7 +169,8 @@ describe('filters actions', () => { ...@@ -164,7 +169,8 @@ describe('filters actions', () => {
}, },
].forEach(testCase => { ].forEach(testCase => {
it(testCase.description, done => { it(testCase.description, done => {
spyOnDependency(module, 'getParameterValues').and.returnValue(testCase.returnValue); const mockValue = testCase.returnValue;
getParameterValues.mockImplementation(() => mockValue);
const state = createState(); const state = createState();
testAction( testAction(
actions.setHideDismissedToggleInitialState, actions.setHideDismissedToggleInitialState,
......
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import testAction from 'spec/helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from 'spec/test_constants';
import createState from 'ee/security_dashboard/store/modules/projects/state'; import createState from 'ee/security_dashboard/store/modules/projects/state';
......
import createState from 'ee/security_dashboard/store/modules/vulnerabilities/state'; import createState from 'ee/security_dashboard/store/modules/vulnerabilities/state';
import { DAYS } from 'ee/security_dashboard/store/modules/vulnerabilities/constants'; import { DAYS } from 'ee/security_dashboard/store/modules/vulnerabilities/constants';
import * as getters from 'ee/security_dashboard/store/modules/vulnerabilities/getters'; import * as getters from 'ee/security_dashboard/store/modules/vulnerabilities/getters';
import mockHistoryData from '../vulnerabilities/data/mock_data_vulnerabilities_history.json'; import mockHistoryData from './data/mock_data_vulnerabilities_history.json';
describe('vulnerabilities module getters', () => { describe('vulnerabilities module getters', () => {
describe('dashboardError', () => { describe('dashboardError', () => {
...@@ -65,16 +65,26 @@ describe('vulnerabilities module getters', () => { ...@@ -65,16 +65,26 @@ describe('vulnerabilities module getters', () => {
getters.getVulnerabilityHistoryByName(state)(name); getters.getVulnerabilityHistoryByName(state)(name);
return { getVulnerabilityHistoryByName }; return { getVulnerabilityHistoryByName };
}; };
const realDate = Date;
beforeEach(() => { beforeEach(() => {
state = createState(); state = createState();
state.vulnerabilitiesHistory = mockHistoryData; state.vulnerabilitiesHistory = mockHistoryData;
jasmine.clock().install(); jest.useFakeTimers();
jasmine.clock().mockDate(new Date(2019, 1, 2)); const currentDate = new Date(2019, 1, 2);
global.Date = class extends Date {
constructor(date) {
if (date) {
// eslint-disable-next-line constructor-super
return super(date);
}
return currentDate;
}
};
}); });
afterEach(function() { afterEach(() => {
jasmine.clock().uninstall(); global.Date = realDate;
}); });
it('should filter the data to the last 30 days and days we have data for', () => { it('should filter the data to the last 30 days and days we have data for', () => {
......
...@@ -19,7 +19,7 @@ describe('mediator', () => { ...@@ -19,7 +19,7 @@ describe('mediator', () => {
beforeEach(() => { beforeEach(() => {
store = createStore(); store = createStore();
spyOn(store, 'dispatch'); jest.spyOn(store, 'dispatch').mockImplementation(() => {});
}); });
it('triggers fetching vulnerabilities after one filter changes', () => { it('triggers fetching vulnerabilities after one filter changes', () => {
......
export {
default,
} from '../../../../../frontend/security_dashboard/store/modules/vulnerabilities/data/mock_data_vulnerabilities';
{
"critical": 2,
"high": 4,
"low": 7,
"medium": 8,
"unknown": 0
}
\ No newline at end of file
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