FIX: correctly check chat tab is present (#23200)

Prior to this fix we would test by visiting the tab which could create a false positive, as the tab could not be present but we could still access the tab, the implementation and tests have been changed to correctly ensure this.
This commit is contained in:
Joffrey JAFFEUX 2023-08-23 13:06:29 +02:00 committed by GitHub
parent a008f61f8f
commit fef0225a22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 9 deletions

View File

@ -1,7 +1,7 @@
import Component from "@glimmer/component"; import Component from "@glimmer/component";
export default class ChatPreferences extends Component { export default class ChatPreferences extends Component {
static shouldRender(model, { siteSettings, currentUser }) { static shouldRender({ model }, { siteSettings, currentUser }) {
return siteSettings.chat_enabled && (model.can_chat || currentUser?.admin); return siteSettings.chat_enabled && (model.can_chat || currentUser?.admin);
} }
} }

View File

@ -5,13 +5,19 @@ import { inject as service } from "@ember/service";
export default class PreferencesChatRoute extends RestrictedUserRoute { export default class PreferencesChatRoute extends RestrictedUserRoute {
@service chat; @service chat;
@service router; @service router;
@service siteSettings;
@service currentUser;
showFooter = true; showFooter = true;
setupController(controller, user) { setupController(controller, user) {
if (!user?.can_chat && !this.currentUser.admin) { if (
!this.siteSettings.chat_enabled ||
(!user.can_chat && !this.currentUser?.admin)
) {
return this.router.transitionTo(`discovery.${defaultHomepage()}`); return this.router.transitionTo(`discovery.${defaultHomepage()}`);
} }
controller.set("model", user); controller.set("model", user);
} }
} }

View File

@ -17,20 +17,21 @@ RSpec.describe "User chat preferences", type: :system do
end end
it "doesnt show the tab" do it "doesnt show the tab" do
visit("/u/#{current_user.username}/preferences") visit("/my/preferences")
expect(page).to have_no_css(".user-nav__preferences-chat", visible: :all) expect(page).to have_no_css(".user-nav__preferences-chat", visible: :all)
end end
it "shows a not found page" do it "shows a not found page" do
visit("/u/#{current_user.username}/preferences/chat") visit("/my/preferences/chat")
expect(page).to have_content(I18n.t("page_not_found.title")) expect(page).to have_content(I18n.t("page_not_found.title"))
end end
end end
it "can select chat sound" do it "can select chat sound" do
visit("/u/#{current_user.username}/preferences/chat") visit("/my/preferences")
find(".user-nav__preferences-chat", visible: :all).click
select_kit = PageObjects::Components::SelectKit.new("#user_chat_sounds") select_kit = PageObjects::Components::SelectKit.new("#user_chat_sounds")
select_kit.expand select_kit.expand
select_kit.select_row_by_value("bell") select_kit.select_row_by_value("bell")
@ -40,7 +41,8 @@ RSpec.describe "User chat preferences", type: :system do
end end
it "can select header_indicator_preference" do it "can select header_indicator_preference" do
visit("/u/#{current_user.username}/preferences/chat") visit("/my/preferences")
find(".user-nav__preferences-chat", visible: :all).click
select_kit = PageObjects::Components::SelectKit.new("#user_chat_header_indicator_preference") select_kit = PageObjects::Components::SelectKit.new("#user_chat_header_indicator_preference")
select_kit.expand select_kit.expand
select_kit.select_row_by_value("dm_and_mentions") select_kit.select_row_by_value("dm_and_mentions")
@ -50,7 +52,8 @@ RSpec.describe "User chat preferences", type: :system do
end end
it "can select separate sidebar mode" do it "can select separate sidebar mode" do
visit("/u/#{current_user.username}/preferences/chat") visit("/my/preferences")
find(".user-nav__preferences-chat", visible: :all).click
select_kit = PageObjects::Components::SelectKit.new("#user_chat_separate_sidebar_mode") select_kit = PageObjects::Components::SelectKit.new("#user_chat_separate_sidebar_mode")
select_kit.expand select_kit.expand
select_kit.select_row_by_value("fullscreen") select_kit.select_row_by_value("fullscreen")
@ -67,8 +70,7 @@ RSpec.describe "User chat preferences", type: :system do
it "allows to change settings" do it "allows to change settings" do
visit("/u/#{user_1.username}/preferences") visit("/u/#{user_1.username}/preferences")
find(".user-nav__preferences-chat", visible: :all).click
find(".user-nav__preferences-chat").click
expect(page).to have_current_path("/u/#{user_1.username}/preferences/chat") expect(page).to have_current_path("/u/#{user_1.username}/preferences/chat")
end end