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

describe 'Dashboard Todos', feature: true do
4 5 6 7
  let(:user)    { create(:user) }
  let(:author)  { create(:user) }
  let(:project) { create(:project) }
  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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
      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

      it 'todo is present' do
        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
    end

    context 'User has multiple pages of Todos' do
      before do
48 49 50 51
        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
52 53 54 55 56

        login_as(user)
      end

      it 'is paginated' do
57 58
        visit dashboard_todos_path

Alfredo Sumaran's avatar
Alfredo Sumaran committed
59 60 61 62
        expect(page).to have_selector('.gl-pagination')
      end

      it 'is has the right number of pages' do
63 64 65
        visit dashboard_todos_path

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

68
      describe 'completing last todo from last page', js: true do
Alfredo Sumaran's avatar
Alfredo Sumaran committed
69
        it 'redirects to the previous page' do
70
          visit dashboard_todos_path(page: 2)
Alfredo Sumaran's avatar
Alfredo Sumaran committed
71
          expect(page).to have_css("#todo_#{Todo.last.id}")
72 73 74 75

          click_link('Done')

          expect(current_path).to eq dashboard_todos_path
Alfredo Sumaran's avatar
Alfredo Sumaran committed
76
          expect(page).to have_css("#todo_#{Todo.first.id}")
Alfredo Sumaran's avatar
Alfredo Sumaran committed
77 78 79 80 81
        end
      end
    end
  end
end