A platform for community discussion. Free, open, simple.
FIX: Unstar channel when unfollowing (#36520)
Martin Brennan73e22d825b9b
diff --git a/plugins/chat/lib/chat/channel_membership_manager.rb b/plugins/chat/lib/chat/channel_membership_manager.rbindex effc37d30e3..f93004c0f03 100644--- a/plugins/chat/lib/chat/channel_membership_manager.rb+++ b/plugins/chat/lib/chat/channel_membership_manager.rb@@ -44,7 +44,7 @@ module ChatActiveRecord::Base.transaction doif membership.following- membership.update!(following: false)+ membership.update!(following: false, starred: false)recalculate_user_countendenddiff --git a/plugins/chat/spec/services/chat/unfollow_channel_spec.rb b/plugins/chat/spec/services/chat/unfollow_channel_spec.rbindex 40b42da06cc..bc6f26e801c 100644--- a/plugins/chat/spec/services/chat/unfollow_channel_spec.rb+++ b/plugins/chat/spec/services/chat/unfollow_channel_spec.rb@@ -31,6 +31,14 @@ RSpec.describe Chat::UnfollowChannel doit "unfollows the channel" doexpect { result }.to change { membership.reload.following }.from(true).to(false)end++ context "when channel is starred" do+ before { membership.update!(starred: true) }++ it "unstars the channel" do+ expect { result }.to change { membership.reload.starred }.from(true).to(false)+ end+ endendcontext "with no existing membership" dodiff --git a/plugins/chat/spec/system/unfollow_dm_channel_spec.rb b/plugins/chat/spec/system/unfollow_dm_channel_spec.rbindex 1b0be5961c8..08f4e93b7f5 100644--- a/plugins/chat/spec/system/unfollow_dm_channel_spec.rb+++ b/plugins/chat/spec/system/unfollow_dm_channel_spec.rb@@ -7,6 +7,7 @@ RSpec.describe "Unfollow dm channel", type: :system dolet!(:chat_page) { PageObjects::Pages::Chat.new }let!(:channel_page) { PageObjects::Pages::ChatChannel.new }+ let(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new }before doSiteSetting.navigation_menu = "sidebar"@@ -32,5 +33,38 @@ RSpec.describe "Unfollow dm channel", type: :system doexpect(page).to have_css(".channel-#{dm_channel_1.id} .urgent", wait: 25)end++ context "when channel was previously starred" do+ let(:membership) { dm_channel_1.membership_for(current_user) }++ before { membership.update!(starred: true) }++ it "does not show the channel back in the starred section" do+ visit("/")++ within(sidebar.sidebar_section_selector("chat-starred-channels")) do+ expect(page).to have_css(".channel-#{dm_channel_1.id}")+ end++ find(".channel-#{dm_channel_1.id}").hover+ find(".channel-#{dm_channel_1.id} .sidebar-section-link-hover").click++ expect(page).to have_no_css(".channel-#{dm_channel_1.id}")++ using_session(:user_1) do+ text = "this is fine"+ sign_in(other_user)+ chat_page.visit_channel(dm_channel_1)+ channel_page.send_message(text)+ expect(channel_page.messages).to have_message(text: text)+ end++ expect(page).to have_no_css(sidebar.sidebar_section_selector("chat-starred-channels"))++ within(sidebar.sidebar_section_selector("chat-dms")) do+ expect(page).to have_css(".channel-#{dm_channel_1.id} .urgent", wait: 25)+ end+ end+ endendenddiff --git a/spec/system/page_objects/components/navigation_menu/base.rb b/spec/system/page_objects/components/navigation_menu/base.rbindex 8ff7f943f59..ccc2a9ec511 100644--- a/spec/system/page_objects/components/navigation_menu/base.rb+++ b/spec/system/page_objects/components/navigation_menu/base.rb@@ -55,12 +55,17 @@ module PageObjectssection_link_present?(name, href: href, active: active, present: false)end+ def sidebar_section_selector(name)+ name = name.parameterize if name.include?(" ") || name.match?(/[A-Z]/)+ ".sidebar-sections [data-section-name='#{name}']"+ end+def has_section?(name)- has_css?(".sidebar-sections [data-section-name='#{name.parameterize}']")+ has_css?(sidebar_section_selector(name))enddef has_no_section?(name)- has_no_css?(".sidebar-sections [data-section-name='#{name.parameterize}']")+ has_no_css?(sidebar_section_selector(name))enddef has_section_expanded?(name)@@ -208,10 +213,6 @@ module PageObjectsprivate- def sidebar_section_selector(name)- ".sidebar-section[data-section-name='#{name}']"- end-def section_link_present?(name, href: nil, active: false, target: nil, count: 1, present:)attributes = { exact_text: name }attributes[:href] = href if href