A platform for community discussion. Free, open, simple.
UX: Only show chat star action if user has joined channel (#41088)
Penar Musarajafe1d1894ab6
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/navbar/channel-title.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/navbar/channel-title.gjsindex 874c6059979..c4298f01a0d 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat/navbar/channel-title.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat/navbar/channel-title.gjs@@ -38,13 +38,13 @@ export default class ChatNavbarChannelTitle extends Component {}get showStarButton() {- return this.currentUser && !!this.args.channel?.currentUserMembership;+ return this.currentUser && this.args.channel?.isFollowing;}@actionasync toggleStarred() {const channel = this.args.channel;- if (!channel?.currentUserMembership || this.isTogglingStarred) {+ if (!channel?.isFollowing || this.isTogglingStarred) {return;}diff --git a/plugins/chat/test/javascripts/components/chat-navbar-channel-title-test.gjs b/plugins/chat/test/javascripts/components/chat-navbar-channel-title-test.gjsnew file mode 100644index 00000000000..392be796ad5--- /dev/null+++ b/plugins/chat/test/javascripts/components/chat-navbar-channel-title-test.gjs@@ -0,0 +1,40 @@+import { getOwner } from "@ember/owner";+import { render } from "@ember/test-helpers";+import { module, test } from "qunit";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import ChatNavbarChannelTitle from "discourse/plugins/chat/discourse/components/chat/navbar/channel-title";+import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";++module("Component | ChatNavbar | ChannelTitle", function (hooks) {+ setupRenderingTest(hooks);++ hooks.beforeEach(function () {+ this.fabricators = new ChatFabricators(getOwner(this));+ });++ test("shows the star button when the user has joined the channel", async function (assert) {+ this.channel = this.fabricators.channel();+ this.channel.currentUserMembership = { following: true };++ await render(+ <template><ChatNavbarChannelTitle @channel={{this.channel}} /></template>+ );++ assert+ .dom(".c-navbar__star-channel-button")+ .exists("the star button is shown");+ });++ test("does not show the star button when the user has not joined the channel", async function (assert) {+ this.channel = this.fabricators.channel();+ this.channel.currentUserMembership = { following: false };++ await render(+ <template><ChatNavbarChannelTitle @channel={{this.channel}} /></template>+ );++ assert+ .dom(".c-navbar__star-channel-button")+ .doesNotExist("the star button is hidden");+ });+});