Commit f3a4b756 authored by Dheeraj Joshi's avatar Dheeraj Joshi Committed by Paul Slaughter

Migrate specs from karma to jest

Refactor security-dashboard-table-row component specs
and migrate it to use jest
parent a81f1b1c
...@@ -3,7 +3,7 @@ import DependenciesTableRow from 'ee/dependencies/components/dependencies_table_ ...@@ -3,7 +3,7 @@ import DependenciesTableRow from 'ee/dependencies/components/dependencies_table_
import DependencyVulnerability from 'ee/dependencies/components/dependency_vulnerability.vue'; import DependencyVulnerability from 'ee/dependencies/components/dependency_vulnerability.vue';
import { MAX_DISPLAYED_VULNERABILITIES_PER_DEPENDENCY } from 'ee/dependencies/components/constants'; import { MAX_DISPLAYED_VULNERABILITIES_PER_DEPENDENCY } from 'ee/dependencies/components/constants';
import { makeDependency } from './utils'; import { makeDependency } from './utils';
import mockDataVulnerabilities from '../../../javascripts/security_dashboard/store/vulnerabilities/data/mock_data_vulnerabilities.json'; import mockDataVulnerabilities from '../../security_dashboard/store/vulnerabilities/data/mock_data_vulnerabilities';
describe('DependenciesTableRow component', () => { describe('DependenciesTableRow component', () => {
let wrapper; let wrapper;
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import DependencyVulnerability from 'ee/dependencies/components/dependency_vulnerability.vue'; import DependencyVulnerability from 'ee/dependencies/components/dependency_vulnerability.vue';
import SeverityBadge from 'ee/vue_shared/security_reports/components/severity_badge.vue'; import SeverityBadge from 'ee/vue_shared/security_reports/components/severity_badge.vue';
import mockDataVulnerabilities from '../../../javascripts/security_dashboard/store/vulnerabilities/data/mock_data_vulnerabilities.json'; import mockDataVulnerabilities from '../../security_dashboard/store/vulnerabilities/data/mock_data_vulnerabilities';
describe('DependencyVulnerability component', () => { describe('DependencyVulnerability component', () => {
let wrapper; let wrapper;
......
import Vue from 'vue'; import Vuex from 'vuex';
import component from 'ee/security_dashboard/components/security_dashboard_table_row.vue'; import SecurityDashboardTableRow from 'ee/security_dashboard/components/security_dashboard_table_row.vue';
import createStore from 'ee/security_dashboard/store'; import createStore from 'ee/security_dashboard/store';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { mount, shallowMount, createLocalVue } from '@vue/test-utils';
import mockDataVulnerabilities from '../store/vulnerabilities/data/mock_data_vulnerabilities.json'; import mockDataVulnerabilities from '../store/vulnerabilities/data/mock_data_vulnerabilities';
import { DASHBOARD_TYPES } from 'ee/security_dashboard/store/constants'; import { DASHBOARD_TYPES } from 'ee/security_dashboard/store/constants';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('Security Dashboard Table Row', () => { describe('Security Dashboard Table Row', () => {
let vm; let wrapper;
let props; let store;
let store = createStore();
const Component = Vue.extend(component); const createComponent = (mountFunc, { props = {}, storeParams = {} } = {}) => {
store = createStore(storeParams);
wrapper = mountFunc(SecurityDashboardTableRow, {
localVue,
store,
propsData: {
...props,
},
});
};
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
const findLoader = () => wrapper.find('.js-skeleton-loader');
const findContent = i => wrapper.findAll('.table-mobile-content').at(i);
const findAllIssueCreated = () => wrapper.findAll('.ic-issue-created');
describe('when loading', () => { describe('when loading', () => {
beforeEach(() => { beforeEach(() => {
props = { isLoading: true }; createComponent(shallowMount, { props: { isLoading: true } });
vm = mountComponentWithStore(Component, { store, props });
});
afterEach(() => {
vm.$destroy();
}); });
it('should display the skeleton loader', () => { it('should display the skeleton loader', () => {
expect(vm.$el.querySelector('.js-skeleton-loader')).not.toBeNull(); expect(findLoader().exists()).toBeTruthy();
}); });
it('should render a ` ` for severity', () => { it('should render a ` ` for severity', () => {
expect(vm.severity).toEqual(' '); expect(wrapper.vm.severity).toEqual(' ');
expect(vm.$el.querySelectorAll('.table-mobile-content')[0].textContent).toContain(' '); expect(findContent(0).text()).toEqual('');
}); });
it('should not render action buttons', () => { it('should not render action buttons', () => {
expect(vm.$el.querySelectorAll('.action-buttons button').length).toBe(0); expect(wrapper.findAll('.action-buttons button').length).toBe(0);
}); });
}); });
...@@ -39,43 +55,37 @@ describe('Security Dashboard Table Row', () => { ...@@ -39,43 +55,37 @@ describe('Security Dashboard Table Row', () => {
let vulnerability = mockDataVulnerabilities[0]; let vulnerability = mockDataVulnerabilities[0];
beforeEach(() => { beforeEach(() => {
props = { vulnerability }; createComponent(mount, { props: { vulnerability } });
vm = mountComponentWithStore(Component, { store, props });
});
afterEach(() => {
vm.$destroy();
}); });
it('should not display the skeleton loader', () => { it('should not display the skeleton loader', () => {
expect(vm.$el.querySelector('.js-skeleton-loader')).not.toExist(); expect(findLoader().exists()).toBeFalsy();
}); });
it('should render the severity', () => { it('should render the severity', () => {
expect( expect(
vm.$el.querySelectorAll('.table-mobile-content')[0].textContent.toLowerCase(), findContent(0)
).toContain(props.vulnerability.severity); .text()
.toLowerCase(),
).toContain(wrapper.props().vulnerability.severity);
}); });
describe('the project name', () => { describe('the project name', () => {
it('should render the name', () => { it('should render the name', () => {
expect(vm.$el.querySelectorAll('.table-mobile-content')[1].textContent).toContain( expect(findContent(1).text()).toContain(wrapper.props().vulnerability.name);
props.vulnerability.name,
);
}); });
it('should render the project namespace', () => { it('should render the project namespace', () => {
expect(vm.$el.querySelectorAll('.table-mobile-content')[1].textContent).toContain( expect(findContent(1).text()).toContain(wrapper.props().vulnerability.location.file);
props.vulnerability.location.file,
);
}); });
it('should fire the openModal action when clicked', () => { it('should fire the openModal action when clicked', () => {
spyOn(vm.$store, 'dispatch'); jest.spyOn(store, 'dispatch').mockImplementation();
vm.$el.querySelector('.vulnerability-title').click(); const el = wrapper.find('.vulnerability-title');
el.trigger('click');
expect(vm.$store.dispatch).toHaveBeenCalledWith('vulnerabilities/openModal', { expect(store.dispatch).toHaveBeenCalledWith('vulnerabilities/openModal', {
vulnerability, vulnerability,
}); });
}); });
...@@ -83,41 +93,27 @@ describe('Security Dashboard Table Row', () => { ...@@ -83,41 +93,27 @@ describe('Security Dashboard Table Row', () => {
describe('Group Security Dashboard', () => { describe('Group Security Dashboard', () => {
beforeEach(() => { beforeEach(() => {
store = createStore({ createComponent(shallowMount, {
dashboardType: DASHBOARD_TYPES.GROUP, props: { vulnerability },
storeParams: { dashboardType: DASHBOARD_TYPES.GROUP },
}); });
props = { vulnerability };
vm = mountComponentWithStore(Component, { store, props });
});
afterEach(() => {
vm.$destroy();
}); });
it('should contain project name as the namespace', () => { it('should contain project name as the namespace', () => {
expect(vm.$el.querySelectorAll('.table-mobile-content')[1].textContent).toContain( expect(findContent(1).text()).toContain(wrapper.props().vulnerability.project.full_name);
props.vulnerability.project.full_name,
);
}); });
}); });
describe('Non-group Security Dashboard', () => { describe('Non-group Security Dashboard', () => {
beforeEach(() => { beforeEach(() => {
store = createStore();
// eslint-disable-next-line prefer-destructuring // eslint-disable-next-line prefer-destructuring
vulnerability = mockDataVulnerabilities[7]; vulnerability = mockDataVulnerabilities[7];
props = { vulnerability };
vm = mountComponentWithStore(Component, { store, props });
});
afterEach(() => { createComponent(shallowMount, { props: { vulnerability } });
vm.$destroy();
}); });
it('should contain container image as the namespace', () => { it('should contain container image as the namespace', () => {
expect(vm.$el.querySelectorAll('.table-mobile-content')[1].textContent).toContain( expect(findContent(1).text()).toContain(wrapper.props().vulnerability.location.image);
props.vulnerability.location.image,
);
}); });
}); });
}); });
...@@ -126,20 +122,15 @@ describe('Security Dashboard Table Row', () => { ...@@ -126,20 +122,15 @@ describe('Security Dashboard Table Row', () => {
const vulnerability = mockDataVulnerabilities[2]; const vulnerability = mockDataVulnerabilities[2];
beforeEach(() => { beforeEach(() => {
props = { vulnerability }; createComponent(shallowMount, { props: { vulnerability } });
vm = mountComponentWithStore(Component, { store, props });
});
afterEach(() => {
vm.$destroy();
}); });
it('should have a `dismissed` class', () => { it('should have a `dismissed` class', () => {
expect(vm.$el.classList).toContain('dismissed'); expect(wrapper.classes()).toContain('dismissed');
}); });
it('should render a `DISMISSED` tag', () => { it('should render a `DISMISSED` tag', () => {
expect(vm.$el.textContent).toContain('dismissed'); expect(wrapper.text()).toContain('dismissed');
}); });
}); });
...@@ -147,16 +138,11 @@ describe('Security Dashboard Table Row', () => { ...@@ -147,16 +138,11 @@ describe('Security Dashboard Table Row', () => {
const vulnerability = mockDataVulnerabilities[3]; const vulnerability = mockDataVulnerabilities[3];
beforeEach(() => { beforeEach(() => {
props = { vulnerability }; createComponent(mount, { props: { vulnerability } });
vm = mountComponentWithStore(Component, { store, props });
});
afterEach(() => {
vm.$destroy();
}); });
it('should have a `ic-issue-created` class', () => { it('should have a `ic-issue-created` class', () => {
expect(vm.$el.querySelectorAll('.ic-issue-created')).toHaveLength(1); expect(findAllIssueCreated()).toHaveLength(1);
}); });
}); });
...@@ -164,16 +150,11 @@ describe('Security Dashboard Table Row', () => { ...@@ -164,16 +150,11 @@ describe('Security Dashboard Table Row', () => {
const vulnerability = mockDataVulnerabilities[6]; const vulnerability = mockDataVulnerabilities[6];
beforeEach(() => { beforeEach(() => {
props = { vulnerability }; createComponent(mount, { props: { vulnerability } });
vm = mountComponentWithStore(Component, { store, props });
});
afterEach(() => {
vm.$destroy();
}); });
it('should not have a `ic-issue-created` class', () => { it('should not have a `ic-issue-created` class', () => {
expect(vm.$el.querySelectorAll('.ic-issue-created')).toHaveLength(0); expect(findAllIssueCreated()).toHaveLength(0);
}); });
}); });
...@@ -181,16 +162,11 @@ describe('Security Dashboard Table Row', () => { ...@@ -181,16 +162,11 @@ describe('Security Dashboard Table Row', () => {
const vulnerability = mockDataVulnerabilities[0]; const vulnerability = mockDataVulnerabilities[0];
beforeEach(() => { beforeEach(() => {
props = { vulnerability }; createComponent(shallowMount, { props: { vulnerability } });
vm = mountComponentWithStore(Component, { store, props });
});
afterEach(() => {
vm.$destroy();
}); });
it('should not have a `ic-issue-created` class', () => { it('should not have a `ic-issue-created` class', () => {
expect(vm.$el.querySelectorAll('.ic-issue-created')).toHaveLength(0); expect(findAllIssueCreated()).toHaveLength(0);
}); });
}); });
}); });
...@@ -12,7 +12,7 @@ import { ...@@ -12,7 +12,7 @@ import {
REQUEST_VULNERABILITIES, REQUEST_VULNERABILITIES,
} from 'ee/security_dashboard/store/modules/vulnerabilities/mutation_types'; } from 'ee/security_dashboard/store/modules/vulnerabilities/mutation_types';
import mockDataVulnerabilities from '../store/vulnerabilities/data/mock_data_vulnerabilities.json'; import mockDataVulnerabilities from '../store/vulnerabilities/data/mock_data_vulnerabilities';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
......
import { isSameVulnerability } from 'ee/security_dashboard/store/modules/vulnerabilities/utils'; import { isSameVulnerability } from 'ee/security_dashboard/store/modules/vulnerabilities/utils';
import mockData from '../../../../javascripts/security_dashboard/store/vulnerabilities/data/mock_data_vulnerabilities.json'; import mockData from '../../../security_dashboard/store/vulnerabilities/data/mock_data_vulnerabilities';
describe('Vulnerabilities utils', () => { describe('Vulnerabilities utils', () => {
const clone = serializable => JSON.parse(JSON.stringify(serializable)); const clone = serializable => JSON.parse(JSON.stringify(serializable));
......
...@@ -4,7 +4,7 @@ import component from 'ee/security_dashboard/components/vulnerability_action_but ...@@ -4,7 +4,7 @@ import component from 'ee/security_dashboard/components/vulnerability_action_but
import createStore from 'ee/security_dashboard/store'; import createStore from 'ee/security_dashboard/store';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { resetStore } from '../helpers'; import { resetStore } from '../helpers';
import mockDataVulnerabilities from '../store/vulnerabilities/data/mock_data_vulnerabilities.json'; import mockDataVulnerabilities from '../store/vulnerabilities/data/mock_data_vulnerabilities';
describe('Security Dashboard Action Buttons', () => { describe('Security Dashboard Action Buttons', () => {
const Component = Vue.extend(component); const Component = Vue.extend(component);
......
...@@ -9,7 +9,7 @@ import * as types from 'ee/security_dashboard/store/modules/vulnerabilities/muta ...@@ -9,7 +9,7 @@ import * as types from 'ee/security_dashboard/store/modules/vulnerabilities/muta
import * as actions from 'ee/security_dashboard/store/modules/vulnerabilities/actions'; import * as actions from 'ee/security_dashboard/store/modules/vulnerabilities/actions';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import mockDataVulnerabilities from './data/mock_data_vulnerabilities.json'; import mockDataVulnerabilities from './data/mock_data_vulnerabilities';
import mockDataVulnerabilitiesCount from './data/mock_data_vulnerabilities_count.json'; import mockDataVulnerabilitiesCount from './data/mock_data_vulnerabilities_count.json';
import mockDataVulnerabilitiesHistory from './data/mock_data_vulnerabilities_history.json'; import mockDataVulnerabilitiesHistory from './data/mock_data_vulnerabilities_history.json';
......
export {
default,
} from '../../../../../frontend/security_dashboard/store/vulnerabilities/data/mock_data_vulnerabilities';
...@@ -2,7 +2,7 @@ import createState from 'ee/security_dashboard/store/modules/vulnerabilities/sta ...@@ -2,7 +2,7 @@ import createState from 'ee/security_dashboard/store/modules/vulnerabilities/sta
import * as types from 'ee/security_dashboard/store/modules/vulnerabilities/mutation_types'; import * as types from 'ee/security_dashboard/store/modules/vulnerabilities/mutation_types';
import mutations from 'ee/security_dashboard/store/modules/vulnerabilities/mutations'; import mutations from 'ee/security_dashboard/store/modules/vulnerabilities/mutations';
import { DAYS } from 'ee/security_dashboard/store/modules/vulnerabilities/constants'; import { DAYS } from 'ee/security_dashboard/store/modules/vulnerabilities/constants';
import mockData from './data/mock_data_vulnerabilities.json'; import mockData from './data/mock_data_vulnerabilities';
describe('vulnerabilities module mutations', () => { describe('vulnerabilities module mutations', () => {
let state; let state;
......
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