todos_spec.rb 5 KB
Newer Older
Alfredo Sumaran's avatar
Alfredo Sumaran committed
1 2 3
require 'spec_helper'

describe 'Dashboard Todos', feature: true do
4 5
  let(:user)    { create(:user) }
  let(:author)  { create(:user) }
6
  let(:project) { create(:project, visibility_level: Gitlab::VisibilityLevel::PUBLIC) }
7
  let(:issue)   { create(:issue) }
Alfredo Sumaran's avatar
Alfredo Sumaran committed
8 9

  describe 'GET /dashboard/todos' do
Alfredo Sumaran's avatar
Alfredo Sumaran committed
10
    context 'User does not have todos' do
Alfredo Sumaran's avatar
Alfredo Sumaran committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
      before do
        login_as(user)
        visit dashboard_todos_path
      end
      it 'shows "All done" message' do
        expect(page).to have_content "You're all done!"
      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

27
      it 'has todo present' do
Alfredo Sumaran's avatar
Alfredo Sumaran committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
        expect(page).to have_selector('.todos-list .todo', count: 1)
      end

      describe 'deleting the todo' do
        before do
          first('.done-todo').click
        end

        it 'is removed from the list' do
          expect(page).not_to have_selector('.todos-list .todo')
        end

        it 'shows "All done" message' do
          expect(page).to have_content("You're all done!")
        end
      end
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

      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

        describe 'deleting the todo' do
          before do
            first('.done-todo').click
          end

          it 'is removed from the list' do
            expect(page).not_to have_selector('.todos-list .todo')
          end

          it 'shows "All done" message' do
            expect(page).to have_content("You're all done!")
          end
        end
      end
Alfredo Sumaran's avatar
Alfredo Sumaran committed
65 66
    end

67 68 69 70 71 72
    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's avatar
DJ Mountney committed
73
        project2 = create(:project, visibility_level: Gitlab::VisibilityLevel::PUBLIC)
74 75 76 77 78 79 80 81 82 83 84 85 86 87
        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's avatar
Alfredo Sumaran committed
88 89
    context 'User has multiple pages of Todos' do
      before do
90 91 92 93
        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's avatar
Alfredo Sumaran committed
94 95 96 97 98

        login_as(user)
      end

      it 'is paginated' do
99 100
        visit dashboard_todos_path

Alfredo Sumaran's avatar
Alfredo Sumaran committed
101 102 103 104
        expect(page).to have_selector('.gl-pagination')
      end

      it 'is has the right number of pages' do
105 106 107
        visit dashboard_todos_path

        expect(page).to have_selector('.gl-pagination .page', count: 2)
Alfredo Sumaran's avatar
Alfredo Sumaran committed
108 109
      end

110
      describe 'completing last todo from last page', js: true do
Alfredo Sumaran's avatar
Alfredo Sumaran committed
111
        it 'redirects to the previous page' do
112
          visit dashboard_todos_path(page: 2)
Alfredo Sumaran's avatar
Alfredo Sumaran committed
113
          expect(page).to have_css("#todo_#{Todo.last.id}")
114 115 116 117

          click_link('Done')

          expect(current_path).to eq dashboard_todos_path
Alfredo Sumaran's avatar
Alfredo Sumaran committed
118
          expect(page).to have_css("#todo_#{Todo.first.id}")
Alfredo Sumaran's avatar
Alfredo Sumaran committed
119 120
        end
      end
121 122 123 124 125 126 127 128 129 130 131 132 133 134

      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
          within('.todos-pending-count') { expect(page).to have_content '0' }
          expect(page).to have_content 'To do 0'
          expect(page).to have_content "You're all done!"
          expect(page).not_to have_selector('.gl-pagination')
        end
      end
Alfredo Sumaran's avatar
Alfredo Sumaran committed
135
    end
136 137 138

    context 'User has a Todo in a project pending deletion' do
      before do
DJ Mountney's avatar
DJ Mountney committed
139
        deleted_project = create(:project, visibility_level: Gitlab::VisibilityLevel::PUBLIC, pending_delete: true)
140
        create(:todo, :mentioned, user: user, project: deleted_project, target: issue, author: author)
141
        create(:todo, :mentioned, user: user, project: deleted_project, target: issue, author: author, state: :done)
142 143 144 145 146
        login_as(user)
        visit dashboard_todos_path
      end

      it 'shows "All done" message' do
147 148 149
        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'
150 151 152
        expect(page).to have_content "You're all done!"
      end
    end
Alfredo Sumaran's avatar
Alfredo Sumaran committed
153 154
  end
end