Commit e70cc016 authored by Dave Pisek's avatar Dave Pisek

Add spec to cover opening of window

parent e85d245c
......@@ -66,7 +66,7 @@ export default {
this.createIssue({ vulnerability, flashError: true });
}
},
openNewJiraIssueWindow({ create_jira_issue_url }) {
createNewJiraIssue({ create_jira_issue_url }) {
window.open(create_jira_issue_url, '_blank');
},
handleDismissVulnerability() {
......
......@@ -17,6 +17,12 @@ describe('Security Dashboard Action Buttons', () => {
});
};
const findAllButtons = () => wrapper.findAll('.btn-group .btn');
const findMoreInfoButton = () => wrapper.find('.js-more-info');
const findCreateIssueButton = () => wrapper.find('.js-create-issue');
const findDismissVulnerabilityButton = () => wrapper.find('.js-dismiss-vulnerability');
const findUndoDismissButton = () => wrapper.find('.js-undo-dismiss');
beforeEach(() => {
store = createStore();
});
......@@ -40,22 +46,16 @@ describe('Security Dashboard Action Buttons', () => {
});
it('should render three buttons in a button group', () => {
expect(wrapper.findAll('.btn-group .btn')).toHaveLength(3);
expect(findAllButtons()).toHaveLength(3);
});
describe('More Info Button', () => {
let button;
beforeEach(() => {
button = wrapper.find('.js-more-info');
});
it('should render the More info button', () => {
expect(button.exists()).toBe(true);
expect(findMoreInfoButton().exists()).toBe(true);
});
it('should emit an `setModalData` event and open the modal when clicked', () => {
button.trigger('click');
findMoreInfoButton().trigger('click');
expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('vulnerabilities/setModalData', {
vulnerability: mockDataVulnerabilities[0],
......@@ -67,18 +67,12 @@ describe('Security Dashboard Action Buttons', () => {
});
describe('Create Issue Button', () => {
let button;
beforeEach(() => {
button = wrapper.find('.js-create-issue');
});
it('should render the create issue button', () => {
expect(button.exists()).toBe(true);
expect(findCreateIssueButton().exists()).toBe(true);
});
it('should emit an `createIssue` event when clicked', () => {
button.trigger('click');
findCreateIssueButton().trigger('click');
expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('vulnerabilities/createIssue', {
vulnerability: mockDataVulnerabilities[0],
......@@ -100,24 +94,30 @@ describe('Security Dashboard Action Buttons', () => {
});
it('should render the correct tooltip', () => {
expect(wrapper.find('.js-create-issue').attributes('title')).toBe('Create Jira issue');
});
});
expect(findCreateIssueButton().attributes('title')).toBe('Create Jira issue');
});
describe('Dismiss Vulnerability Button', () => {
let button;
it('should open a new window when the create-issue button is clicked', () => {
jest.spyOn(window, 'open').mockReturnValueOnce();
beforeEach(() => {
button = wrapper.find('.js-dismiss-vulnerability');
expect(window.open).not.toHaveBeenCalled();
findCreateIssueButton().trigger('click');
expect(window.open).toHaveBeenCalledWith(
mockDataVulnerabilities[8].create_jira_issue_url,
'_blank',
);
});
});
});
describe('Dismiss Vulnerability Button', () => {
it('should render the dismiss vulnerability button', () => {
expect(button.exists()).toBe(true);
expect(findDismissVulnerabilityButton().exists()).toBe(true);
});
it('should emit an `dismissVulnerability` event when clicked', () => {
button.trigger('click');
findDismissVulnerabilityButton().trigger('click');
expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith(
'vulnerabilities/dismissVulnerability',
......@@ -140,11 +140,11 @@ describe('Security Dashboard Action Buttons', () => {
});
it('should only render one button', () => {
expect(wrapper.findAll('.btn')).toHaveLength(1);
expect(findAllButtons()).toHaveLength(1);
});
it('should not render the create issue button', () => {
expect(wrapper.find('.js-create-issue').exists()).toBe(false);
expect(findCreateIssueButton().exists()).toBe(false);
});
});
......@@ -160,15 +160,15 @@ describe('Security Dashboard Action Buttons', () => {
});
it('should render two buttons in a button group', () => {
expect(wrapper.findAll('.btn-group .btn')).toHaveLength(2);
expect(findAllButtons()).toHaveLength(2);
});
it('should not render the dismiss vulnerability button', () => {
expect(wrapper.find('.js-dismiss-vulnerability').exists()).toBe(false);
expect(findDismissVulnerabilityButton().exists()).toBe(false);
});
it('should render the undo dismiss button', () => {
expect(wrapper.find('.js-undo-dismiss').exists()).toBe(true);
expect(findUndoDismissButton().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