FIX: Render user profile trust level name for TL0 (#22740)

* Why was this change necessary?
The current logic in the user.hbs template file does not render the
trust level element for the user's info panel when the user is TL0,
because 0 is treated as falsey in the `if` conditional block.

Ref: https://meta.discourse.org/t/tl0-not-displayed-on-users-profile-pages/271779/10

* How does it address the problem?

This PR adds a predicate helper method local to the user controller that
includes an additional check which returns true if the trust_level of
the user is 0 on top of the existing logic. This allows TL0 users to
have their trust level rendered correctly in their profile's info panel.
This commit is contained in:
Kelv 2023-07-21 15:16:34 +08:00 committed by GitHub
parent 384068f4c7
commit 2968fb6a5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 1 deletions

View File

@ -68,6 +68,8 @@ export default Controller.extend(CanCheckEmails, {
};
}),
isTrustLevelZero: equal("model.trust_level", 0),
hasTrustLevel: or("isTrustLevelZero", "model.trust_level"),
showStaffCounters: or(
"hasGivenFlags",
"hasFlaggedPosts",

View File

@ -384,7 +384,7 @@
@model={{this.model.invited_by}}
>{{this.model.invited_by.username}}</LinkTo></dd></div>
{{/if}}
{{#if this.model.trust_level}}
{{#if this.hasTrustLevel}}
<div><dt class="trust-level">{{i18n "user.trust_level"}}</dt><dd
class="trust-level"
>{{this.model.trustLevel.name}}</dd></div>

View File

@ -29,6 +29,12 @@ module PageObjects
staff_counters.find("a[href='/u/#{user.username}/messages/warnings']").click
self
end
def expand_info_panel
button = page.find("button[aria-controls='collapsed-info-panel']")
button.click if button["aria-expanded"] == "false"
self
end
end
end
end

View File

@ -0,0 +1,19 @@
# frozen_string_literal: true
RSpec.describe "User Profile Info Panel", system: true do
let(:user_page) { PageObjects::Pages::User.new }
describe "trust level" do
TrustLevel.levels.values.each do |trust_level|
context "when user has trust level #{trust_level}" do
fab!(:user) { Fabricate(:user, trust_level: trust_level) }
before { sign_in(user) }
it "displays the correct trust level element" do
user_page.visit(user).expand_info_panel
expect(user_page).to have_css("dd.trust-level", text: TrustLevel.name(trust_level))
end
end
end
end
end