Commit 8c9a06c3 authored by Sean McGivern's avatar Sean McGivern

Merge branch '24923_nested_tasks' into 'master'

Fix nested tasks in ordered list

Closes #24923

See merge request !8626
parents c08b1f70 f30ad3ff
...@@ -11,7 +11,7 @@ module Taskable ...@@ -11,7 +11,7 @@ module Taskable
INCOMPLETE = 'incomplete'.freeze INCOMPLETE = 'incomplete'.freeze
ITEM_PATTERN = / ITEM_PATTERN = /
^ ^
(?:\s*[-+*]|(?:\d+\.))? # optional list prefix \s*(?:[-+*]|(?:\d+\.))? # optional list prefix
\s* # optional whitespace prefix \s* # optional whitespace prefix
(\[\s\]|\[[xX]\]) # checkbox (\[\s\]|\[[xX]\]) # checkbox
(\s.+) # followed by whitespace and some text. (\s.+) # followed by whitespace and some text.
......
---
title: Fix nested tasks in ordered list
merge_request: 8626
author:
...@@ -300,6 +300,20 @@ You can add task lists to issues, merge requests and comments. To create a task ...@@ -300,6 +300,20 @@ You can add task lists to issues, merge requests and comments. To create a task
- [x] Sub-task 2 - [x] Sub-task 2
- [ ] Sub-task 3 - [ ] Sub-task 3
Tasks formatted as ordered lists are supported as well:
```no-highlight
1. [x] Completed task
1. [ ] Incomplete task
1. [ ] Sub-task 1
1. [x] Sub-task 2
```
1. [x] Completed task
1. [ ] Incomplete task
1. [ ] Sub-task 1
1. [x] Sub-task 2
Task lists can only be created in descriptions, not in titles. Task item state can be managed by editing the description's Markdown or by toggling the rendered check boxes. Task lists can only be created in descriptions, not in titles. Task item state can be managed by editing the description's Markdown or by toggling the rendered check boxes.
### Videos ### Videos
......
...@@ -36,6 +36,19 @@ feature 'Task Lists', feature: true do ...@@ -36,6 +36,19 @@ feature 'Task Lists', feature: true do
MARKDOWN MARKDOWN
end end
let(:nested_tasks_markdown) do
<<-EOT.strip_heredoc
- [ ] Task a
- [x] Task a.1
- [ ] Task a.2
- [ ] Task b
1. [ ] Task 1
1. [ ] Task 1.1
1. [x] Task 1.2
EOT
end
before do before do
Warden.test_mode! Warden.test_mode!
...@@ -123,6 +136,35 @@ feature 'Task Lists', feature: true do ...@@ -123,6 +136,35 @@ feature 'Task Lists', feature: true do
expect(page).to have_content("1 of 1 task completed") expect(page).to have_content("1 of 1 task completed")
end end
end end
describe 'nested tasks', js: true do
let(:issue) { create(:issue, description: nested_tasks_markdown, author: user, project: project) }
before { visit_issue(project, issue) }
it 'renders' do
expect(page).to have_selector('ul.task-list', count: 2)
expect(page).to have_selector('li.task-list-item', count: 7)
expect(page).to have_selector('ul input[checked]', count: 1)
expect(page).to have_selector('ol input[checked]', count: 1)
end
it 'solves tasks' do
expect(page).to have_content("2 of 7 tasks completed")
page.find('li.task-list-item', text: 'Task b').find('input').click
page.find('li.task-list-item ul li.task-list-item', text: 'Task a.2').find('input').click
page.find('li.task-list-item ol li.task-list-item', text: 'Task 1.1').find('input').click
expect(page).to have_content("5 of 7 tasks completed")
visit_issue(project, issue) # reload to see new system notes
expect(page).to have_content('marked the task Task b as complete')
expect(page).to have_content('marked the task Task a.2 as complete')
expect(page).to have_content('marked the task Task 1.1 as complete')
end
end
end end
describe 'for Notes' do describe 'for Notes' do
......
...@@ -33,6 +33,30 @@ shared_examples 'a Taskable' do ...@@ -33,6 +33,30 @@ shared_examples 'a Taskable' do
end end
end end
describe 'with nested tasks' do
before do
subject.description = <<-EOT.strip_heredoc
- [ ] Task a
- [x] Task a.1
- [ ] Task a.2
- [ ] Task b
1. [ ] Task 1
1. [ ] Task 1.1
1. [ ] Task 1.2
1. [x] Task 2
1. [x] Task 2.1
EOT
end
it 'returns the correct task status' do
expect(subject.task_status).to match('3 of')
expect(subject.task_status).to match('9 tasks completed')
expect(subject.task_status_short).to match('3/')
expect(subject.task_status_short).to match('9 tasks')
end
end
describe 'with an incomplete task' do describe 'with an incomplete task' do
before do before do
subject.description = <<-EOT.strip_heredoc subject.description = <<-EOT.strip_heredoc
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment