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
|
import { shallowMount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import CommentFieldLayout from '~/notes/components/comment_field_layout.vue';
import AttachmentsWarning from '~/notes/components/attachments_warning.vue';
import EmailParticipantsWarning from '~/notes/components/email_participants_warning.vue';
import NoteableWarning from '~/vue_shared/components/notes/noteable_warning.vue';
describe('Comment Field Layout Component', () => {
let wrapper;
const LOCKED_DISCUSSION_DOCS_PATH = 'docs/locked/path';
const CONFIDENTIAL_ISSUES_DOCS_PATH = 'docs/confidential/path';
const noteableDataMock = {
confidential: false,
discussion_locked: false,
locked_discussion_docs_path: LOCKED_DISCUSSION_DOCS_PATH,
confidential_issues_docs_path: CONFIDENTIAL_ISSUES_DOCS_PATH,
};
const commentFieldWithAttachmentData = {
noteableData: {
...noteableDataMock,
issue_email_participants: [{ email: 'someone@gitlab.com' }, { email: 'another@gitlab.com' }],
},
containsLink: true,
};
const findIssuableNoteWarning = () => wrapper.findComponent(NoteableWarning);
const findEmailParticipantsWarning = () => wrapper.findComponent(EmailParticipantsWarning);
const findAttachmentsWarning = () => wrapper.findComponent(AttachmentsWarning);
const findErrorAlert = () => wrapper.findByTestId('comment-field-alert-container');
const createWrapper = (props = {}, provide = {}) => {
wrapper = extendedWrapper(
shallowMount(CommentFieldLayout, {
propsData: {
noteableData: noteableDataMock,
...props,
},
provide: {
glFeatures: {
serviceDeskNewNoteEmailNativeAttachments: true,
},
...provide,
},
}),
);
};
describe('.error-alert', () => {
it('does not exist by default', () => {
createWrapper();
expect(findErrorAlert().exists()).toBe(false);
});
it('exists when withAlertContainer is true', () => {
createWrapper({ withAlertContainer: true });
expect(findErrorAlert().isVisible()).toBe(true);
});
});
describe('issue is not confidential and not locked', () => {
it('does not show IssuableNoteWarning', () => {
createWrapper();
expect(findIssuableNoteWarning().exists()).toBe(false);
});
});
describe('issue is confidential', () => {
beforeEach(() => {
createWrapper({
noteableData: { ...noteableDataMock, confidential: true },
});
});
it('shows IssuableNoteWarning', () => {
expect(findIssuableNoteWarning().isVisible()).toBe(true);
});
it('sets IssuableNoteWarning props', () => {
expect(findIssuableNoteWarning().props()).toMatchObject({
isLocked: false,
isConfidential: true,
lockedNoteableDocsPath: LOCKED_DISCUSSION_DOCS_PATH,
confidentialNoteableDocsPath: CONFIDENTIAL_ISSUES_DOCS_PATH,
});
});
});
describe('issue is locked', () => {
beforeEach(() => {
createWrapper({
noteableData: { ...noteableDataMock, discussion_locked: true },
});
});
it('shows IssuableNoteWarning', () => {
expect(findIssuableNoteWarning().isVisible()).toBe(true);
});
it('sets IssuableNoteWarning props', () => {
expect(findIssuableNoteWarning().props()).toMatchObject({
isConfidential: false,
isLocked: true,
lockedNoteableDocsPath: LOCKED_DISCUSSION_DOCS_PATH,
confidentialNoteableDocsPath: CONFIDENTIAL_ISSUES_DOCS_PATH,
});
});
});
describe('issue has no email participants', () => {
it('does not show EmailParticipantsWarning', () => {
createWrapper();
expect(findEmailParticipantsWarning().exists()).toBe(false);
});
it('does not show AttachmentWarning', () => {
createWrapper();
expect(findAttachmentsWarning().exists()).toBe(false);
});
});
describe('issue has email participants', () => {
beforeEach(() => {
createWrapper(commentFieldWithAttachmentData);
});
it('shows EmailParticipantsWarning', () => {
expect(findEmailParticipantsWarning().exists()).toBe(true);
});
it('shows AttachmentsWarning', () => {
expect(findAttachmentsWarning().isVisible()).toBe(true);
});
it('sets EmailParticipantsWarning props', () => {
expect(findEmailParticipantsWarning().props('emails')).toEqual([
'someone@gitlab.com',
'another@gitlab.com',
]);
});
});
describe('issue has email participants, but note is internal', () => {
it('does not show EmailParticipantsWarning', () => {
createWrapper({
noteableData: {
...noteableDataMock,
issue_email_participants: [{ email: 'someone@gitlab.com' }],
},
isInternalNote: true,
});
expect(findEmailParticipantsWarning().exists()).toBe(false);
});
});
describe('serviceDeskNewNoteEmailNativeAttachments flag', () => {
it('shows warning message when flag is enabled', () => {
createWrapper(commentFieldWithAttachmentData, {
glFeatures: { serviceDeskNewNoteEmailNativeAttachments: true },
});
expect(findAttachmentsWarning().exists()).toBe(true);
});
it('shows warning message when flag is disables', () => {
createWrapper(commentFieldWithAttachmentData, {
glFeatures: { serviceDeskNewNoteEmailNativeAttachments: false },
});
expect(findAttachmentsWarning().exists()).toBe(false);
});
});
});
|