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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
import { GlIcon, GlSprintf } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import NoteableWarning from '~/vue_shared/components/notes/noteable_warning.vue';
describe('Issue Warning Component', () => {
let wrapper;
const findIcon = (w = wrapper) => w.findComponent(GlIcon);
const findLockedBlock = (w = wrapper) => w.findComponent({ ref: 'locked' });
const findConfidentialBlock = (w = wrapper) => w.findComponent({ ref: 'confidential' });
const findLockedAndConfidentialBlock = (w = wrapper) =>
w.findComponent({ ref: 'lockedAndConfidential' });
const createComponent = (props) =>
shallowMount(NoteableWarning, {
propsData: {
...props,
},
stubs: {
GlSprintf,
},
});
describe('when issue is locked but not confidential', () => {
beforeEach(() => {
wrapper = createComponent({
isLocked: true,
lockedNoteableDocsPath: 'locked-path',
isConfidential: false,
});
});
it('renders information about locked issue', () => {
expect(findLockedBlock().exists()).toBe(true);
expect(findLockedBlock().element).toMatchSnapshot();
});
it('renders warning icon', () => {
expect(findIcon().exists()).toBe(true);
});
it('does not render information about locked and confidential issue', () => {
expect(findLockedAndConfidentialBlock().exists()).toBe(false);
});
it('does not render information about confidential issue', () => {
expect(findConfidentialBlock().exists()).toBe(false);
});
});
describe('when noteable is confidential but not locked', () => {
beforeEach(() => {
wrapper = createComponent({
isLocked: false,
isConfidential: true,
confidentialNoteableDocsPath: 'confidential-path',
});
});
it('renders information about confidential issue', async () => {
expect(findConfidentialBlock().exists()).toBe(true);
expect(findConfidentialBlock().element).toMatchSnapshot();
await nextTick();
expect(findConfidentialBlock(wrapper).text()).toContain('This is a confidential issue.');
});
it('renders warning icon', () => {
expect(wrapper.findComponent(GlIcon).exists()).toBe(true);
});
it('does not render information about locked noteable', () => {
expect(findLockedBlock().exists()).toBe(false);
});
it('does not render information about locked and confidential noteable', () => {
expect(findLockedAndConfidentialBlock().exists()).toBe(false);
});
});
describe('when noteable is locked and confidential', () => {
beforeEach(() => {
wrapper = createComponent({
isLocked: true,
isConfidential: true,
});
});
it('renders information about locked and confidential noteable', () => {
expect(findLockedAndConfidentialBlock().exists()).toBe(true);
expect(findLockedAndConfidentialBlock().element).toMatchSnapshot();
});
it('does not render warning icon', () => {
expect(wrapper.findComponent(GlIcon).exists()).toBe(false);
});
it('does not render information about locked noteable', () => {
expect(findLockedBlock().exists()).toBe(false);
});
it('does not render information about confidential noteable', () => {
expect(findConfidentialBlock().exists()).toBe(false);
});
});
describe('when noteableType prop is defined', () => {
let wrapperLocked;
let wrapperConfidential;
let wrapperLockedAndConfidential;
beforeEach(() => {
wrapperLocked = createComponent({
isLocked: true,
isConfidential: false,
});
wrapperConfidential = createComponent({
isLocked: false,
isConfidential: true,
});
wrapperLockedAndConfidential = createComponent({
isLocked: true,
isConfidential: true,
});
});
it('renders confidential & locked messages with noteable "issue"', () => {
expect(findLockedBlock(wrapperLocked).text()).toContain(
'The discussion in this issue is locked.',
);
expect(findConfidentialBlock(wrapperConfidential).text()).toContain(
'This is a confidential issue.',
);
expect(findLockedAndConfidentialBlock(wrapperLockedAndConfidential).text()).toContain(
'This issue is confidential and its discussion is locked.',
);
});
it('renders confidential & locked messages with noteable "epic"', async () => {
wrapperLocked.setProps({
noteableType: 'Epic',
});
wrapperConfidential.setProps({
noteableType: 'Epic',
});
wrapperLockedAndConfidential.setProps({
noteableType: 'Epic',
});
await nextTick();
expect(findLockedBlock(wrapperLocked).text()).toContain(
'The discussion in this epic is locked.',
);
await nextTick();
expect(findConfidentialBlock(wrapperConfidential).text()).toContain(
'This is a confidential epic.',
);
await nextTick();
expect(findLockedAndConfidentialBlock(wrapperLockedAndConfidential).text()).toContain(
'This epic is confidential and its discussion is locked.',
);
});
it('renders confidential & locked messages with noteable "merge request"', async () => {
wrapperLocked.setProps({
noteableType: 'MergeRequest',
});
wrapperConfidential.setProps({
noteableType: 'MergeRequest',
});
wrapperLockedAndConfidential.setProps({
noteableType: 'MergeRequest',
});
await nextTick();
expect(findLockedBlock(wrapperLocked).text()).toContain(
'The discussion in this merge request is locked.',
);
await nextTick();
expect(findConfidentialBlock(wrapperConfidential).text()).toContain(
'This is a confidential merge request.',
);
await nextTick();
expect(findLockedAndConfidentialBlock(wrapperLockedAndConfidential).text()).toContain(
'This merge request is confidential and its discussion is locked.',
);
});
});
});
|