-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: Order items properly in user menu
The recent changes to the user menu changed how we were ordering the items in it. A small bug was noticed though, as we’re not displaying the unread assignments at the very top. This patch fixes the ordering like this: - Unread individual assignment notifications - Unread group assignment notifications - Read individual assignments - Read group assignments In each group of items, they are sorted by date, the most recent ones being at the top.
- Loading branch information
Showing
4 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
Fabricator(:assignment_notification, from: :notification) do | ||
transient :group | ||
notification_type Notification.types[:assigned] | ||
post_number 1 | ||
data do |attrs| | ||
{ | ||
message: | ||
( | ||
if attrs[:group] | ||
"discourse_assign.assign_group_notification" | ||
else | ||
"discourse_assign.assign_notification" | ||
end | ||
), | ||
display_username: attrs[:group] ? "group" : "user", | ||
assignment_id: rand(1..100), | ||
}.to_json | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module PageObjects | ||
module Components | ||
class UserMenu < PageObjects::Components::Base | ||
def click_assignments_tab | ||
click_link("user-menu-button-assign-list") | ||
has_css?("#quick-access-assign-list") | ||
self | ||
end | ||
|
||
def has_assignments_in_order?(assignments) | ||
expect(all(".notification.assigned .item-description").map(&:text)).to eq(assignments) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe "Assign | User Menu", type: :system, js: true do | ||
fab!(:admin) { Fabricate(:admin) } | ||
|
||
let(:user_menu) { PageObjects::Components::UserMenu.new } | ||
|
||
before do | ||
SiteSetting.assign_enabled = true | ||
sign_in(admin) | ||
end | ||
|
||
describe "Assign tab ordering" do | ||
let!(:unread_user_assign) { Fabricate(:assignment_notification, user: admin) } | ||
let!(:unread_user_assign_2) { Fabricate(:assignment_notification, user: admin) } | ||
let!(:read_user_assign) { Fabricate(:assignment_notification, user: admin, read: true) } | ||
let!(:read_user_assign_2) { Fabricate(:assignment_notification, user: admin, read: true) } | ||
let!(:unread_group_assign) { Fabricate(:assignment_notification, user: admin, group: true) } | ||
let!(:read_group_assign) do | ||
Fabricate(:assignment_notification, user: admin, read: true, group: true) | ||
end | ||
let(:expected_order) do | ||
[ | ||
unread_user_assign_2, | ||
unread_user_assign, | ||
unread_group_assign, | ||
read_user_assign_2, | ||
read_user_assign, | ||
read_group_assign, | ||
].map { _1.topic.fancy_title } | ||
end | ||
|
||
it "orders the items properly" do | ||
visit "/" | ||
user_menu.open | ||
user_menu.click_assignments_tab | ||
expect(user_menu).to have_assignments_in_order(expected_order) | ||
end | ||
end | ||
end |