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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
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 findConfidentialIcon = () => wrapper.findComponent(ConfidentialityBadge);
const findLockedIcon = () => wrapper.findByTestId('locked');
const findHiddenIcon = () => wrapper.findByTestId('hidden');
const renderTestMessage = (renders) => (renders ? 'renders' : 'does not render');
const createComponent = ({ store, provide }) => {
wrapper = shallowMountExtended(HeaderMetadata, {
mocks: {
$store: store,
},
provide,
directives: {
GlTooltip: createMockDirective('gl-tooltip'),
},
});
};
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(lockStatus)} the locked icon`, () => {
const lockedIcon = findLockedIcon();
expect(lockedIcon.exists()).toBe(lockStatus);
if (lockStatus) {
expect(lockedIcon.attributes('title')).toBe(
`This merge request is locked. Only project members can comment.`,
);
expect(getBinding(lockedIcon.element, 'gl-tooltip')).not.toBeUndefined();
}
});
it(`${renderTestMessage(confidentialStatus)} the confidential icon`, () => {
const confidentialIcon = findConfidentialIcon();
expect(confidentialIcon.exists()).toBe(confidentialStatus);
if (confidentialStatus && !hiddenStatus) {
expect(confidentialIcon.props()).toMatchObject({
workspaceType: 'project',
issuableType: 'issue',
});
}
});
it(`${renderTestMessage(confidentialStatus)} the hidden icon`, () => {
const hiddenIcon = findHiddenIcon();
expect(hiddenIcon.exists()).toBe(hiddenStatus);
if (hiddenStatus) {
expect(hiddenIcon.attributes('title')).toBe(
`This merge request is hidden because its author has been banned`,
);
expect(getBinding(hiddenIcon.element, 'gl-tooltip')).not.toBeUndefined();
}
});
},
);
});
|