2016-04-07 22:22:58 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'Dashboard Todos', feature: true do
|
2016-04-22 13:04:05 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:author) { create(:user) }
|
2016-06-01 19:44:35 -04:00
|
|
|
let(:project) { create(:project, visibility_level: Gitlab::VisibilityLevel::PUBLIC) }
|
2016-04-22 13:04:05 -04:00
|
|
|
let(:issue) { create(:issue) }
|
2016-04-07 22:22:58 -04:00
|
|
|
|
|
|
|
describe 'GET /dashboard/todos' do
|
2016-04-18 17:28:15 -04:00
|
|
|
context 'User does not have todos' do
|
2016-04-07 22:22:58 -04:00
|
|
|
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
|
|
|
|
|
2016-05-26 23:37:41 -04:00
|
|
|
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)
|
|
|
|
|
2016-06-02 18:30:13 -04:00
|
|
|
project2 = create(:project, visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
2016-05-26 23:37:41 -04:00
|
|
|
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
|
|
|
|
|
2016-04-07 22:22:58 -04:00
|
|
|
context 'User has multiple pages of Todos' do
|
|
|
|
before do
|
2016-04-22 13:04:05 -04:00
|
|
|
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)
|
2016-04-07 22:22:58 -04:00
|
|
|
|
|
|
|
login_as(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is paginated' do
|
2016-04-22 13:04:05 -04:00
|
|
|
visit dashboard_todos_path
|
|
|
|
|
2016-04-07 22:22:58 -04:00
|
|
|
expect(page).to have_selector('.gl-pagination')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is has the right number of pages' do
|
2016-04-22 13:04:05 -04:00
|
|
|
visit dashboard_todos_path
|
|
|
|
|
|
|
|
expect(page).to have_selector('.gl-pagination .page', count: 2)
|
2016-04-07 22:22:58 -04:00
|
|
|
end
|
|
|
|
|
2016-04-22 13:04:05 -04:00
|
|
|
describe 'completing last todo from last page', js: true do
|
2016-04-07 22:22:58 -04:00
|
|
|
it 'redirects to the previous page' do
|
2016-04-22 13:04:05 -04:00
|
|
|
visit dashboard_todos_path(page: 2)
|
2016-04-27 15:50:24 -04:00
|
|
|
expect(page).to have_css("#todo_#{Todo.last.id}")
|
2016-04-22 13:04:05 -04:00
|
|
|
|
|
|
|
click_link('Done')
|
|
|
|
|
|
|
|
expect(current_path).to eq dashboard_todos_path
|
2016-04-27 15:50:24 -04:00
|
|
|
expect(page).to have_css("#todo_#{Todo.first.id}")
|
2016-04-07 22:22:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-05-25 21:52:10 -04:00
|
|
|
|
|
|
|
context 'User has a Todo in a project pending deletion' do
|
|
|
|
before do
|
2016-06-02 18:30:13 -04:00
|
|
|
deleted_project = create(:project, visibility_level: Gitlab::VisibilityLevel::PUBLIC, pending_delete: true)
|
2016-05-25 21:52:10 -04:00
|
|
|
create(:todo, :mentioned, user: user, project: deleted_project, target: issue, author: author)
|
|
|
|
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
|
2016-04-07 22:22:58 -04:00
|
|
|
end
|
|
|
|
end
|