Commit f4ffeb31 authored by Dave Pisek's avatar Dave Pisek

Specs refactor: use testids, export i18n

* switches from `js-*` hooks to testids
* exports i18n translations
parent 9631797d
...@@ -6,7 +6,16 @@ import { BV_SHOW_MODAL } from '~/lib/utils/constants'; ...@@ -6,7 +6,16 @@ import { BV_SHOW_MODAL } from '~/lib/utils/constants';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
export const i18n = {
moreInfo: s__('SecurityReports|More info'),
createIssue: s__('SecurityReports|Create issue'),
createJiraIssue: s__('SecurityReports|Create Jira issue'),
revertDismissVulnerability: s__('SecurityReports|Undo dismiss'),
dismissVulnerability: s__('SecurityReports|Dismiss vulnerability'),
};
export default { export default {
i18n,
name: 'SecurityDashboardActionButtons', name: 'SecurityDashboardActionButtons',
components: { components: {
GlButton, GlButton,
...@@ -82,13 +91,6 @@ export default { ...@@ -82,13 +91,6 @@ export default {
this.$root.$emit(BV_SHOW_MODAL, VULNERABILITY_MODAL_ID); this.$root.$emit(BV_SHOW_MODAL, VULNERABILITY_MODAL_ID);
}, },
}, },
i18n: {
moreInfo: s__('SecurityReports|More info'),
createIssue: s__('SecurityReports|Create issue'),
createJiraIssue: s__('SecurityReports|Create Jira issue'),
revertDismissVulnerability: s__('SecurityReports|Undo dismiss'),
dismissVulnerability: s__('SecurityReports|Dismiss vulnerability'),
},
}; };
</script> </script>
...@@ -103,6 +105,7 @@ export default { ...@@ -103,6 +105,7 @@ export default {
variant="info" variant="info"
category="secondary" category="secondary"
icon="information-o" icon="information-o"
data-testid="more-info"
@click="openModal({ vulnerability })" @click="openModal({ vulnerability })"
/> />
<gl-button <gl-button
...@@ -131,6 +134,7 @@ export default { ...@@ -131,6 +134,7 @@ export default {
variant="warning" variant="warning"
category="secondary" category="secondary"
icon="redo" icon="redo"
data-testid="undo-dismiss"
@click="handleUndoDismiss" @click="handleUndoDismiss"
/> />
<gl-button <gl-button
...@@ -144,6 +148,7 @@ export default { ...@@ -144,6 +148,7 @@ export default {
variant="warning" variant="warning"
category="secondary" category="secondary"
icon="cancel" icon="cancel"
data-testid="dismiss-vulnerability"
@click="handleDismissVulnerability" @click="handleDismissVulnerability"
/> />
</template> </template>
......
import { createWrapper, mount } from '@vue/test-utils'; import { createWrapper, mount } from '@vue/test-utils';
import VulnerabilityActionButtons from 'ee/security_dashboard/components/vulnerability_action_buttons.vue'; import { GlButton } from '@gitlab/ui';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import VulnerabilityActionButtons, {
i18n,
} from 'ee/security_dashboard/components/vulnerability_action_buttons.vue';
import createStore from 'ee/security_dashboard/store'; import createStore from 'ee/security_dashboard/store';
import { VULNERABILITY_MODAL_ID } from 'ee/vue_shared/security_reports/components/constants'; import { VULNERABILITY_MODAL_ID } from 'ee/vue_shared/security_reports/components/constants';
import { BV_SHOW_MODAL } from '~/lib/utils/constants'; import { BV_SHOW_MODAL } from '~/lib/utils/constants';
...@@ -10,18 +14,18 @@ describe('Security Dashboard Action Buttons', () => { ...@@ -10,18 +14,18 @@ describe('Security Dashboard Action Buttons', () => {
let store; let store;
let wrapper; let wrapper;
const createComponent = ({ ...options }) => { const createComponent = ({ ...options }) =>
return mount(VulnerabilityActionButtons, { extendedWrapper(
...options, mount(VulnerabilityActionButtons, {
store, ...options,
}); store,
}; }),
);
const findAllButtons = () => wrapper.findAll('.btn-group .btn'); const findAllButtons = () => wrapper.findAllComponents(GlButton);
const findMoreInfoButton = () => wrapper.find('.js-more-info'); const findMoreInfoButton = () => wrapper.findByTestId('more-info');
const findCreateIssueButton = () => wrapper.find('.js-create-issue'); const findCreateIssueButton = () => wrapper.findByTestId('create-issue');
const findDismissVulnerabilityButton = () => wrapper.find('.js-dismiss-vulnerability'); const findDismissVulnerabilityButton = () => wrapper.findByTestId('dismiss-vulnerability');
const findUndoDismissButton = () => wrapper.find('.js-undo-dismiss'); const findUndoDismissButton = () => wrapper.findByTestId('undo-dismiss');
beforeEach(() => { beforeEach(() => {
store = createStore(); store = createStore();
...@@ -71,6 +75,10 @@ describe('Security Dashboard Action Buttons', () => { ...@@ -71,6 +75,10 @@ describe('Security Dashboard Action Buttons', () => {
expect(findCreateIssueButton().exists()).toBe(true); expect(findCreateIssueButton().exists()).toBe(true);
}); });
it('should render the correct tooltip', () => {
expect(findCreateIssueButton().attributes('title')).toBe(i18n.createIssue);
});
it('should emit an `createIssue` event when clicked', () => { it('should emit an `createIssue` event when clicked', () => {
findCreateIssueButton().trigger('click'); findCreateIssueButton().trigger('click');
...@@ -94,7 +102,7 @@ describe('Security Dashboard Action Buttons', () => { ...@@ -94,7 +102,7 @@ describe('Security Dashboard Action Buttons', () => {
}); });
it('should render the correct tooltip', () => { it('should render the correct tooltip', () => {
expect(findCreateIssueButton().attributes('title')).toBe('Create Jira issue'); expect(findCreateIssueButton().attributes('title')).toBe(i18n.createJiraIssue);
}); });
it('should open a new window when the create-issue button is clicked', () => { it('should open a new window when the create-issue button is clicked', () => {
...@@ -130,7 +138,7 @@ describe('Security Dashboard Action Buttons', () => { ...@@ -130,7 +138,7 @@ describe('Security Dashboard Action Buttons', () => {
}); });
}); });
describe('with a vulnerbility that has an issue', () => { describe('with a vulnerability that has an issue', () => {
beforeEach(() => { beforeEach(() => {
wrapper = createComponent({ wrapper = createComponent({
propsData: { propsData: {
......
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