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 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 VulnerabilityActionButtons from 'ee/security_dashboard/components/vulnerability_action_buttons.vue';
import createStore from 'ee/security_dashboard/store'; import createStore from 'ee/security_dashboard/store';
...@@ -38,49 +38,51 @@ describe('Security Dashboard Action Buttons', () => { ...@@ -38,49 +38,51 @@ describe('Security Dashboard Action Buttons', () => {
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); // vm.$destroy();
resetStore(store); resetStore(store);
}); });
describe('with a fresh vulnerability', () => { describe('with a fresh vulnerability', () => {
beforeEach(() => { beforeEach(() => {
props = { wrapper = createComponent({
vulnerability: mockDataVulnerabilities[0], propsData: {
canCreateIssue: true, vulnerability: mockDataVulnerabilities[0],
canDismissVulnerability: true, canCreateIssue: true,
}; canDismissVulnerability: true,
vm = mountComponentWithStore(Component, { store, props }); },
jest.spyOn(vm.$store, 'dispatch').mockReturnValue(Promise.resolve()); });
jest.spyOn(wrapper.vm.$store, 'dispatch').mockReturnValue(Promise.resolve());
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); wrapper.destroy();
}); });
it('should render three buttons in a button group', () => { 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', () => { describe('More Info Button', () => {
let button; let button;
beforeEach(() => { beforeEach(() => {
button = vm.$el.querySelector('.js-more-info'); button = wrapper.find('.js-more-info');
}); });
it('should render the More info button', () => { 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', () => { it('should emit an `setModalData` event and open the modal when clicked', () => {
jest.spyOn(vm.$root, '$emit'); button.trigger('click');
button.click();
expect(vm.$store.dispatch).toHaveBeenCalledWith('vulnerabilities/setModalData', { expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('vulnerabilities/setModalData', {
vulnerability: mockDataVulnerabilities[0], 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', () => { ...@@ -88,17 +90,17 @@ describe('Security Dashboard Action Buttons', () => {
let button; let button;
beforeEach(() => { beforeEach(() => {
button = vm.$el.querySelector('.js-create-issue'); button = wrapper.find('.js-create-issue');
}); });
it('should render the create issue button', () => { it('should render the create issue button', () => {
expect(button).not.toBeNull(); expect(button.exists()).toBe(true);
}); });
it('should emit an `createIssue` event when clicked', () => { 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], vulnerability: mockDataVulnerabilities[0],
flashError: true, flashError: true,
}); });
...@@ -131,20 +133,23 @@ describe('Security Dashboard Action Buttons', () => { ...@@ -131,20 +133,23 @@ describe('Security Dashboard Action Buttons', () => {
let button; let button;
beforeEach(() => { beforeEach(() => {
button = vm.$el.querySelector('.js-dismiss-vulnerability'); button = wrapper.find('.js-dismiss-vulnerability');
}); });
it('should render the dismiss vulnerability button', () => { it('should render the dismiss vulnerability button', () => {
expect(button).not.toBeNull(); expect(button.exists()).toBe(true);
}); });
it('should emit an `dismissVulnerability` event when clicked', () => { it('should emit an `dismissVulnerability` event when clicked', () => {
button.click(); button.trigger('click');
expect(vm.$store.dispatch).toHaveBeenCalledWith('vulnerabilities/dismissVulnerability', { expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith(
vulnerability: mockDataVulnerabilities[0], 'vulnerabilities/dismissVulnerability',
flashError: true, {
}); 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