Skip to content

Commit

Permalink
FIX: correctly handles mobile and default (#23152)
Browse files Browse the repository at this point in the history
This commit ensures we have correct icon and title on mobile for the chat header icon.

It also fixes a bug where the site setting was not correctly used when the user has not yet set the user option.

Both cases are now correctly tested.
  • Loading branch information
jjaffeux committed Aug 18, 2023
1 parent 477a5dd commit b03c26e
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
Expand Up @@ -27,7 +27,8 @@ export default class ChatHeaderIcon extends Component {
get title() {
if (
this.chatStateManager.isFullPageActive &&
!this.chatSeparateSidebarMode.never
!this.chatSeparateSidebarMode.never &&
!this.site.mobileView
) {
return "sidebar.panels.forum.label";
}
Expand All @@ -38,7 +39,8 @@ export default class ChatHeaderIcon extends Component {
get icon() {
if (
this.chatStateManager.isFullPageActive &&
!this.chatSeparateSidebarMode.never
!this.chatSeparateSidebarMode.never &&
!this.site.mobileView
) {
return "random";
}
Expand Down
@@ -1,5 +1,8 @@
export function getUserChatSeparateSidebarMode(user) {
const mode = user?.get("user_option.chat_separate_sidebar_mode");
let mode = user?.get("user_option.chat_separate_sidebar_mode");
if (mode === "default") {
mode = user.siteSettings.chat_separate_sidebar_mode;
}

return {
never: "never" === mode,
Expand Down
7 changes: 6 additions & 1 deletion plugins/chat/assets/javascripts/discourse/routes/chat.js
Expand Up @@ -63,7 +63,12 @@ export default class ChatRoute extends DiscourseRoute {
activate() {
withPluginApi("1.8.0", (api) => {
api.setSidebarPanel("chat");
if (getUserChatSeparateSidebarMode(this.currentUser).never) {

const chatSeparateSidebarMode = getUserChatSeparateSidebarMode(
this.currentUser
);

if (chatSeparateSidebarMode.never) {
api.setCombinedSidebarMode();
api.hideSidebarSwitchPanelButtons();
} else {
Expand Down
30 changes: 30 additions & 0 deletions plugins/chat/spec/system/separate_sidebar_mode_spec.rb
Expand Up @@ -17,6 +17,36 @@
sign_in(current_user)
end

describe "when separate sidebar mode is not set" do
before do
SiteSetting.chat_separate_sidebar_mode = "always"
chat_page.prefers_full_page
end

it "uses the site setting" do
visit("/")

expect(sidebar_component).to have_switch_button("chat")
expect(header_component).to have_open_chat_button
expect(sidebar_component).to have_no_section("chat-channels")
expect(sidebar_component).to have_section("Categories")

chat_page.open_from_header

expect(sidebar_component).to have_switch_button("main")
expect(header_component).to have_open_forum_button
expect(sidebar_component).to have_section("chat-channels")
expect(sidebar_component).to have_no_section("Categories")

find("#site-logo").click

expect(sidebar_component).to have_switch_button("chat")
expect(header_component).to have_open_chat_button
expect(sidebar_component).to have_no_section("chat-channels")
expect(sidebar_component).to have_section("Categories")
end
end

describe "when separate sidebar mode is never" do
before do
current_user.user_option.update!(
Expand Down
13 changes: 13 additions & 0 deletions plugins/chat/test/javascripts/components/chat-header-icon-test.js
Expand Up @@ -41,4 +41,17 @@ module("Discourse Chat | Component | chat-header-icon", function (hooks) {

assert.dom(".d-icon-random").exists();
});

test("mobile", async function (assert) {
this.site.mobileView = true;

await render(hbs`<Chat::Header::Icon />`);

assert
.dom(".icon.btn-flat")
.hasAttribute("title", I18n.t("chat.title_capitalized"))
.hasAttribute("href", "/chat");

assert.dom(".d-icon-d-chat").exists();
});
});

0 comments on commit b03c26e

Please sign in to comment.