Skip to content

Commit

Permalink
Merge pull request #2507 from alphagov/add-user-to-top-assignee-list
Browse files Browse the repository at this point in the history
Add user to top assignee list
  • Loading branch information
ellohez authored Jan 30, 2025
2 parents 08d2ad3 + 97a6107 commit d00ebb4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
23 changes: 17 additions & 6 deletions app/presenters/filtered_editions_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ def edition_states

def assignees
users = [{ text: "All assignees", value: "" }]
users << create_assignee_list_item(@user)

available_users.map do |user|
users << if user.id.to_s == @assigned_to_filter
{ text: user.name, value: user.id, selected: "true" }
else
{ text: user.name, value: user.id }
end
end
next if user == @user

users << create_assignee_list_item(user)
end
users
end

Expand All @@ -62,6 +60,19 @@ def editions

private

def create_assignee_list_item(user)
user_name = if user == @user
"#{user.name} (You)"
else
user.name
end
if user.id.to_s == @assigned_to_filter
{ text: user_name, value: user.id, selected: "true" }
else
{ text: user_name, value: user.id }
end
end

def query_editions
result = editions_by_content_type
result = apply_states_filter(result)
Expand Down
35 changes: 30 additions & 5 deletions test/unit/presenters/filtered_editions_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,39 @@ def a_gds_user
assert_includes(assignees, { text: "All assignees", value: "" })
end

should "return the current user after the 'All assignees' item" do
current_user = FactoryBot.create(:user, name: "River Tam", id: 123)
assignees = FilteredEditionsPresenter.new(current_user).assignees

assert_equal("#{current_user.name} (You)", assignees[1][:text])
assert_equal(current_user.id, assignees[1][:value])
end

should "only return the current user once" do
current_user = FactoryBot.create(:user, name: "River Tam", id: 123)
bob = FactoryBot.create(:user, name: "Bob")
assignees = FilteredEditionsPresenter.new(current_user).assignees

assert_equal(1, assignees.count { |user| user[:text] == "#{current_user.name} (You)" })
assert_equal(bob.name, assignees[2][:text])
assert_not_includes assignees.map { |user| user[:text] }, current_user.name
end

should "return users who are not the assignee as unselected" do
anna = FactoryBot.create(:user, name: "Anna")
assignees = FilteredEditionsPresenter.new(a_gds_user).assignees

assert_includes(assignees, { text: anna.name, value: anna.id })
end

should "return the assignee as selected" do
should "return the assignee as selected (when the assignee is the current user)" do
a_user = a_gds_user
assignees = FilteredEditionsPresenter.new(a_user, assigned_to_filter: a_user.id.to_s).assignees

assert_includes(assignees, { text: "#{a_user.name} (You)", value: a_user.id, selected: "true" })
end

should "return the assignee as selected (when the assignee is not the current user)" do
anna = FactoryBot.create(:user, name: "Anna")
assignees = FilteredEditionsPresenter.new(a_gds_user, assigned_to_filter: anna.id.to_s).assignees

Expand All @@ -246,9 +271,10 @@ def a_gds_user

assignees = FilteredEditionsPresenter.new(a_gds_user).assignees

assert_equal(anna.name, assignees[1][:text])
assert_equal(bob.name, assignees[2][:text])
assert_equal(charlie.name, assignees[3][:text])
# First two items are 'All assignees' and the current user
assert_equal(anna.name, assignees[2][:text])
assert_equal(bob.name, assignees[3][:text])
assert_equal(charlie.name, assignees[4][:text])
end

should "not include disabled users" do
Expand All @@ -259,7 +285,6 @@ def a_gds_user

assert_equal(2, users.count)
assert_equal("All assignees", users[0][:text])
assert_equal(a_user.name, users[1][:text])
assert_not_includes users.map { |user| user[:text] }, disabled_user.name
end
end
Expand Down

0 comments on commit d00ebb4

Please sign in to comment.