Commit bb3521f0 authored by David Kim's avatar David Kim Committed by Dmytro Zaporozhets (DZ)

Add Review Requested to Todo list filter

parent cb3b5278
......@@ -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,28 +200,44 @@ RSpec.describe Todo do
describe '#self_assigned?' do
let(:user_1) { build(:user) }
context 'when self_added' do
before do
subject.user = user_1
subject.author = user_1
end
it 'returns true for ASSIGNED' do
subject.action = Todo::ASSIGNED
expect(subject).to be_self_assigned
end
it 'is true when todo is ASSIGNED and self_added' do
it 'returns true for REVIEW_REQUESTED' do
subject.action = Todo::REVIEW_REQUESTED
expect(subject).to be_self_assigned
end
it 'is false when the todo is not ASSIGNED' do
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
context 'when todo is not self_added' do
before do
subject.user = user_1
subject.author = build(:user)
end
it 'returns false' do
subject.action = Todo::ASSIGNED
expect(subject).not_to be_self_assigned
end
end
end
describe '.for_action' do
it 'returns the todos for a given action' do
......
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