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