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.

92 lines
3.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';
2023-03-17 16:20:25 +05:30
const ISSUABLE_TYPE_MR = 'merge_request';
2020-10-24 23:57:45 +05:30
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: {
2023-05-27 22:25:52 +05:30
GlTooltip: createMockDirective('gl-tooltip'),
2021-11-11 11:23:49 +05:30
},
});
2020-10-24 23:57:45 +05:30
};
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;
2023-03-17 16:20:25 +05:30
store.getters.getNoteableData.targetType = issuableType;
2021-11-11 11:23:49 +05:30
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`, () => {
2022-07-16 23:28:13 +05:30
const confidentialEl = findConfidentialIcon();
expect(confidentialEl.exists()).toBe(confidentialStatus);
if (confidentialStatus && !hiddenStatus) {
expect(confidentialEl.props()).toMatchObject({
workspaceType: 'project',
issuableType: 'issue',
});
}
2020-10-24 23:57:45 +05:30
});
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(
2023-03-17 16:20:25 +05:30
`This ${issuableType.replace('_', ' ')} is hidden because its author has been banned`,
2021-11-11 11:23:49 +05:30
);
expect(getBinding(hiddenIcon.element, 'gl-tooltip')).not.toBeUndefined();
}
});
2020-10-24 23:57:45 +05:30
},
);
});
});