diff options
author | Marin Jankovski <maxlazio@gmail.com> | 2014-10-06 17:29:06 +0200 |
---|---|---|
committer | Marin Jankovski <maxlazio@gmail.com> | 2014-10-06 17:29:06 +0200 |
commit | 0fed1b587630ff98808c61881511ee7c077c3db6 (patch) | |
tree | 8b164d6ac47fb33157952094184eb2f529a41a0c /spec | |
parent | 0c291f35f5324d159155d16aa632fad412a2d3a3 (diff) | |
parent | 31bc42de57b3cfd7bf068df06d15372307b8661b (diff) | |
download | gitlab-ce-0fed1b587630ff98808c61881511ee7c077c3db6.tar.gz |
Merge pull request #7964 from mr-vinn/task-lists
Add task lists to issues and merge requests
Diffstat (limited to 'spec')
-rw-r--r-- | spec/helpers/gitlab_markdown_helper_spec.rb | 101 | ||||
-rw-r--r-- | spec/models/issue_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 4 | ||||
-rw-r--r-- | spec/support/taskable_shared_examples.rb | 42 |
4 files changed, 150 insertions, 1 deletions
diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index 73b3d91e96e..15033f07432 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -616,7 +616,7 @@ describe GitlabMarkdownHelper do end end - describe "markdwon for empty repository" do + describe 'markdown for empty repository' do before do @project = empty_project @repository = empty_project.repository @@ -652,4 +652,103 @@ describe GitlabMarkdownHelper do helper.render_wiki_content(@wiki) end end + + describe '#gfm_with_tasks' do + before(:all) do + @source_text_asterisk = <<EOT.gsub(/^\s{8}/, '') + * [ ] valid unchecked task + * [x] valid lowercase checked task + * [X] valid uppercase checked task + * [ ] valid unchecked nested task + * [x] valid checked nested task + + [ ] not an unchecked task - no list item + [x] not a checked task - no list item + + * [ ] not an unchecked task - too many spaces + * [x ] not a checked task - too many spaces + * [] not an unchecked task - no spaces + * Not a task [ ] - not at beginning +EOT + + @source_text_dash = <<EOT.gsub(/^\s{8}/, '') + - [ ] valid unchecked task + - [x] valid lowercase checked task + - [X] valid uppercase checked task + - [ ] valid unchecked nested task + - [x] valid checked nested task +EOT + end + + it 'should render checkboxes at beginning of asterisk list items' do + rendered_text = markdown(@source_text_asterisk, parse_tasks: true) + + expect(rendered_text).to match(/<input.*checkbox.*valid unchecked task/) + expect(rendered_text).to match( + /<input.*checkbox.*valid lowercase checked task/ + ) + expect(rendered_text).to match( + /<input.*checkbox.*valid uppercase checked task/ + ) + end + + it 'should render checkboxes at beginning of dash list items' do + rendered_text = markdown(@source_text_dash, parse_tasks: true) + + expect(rendered_text).to match(/<input.*checkbox.*valid unchecked task/) + expect(rendered_text).to match( + /<input.*checkbox.*valid lowercase checked task/ + ) + expect(rendered_text).to match( + /<input.*checkbox.*valid uppercase checked task/ + ) + end + + it 'should not be confused by whitespace before bullets' do + rendered_text_asterisk = markdown(@source_text_asterisk, + parse_tasks: true) + rendered_text_dash = markdown(@source_text_dash, parse_tasks: true) + + expect(rendered_text_asterisk).to match( + /<input.*checkbox.*valid unchecked nested task/ + ) + expect(rendered_text_asterisk).to match( + /<input.*checkbox.*valid checked nested task/ + ) + expect(rendered_text_dash).to match( + /<input.*checkbox.*valid unchecked nested task/ + ) + expect(rendered_text_dash).to match( + /<input.*checkbox.*valid checked nested task/ + ) + end + + it 'should not render checkboxes outside of list items' do + rendered_text = markdown(@source_text_asterisk, parse_tasks: true) + + expect(rendered_text).not_to match( + /<input.*checkbox.*not an unchecked task - no list item/ + ) + expect(rendered_text).not_to match( + /<input.*checkbox.*not a checked task - no list item/ + ) + end + + it 'should not render checkboxes with invalid formatting' do + rendered_text = markdown(@source_text_asterisk, parse_tasks: true) + + expect(rendered_text).not_to match( + /<input.*checkbox.*not an unchecked task - too many spaces/ + ) + expect(rendered_text).not_to match( + /<input.*checkbox.*not a checked task - too many spaces/ + ) + expect(rendered_text).not_to match( + /<input.*checkbox.*not an unchecked task - no spaces/ + ) + expect(rendered_text).not_to match( + /Not a task.*<input.*checkbox.*not at beginning/ + ) + end + end end diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 8b299cea67c..6b6efe832e5 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -60,4 +60,8 @@ describe Issue do let(:backref_text) { "issue ##{subject.iid}" } let(:set_mentionable_text) { ->(txt){ subject.description = txt } } end + + it_behaves_like 'a Taskable' do + let(:subject) { create :issue } + end end diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index c40f75290ed..7b0d261d72f 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -119,4 +119,8 @@ describe MergeRequest do let(:backref_text) { "merge request !#{subject.iid}" } let(:set_mentionable_text) { ->(txt){ subject.title = txt } } end + + it_behaves_like 'a Taskable' do + let(:subject) { create :merge_request, :simple } + end end diff --git a/spec/support/taskable_shared_examples.rb b/spec/support/taskable_shared_examples.rb new file mode 100644 index 00000000000..42252675683 --- /dev/null +++ b/spec/support/taskable_shared_examples.rb @@ -0,0 +1,42 @@ +# Specs for task state functionality for issues and merge requests. +# +# Requires a context containing: +# let(:subject) { Issue or MergeRequest } +shared_examples 'a Taskable' do + before do + subject.description = <<EOT.gsub(/ {6}/, '') + * [ ] Task 1 + * [x] Task 2 + * [x] Task 3 + * [ ] Task 4 + * [ ] Task 5 +EOT + end + + it 'updates the Nth task correctly' do + subject.update_nth_task(1, true) + expect(subject.description).to match(/\[x\] Task 1/) + + subject.update_nth_task(2, true) + expect(subject.description).to match('\[x\] Task 2') + + subject.update_nth_task(3, false) + expect(subject.description).to match('\[ \] Task 3') + + subject.update_nth_task(4, false) + expect(subject.description).to match('\[ \] Task 4') + end + + it 'returns the correct task status' do + expect(subject.task_status).to match('5 tasks') + expect(subject.task_status).to match('2 done') + expect(subject.task_status).to match('3 unfinished') + end + + it 'knows if it has tasks' do + expect(subject.tasks?).to be_true + + subject.description = 'Now I have no tasks' + expect(subject.tasks?).to be_false + end +end |