debian-mirror-gitlab/spec/frontend/vue_shared/components/issuable/issuable_header_warnings_spec.js

74 lines
2.2 KiB
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import { createStore as createMrStore } from '~/mr_notes/stores';
2021-03-11 19:13:27 +05:30
import createIssueStore from '~/notes/stores';
import IssuableHeaderWarnings from '~/vue_shared/components/issuable/issuable_header_warnings.vue';
2020-10-24 23:57:45 +05:30
const ISSUABLE_TYPE_ISSUE = 'issue';
const ISSUABLE_TYPE_MR = 'merge request';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('IssuableHeaderWarnings', () => {
let wrapper;
let store;
const findConfidentialIcon = () => wrapper.find('[data-testid="confidential"]');
const findLockedIcon = () => wrapper.find('[data-testid="locked"]');
2021-03-08 18:12:59 +05:30
const renderTestMessage = (renders) => (renders ? 'renders' : 'does not render');
2020-10-24 23:57:45 +05:30
2021-03-08 18:12:59 +05:30
const setLock = (locked) => {
2020-10-24 23:57:45 +05:30
store.getters.getNoteableData.discussion_locked = locked;
};
2021-03-08 18:12:59 +05:30
const setConfidential = (confidential) => {
2020-10-24 23:57:45 +05:30
store.getters.getNoteableData.confidential = confidential;
};
const createComponent = () => {
wrapper = shallowMount(IssuableHeaderWarnings, { store, localVue });
};
afterEach(() => {
wrapper.destroy();
wrapper = null;
store = null;
});
describe.each`
issuableType
${ISSUABLE_TYPE_ISSUE} | ${ISSUABLE_TYPE_MR}
`(`when issuableType=$issuableType`, ({ issuableType }) => {
beforeEach(() => {
store = issuableType === ISSUABLE_TYPE_ISSUE ? createIssueStore() : createMrStore();
createComponent();
});
describe.each`
lockStatus | confidentialStatus
${true} | ${true}
${true} | ${false}
${false} | ${true}
${false} | ${false}
`(
`when locked=$lockStatus and confidential=$confidentialStatus`,
({ lockStatus, confidentialStatus }) => {
beforeEach(() => {
setLock(lockStatus);
setConfidential(confidentialStatus);
});
it(`${renderTestMessage(lockStatus)} the locked icon`, () => {
expect(findLockedIcon().exists()).toBe(lockStatus);
});
it(`${renderTestMessage(confidentialStatus)} the confidential icon`, () => {
expect(findConfidentialIcon().exists()).toBe(confidentialStatus);
});
},
);
});
});