Commit e93ebb2b authored by Mark Florian's avatar Mark Florian

Merge branch '194306-migrate-security-dashboard-store-tests-to-jest' into 'master'

Refactor security_dashboard store tests to be Jest

See merge request gitlab-org/gitlab!28134
parents 93d17d64 17651e21
......@@ -441,11 +441,11 @@ export const receiveUndoDismissError = ({ commit }, { flashError }) => {
};
export const downloadPatch = ({ state }) => {
/*
/*
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
relies on a old version of vue-bootstrap and it doesn't allow us to
set a href for a file download.
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
set a href for a file download.
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 * 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 Tracking from '~/tracking';
import { getParameterValues } from '~/lib/utils/url_utility';
jest.mock('~/lib/utils/url_utility', () => ({
getParameterValues: jest.fn().mockReturnValue([]),
}));
describe('filters actions', () => {
beforeEach(() => {
spyOn(Tracking, 'event');
jest.spyOn(Tracking, 'event').mockImplementation(() => {});
});
describe('setFilter', () => {
......@@ -85,7 +90,7 @@ describe('filters actions', () => {
},
{
type: types.SET_FILTER,
payload: jasmine.objectContaining({
payload: expect.objectContaining({
filterId: 'project_id',
optionId: ALL,
}),
......@@ -164,7 +169,7 @@ describe('filters actions', () => {
},
].forEach(testCase => {
it(testCase.description, done => {
spyOnDependency(module, 'getParameterValues').and.returnValue(testCase.returnValue);
getParameterValues.mockReturnValue(testCase.returnValue);
const state = createState();
testAction(
actions.setHideDismissedToggleInitialState,
......
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 createState from 'ee/security_dashboard/store/modules/projects/state';
......
import createState from 'ee/security_dashboard/store/modules/vulnerabilities/state';
import { DAYS } from 'ee/security_dashboard/store/modules/vulnerabilities/constants';
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('dashboardError', () => {
......@@ -69,12 +69,13 @@ describe('vulnerabilities module getters', () => {
beforeEach(() => {
state = createState();
state.vulnerabilitiesHistory = mockHistoryData;
jasmine.clock().install();
jasmine.clock().mockDate(new Date(2019, 1, 2));
});
afterEach(function() {
jasmine.clock().uninstall();
const mockDate = new Date(2019, 1, 2);
const originalDate = Date;
jest.spyOn(global, 'Date').mockImplementation(() => mockDate);
global.Date.now = originalDate.now;
global.Date.parse = originalDate.parse;
global.Date.UTC = originalDate.UTC;
});
it('should filter the data to the last 30 days and days we have data for', () => {
......
......@@ -19,7 +19,7 @@ describe('mediator', () => {
beforeEach(() => {
store = createStore();
spyOn(store, 'dispatch');
jest.spyOn(store, 'dispatch').mockImplementation(() => {});
});
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