Commit 0325d26d authored by Robert Speicher's avatar Robert Speicher Committed by Yorick Peterse

Merge branch 'rs-todos-feature-spec' into 'master'

Refactor Todos feature spec to be faster and less brittle

We now only create two Todos instead of 21 when testing pagination, and
we've updated the test to be less brittle when dealing with slower CI
environments.

See merge request !3889
parent 009e2ed1
require 'spec_helper' require 'spec_helper'
describe 'Dashboard Todos', feature: true do describe 'Dashboard Todos', feature: true do
let(:user){ create(:user) } let(:user) { create(:user) }
let(:author){ create(:user) } let(:author) { create(:user) }
let(:project){ create(:project) } let(:project) { create(:project) }
let(:issue){ create(:issue) } let(:issue) { create(:issue) }
let(:todos_per_page){ Todo.default_per_page }
let(:todos_total){ todos_per_page + 1 }
describe 'GET /dashboard/todos' do describe 'GET /dashboard/todos' do
context 'User does not have todos' do context 'User does not have todos' do
...@@ -46,31 +44,35 @@ describe 'Dashboard Todos', feature: true do ...@@ -46,31 +44,35 @@ describe 'Dashboard Todos', feature: true do
end end
context 'User has multiple pages of Todos' do context 'User has multiple pages of Todos' do
let(:todo_total_pages){ (todos_total.to_f/todos_per_page).ceil }
before do before do
todos_total.times do allow(Todo).to receive(:default_per_page).and_return(1)
create(:todo, :mentioned, user: user, project: project, target: issue, author: author)
end # Create just enough records to cause us to paginate
create_list(:todo, 2, :mentioned, user: user, project: project, target: issue, author: author)
login_as(user) login_as(user)
visit dashboard_todos_path
end end
it 'is paginated' do it 'is paginated' do
visit dashboard_todos_path
expect(page).to have_selector('.gl-pagination') expect(page).to have_selector('.gl-pagination')
end end
it 'is has the right number of pages' do it 'is has the right number of pages' do
expect(page).to have_selector('.gl-pagination .page', count: todo_total_pages) visit dashboard_todos_path
expect(page).to have_selector('.gl-pagination .page', count: 2)
end end
describe 'deleting last todo from last page', js: true do describe 'completing last todo from last page', js: true do
it 'redirects to the previous page' do it 'redirects to the previous page' do
page.within('.gl-pagination') do visit dashboard_todos_path(page: 2)
click_link todo_total_pages.to_s expect(page).to have_content(Todo.first.body)
end
first('.done-todo').click click_link('Done')
expect(current_path).to eq dashboard_todos_path
expect(page).to have_content(Todo.last.body) expect(page).to have_content(Todo.last.body)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment