1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
import { shallowMount } from '@vue/test-utils';
import HiddenBadge from '~/issuable/components/hidden_badge.vue';
import LockedBadge from '~/issuable/components/locked_badge.vue';
import HeaderMetadata from '~/merge_requests/components/header_metadata.vue';
import mrStore from '~/mr_notes/stores';
import ConfidentialityBadge from '~/vue_shared/components/confidentiality_badge.vue';
jest.mock('~/mr_notes/stores', () => jest.requireActual('helpers/mocks/mr_notes/stores'));
describe('HeaderMetadata component', () => {
let wrapper;
const findConfidentialBadge = () => wrapper.findComponent(ConfidentialityBadge);
const findLockedBadge = () => wrapper.findComponent(LockedBadge);
const findHiddenBadge = () => wrapper.findComponent(HiddenBadge);
const renderTestMessage = (renders) => (renders ? 'renders' : 'does not render');
const createComponent = ({ store, provide }) => {
wrapper = shallowMount(HeaderMetadata, {
mocks: {
$store: store,
},
provide,
});
};
describe.each`
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}
`(
`when locked=$lockStatus, confidential=$confidentialStatus, and hidden=$hiddenStatus`,
({ lockStatus, confidentialStatus, hiddenStatus }) => {
const store = mrStore;
beforeEach(() => {
store.getters.getNoteableData = {};
store.getters.getNoteableData.confidential = confidentialStatus;
store.getters.getNoteableData.discussion_locked = lockStatus;
store.getters.getNoteableData.targetType = 'merge_request';
createComponent({ store, provide: { hidden: hiddenStatus } });
});
it(`${renderTestMessage(confidentialStatus)} the confidential badge`, () => {
const confidentialBadge = findConfidentialBadge();
expect(confidentialBadge.exists()).toBe(confidentialStatus);
if (confidentialStatus && !hiddenStatus) {
expect(confidentialBadge.props()).toMatchObject({
workspaceType: 'project',
issuableType: 'issue',
});
}
});
it(`${renderTestMessage(lockStatus)} the locked badge`, () => {
expect(findLockedBadge().exists()).toBe(lockStatus);
});
it(`${renderTestMessage(hiddenStatus)} the hidden badge`, () => {
expect(findHiddenBadge().exists()).toBe(hiddenStatus);
});
},
);
});
|