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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Task Lists', :js, feature_category: :team_planning do
include Warden::Test::Helpers
let_it_be(:project) { create(:project, :public, :repository) }
let_it_be(:user) { create(:user) }
let_it_be(:user2) { create(:user) }
let(:markdown) do
<<-MARKDOWN.strip_heredoc
This is a task list:
- [ ] Incomplete entry 1
- [x] Complete entry 1
- [ ] Incomplete entry 2
- [x] Complete entry 2
- [ ] Incomplete entry 3
- [ ] Incomplete entry 4
MARKDOWN
end
let(:single_incomplete_markdown) do
<<-MARKDOWN.strip_heredoc
This is a task list:
- [ ] Incomplete entry 1
MARKDOWN
end
let(:single_complete_markdown) do
<<-MARKDOWN.strip_heredoc
This is a task list:
- [x] Incomplete entry 1
MARKDOWN
end
before_all do
project.add_maintainer(user)
project.add_guest(user2)
end
before do
sign_in(user)
end
def visit_issue(project, issue)
visit project_issue_path(project, issue)
end
describe 'for Issues' do
describe 'multiple tasks' do
let!(:issue) { create(:issue, description: markdown, author: user, project: project) }
it 'renders' do
visit_issue(project, issue)
wait_for_requests
expect(page).to have_selector('ul.task-list', count: 1)
expect(page).to have_selector('li.task-list-item', count: 6)
expect(page).to have_selector('ul input[checked]', count: 2)
end
it 'contains the required selectors' do
visit_issue(project, issue)
wait_for_requests
expect(page).to have_selector(".md .task-list .task-list-item .task-list-item-checkbox")
expect(page).to have_selector('.btn-close')
end
it 'is only editable by author' do
visit_issue(project, issue)
wait_for_requests
expect(page).to have_selector(".md .task-list .task-list-item .task-list-item-checkbox")
logout(:user)
login_as(user2)
visit current_path
wait_for_requests
expect(page).to have_selector(".md .task-list .task-list-item .task-list-item-checkbox")
end
it 'provides a summary on Issues#index' do
visit project_issues_path(project)
expect(page).to have_content("2 of 6 checklist items completed")
end
end
describe 'single incomplete task' do
let!(:issue) { create(:issue, description: single_incomplete_markdown, author: user, project: project) }
it 'renders' do
visit_issue(project, issue)
wait_for_requests
expect(page).to have_selector('ul.task-list', count: 1)
expect(page).to have_selector('li.task-list-item', count: 1)
expect(page).to have_selector('ul input[checked]', count: 0)
end
it 'provides a summary on Issues#index' do
visit project_issues_path(project)
expect(page).to have_content("0 of 1 checklist item completed")
end
end
describe 'single complete task' do
let!(:issue) { create(:issue, description: single_complete_markdown, author: user, project: project) }
it 'renders' do
visit_issue(project, issue)
wait_for_requests
expect(page).to have_selector('ul.task-list', count: 1)
expect(page).to have_selector('li.task-list-item', count: 1)
expect(page).to have_selector('ul input[checked]', count: 1)
end
it 'provides a summary on Issues#index' do
visit project_issues_path(project)
expect(page).to have_content("1 of 1 checklist item completed")
end
end
end
describe 'for Notes' do
let!(:issue) { create(:issue, author: user, project: project) }
describe 'multiple tasks' do
let!(:note) do
create(:note, note: markdown, noteable: issue, project: project, author: user)
end
it 'renders for note body' do
visit_issue(project, issue)
expect(page).to have_selector('.note ul.task-list', count: 1)
expect(page).to have_selector('.note li.task-list-item', count: 6)
expect(page).to have_selector('.note ul input[checked]', count: 2)
end
it 'contains the required selectors' do
visit_issue(project, issue)
expect(page).to have_selector('.note .js-task-list-container')
expect(page).to have_selector('.note .js-task-list-container .task-list .task-list-item .task-list-item-checkbox')
end
it 'is only editable by author' do
visit_issue(project, issue)
expect(page).to have_selector('.js-task-list-container')
gitlab_sign_out
gitlab_sign_in(user2)
visit current_path
expect(page).not_to have_selector('.js-task-list-container')
end
end
describe 'single incomplete task' do
let!(:note) do
create(:note, note: single_incomplete_markdown, noteable: issue, project: project, author: user)
end
it 'renders for note body' do
visit_issue(project, issue)
expect(page).to have_selector('.note ul.task-list', count: 1)
expect(page).to have_selector('.note li.task-list-item', count: 1)
expect(page).to have_selector('.note ul input[checked]', count: 0)
end
end
describe 'single complete task' do
let!(:note) do
create(:note, note: single_complete_markdown, noteable: issue, project: project, author: user)
end
it 'renders for note body' do
visit_issue(project, issue)
expect(page).to have_selector('.note ul.task-list', count: 1)
expect(page).to have_selector('.note li.task-list-item', count: 1)
expect(page).to have_selector('.note ul input[checked]', count: 1)
end
end
end
describe 'for Merge Requests' do
def visit_merge_request(project, merge)
visit project_merge_request_path(project, merge)
end
shared_examples 'multiple tasks' do
it 'renders for description' do
visit_merge_request(project, merge)
wait_for_requests
expect(page).to have_selector('ul.task-list', count: 1)
expect(page).to have_selector('li.task-list-item', count: 6)
expect(page).to have_selector('ul input[checked]', count: 2)
end
it 'contains the required selectors' do
visit_merge_request(project, merge)
wait_for_requests
container = '.detail-page-description .description.js-task-list-container'
expect(page).to have_selector(container)
expect(page).to have_selector("#{container} .md .task-list .task-list-item .task-list-item-checkbox")
expect(page).to have_selector("#{container} .js-task-list-field", visible: false)
expect(page).to have_selector('form.js-issuable-update')
end
it 'is only editable by author' do
visit_merge_request(project, merge)
wait_for_requests
expect(page).to have_selector('.js-task-list-container')
expect(page).to have_selector('li.task-list-item.enabled', count: 6)
logout(:user)
login_as(user2)
visit current_path
wait_for_requests
expect(page).not_to have_selector('.js-task-list-container')
expect(page).to have_selector('li.task-list-item.enabled', count: 0)
expect(page).to have_selector('li.task-list-item input[disabled]', count: 6)
end
end
context 'when merge request is open' do
let!(:merge) { create(:merge_request, :simple, description: markdown, author: user, source_project: project) }
it_behaves_like 'multiple tasks'
it 'provides a summary on MergeRequests#index' do
visit project_merge_requests_path(project)
expect(page).to have_content("2 of 6 checklist items completed")
end
end
context 'when merge request is closed' do
let!(:merge) { create(:merge_request, :closed, :simple, description: markdown, author: user, source_project: project) }
it_behaves_like 'multiple tasks'
end
describe 'single incomplete task' do
let!(:merge) { create(:merge_request, :simple, description: single_incomplete_markdown, author: user, source_project: project) }
it 'renders for description' do
visit_merge_request(project, merge)
wait_for_requests
expect(page).to have_selector('ul.task-list', count: 1)
expect(page).to have_selector('li.task-list-item', count: 1)
expect(page).to have_selector('ul input[checked]', count: 0)
end
it 'provides a summary on MergeRequests#index' do
visit project_merge_requests_path(project)
expect(page).to have_content("0 of 1 checklist item completed")
end
end
describe 'single complete task' do
let!(:merge) { create(:merge_request, :simple, description: single_complete_markdown, author: user, source_project: project) }
it 'renders for description' do
visit_merge_request(project, merge)
wait_for_requests
expect(page).to have_selector('ul.task-list', count: 1)
expect(page).to have_selector('li.task-list-item', count: 1)
expect(page).to have_selector('ul input[checked]', count: 1)
end
it 'provides a summary on MergeRequests#index' do
visit project_merge_requests_path(project)
expect(page).to have_content("1 of 1 checklist item completed")
end
end
end
describe 'markdown task edge cases' do
describe 'commented tasks' do
let(:commented_tasks_markdown) do
<<-EOT.strip_heredoc
<!-- comment text -->
text
<!-- - [ ] commented out task -->
<!--
- [ ] a
-->
- [ ] b
EOT
end
let!(:issue) { create(:issue, description: commented_tasks_markdown, author: user, project: project) }
it 'renders' do
visit_issue(project, issue)
wait_for_requests
expect(page).to have_selector('ul.task-list', count: 1)
expect(page).to have_selector('li.task-list-item', count: 1)
expect(page).to have_selector('ul input[checked]', count: 0)
find('.task-list-item-checkbox').click
wait_for_requests
visit_issue(project, issue)
wait_for_requests
expect(page).to have_selector('ul.task-list', count: 1)
expect(page).to have_selector('li.task-list-item', count: 1)
expect(page).to have_selector('ul input[checked]', count: 1)
expect(page).to have_content('1 of 1 checklist item completed')
end
end
describe 'tasks in code blocks' do
let(:code_tasks_markdown) do
<<-EOT.strip_heredoc
```
- [ ] a
```
- [ ] b
EOT
end
let!(:issue) { create(:issue, description: code_tasks_markdown, author: user, project: project) }
it 'renders' do
visit_issue(project, issue)
wait_for_requests
expect(page).to have_selector('ul.task-list', count: 1)
expect(page).to have_selector('li.task-list-item', count: 1)
expect(page).to have_selector('ul input[checked]', count: 0)
find('.task-list-item-checkbox').click
wait_for_requests
visit_issue(project, issue)
wait_for_requests
expect(page).to have_selector('ul.task-list', count: 1)
expect(page).to have_selector('li.task-list-item', count: 1)
expect(page).to have_selector('ul input[checked]', count: 1)
expect(page).to have_content('1 of 1 checklist item completed')
end
end
describe 'summary with no blank line' do
let(:summary_no_blank_line_markdown) do
<<-EOT.strip_heredoc
<details>
<summary>No blank line after summary element breaks task list</summary>
1. [ ] People Ops: do such and such
</details>
* [ ] Task 1
EOT
end
let!(:issue) { create(:issue, description: summary_no_blank_line_markdown, author: user, project: project) }
it 'renders' do
visit_issue(project, issue)
wait_for_requests
expect(page).to have_selector('ul.task-list', count: 1)
expect(page).to have_selector('li.task-list-item', count: 1)
expect(page).to have_selector('ul input[checked]', count: 0)
find('.task-list-item-checkbox').click
wait_for_requests
visit_issue(project, issue)
wait_for_requests
expect(page).to have_selector('ul.task-list', count: 1)
expect(page).to have_selector('li.task-list-item', count: 1)
expect(page).to have_selector('ul input[checked]', count: 1)
end
end
describe 'summary properly formatted' do
let(:summary_markdown) do
<<-EOT.strip_heredoc
<details open>
<summary>Valid detail/summary with tasklist</summary>
- [ ] People Ops: do such and such
</details>
* [x] Task 1
EOT
end
let!(:issue) { create(:issue, description: summary_markdown, author: user, project: project) }
it 'renders' do
visit_issue(project, issue)
wait_for_requests
expect(page).to have_selector('ul.task-list', count: 2)
expect(page).to have_selector('li.task-list-item', count: 2)
expect(page).to have_selector('ul input[checked]', count: 1)
first('.task-list-item-checkbox').click
wait_for_requests
visit_issue(project, issue)
wait_for_requests
expect(page).to have_selector('ul.task-list', count: 2)
expect(page).to have_selector('li.task-list-item', count: 2)
expect(page).to have_selector('ul input[checked]', count: 2)
expect(page).to have_content('2 of 2 checklist items completed')
end
end
describe 'markdown starting with new line character' do
let(:markdown_starting_with_new_line) do
<<-EOT.strip_heredoc
- [ ] Task 1
EOT
end
let(:merge_request) { create(:merge_request, description: markdown_starting_with_new_line, author: user, source_project: project) }
it 'allows the task to be checked' do
visit project_merge_request_path(project, merge_request)
wait_for_requests
expect(page).to have_selector('ul input[checked]', count: 0)
find('.task-list-item-checkbox').click
wait_for_requests
visit project_merge_request_path(project, merge_request)
wait_for_requests
expect(page).to have_selector('ul input[checked]', count: 1)
end
end
end
end
|