From c2fd9d5116af838ae11b7c040a1c62a3191fe092 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 8 Dec 2022 22:48:29 +0100 Subject: [PATCH] FIX: correctly hides admin settings in channel settings (#19384) This would need even more test which are being created in a separate branch. --- .../components/chat-channel-settings-view.js | 2 +- .../chat-channel-settings-view-test.js | 49 ++++++++++++------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-settings-view.js b/plugins/chat/assets/javascripts/discourse/components/chat-channel-settings-view.js index 1dc4f4d3c31..89a23c8575b 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-settings-view.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-settings-view.js @@ -61,7 +61,7 @@ export default class ChatChannelSettingsView extends Component { @computed("autoJoinAvailable", "togglingChannelWideMentionsAvailable") get adminSectionAvailable() { return ( - this.chatGuardian.canEditChatChannel && + this.chatGuardian.canEditChatChannel() && (this.autoJoinAvailable || this.togglingChannelWideMentionsAvailable) ); } diff --git a/plugins/chat/test/javascripts/components/chat-channel-settings-view-test.js b/plugins/chat/test/javascripts/components/chat-channel-settings-view-test.js index 4a97c2d31ac..ef4fd1c4e7b 100644 --- a/plugins/chat/test/javascripts/components/chat-channel-settings-view-test.js +++ b/plugins/chat/test/javascripts/components/chat-channel-settings-view-test.js @@ -119,7 +119,7 @@ module( }, }); - componentTest("allow channel wide mentions", { + componentTest("hide channel wide mentions", { template: hbs`{{chat-channel-settings-view channel=channel}}`, beforeEach() { @@ -127,23 +127,21 @@ module( }, async test(assert) { - pretender.put(`/chat/api/chat_channels/${this.channel.id}.json`, () => { - return [ - 200, - { "Content-Type": "application/json" }, - { - allow_channel_wide_mentions: false, - }, - ]; - }); + assert + .dom(".channel-settings-view__channel-wide-mentions-selector") + .doesNotExist(); + }, + }); - const sk = selectKit( - ".channel-settings-view__channel-wide-mentions-selector" - ); - await sk.expand(); - await sk.selectRowByName("No"); + componentTest("hide channel auto join", { + template: hbs`{{chat-channel-settings-view channel=channel}}`, - assert.equal(sk.header().value(), "false"); + beforeEach() { + this.set("channel", fabricators.chatChannel()); + }, + + async test(assert) { + assert.dom(".channel-settings-view__auto-join-selector").doesNotExist(); }, }); } @@ -253,7 +251,7 @@ module( }, }); - componentTest("allow channel wide mentions", { + componentTest("hide channel wide mentions", { template: hbs`{{chat-channel-settings-view channel=channel}}`, beforeEach() { @@ -271,5 +269,22 @@ module( .doesNotExist(); }, }); + + componentTest("hide channel auto join", { + template: hbs`{{chat-channel-settings-view channel=channel}}`, + + beforeEach() { + this.set( + "channel", + fabricators.chatChannel({ + chatable_type: CHATABLE_TYPES.directMessageChannel, + }) + ); + }, + + async test(assert) { + assert.dom(".channel-settings-view__auto-join-selector").doesNotExist(); + }, + }); } );