Commit e85d245c authored by Dave Pisek's avatar Dave Pisek

Change all specs to move away from mount-helper

* No more mount helper
parent 7567cda6
import Vue from 'vue';
import { createWrapper, mount } from '@vue/test-utils'; import { createWrapper, mount } from '@vue/test-utils';
import VulnerabilityActionButtons from 'ee/security_dashboard/components/vulnerability_action_buttons.vue'; import VulnerabilityActionButtons from 'ee/security_dashboard/components/vulnerability_action_buttons.vue';
import createStore from 'ee/security_dashboard/store'; import createStore from 'ee/security_dashboard/store';
import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
import { VULNERABILITY_MODAL_ID } from 'ee/vue_shared/security_reports/components/constants'; import { VULNERABILITY_MODAL_ID } from 'ee/vue_shared/security_reports/components/constants';
import { BV_SHOW_MODAL } from '~/lib/utils/constants'; import { BV_SHOW_MODAL } from '~/lib/utils/constants';
import { resetStore } from '../helpers'; import { resetStore } from '../helpers';
import mockDataVulnerabilities from '../store/modules/vulnerabilities/data/mock_data_vulnerabilities'; import mockDataVulnerabilities from '../store/modules/vulnerabilities/data/mock_data_vulnerabilities';
describe('Security Dashboard Action Buttons', () => { describe('Security Dashboard Action Buttons', () => {
const Component = Vue.extend(VulnerabilityActionButtons);
let vm;
let store; let store;
let props;
let wrapper; let wrapper;
const defaultProps = { const createComponent = ({ ...options }) => {
vulnerability: mockDataVulnerabilities[0],
canCreateIssue: true,
canDismissVulnerability: true,
};
const createComponent = ({ propsData, ...options }) => {
return mount(VulnerabilityActionButtons, { return mount(VulnerabilityActionButtons, {
store: createStore(),
propsData: {
...defaultProps,
...propsData,
},
...options, ...options,
store,
}); });
}; };
...@@ -38,8 +22,8 @@ describe('Security Dashboard Action Buttons', () => { ...@@ -38,8 +22,8 @@ describe('Security Dashboard Action Buttons', () => {
}); });
afterEach(() => { afterEach(() => {
// vm.$destroy();
resetStore(store); resetStore(store);
wrapper.destroy();
}); });
describe('with a fresh vulnerability', () => { describe('with a fresh vulnerability', () => {
...@@ -55,10 +39,6 @@ describe('Security Dashboard Action Buttons', () => { ...@@ -55,10 +39,6 @@ describe('Security Dashboard Action Buttons', () => {
jest.spyOn(wrapper.vm.$store, 'dispatch').mockReturnValue(Promise.resolve()); jest.spyOn(wrapper.vm.$store, 'dispatch').mockReturnValue(Promise.resolve());
}); });
afterEach(() => {
wrapper.destroy();
});
it('should render three buttons in a button group', () => { it('should render three buttons in a button group', () => {
expect(wrapper.findAll('.btn-group .btn')).toHaveLength(3); expect(wrapper.findAll('.btn-group .btn')).toHaveLength(3);
}); });
...@@ -108,10 +88,6 @@ describe('Security Dashboard Action Buttons', () => { ...@@ -108,10 +88,6 @@ describe('Security Dashboard Action Buttons', () => {
describe('with Jira issues for vulnerabilities enabled', () => { describe('with Jira issues for vulnerabilities enabled', () => {
beforeEach(() => { beforeEach(() => {
props = {
vulnerability: mockDataVulnerabilities[8],
canCreateIssue: true,
};
wrapper = createComponent({ wrapper = createComponent({
propsData: { propsData: {
vulnerability: mockDataVulnerabilities[8], vulnerability: mockDataVulnerabilities[8],
...@@ -156,49 +132,43 @@ describe('Security Dashboard Action Buttons', () => { ...@@ -156,49 +132,43 @@ describe('Security Dashboard Action Buttons', () => {
describe('with a vulnerbility that has an issue', () => { describe('with a vulnerbility that has an issue', () => {
beforeEach(() => { beforeEach(() => {
props = { wrapper = createComponent({
vulnerability: mockDataVulnerabilities[3], propsData: {
}; vulnerability: mockDataVulnerabilities[3],
vm = mountComponentWithStore(Component, { store, props }); },
}); });
afterEach(() => {
vm.$destroy();
}); });
it('should only render one button', () => { it('should only render one button', () => {
expect(vm.$el.querySelectorAll('.btn')).toHaveLength(1); expect(wrapper.findAll('.btn')).toHaveLength(1);
}); });
it('should not render the create issue button', () => { it('should not render the create issue button', () => {
expect(vm.$el.querySelector('.js-create-issue')).toBeNull(); expect(wrapper.find('.js-create-issue').exists()).toBe(false);
}); });
}); });
describe('with a vulnerability that has been dismissed', () => { describe('with a vulnerability that has been dismissed', () => {
beforeEach(() => { beforeEach(() => {
props = { wrapper = createComponent({
vulnerability: mockDataVulnerabilities[2], propsData: {
canDismissVulnerability: true, vulnerability: mockDataVulnerabilities[2],
isDismissed: true, canDismissVulnerability: true,
}; isDismissed: true,
vm = mountComponentWithStore(Component, { store, props }); },
}); });
afterEach(() => {
vm.$destroy();
}); });
it('should render two buttons in a button group', () => { it('should render two buttons in a button group', () => {
expect(vm.$el.querySelectorAll('.btn-group .btn')).toHaveLength(2); expect(wrapper.findAll('.btn-group .btn')).toHaveLength(2);
}); });
it('should not render the dismiss vulnerability button', () => { it('should not render the dismiss vulnerability button', () => {
expect(vm.$el.querySelector('.js-dismiss-vulnerability')).toBeNull(); expect(wrapper.find('.js-dismiss-vulnerability').exists()).toBe(false);
}); });
it('should render the undo dismiss button', () => { it('should render the undo dismiss button', () => {
expect(vm.$el.querySelector('.js-undo-dismiss')).not.toBeNull(); expect(wrapper.find('.js-undo-dismiss').exists()).toBe(true);
}); });
}); });
}); });
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