Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: correctly check chat tab is present #23200

Merged
merged 1 commit into from Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,7 +1,7 @@
import Component from "@glimmer/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);
}
}
Expand Up @@ -5,13 +5,19 @@ import { inject as service } from "@ember/service";
export default class PreferencesChatRoute extends RestrictedUserRoute {
@service chat;
@service router;
@service siteSettings;
@service currentUser;

showFooter = true;

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()}`);
}

controller.set("model", user);
}
}
16 changes: 9 additions & 7 deletions plugins/chat/spec/system/user_chat_preferences_spec.rb
Expand Up @@ -17,20 +17,21 @@
end

it "doesn’t 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)
end

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"))
end
end

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.expand
select_kit.select_row_by_value("bell")
Expand All @@ -40,7 +41,8 @@
end

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.expand
select_kit.select_row_by_value("dm_and_mentions")
Expand All @@ -50,7 +52,8 @@
end

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.expand
select_kit.select_row_by_value("fullscreen")
Expand All @@ -67,8 +70,7 @@

it "allows to change settings" do
visit("/u/#{user_1.username}/preferences")

find(".user-nav__preferences-chat").click
find(".user-nav__preferences-chat", visible: :all).click

expect(page).to have_current_path("/u/#{user_1.username}/preferences/chat")
end
Expand Down