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