Merge branch '24923_nested_tasks' into 'master'

Fix nested tasks in ordered list

Closes #24923

See merge request !8626
This commit is contained in:
Sean McGivern 2017-01-24 17:18:48 +00:00
commit 8c9a06c37c
5 changed files with 89 additions and 5 deletions

View file

@ -11,7 +11,7 @@ module Taskable
INCOMPLETE = 'incomplete'.freeze
ITEM_PATTERN = /
^
(?:\s*[-+*]|(?:\d+\.))? # optional list prefix
\s*(?:[-+*]|(?:\d+\.))? # optional list prefix
\s* # optional whitespace prefix
(\[\s\]|\[[xX]\]) # checkbox
(\s.+) # followed by whitespace and some text.

View file

@ -0,0 +1,4 @@
---
title: Fix nested tasks in ordered list
merge_request: 8626
author:

View file

@ -300,6 +300,20 @@ You can add task lists to issues, merge requests and comments. To create a task
- [x] Sub-task 2
- [ ] 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.
### Videos

View file

@ -36,6 +36,19 @@ feature 'Task Lists', feature: true do
MARKDOWN
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
Warden.test_mode!
@ -123,6 +136,35 @@ feature 'Task Lists', feature: true do
expect(page).to have_content("1 of 1 task completed")
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
describe 'for Notes' do

View file

@ -33,6 +33,30 @@ shared_examples 'a Taskable' do
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
before do
subject.description = <<-EOT.strip_heredoc