BigW Consortium Gitlab

todos_spec.rb 7.04 KB
Newer Older
Alfredo Sumaran committed
1 2 3
require 'spec_helper'

describe 'Dashboard Todos', feature: true do
4 5
  include WaitForAjax

6 7
  let(:user)    { create(:user) }
  let(:author)  { create(:user) }
8
  let(:project) { create(:project, visibility_level: Gitlab::VisibilityLevel::PUBLIC) }
Phil Hughes committed
9
  let(:issue)   { create(:issue, due_date: Date.today) }
Alfredo Sumaran committed
10 11

  describe 'GET /dashboard/todos' do
Alfredo Sumaran committed
12
    context 'User does not have todos' do
Alfredo Sumaran committed
13 14 15 16 17
      before do
        login_as(user)
        visit dashboard_todos_path
      end
      it 'shows "All done" message' do
Phil Hughes committed
18
        expect(page).to have_content "Todos let you see what you should do next."
Alfredo Sumaran committed
19 20 21 22 23 24 25 26 27 28
      end
    end

    context 'User has a todo', js: true do
      before do
        create(:todo, :mentioned, user: user, project: project, target: issue, author: author)
        login_as(user)
        visit dashboard_todos_path
      end

29
      it 'has todo present' do
Alfredo Sumaran committed
30 31 32
        expect(page).to have_selector('.todos-list .todo', count: 1)
      end

Phil Hughes committed
33 34 35 36 37 38
      it 'shows due date as today' do
        page.within first('.todo') do
          expect(page).to have_content 'Due today'
        end
      end

39
      shared_examples 'deleting the todo' do
Alfredo Sumaran committed
40
        before do
41 42 43 44 45
          first('.js-done-todo').click
        end

        it 'is marked as done-reversible in the list' do
          expect(page).to have_selector('.todos-list .todo.todo-pending.done-reversible')
Alfredo Sumaran committed
46 47
        end

48 49 50
        it 'shows Undo button' do
          expect(page).to have_selector('.js-undo-todo', visible: true)
          expect(page).to have_selector('.js-done-todo', visible: false)
Alfredo Sumaran committed
51 52
        end

53 54 55 56 57 58 59
        it 'updates todo count' do
          expect(page).to have_content 'To do 0'
          expect(page).to have_content 'Done 1'
        end

        it 'has not "All done" message' do
          expect(page).not_to have_selector('.todos-all-done')
Alfredo Sumaran committed
60 61
        end
      end
62

63
      shared_examples 'deleting and restoring the todo' do
64
        before do
65 66 67
          first('.js-done-todo').click
          wait_for_ajax
          first('.js-undo-todo').click
68 69
        end

70 71 72 73
        it 'is marked back as pending in the list' do
          expect(page).not_to have_selector('.todos-list .todo.todo-pending.done-reversible')
          expect(page).to have_selector('.todos-list .todo.todo-pending')
        end
74

75 76 77 78
        it 'shows Done button' do
          expect(page).to have_selector('.js-undo-todo', visible: false)
          expect(page).to have_selector('.js-done-todo', visible: true)
        end
79

80 81 82
        it 'updates todo count' do
          expect(page).to have_content 'To do 1'
          expect(page).to have_content 'Done 0'
83 84
        end
      end
85 86 87 88 89 90 91 92 93 94 95 96 97

      it_behaves_like 'deleting the todo'
      it_behaves_like 'deleting and restoring the todo'

      context 'todo is stale on the page' do
        before do
          todos = TodosFinder.new(user, state: :pending).execute
          TodoService.new.mark_todos_as_done(todos, user)
        end

        it_behaves_like 'deleting the todo'
        it_behaves_like 'deleting and restoring the todo'
      end
Alfredo Sumaran committed
98 99
    end

100 101 102 103 104 105
    context 'User has Todos with labels spanning multiple projects' do
      before do
        label1 = create(:label, project: project)
        note1 = create(:note_on_issue, note: "Hello #{label1.to_reference(format: :name)}", noteable_id: issue.id, noteable_type: 'Issue', project: issue.project)
        create(:todo, :mentioned, project: project, target: issue, user: user, note_id: note1.id)

DJ Mountney committed
106
        project2 = create(:project, visibility_level: Gitlab::VisibilityLevel::PUBLIC)
107 108 109 110 111 112 113 114 115 116 117 118 119 120
        label2 = create(:label, project: project2)
        issue2 = create(:issue, project: project2)
        note2 = create(:note_on_issue, note: "Test #{label2.to_reference(format: :name)}", noteable_id: issue2.id, noteable_type: 'Issue', project: project2)
        create(:todo, :mentioned, project: project2, target: issue2, user: user, note_id: note2.id)

        login_as(user)
        visit dashboard_todos_path
      end

      it 'shows page with two Todos' do
        expect(page).to have_selector('.todos-list .todo', count: 2)
      end
    end

Alfredo Sumaran committed
121 122
    context 'User has multiple pages of Todos' do
      before do
123 124 125 126
        allow(Todo).to receive(:default_per_page).and_return(1)

        # Create just enough records to cause us to paginate
        create_list(:todo, 2, :mentioned, user: user, project: project, target: issue, author: author)
Alfredo Sumaran committed
127 128 129 130 131

        login_as(user)
      end

      it 'is paginated' do
132 133
        visit dashboard_todos_path

Alfredo Sumaran committed
134 135 136 137
        expect(page).to have_selector('.gl-pagination')
      end

      it 'is has the right number of pages' do
138 139 140
        visit dashboard_todos_path

        expect(page).to have_selector('.gl-pagination .page', count: 2)
Alfredo Sumaran committed
141 142
      end

143 144 145 146 147 148 149 150
      describe 'mark all as done', js: true do
        before do
          visit dashboard_todos_path
          click_link('Mark all as done')
        end

        it 'shows "All done" message!' do
          expect(page).to have_content 'To do 0'
Phil Hughes committed
151
          expect(page).to have_content "You're all done!"
152 153 154
          expect(page).not_to have_selector('.gl-pagination')
        end
      end
Alfredo Sumaran committed
155
    end
156 157 158

    context 'User has a Todo in a project pending deletion' do
      before do
DJ Mountney committed
159
        deleted_project = create(:project, visibility_level: Gitlab::VisibilityLevel::PUBLIC, pending_delete: true)
160
        create(:todo, :mentioned, user: user, project: deleted_project, target: issue, author: author)
161
        create(:todo, :mentioned, user: user, project: deleted_project, target: issue, author: author, state: :done)
162 163 164 165 166
        login_as(user)
        visit dashboard_todos_path
      end

      it 'shows "All done" message' do
167 168 169
        within('.todos-pending-count') { expect(page).to have_content '0' }
        expect(page).to have_content 'To do 0'
        expect(page).to have_content 'Done 0'
170
        expect(page).to have_selector('.todos-all-done', count: 1)
171 172
      end
    end
173

174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
    context 'User have large number of todos' do
      before do
        create_list(:todo, 101, :mentioned, user: user, project: project, target: issue, author: author)

        login_as(user)
        visit dashboard_todos_path
      end

      it 'shows 99+ for count >= 100 in notification' do
        expect(page).to have_selector('.todos-pending-count', text: '99+')
      end

      it 'shows exact number in To do tab' do
        expect(page).to have_selector('.todos-pending .badge', text: '101')
      end

      it 'shows exact number for count < 100' do
        3.times { first('.js-done-todo').click }

        expect(page).to have_selector('.todos-pending-count', text: '98')
      end
    end

197 198 199 200 201 202 203 204 205
    context 'User has a Build Failed todo' do
      let!(:todo) { create(:todo, :build_failed, user: user, project: project, author: author) }

      before do
        login_as user
        visit dashboard_todos_path
      end

      it 'shows the todo' do
Sean McGivern committed
206
        expect(page).to have_content 'The build failed for merge request'
207 208 209 210 211
      end

      it 'links to the pipelines for the merge request' do
        href = pipelines_namespace_project_merge_request_path(project.namespace, project, todo.target)

212
        expect(page).to have_link "merge request #{todo.target.to_reference(full: true)}", href
213 214
      end
    end
Alfredo Sumaran committed
215 216
  end
end