task_lists_spec.rb 8.8 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'Task Lists' do
4 5
  include Warden::Test::Helpers

6
  let(:project) { create(:project, :repository) }
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  let(:user)    { create(:user) }
  let(: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

Clement Ho's avatar
Clement Ho committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
  let(:singleIncompleteMarkdown) do
    <<-MARKDOWN.strip_heredoc
    This is a task list:

    - [ ] Incomplete entry 1
    MARKDOWN
  end

  let(:singleCompleteMarkdown) do
    <<-MARKDOWN.strip_heredoc
    This is a task list:

    - [x] Incomplete entry 1
    MARKDOWN
  end

39 40 41 42 43 44 45 46 47 48 49 50 51
  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

52 53 54
  before do
    Warden.test_mode!

55
    project.add_maintainer(user)
56
    project.add_guest(user2)
57 58 59 60 61

    login_as(user)
  end

  def visit_issue(project, issue)
62
    visit project_issue_path(project, issue)
63 64
  end

65
  describe 'for Issues' do
66
    describe 'multiple tasks', :js do
Clement Ho's avatar
Clement Ho committed
67
      let!(:issue) { create(:issue, description: markdown, author: user, project: project) }
68

Clement Ho's avatar
Clement Ho committed
69 70
      it 'renders' do
        visit_issue(project, issue)
71
        wait_for_requests
72

Clement Ho's avatar
Clement Ho committed
73 74 75 76 77 78 79
        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)
80
        wait_for_requests
Clement Ho's avatar
Clement Ho committed
81

Regis's avatar
Regis committed
82
        expect(page).to have_selector(".wiki .task-list .task-list-item .task-list-item-checkbox")
Clement Ho's avatar
Clement Ho committed
83 84
        expect(page).to have_selector('a.btn-close')
      end
85

Clement Ho's avatar
Clement Ho committed
86 87
      it 'is only editable by author' do
        visit_issue(project, issue)
88
        wait_for_requests
89

Regis's avatar
Regis committed
90
        expect(page).to have_selector(".wiki .task-list .task-list-item .task-list-item-checkbox")
91

Clement Ho's avatar
Clement Ho committed
92 93 94
        logout(:user)
        login_as(user2)
        visit current_path
95
        wait_for_requests
Regis's avatar
Regis committed
96 97

        expect(page).to have_selector(".wiki .task-list .task-list-item .task-list-item-checkbox")
Clement Ho's avatar
Clement Ho committed
98 99 100
      end

      it 'provides a summary on Issues#index' do
101
        visit project_issues_path(project)
Clement Ho's avatar
Clement Ho committed
102 103
        expect(page).to have_content("2 of 6 tasks completed")
      end
104 105
    end

106
    describe 'single incomplete task', :js do
Clement Ho's avatar
Clement Ho committed
107
      let!(:issue) { create(:issue, description: singleIncompleteMarkdown, author: user, project: project) }
108

Clement Ho's avatar
Clement Ho committed
109 110
      it 'renders' do
        visit_issue(project, issue)
111
        wait_for_requests
112

Clement Ho's avatar
Clement Ho committed
113 114 115 116 117 118
        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
119
        visit project_issues_path(project)
Regis's avatar
Regis committed
120

Clement Ho's avatar
Clement Ho committed
121 122
        expect(page).to have_content("0 of 1 task completed")
      end
123 124
    end

125
    describe 'single complete task', :js do
Clement Ho's avatar
Clement Ho committed
126 127 128 129
      let!(:issue) { create(:issue, description: singleCompleteMarkdown, author: user, project: project) }

      it 'renders' do
        visit_issue(project, issue)
130
        wait_for_requests
131

Clement Ho's avatar
Clement Ho committed
132 133 134 135 136 137
        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
138
        visit project_issues_path(project)
Regis's avatar
Regis committed
139

Clement Ho's avatar
Clement Ho committed
140 141
        expect(page).to have_content("1 of 1 task completed")
      end
142 143 144 145 146
    end
  end

  describe 'for Notes' do
    let!(:issue) { create(:issue, author: user, project: project) }
Clement Ho's avatar
Clement Ho committed
147 148 149 150 151 152
    describe 'multiple tasks' do
      let!(:note) do
        create(:note, note: markdown, noteable: issue,
                      project: project, author: user)
      end

153
      it 'renders for note body', :js do
Clement Ho's avatar
Clement Ho committed
154 155 156 157 158 159 160
        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

161
      it 'contains the required selectors', :js do
Clement Ho's avatar
Clement Ho committed
162 163 164 165 166 167
        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

168
      it 'is only editable by author', :js do
Clement Ho's avatar
Clement Ho committed
169 170 171
        visit_issue(project, issue)
        expect(page).to have_selector('.js-task-list-container')

172
        gitlab_sign_out
Clement Ho's avatar
Clement Ho committed
173

174
        gitlab_sign_in(user2)
Clement Ho's avatar
Clement Ho committed
175 176 177
        visit current_path
        expect(page).not_to have_selector('.js-task-list-container')
      end
178
    end
179

Clement Ho's avatar
Clement Ho committed
180 181 182 183 184
    describe 'single incomplete task' do
      let!(:note) do
        create(:note, note: singleIncompleteMarkdown, noteable: issue,
                      project: project, author: user)
      end
185

186
      it 'renders for note body', :js do
Clement Ho's avatar
Clement Ho committed
187
        visit_issue(project, issue)
188

Clement Ho's avatar
Clement Ho committed
189 190 191 192
        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
193 194
    end

Clement Ho's avatar
Clement Ho committed
195 196 197 198 199
    describe 'single complete task' do
      let!(:note) do
        create(:note, note: singleCompleteMarkdown, noteable: issue,
                      project: project, author: user)
      end
200

201
      it 'renders for note body', :js do
Clement Ho's avatar
Clement Ho committed
202
        visit_issue(project, issue)
203

Clement Ho's avatar
Clement Ho committed
204 205 206 207
        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
208 209 210 211 212
    end
  end

  describe 'for Merge Requests' do
    def visit_merge_request(project, merge)
213
      visit project_merge_request_path(project, merge)
214 215
    end

Clement Ho's avatar
Clement Ho committed
216
    describe 'multiple tasks' do
217
      let(:project) { create(:project, :repository) }
Clement Ho's avatar
Clement Ho committed
218
      let!(:merge) { create(:merge_request, :simple, description: markdown, author: user, source_project: project) }
219

Clement Ho's avatar
Clement Ho committed
220 221
      it 'renders for description' do
        visit_merge_request(project, merge)
222

Clement Ho's avatar
Clement Ho committed
223 224 225 226
        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
227

Clement Ho's avatar
Clement Ho committed
228 229
      it 'contains the required selectors' do
        visit_merge_request(project, merge)
230

Clement Ho's avatar
Clement Ho committed
231
        container = '.detail-page-description .description.js-task-list-container'
232

Clement Ho's avatar
Clement Ho committed
233 234
        expect(page).to have_selector(container)
        expect(page).to have_selector("#{container} .wiki .task-list .task-list-item .task-list-item-checkbox")
235
        expect(page).to have_selector("#{container} .js-task-list-field")
Clement Ho's avatar
Clement Ho committed
236 237 238
        expect(page).to have_selector('form.js-issuable-update')
        expect(page).to have_selector('a.btn-close')
      end
239

Clement Ho's avatar
Clement Ho committed
240 241 242
      it 'is only editable by author' do
        visit_merge_request(project, merge)
        expect(page).to have_selector('.js-task-list-container')
243

Clement Ho's avatar
Clement Ho committed
244
        logout(:user)
245

Clement Ho's avatar
Clement Ho committed
246 247 248 249 250 251
        login_as(user2)
        visit current_path
        expect(page).not_to have_selector('.js-task-list-container')
      end

      it 'provides a summary on MergeRequests#index' do
252
        visit project_merge_requests_path(project)
Clement Ho's avatar
Clement Ho committed
253 254 255
        expect(page).to have_content("2 of 6 tasks completed")
      end
    end
256

Clement Ho's avatar
Clement Ho committed
257 258 259 260 261 262 263 264 265 266 267 268
    describe 'single incomplete task' do
      let!(:merge) { create(:merge_request, :simple, description: singleIncompleteMarkdown, author: user, source_project: project) }

      it 'renders for description' do
        visit_merge_request(project, merge)

        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
269
        visit project_merge_requests_path(project)
Clement Ho's avatar
Clement Ho committed
270 271
        expect(page).to have_content("0 of 1 task completed")
      end
272 273
    end

Clement Ho's avatar
Clement Ho committed
274 275 276 277 278 279 280 281 282 283 284 285
    describe 'single complete task' do
      let!(:merge) { create(:merge_request, :simple, description: singleCompleteMarkdown, author: user, source_project: project) }

      it 'renders for description' do
        visit_merge_request(project, merge)

        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
286
        visit project_merge_requests_path(project)
Clement Ho's avatar
Clement Ho committed
287 288
        expect(page).to have_content("1 of 1 task completed")
      end
289 290 291
    end
  end
end