From a008f61f8f00dade8810e0d755b69c1adee9f54b Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 23 Aug 2023 13:05:15 +0200 Subject: [PATCH] FIX: correctly closes panel when exiting chat (#23201) We don't use activate/deactivate as it would cause: close/open in short succession when going from threads to thread for example. --- .../discourse/routes/chat-channel-thread.js | 3 ++- .../discourse/routes/chat-channel-threads.js | 7 +++++- plugins/chat/spec/system/navigation_spec.rb | 24 +++++++++++++++++++ .../components/navigation_menu/base.rb | 4 ++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat-channel-thread.js b/plugins/chat/assets/javascripts/discourse/routes/chat-channel-thread.js index 0600e2266a5..5a04de8e906 100644 --- a/plugins/chat/assets/javascripts/discourse/routes/chat-channel-thread.js +++ b/plugins/chat/assets/javascripts/discourse/routes/chat-channel-thread.js @@ -30,7 +30,8 @@ export default class ChatChannelThread extends DiscourseRoute { if ( transition.targetName === "chat.channel.index" || transition.targetName === "chat.channel.near-message" || - transition.targetName === "chat.index" + transition.targetName === "chat.index" || + !transition.targetName.startsWith("chat") ) { this.chatStateManager.closeSidePanel(); } diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat-channel-threads.js b/plugins/chat/assets/javascripts/discourse/routes/chat-channel-threads.js index 7599442cdba..e047af52ac1 100644 --- a/plugins/chat/assets/javascripts/discourse/routes/chat-channel-threads.js +++ b/plugins/chat/assets/javascripts/discourse/routes/chat-channel-threads.js @@ -21,7 +21,12 @@ export default class ChatChannelThreads extends DiscourseRoute { @action willTransition(transition) { - if (transition.targetName === "chat.channel.index") { + if ( + transition.targetName === "chat.channel.index" || + transition.targetName === "chat.channel.near-message" || + transition.targetName === "chat.index" || + !transition.targetName.startsWith("chat") + ) { this.chatStateManager.closeSidePanel(); } } diff --git a/plugins/chat/spec/system/navigation_spec.rb b/plugins/chat/spec/system/navigation_spec.rb index b41513f9198..ec28288fa71 100644 --- a/plugins/chat/spec/system/navigation_spec.rb +++ b/plugins/chat/spec/system/navigation_spec.rb @@ -352,5 +352,29 @@ RSpec.describe "Navigation", type: :system do expect(sidebar_component).to have_no_section_link(category_channel.name, active: true) end end + + context "when exiting a thread for homepage" do + fab!(:thread) { Fabricate(:chat_thread, channel: category_channel) } + + before do + current_user.user_option.update( + chat_separate_sidebar_mode: UserOption.chat_separate_sidebar_modes[:always], + ) + chat_page.prefers_full_page + category_channel.update!(threading_enabled: true) + thread.add(current_user) + end + + it "correctly closes the panel" do + chat_page.visit_thread(thread) + + expect(side_panel_page).to have_open_thread(thread) + + find("#site-logo").click + sidebar_component.switch_to_chat + + expect(page).to have_no_css(".chat-side-panel") + end + end end end diff --git a/spec/system/page_objects/components/navigation_menu/base.rb b/spec/system/page_objects/components/navigation_menu/base.rb index 7f41ea2447a..7eda232bc75 100644 --- a/spec/system/page_objects/components/navigation_menu/base.rb +++ b/spec/system/page_objects/components/navigation_menu/base.rb @@ -30,6 +30,10 @@ module PageObjects has_css?(".sidebar-sections [data-section-name='#{name.parameterize}']") end + def switch_to_chat + find(".sidebar__panel-switch-button[data-key='chat']").click + end + def has_no_section?(name) has_no_css?(".sidebar-sections [data-section-name='#{name.parameterize}']") end