Commit 7567cda6 authored by Dave Pisek's avatar Dave Pisek

Specs refactor - move more away from mount-helper

* Changes about 50% of specs to not rely on the component being mounted
  via the mount-helper
parent eb911339
import Vue from 'vue';
import { mount } from '@vue/test-utils';
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';
......@@ -38,49 +38,51 @@ describe('Security Dashboard Action Buttons', () => {
});
afterEach(() => {
vm.$destroy();
// vm.$destroy();
resetStore(store);
});
describe('with a fresh vulnerability', () => {
beforeEach(() => {
props = {
vulnerability: mockDataVulnerabilities[0],
canCreateIssue: true,
canDismissVulnerability: true,
};
vm = mountComponentWithStore(Component, { store, props });
jest.spyOn(vm.$store, 'dispatch').mockReturnValue(Promise.resolve());
wrapper = createComponent({
propsData: {
vulnerability: mockDataVulnerabilities[0],
canCreateIssue: true,
canDismissVulnerability: true,
},
});
jest.spyOn(wrapper.vm.$store, 'dispatch').mockReturnValue(Promise.resolve());
});
afterEach(() => {
vm.$destroy();
wrapper.destroy();
});
it('should render three buttons in a button group', () => {
expect(vm.$el.querySelectorAll('.btn-group .btn')).toHaveLength(3);
expect(wrapper.findAll('.btn-group .btn')).toHaveLength(3);
});
describe('More Info Button', () => {
let button;
beforeEach(() => {
button = vm.$el.querySelector('.js-more-info');
button = wrapper.find('.js-more-info');
});
it('should render the More info button', () => {
expect(button).not.toBeNull();
expect(button.exists()).toBe(true);
});
it('should emit an `setModalData` event and open the modal when clicked', () => {
jest.spyOn(vm.$root, '$emit');
button.click();
button.trigger('click');
expect(vm.$store.dispatch).toHaveBeenCalledWith('vulnerabilities/setModalData', {
expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('vulnerabilities/setModalData', {
vulnerability: mockDataVulnerabilities[0],
});
expect(vm.$root.$emit).toHaveBeenCalledWith(BV_SHOW_MODAL, VULNERABILITY_MODAL_ID);
expect(createWrapper(wrapper.vm.$root).emitted(BV_SHOW_MODAL)).toEqual([
[VULNERABILITY_MODAL_ID],
]);
});
});
......@@ -88,17 +90,17 @@ describe('Security Dashboard Action Buttons', () => {
let button;
beforeEach(() => {
button = vm.$el.querySelector('.js-create-issue');
button = wrapper.find('.js-create-issue');
});
it('should render the create issue button', () => {
expect(button).not.toBeNull();
expect(button.exists()).toBe(true);
});
it('should emit an `createIssue` event when clicked', () => {
button.click();
button.trigger('click');
expect(vm.$store.dispatch).toHaveBeenCalledWith('vulnerabilities/createIssue', {
expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('vulnerabilities/createIssue', {
vulnerability: mockDataVulnerabilities[0],
flashError: true,
});
......@@ -131,20 +133,23 @@ describe('Security Dashboard Action Buttons', () => {
let button;
beforeEach(() => {
button = vm.$el.querySelector('.js-dismiss-vulnerability');
button = wrapper.find('.js-dismiss-vulnerability');
});
it('should render the dismiss vulnerability button', () => {
expect(button).not.toBeNull();
expect(button.exists()).toBe(true);
});
it('should emit an `dismissVulnerability` event when clicked', () => {
button.click();
expect(vm.$store.dispatch).toHaveBeenCalledWith('vulnerabilities/dismissVulnerability', {
vulnerability: mockDataVulnerabilities[0],
flashError: true,
});
button.trigger('click');
expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith(
'vulnerabilities/dismissVulnerability',
{
vulnerability: mockDataVulnerabilities[0],
flashError: 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