Commit 8ddcb333 authored by Dmytro Zaporozhets (DZ)'s avatar Dmytro Zaporozhets (DZ)

Merge branch 'add-review-request-to-to-do-list-filter' into 'master'

Add Review Requested to Todo list filter

See merge request gitlab-org/gitlab!42344
parents ed1c5289 bb3521f0
......@@ -16,6 +16,7 @@ module TodosHelper
def todo_action_name(todo)
case todo.action
when Todo::ASSIGNED then todo.self_added? ? 'assigned' : 'assigned you'
when Todo::REVIEW_REQUESTED then 'requested a review of'
when Todo::MENTIONED then "mentioned #{todo_action_subject(todo)} on"
when Todo::BUILD_FAILED then 'The build failed for'
when Todo::MARKED then 'added a todo for'
......@@ -26,6 +27,13 @@ module TodosHelper
end
end
def todo_self_addressing(todo)
case todo.action
when Todo::ASSIGNED then 'to yourself'
when Todo::REVIEW_REQUESTED then 'from yourself'
end
end
def todo_target_link(todo)
text = raw(todo_target_type_name(todo) + ' ') +
if todo.for_commit?
......@@ -141,6 +149,7 @@ module TodosHelper
[
{ id: '', text: 'Any Action' },
{ id: Todo::ASSIGNED, text: 'Assigned' },
{ id: Todo::REVIEW_REQUESTED, text: 'Review requested' },
{ id: Todo::MENTIONED, text: 'Mentioned' },
{ id: Todo::MARKED, text: 'Added' },
{ id: Todo::BUILD_FAILED, text: 'Pipelines' },
......
......@@ -227,7 +227,7 @@ class Todo < ApplicationRecord
end
def self_assigned?
assigned? && self_added?
self_added? && (assigned? || review_requested?)
end
private
......
......@@ -31,7 +31,7 @@
- if todo.self_assigned?
%span.title-item.action-name
to yourself
= todo_self_addressing(todo)
%span.title-item
&middot;
......
......@@ -12,6 +12,10 @@ FactoryBot.define do
action { Todo::ASSIGNED }
end
trait :review_requested do
action { Todo::REVIEW_REQUESTED }
end
trait :mentioned do
action { Todo::MENTIONED }
end
......
......@@ -130,6 +130,7 @@ RSpec.describe 'Dashboard > User filters todos', :js do
before do
create(:todo, :build_failed, user: user_1, author: user_2, project: project_1)
create(:todo, :marked, user: user_1, author: user_2, project: project_1, target: issue1)
create(:todo, :review_requested, user: user_1, author: user_2, project: project_1, target: issue1)
end
it 'filters by Assigned' do
......@@ -138,6 +139,12 @@ RSpec.describe 'Dashboard > User filters todos', :js do
expect_to_see_action(:assigned)
end
it 'filters by Review Requested' do
filter_action('Review requested')
expect_to_see_action(:review_requested)
end
it 'filters by Mentioned' do
filter_action('Mentioned')
......@@ -168,6 +175,7 @@ RSpec.describe 'Dashboard > User filters todos', :js do
def expect_to_see_action(action_name)
action_names = {
assigned: ' assigned you ',
review_requested: ' requested a review of ',
mentioned: ' mentioned ',
marked: ' added a todo for ',
build_failed: ' build failed for '
......
......@@ -197,6 +197,21 @@ RSpec.describe 'Dashboard Todos' do
end
end
end
context 'review request todo' do
let(:merge_request) { create(:merge_request, title: "Fixes issue") }
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
expect(page).to have_content("You requested a review of merge request #{merge_request.to_reference} \"Fixes issue\" at #{project.namespace.owner_name} / #{project.name} from yourself")
end
end
end
end
context 'User has done todos', :js do
......
......@@ -200,26 +200,42 @@ RSpec.describe Todo do
describe '#self_assigned?' do
let(:user_1) { build(:user) }
before do
subject.user = user_1
subject.author = user_1
subject.action = Todo::ASSIGNED
end
context 'when self_added' do
before do
subject.user = user_1
subject.author = user_1
end
it 'is true when todo is ASSIGNED and self_added' do
expect(subject).to be_self_assigned
end
it 'returns true for ASSIGNED' do
subject.action = Todo::ASSIGNED
expect(subject).to be_self_assigned
end
it 'is false when the todo is not ASSIGNED' do
subject.action = Todo::MENTIONED
it 'returns true for REVIEW_REQUESTED' do
subject.action = Todo::REVIEW_REQUESTED
expect(subject).not_to be_self_assigned
expect(subject).to be_self_assigned
end
it 'returns false for other action' do
subject.action = Todo::MENTIONED
expect(subject).not_to be_self_assigned
end
end
it 'is false when todo is not self_added' do
subject.author = build(:user)
context 'when todo is not self_added' do
before do
subject.user = user_1
subject.author = build(:user)
end
expect(subject).not_to be_self_assigned
it 'returns false' do
subject.action = Todo::ASSIGNED
expect(subject).not_to be_self_assigned
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