2021-12-08 04:13:01 -05:00
|
|
|
import Vue from 'vue';
|
2020-07-24 05:09:41 -04:00
|
|
|
import Vuex from 'vuex';
|
2021-08-25 05:10:52 -04:00
|
|
|
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
|
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2020-07-24 05:09:41 -04:00
|
|
|
import { createStore as createMrStore } from '~/mr_notes/stores';
|
2021-02-14 13:09:20 -05:00
|
|
|
import createIssueStore from '~/notes/stores';
|
2021-12-06 19:14:07 -05:00
|
|
|
import IssuableHeaderWarnings from '~/issuable/components/issuable_header_warnings.vue';
|
2020-07-24 05:09:41 -04:00
|
|
|
|
|
|
|
const ISSUABLE_TYPE_ISSUE = 'issue';
|
|
|
|
const ISSUABLE_TYPE_MR = 'merge request';
|
|
|
|
|
2021-12-08 04:13:01 -05:00
|
|
|
Vue.use(Vuex);
|
2020-07-24 05:09:41 -04:00
|
|
|
|
|
|
|
describe('IssuableHeaderWarnings', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2021-08-25 05:10:52 -04:00
|
|
|
const findConfidentialIcon = () => wrapper.findByTestId('confidential');
|
|
|
|
const findLockedIcon = () => wrapper.findByTestId('locked');
|
|
|
|
const findHiddenIcon = () => wrapper.findByTestId('hidden');
|
2020-07-24 05:09:41 -04:00
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
const renderTestMessage = (renders) => (renders ? 'renders' : 'does not render');
|
2020-07-24 05:09:41 -04:00
|
|
|
|
2021-08-25 05:10:52 -04:00
|
|
|
const createComponent = ({ store, provide }) => {
|
|
|
|
wrapper = shallowMountExtended(IssuableHeaderWarnings, {
|
|
|
|
store,
|
|
|
|
provide,
|
|
|
|
directives: {
|
|
|
|
GlTooltip: createMockDirective(),
|
|
|
|
},
|
|
|
|
});
|
2020-07-24 05:09:41 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe.each`
|
|
|
|
issuableType
|
|
|
|
${ISSUABLE_TYPE_ISSUE} | ${ISSUABLE_TYPE_MR}
|
|
|
|
`(`when issuableType=$issuableType`, ({ issuableType }) => {
|
|
|
|
describe.each`
|
2021-08-25 05:10:52 -04:00
|
|
|
lockStatus | confidentialStatus | hiddenStatus
|
|
|
|
${true} | ${true} | ${false}
|
|
|
|
${true} | ${false} | ${false}
|
|
|
|
${false} | ${true} | ${false}
|
|
|
|
${false} | ${false} | ${false}
|
|
|
|
${true} | ${true} | ${true}
|
|
|
|
${true} | ${false} | ${true}
|
|
|
|
${false} | ${true} | ${true}
|
|
|
|
${false} | ${false} | ${true}
|
2020-07-24 05:09:41 -04:00
|
|
|
`(
|
2021-08-25 05:10:52 -04:00
|
|
|
`when locked=$lockStatus, confidential=$confidentialStatus, and hidden=$hiddenStatus`,
|
|
|
|
({ lockStatus, confidentialStatus, hiddenStatus }) => {
|
|
|
|
const store = issuableType === ISSUABLE_TYPE_ISSUE ? createIssueStore() : createMrStore();
|
|
|
|
|
2020-07-24 05:09:41 -04:00
|
|
|
beforeEach(() => {
|
2021-08-25 05:10:52 -04:00
|
|
|
store.getters.getNoteableData.confidential = confidentialStatus;
|
|
|
|
store.getters.getNoteableData.discussion_locked = lockStatus;
|
|
|
|
|
|
|
|
createComponent({ store, provide: { hidden: hiddenStatus } });
|
2020-07-24 05:09:41 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it(`${renderTestMessage(lockStatus)} the locked icon`, () => {
|
|
|
|
expect(findLockedIcon().exists()).toBe(lockStatus);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`${renderTestMessage(confidentialStatus)} the confidential icon`, () => {
|
|
|
|
expect(findConfidentialIcon().exists()).toBe(confidentialStatus);
|
|
|
|
});
|
2021-08-25 05:10:52 -04:00
|
|
|
|
|
|
|
it(`${renderTestMessage(confidentialStatus)} the hidden icon`, () => {
|
|
|
|
const hiddenIcon = findHiddenIcon();
|
|
|
|
|
|
|
|
expect(hiddenIcon.exists()).toBe(hiddenStatus);
|
|
|
|
|
|
|
|
if (hiddenStatus) {
|
|
|
|
expect(hiddenIcon.attributes('title')).toBe(
|
|
|
|
'This issue is hidden because its author has been banned',
|
|
|
|
);
|
|
|
|
expect(getBinding(hiddenIcon.element, 'gl-tooltip')).not.toBeUndefined();
|
|
|
|
}
|
|
|
|
});
|
2020-07-24 05:09:41 -04:00
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|