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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

88 lines
3 KiB
JavaScript
Raw Normal View History

2022-01-26 12:08:38 +05:30
import Vue from 'vue';
2020-10-24 23:57:45 +05:30
import Vuex from 'vuex';
2021-11-11 11:23:49 +05:30
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
2020-10-24 23:57:45 +05:30
import { createStore as createMrStore } from '~/mr_notes/stores';
2021-03-11 19:13:27 +05:30
import createIssueStore from '~/notes/stores';
2022-01-26 12:08:38 +05:30
import IssuableHeaderWarnings from '~/issuable/components/issuable_header_warnings.vue';
2020-10-24 23:57:45 +05:30
const ISSUABLE_TYPE_ISSUE = 'issue';
const ISSUABLE_TYPE_MR = 'merge request';
2022-01-26 12:08:38 +05:30
Vue.use(Vuex);
2020-10-24 23:57:45 +05:30
describe('IssuableHeaderWarnings', () => {
let wrapper;
2021-11-11 11:23:49 +05:30
const findConfidentialIcon = () => wrapper.findByTestId('confidential');
const findLockedIcon = () => wrapper.findByTestId('locked');
const findHiddenIcon = () => wrapper.findByTestId('hidden');
2020-10-24 23:57:45 +05:30
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-11-11 11:23:49 +05:30
const createComponent = ({ store, provide }) => {
wrapper = shallowMountExtended(IssuableHeaderWarnings, {
store,
provide,
directives: {
GlTooltip: createMockDirective(),
},
});
2020-10-24 23:57:45 +05:30
};
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
describe.each`
issuableType
${ISSUABLE_TYPE_ISSUE} | ${ISSUABLE_TYPE_MR}
`(`when issuableType=$issuableType`, ({ issuableType }) => {
describe.each`
2021-11-11 11:23:49 +05:30
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-10-24 23:57:45 +05:30
`(
2021-11-11 11:23:49 +05:30
`when locked=$lockStatus, confidential=$confidentialStatus, and hidden=$hiddenStatus`,
({ lockStatus, confidentialStatus, hiddenStatus }) => {
const store = issuableType === ISSUABLE_TYPE_ISSUE ? createIssueStore() : createMrStore();
2020-10-24 23:57:45 +05:30
beforeEach(() => {
2021-11-11 11:23:49 +05:30
store.getters.getNoteableData.confidential = confidentialStatus;
store.getters.getNoteableData.discussion_locked = lockStatus;
createComponent({ store, provide: { hidden: hiddenStatus } });
2020-10-24 23:57:45 +05:30
});
it(`${renderTestMessage(lockStatus)} the locked icon`, () => {
expect(findLockedIcon().exists()).toBe(lockStatus);
});
it(`${renderTestMessage(confidentialStatus)} the confidential icon`, () => {
expect(findConfidentialIcon().exists()).toBe(confidentialStatus);
});
2021-11-11 11:23:49 +05:30
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-10-24 23:57:45 +05:30
},
);
});
});