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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
require 'spec_helper'
shared_examples 'discussion comments' do |resource_name|
let(:form_selector) { '.js-main-target-form' }
let(:dropdown_selector) { "#{form_selector} .comment-type-dropdown" }
let(:toggle_selector) { "#{dropdown_selector} .dropdown-toggle" }
let(:menu_selector) { "#{dropdown_selector} .dropdown-menu" }
let(:submit_selector) { "#{form_selector} .js-comment-submit-button" }
let(:close_selector) { "#{form_selector} .btn-comment-and-close" }
it 'should show a comment type toggle' do
expect(page).to have_selector toggle_selector
end
describe 'when the toggle is clicked' do
before do
find("#{form_selector} .note-textarea").send_keys('a')
find(toggle_selector).click
end
it 'opens a comment type dropdown with "Comment" and "Start discussion"' do
expect(page).to have_selector menu_selector
end
it 'has a "Comment" item' do
menu = find(menu_selector)
expect(menu).to have_content 'Comment'
expect(menu).to have_content "Add a general comment to this #{resource_name}."
end
it 'has a "Start discussion" item' do
menu = find(menu_selector)
expect(menu).to have_content 'Start discussion'
expect(menu).to have_content 'Discuss a specific suggestion or question that needs to be resolved.'
end
it 'has the "Comment" item selected by default' do
find("#{menu_selector} li", match: :first)
items = all("#{menu_selector} li")
expect(items.first).to have_content 'Comment'
expect(items.first).to have_selector '.fa-check'
expect(items.first['class']).to match 'droplab-item-selected'
expect(items.last).to have_content 'Start discussion'
expect(items.last).not_to have_selector '.fa-check'
expect(items.last['class']).not_to match 'droplab-item-selected'
end
it '"Comment" will post a comment' do
find(submit_selector).click
find('.timeline .timeline-entry', match: :first)
new_comment = all('.timeline .timeline-entry').last
expect(new_comment).to have_content 'a'
expect(new_comment).not_to have_selector '.discussion'
end
if resource_name =~ /(issue|merge request)/
it "Comment & close' will post a comment and close the #{resource_name}" do
find(close_selector).click
find('.timeline .timeline-entry', match: :first)
entries = all('.timeline .timeline-entry')
close_note = entries.last
new_comment = entries[-2]
expect(close_note).to have_content 'closed'
expect(new_comment).not_to have_selector '.discussion'
end
end
it 'closes the menu when clicking the toggle' do
find(toggle_selector).click
expect(page).not_to have_selector menu_selector
end
it 'closes the menu when clicking the body' do
find('body').click
expect(page).not_to have_selector menu_selector
end
describe 'when selecting "Start discussion"' do
before do
find("#{menu_selector} li", match: :first)
first("#{menu_selector} li").click
end
it 'updates the note_type input to "DiscussionNote"' do
expect(find("#{form_selector} #note_type").value).to be 'DiscussionNote'
end
it 'updates the submit button text' do
expect(find(dropdown_selector)).to have_content "Start discussion"
end
if resource_name =~ /(issue|merge request)/
it 'updates the close button text' do
expect(find(close_selector)).to have_content "Start discussion & close #{resource_name}"
end
end
it 'closes the dropdown' do
expect(page).not_to have_selector menu_selector
end
it '"Start discussion" will post a discussion' do
find(submit_selector).click
find('.timeline .timeline-entry', match: :first)
new_comment = all('.timeline .timeline-entry').last
expect(new_comment).to have_content 'a'
expect(new_comment).to have_selector '.discussion'
end
if resource_name =~ /(issue|merge request)/
it "'Start discussion & close' will post a discussion and close the #{resource_name}" do
find(close_selector).click
find('.timeline .timeline-entry', match: :first)
entries = all('.timeline .timeline-entry')
close_note = entries.last
new_discussion = entries[-2]
expect(close_note).to have_content 'closed'
expect(new_discussion).to have_selector '.discussion'
end
end
describe 'when opening the menu' do
before do
find(toggle_selector).click
end
it 'should have "Start discussion" selected' do
find("#{menu_selector} li", match: :first)
items = all("#{menu_selector} li")
expect(items.first).to have_content 'Comment'
expect(items.first).not_to have_selector '.fa-check'
expect(items.first).not_to have_selector '.droplab-item-selected'
expect(items.last).to have_content 'Start discussion'
expect(items.last).to have_selector '.fa-check'
expect(items.last).to have_selector '.droplab-item-selected'
end
describe 'when selecting "Comment"' do
before do
find("#{menu_selector} li", match: :first)
all("#{menu_selector} li").last.click
end
it 'clears the note_type input"' do
expect(find("#{form_selector} #note_type").value).to be ''
end
it 'updates the submit button text' do
expect(find(dropdown_selector)).to have_content "Comment"
end
if resource_name =~ /(issue|merge request)/
it 'updates the close button text' do
expect(find(close_selector)).to have_content "Comment & close #{resource_name}"
end
end
it 'closes the dropdown' do
expect(page).not_to have_selector menu_selector
end
it 'should have "Comment" selected when opening the menu' do
find(toggle_selector).click
find("#{menu_selector} li", match: :first)
items = all("#{menu_selector} li")
expect(items.first).to have_content 'Comment'
expect(items.first).to have_selector '.fa-check'
expect(items.first).to have_selector '.droplab-item-selected'
expect(items.last).to have_content 'Start discussion'
expect(items.last).not_to have_selector '.fa-check'
expect(items.last).not_to have_selector '.droplab-item-selected'
end
end
end
end
end
if resource_name =~ /(issue|merge request)/
describe "on a closed #{resource_name}" do
end
end
end
describe 'Discussion Comments', :feature, :js do
include RepoHelpers
let(:user) { create(:user) }
let(:project) { create(:project) }
before do
project.team << [user, :developer]
login_as(user)
end
describe 'on a merge request' do
let(:merge_request) { create(:merge_request, source_project: project) }
before do
visit namespace_project_merge_request_path(project.namespace, project, merge_request)
end
it_behaves_like 'discussion comments', 'merge request'
end
describe 'on an issue' do
let(:issue) { create(:issue, project: project) }
before do
visit namespace_project_issue_path(project.namespace, project, issue)
end
it_behaves_like 'discussion comments', 'issue'
end
describe 'on an snippet' do
let(:snippet) { create(:personal_snippet, :public, author: user) }
before do
visit snippet_path(snippet)
end
it_behaves_like 'discussion comments', 'snippet'
end
describe 'on a commit' do
before do
visit namespace_project_commit_path(project.namespace, project, sample_commit.id)
end
it_behaves_like 'discussion comments', 'commit'
end
end
|