BigW Consortium Gitlab

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

3
feature 'Task Lists', feature: true do
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  include Warden::Test::Helpers

  let(:project) { create(:project) }
  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

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 52
  before do
    Warden.test_mode!

    project.team << [user, :master]
    project.team << [user2, :guest]

    login_as(user)
  end

  def visit_issue(project, issue)
    visit namespace_project_issue_path(project.namespace, project, issue)
  end

  describe 'for Issues' do
53 54
    describe 'multiple tasks' do
      let!(:issue) { create(:issue, description: markdown, author: user, project: project) }
55

56 57
      it 'renders' do
        visit_issue(project, issue)
58

59 60 61 62 63 64 65 66 67
        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)

        container = '.detail-page-description .description.js-task-list-container'
68

69 70 71 72 73 74
        expect(page).to have_selector(container)
        expect(page).to have_selector("#{container} .wiki .task-list .task-list-item .task-list-item-checkbox")
        expect(page).to have_selector("#{container} .js-task-list-field")
        expect(page).to have_selector('form.js-issuable-update')
        expect(page).to have_selector('a.btn-close')
      end
75

76 77 78
      it 'is only editable by author' do
        visit_issue(project, issue)
        expect(page).to have_selector('.js-task-list-container')
79

80 81 82 83 84 85 86 87 88 89 90
        logout(:user)

        login_as(user2)
        visit current_path
        expect(page).not_to have_selector('.js-task-list-container')
      end

      it 'provides a summary on Issues#index' do
        visit namespace_project_issues_path(project.namespace, project)
        expect(page).to have_content("2 of 6 tasks completed")
      end
91 92
    end

93 94
    describe 'single incomplete task' do
      let!(:issue) { create(:issue, description: singleIncompleteMarkdown, author: user, project: project) }
95

96 97
      it 'renders' do
        visit_issue(project, issue)
98

99 100 101 102 103 104 105 106 107
        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 namespace_project_issues_path(project.namespace, project)
        expect(page).to have_content("0 of 1 task completed")
      end
108 109
    end

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    describe 'single complete task' do
      let!(:issue) { create(:issue, description: singleCompleteMarkdown, author: user, project: project) }

      it 'renders' do
        visit_issue(project, issue)

        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 namespace_project_issues_path(project.namespace, project)
        expect(page).to have_content("1 of 1 task completed")
      end
125 126 127 128 129
    end
  end

  describe 'for Notes' do
    let!(:issue) { create(:issue, author: user, project: project) }
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
    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')
        expect(page).to have_selector('.note .js-task-list-container .js-task-list-field')
      end

      it 'is only editable by author' do
        visit_issue(project, issue)
        expect(page).to have_selector('.js-task-list-container')

        logout(:user)

        login_as(user2)
        visit current_path
        expect(page).not_to have_selector('.js-task-list-container')
      end
162
    end
163

164 165 166 167 168
    describe 'single incomplete task' do
      let!(:note) do
        create(:note, note: singleIncompleteMarkdown, noteable: issue,
                      project: project, author: user)
      end
169

170 171
      it 'renders for note body' do
        visit_issue(project, issue)
172

173 174 175 176
        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
177 178
    end

179 180 181 182 183
    describe 'single complete task' do
      let!(:note) do
        create(:note, note: singleCompleteMarkdown, noteable: issue,
                      project: project, author: user)
      end
184

185 186
      it 'renders for note body' do
        visit_issue(project, issue)
187

188 189 190 191
        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
192 193 194 195 196 197 198 199
    end
  end

  describe 'for Merge Requests' do
    def visit_merge_request(project, merge)
      visit namespace_project_merge_request_path(project.namespace, project, merge)
    end

200 201
    describe 'multiple tasks' do
      let!(:merge) { create(:merge_request, :simple, description: markdown, author: user, source_project: project) }
202

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

206 207 208 209
        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
210

211 212
      it 'contains the required selectors' do
        visit_merge_request(project, merge)
213

214
        container = '.detail-page-description .description.js-task-list-container'
215

216 217 218 219 220 221
        expect(page).to have_selector(container)
        expect(page).to have_selector("#{container} .wiki .task-list .task-list-item .task-list-item-checkbox")
        expect(page).to have_selector("#{container} .js-task-list-field")
        expect(page).to have_selector('form.js-issuable-update')
        expect(page).to have_selector('a.btn-close')
      end
222

223 224 225
      it 'is only editable by author' do
        visit_merge_request(project, merge)
        expect(page).to have_selector('.js-task-list-container')
226

227
        logout(:user)
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
        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
        visit namespace_project_merge_requests_path(project.namespace, project)
        expect(page).to have_content("2 of 6 tasks completed")
      end
    end
    
    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
        visit namespace_project_merge_requests_path(project.namespace, project)
        expect(page).to have_content("0 of 1 task completed")
      end
255 256
    end

257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
    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
        visit namespace_project_merge_requests_path(project.namespace, project)
        expect(page).to have_content("1 of 1 task completed")
      end
272 273 274
    end
  end
end