debian-mirror-gitlab/spec/features/dashboard/todos/todos_spec.rb

473 lines
15 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'Dashboard Todos', feature_category: :team_planning do
2021-08-04 16:29:09 +05:30
include DesignManagementTestHelpers
2022-03-02 08:16:31 +05:30
let_it_be(:user) { create(:user, username: 'john') }
let_it_be(:user2) { create(:user, username: 'diane') }
let_it_be(:author) { create(:user) }
2020-05-24 23:13:21 +05:30
let_it_be(:project) { create(:project, :public) }
2022-03-02 08:16:31 +05:30
let_it_be(:issue) { create(:issue, project: project, due_date: Date.today, title: "Fix bug") }
2021-08-04 16:29:09 +05:30
before_all do
project.add_developer(user)
end
2017-09-10 17:25:29 +05:30
context 'User does not have todos' do
before do
sign_in(user)
visit dashboard_todos_path
end
it 'shows "All done" message' do
2019-09-30 21:07:59 +05:30
expect(page).to have_content 'Your To-Do List shows what to work on next'
2017-09-10 17:25:29 +05:30
end
2022-03-02 08:16:31 +05:30
context 'when user was assigned to an issue and marked it as done' do
before do
sign_in(user)
end
it 'shows "Are you looking for things to do?" message' do
create(:todo, :assigned, :done, user: user, project: project, target: issue, author: user2)
visit dashboard_todos_path
expect(page).to have_content 'Are you looking for things to do? Take a look at open issues, contribute to a merge request, or mention someone in a comment to automatically assign them a new to-do item.'
end
end
2017-09-10 17:25:29 +05:30
end
2019-07-07 11:18:12 +05:30
context 'when the todo references a merge request' do
let(:referenced_mr) { create(:merge_request, source_project: project) }
2021-08-04 16:29:09 +05:30
let(:note) { create(:note, project: project, note: "Check out #{referenced_mr.to_reference}", noteable: create(:issue, project: project)) }
let!(:todo) { create(:todo, :mentioned, user: user, project: project, author: author, note: note, target: note.noteable) }
2019-07-07 11:18:12 +05:30
before do
sign_in(user)
visit dashboard_todos_path
end
2023-03-04 22:38:38 +05:30
it 'renders the mr reference' do
expect(page).to have_content(referenced_mr.to_reference)
2022-08-13 15:12:31 +05:30
end
end
2021-08-04 16:29:09 +05:30
context 'user has an unauthorized todo' do
2017-09-10 17:25:29 +05:30
before do
2021-08-04 16:29:09 +05:30
sign_in(user)
end
it 'does not render the todo' do
unauthorized_issue = create(:issue)
create(:todo, :mentioned, user: user, project: unauthorized_issue.project, target: unauthorized_issue, author: author)
2017-09-10 17:25:29 +05:30
create(:todo, :mentioned, user: user, project: project, target: issue, author: author)
2021-08-04 16:29:09 +05:30
visit dashboard_todos_path
expect(page).to have_selector('.todos-list .todo', count: 1)
end
end
context 'User has a todo', :js do
let_it_be(:user_todo) { create(:todo, :mentioned, user: user, project: project, target: issue, author: author) }
before do
2017-09-10 17:25:29 +05:30
sign_in(user)
visit dashboard_todos_path
end
it 'has todo present' do
expect(page).to have_selector('.todos-list .todo', count: 1)
end
it 'shows due date as today' do
within first('.todo') do
expect(page).to have_content 'Due today'
end
end
shared_examples 'deleting the todo' do
before do
within first('.todo') do
2023-03-04 22:38:38 +05:30
find('[data-testid="check-icon"]').click
2017-09-10 17:25:29 +05:30
end
end
it 'is marked as done-reversible in the list' do
expect(page).to have_selector('.todos-list .todo.todo-pending.done-reversible')
end
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)
end
it 'updates todo count' do
2019-09-30 21:07:59 +05:30
expect(page).to have_content 'To Do 0'
2017-09-10 17:25:29 +05:30
expect(page).to have_content 'Done 1'
end
it 'has not "All done" message' do
2021-06-08 01:23:25 +05:30
expect(page).not_to have_selector('.empty-state')
2017-09-10 17:25:29 +05:30
end
end
shared_examples 'deleting and restoring the todo' do
before do
within first('.todo') do
2023-03-04 22:38:38 +05:30
find('[data-testid="check-icon"]').click
2017-09-10 17:25:29 +05:30
wait_for_requests
2023-03-04 22:38:38 +05:30
find('[data-testid="redo-icon"]').click
2017-09-10 17:25:29 +05:30
end
end
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
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
it 'updates todo count' do
2019-09-30 21:07:59 +05:30
expect(page).to have_content 'To Do 1'
2017-09-10 17:25:29 +05:30
expect(page).to have_content 'Done 0'
end
end
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
2020-06-23 00:09:42 +05:30
TodoService.new.resolve_todos(todos, user)
2017-09-10 17:25:29 +05:30
end
it_behaves_like 'deleting the todo'
it_behaves_like 'deleting and restoring the todo'
end
end
context 'User created todos for themself' do
before do
sign_in(user)
end
context 'issue assigned todo' do
before do
create(:todo, :assigned, user: user, project: project, target: issue, author: user)
visit dashboard_todos_path
end
it 'shows issue assigned to yourself message' do
2019-03-02 22:35:43 +05:30
page.within('.js-todos-all') do
2023-03-04 22:38:38 +05:30
expect(page).to have_content("Fix bug · #{project.namespace.owner_name} / #{project.name} #{issue.to_reference}")
expect(page).to have_content("You assigned to yourself.")
2017-09-10 17:25:29 +05:30
end
end
end
context 'marked todo' do
before do
create(:todo, :marked, user: user, project: project, target: issue, author: user)
visit dashboard_todos_path
end
2023-03-04 22:38:38 +05:30
it 'shows you added a to-do item message' do
2019-03-02 22:35:43 +05:30
page.within('.js-todos-all') do
2023-03-04 22:38:38 +05:30
expect(page).to have_content("Fix bug · #{project.namespace.owner_name} / #{project.name} #{issue.to_reference}")
expect(page).to have_content("You added a to-do item.")
2017-09-10 17:25:29 +05:30
end
end
end
context 'mentioned todo' do
before do
create(:todo, :mentioned, user: user, project: project, target: issue, author: user)
visit dashboard_todos_path
end
it 'shows you mentioned yourself message' do
2019-03-02 22:35:43 +05:30
page.within('.js-todos-all') do
2023-03-04 22:38:38 +05:30
expect(page).to have_content("Fix bug · #{project.namespace.owner_name} / #{project.name} #{issue.to_reference}")
expect(page).to have_content("You mentioned yourself.")
2017-09-10 17:25:29 +05:30
end
end
end
context 'directly_addressed todo' do
before do
create(:todo, :directly_addressed, user: user, project: project, target: issue, author: user)
visit dashboard_todos_path
end
2022-07-16 23:28:13 +05:30
it 'shows you directly addressed yourself message being displayed as mentioned yourself' do
2019-03-02 22:35:43 +05:30
page.within('.js-todos-all') do
2023-03-04 22:38:38 +05:30
expect(page).to have_content("Fix bug · #{project.namespace.owner_name} / #{project.name} #{issue.to_reference}")
expect(page).to have_content("You mentioned yourself.")
2017-09-10 17:25:29 +05:30
end
end
end
context 'approval todo' do
2021-08-04 16:29:09 +05:30
let(:merge_request) { create(:merge_request, title: "Fixes issue", source_project: project) }
2017-09-10 17:25:29 +05:30
before do
create(:todo, :approval_required, user: user, project: project, target: merge_request, author: user)
visit dashboard_todos_path
end
it 'shows you set yourself as an approver message' do
2019-03-02 22:35:43 +05:30
page.within('.js-todos-all') do
2023-03-04 22:38:38 +05:30
expect(page).to have_content("Fixes issue · #{project.namespace.owner_name} / #{project.name} #{merge_request.to_reference}")
expect(page).to have_content("You set yourself as an approver.")
2017-09-10 17:25:29 +05:30
end
end
end
2021-01-03 14:25:43 +05:30
context 'review request todo' do
2021-08-04 16:29:09 +05:30
let(:merge_request) { create(:merge_request, title: "Fixes issue", source_project: project) }
2021-01-03 14:25:43 +05:30
before do
create(:todo, :review_requested, user: user, project: project, target: merge_request, author: user)
visit dashboard_todos_path
end
it 'shows you set yourself as an reviewer message' do
page.within('.js-todos-all') do
2023-03-04 22:38:38 +05:30
expect(page).to have_content("Fixes issue · #{project.namespace.owner_name} / #{project.name} #{merge_request.to_reference}")
expect(page).to have_content("You requested a review from yourself.")
end
end
end
end
context 'User has automatically created todos' do
before do
sign_in(user)
end
context 'unmergeable todo' do
before do
create(:todo, :unmergeable, user: user, project: project, target: issue, author: user)
visit dashboard_todos_path
end
it 'shows unmergeable message' do
page.within('.js-todos-all') do
expect(page).to have_content("Fix bug · #{project.namespace.owner_name} / #{project.name} #{issue.to_reference}")
expect(page).to have_content("Could not merge.")
2021-01-03 14:25:43 +05:30
end
end
end
2017-09-10 17:25:29 +05:30
end
2018-03-17 18:26:18 +05:30
context 'User has done todos', :js do
2017-09-10 17:25:29 +05:30
before do
create(:todo, :mentioned, :done, user: user, project: project, target: issue, author: author)
sign_in(user)
visit dashboard_todos_path(state: :done)
end
it 'has the done todo present' do
expect(page).to have_selector('.todos-list .todo.todo-done', count: 1)
end
describe 'restoring the todo' do
before do
within first('.todo') do
2023-03-04 22:38:38 +05:30
find('[data-testid="todo-add-icon"]').click
2017-09-10 17:25:29 +05:30
end
end
it 'is removed from the list' do
expect(page).not_to have_selector('.todos-list .todo.todo-done')
end
it 'updates todo count' do
2019-09-30 21:07:59 +05:30
expect(page).to have_content 'To Do 1'
2017-09-10 17:25:29 +05:30
expect(page).to have_content 'Done 0'
end
end
end
2021-01-03 14:25:43 +05:30
context 'User has to dos with labels spanning multiple projects' do
2017-09-10 17:25:29 +05:30
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)
project2 = create(:project, :public)
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)
gitlab_sign_in(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
context 'User has multiple pages of Todos' do
before do
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)
sign_in(user)
end
it 'is paginated' do
visit dashboard_todos_path
expect(page).to have_selector('.gl-pagination')
end
it 'is has the right number of pages' do
visit dashboard_todos_path
2018-11-08 19:23:39 +05:30
expect(page).to have_selector('.gl-pagination .js-pagination-page', count: 2)
2017-09-10 17:25:29 +05:30
end
2018-03-17 18:26:18 +05:30
describe 'mark all as done', :js do
2017-09-10 17:25:29 +05:30
before do
visit dashboard_todos_path
2018-03-17 18:26:18 +05:30
find('.js-todos-mark-all').click
2017-09-10 17:25:29 +05:30
end
it 'shows "All done" message!' do
2019-09-30 21:07:59 +05:30
expect(page).to have_content 'To Do 0'
2017-09-10 17:25:29 +05:30
expect(page).to have_content "You're all done!"
expect(page).not_to have_selector('.gl-pagination')
end
it 'shows "Undo mark all as done" button' do
expect(page).to have_selector('.js-todos-mark-all', visible: false)
expect(page).to have_selector('.js-todos-undo-all', visible: true)
end
end
2018-03-17 18:26:18 +05:30
describe 'undo mark all as done', :js do
2017-09-10 17:25:29 +05:30
before do
visit dashboard_todos_path
end
it 'shows the restored todo list' do
mark_all_and_undo
expect(page).to have_selector('.todos-list .todo', count: 1)
expect(page).to have_selector('.gl-pagination')
expect(page).not_to have_content "You're all done!"
end
it 'updates todo count' do
mark_all_and_undo
2019-09-30 21:07:59 +05:30
expect(page).to have_content 'To Do 2'
2017-09-10 17:25:29 +05:30
expect(page).to have_content 'Done 0'
end
it 'shows "Mark all as done" button' do
mark_all_and_undo
expect(page).to have_selector('.js-todos-mark-all', visible: true)
expect(page).to have_selector('.js-todos-undo-all', visible: false)
end
context 'User has deleted a todo' do
before do
within first('.todo') do
2023-03-04 22:38:38 +05:30
find('[data-testid="check-icon"]').click
2017-09-10 17:25:29 +05:30
end
end
it 'shows the restored todo list with the deleted todo' do
mark_all_and_undo
expect(page).to have_selector('.todos-list .todo.todo-pending', count: 1)
end
end
def mark_all_and_undo
2018-03-17 18:26:18 +05:30
find('.js-todos-mark-all').click
2017-09-10 17:25:29 +05:30
wait_for_requests
2018-03-17 18:26:18 +05:30
find('.js-todos-undo-all').click
2017-09-10 17:25:29 +05:30
wait_for_requests
end
end
end
context 'User has a Build Failed todo' do
2021-08-04 16:29:09 +05:30
let!(:todo) { create(:todo, :build_failed, user: user, project: project, author: author, target: create(:merge_request, source_project: project)) }
2017-09-10 17:25:29 +05:30
before do
sign_in(user)
visit dashboard_todos_path
end
it 'shows the todo' do
2023-03-04 22:38:38 +05:30
expect(page).to have_content 'The pipeline failed.'
2017-09-10 17:25:29 +05:30
end
end
2020-05-24 23:13:21 +05:30
context 'User has a todo regarding a design' do
let_it_be(:target) { create(:design, issue: issue, project: project) }
let_it_be(:note) { create(:note, project: project, note: 'I am note, hear me roar') }
let_it_be(:todo) do
create(:todo, :mentioned,
user: user,
project: project,
target: target,
author: author,
note: note)
end
before do
2021-08-04 16:29:09 +05:30
enable_design_management
2020-05-24 23:13:21 +05:30
project.add_developer(user)
sign_in(user)
visit dashboard_todos_path
end
it 'has todo present' do
expect(page).to have_selector('.todos-list .todo', count: 1)
end
2023-03-04 22:38:38 +05:30
end
2020-05-24 23:13:21 +05:30
2023-03-04 22:38:38 +05:30
context 'User has a todo for an access requested raised for group membership' do
let_it_be(:group) { create(:group, :public) }
2020-05-24 23:13:21 +05:30
2023-03-04 22:38:38 +05:30
let_it_be(:todo) do
create(:todo, :member_access_requested,
user: user,
target: group,
author: author,
group: group)
end
before do
group.add_owner(user)
sign_in(user)
2020-05-24 23:13:21 +05:30
2023-03-04 22:38:38 +05:30
visit dashboard_todos_path
end
it 'has todo present with access request content' do
expect(page).to have_selector('.todos-list .todo', count: 1)
expect(page).to have_content "#{author.name} has requested access to group #{group.name}"
2020-05-24 23:13:21 +05:30
end
end
2017-09-10 17:25:29 +05:30
end