0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-09 21:45:25 +08:00
discourse/plugins/chat/test/javascripts/components/toggle-channel-membership-button-test.gjs
Penar Musaraj 7cfe964e8d
FEATURE: allow anonymous users to view public chat channels (#40688)
This PR allows site admins to configure chat on a site to be visible to
anonymous users. This allows for more visibility in the site's chat
activity, should be a better default.

To enable, the site needs to: 

- enable the "Granular anonymous and logged in groups permissions"
upcoming change
- add anonymous users to `chat_allowed_groups`
- optional (but useful): also add `trust_level_0` users to `chat allowed
groups`

---------

Co-authored-by: Martin Brennan <martin@discourse.org>
2026-06-18 15:18:51 -04:00

45 lines
1.6 KiB
Text
Vendored

import { getOwner } from "@ember/owner";
import { click, render } from "@ember/test-helpers";
import { module, test } from "qunit";
import sinon from "sinon";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import ToggleChannelMembershipButton from "discourse/plugins/chat/discourse/components/toggle-channel-membership-button";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module("Component | ToggleChannelMembershipButton", function (hooks) {
setupRenderingTest(hooks, { anonymous: true });
hooks.beforeEach(function () {
this.showLogin = sinon.stub();
this.chatStateManager = this.owner.lookup("service:chat-state-manager");
this.chatStateManager.isDrawerActive = true;
sinon.stub(this.chatStateManager, "didCloseDrawer");
this.owner.register(
"route:application",
{ send: this.showLogin },
{ instantiate: false }
);
this.channel = new ChatFabricators(getOwner(this)).channel({
chatable_type: "Category",
current_user_membership: null,
meta: { can_join_chat_channel: true },
});
});
test("anonymous users are sent to login when joining a channel", async function (assert) {
await render(
<template>
<ToggleChannelMembershipButton @channel={{this.channel}} />
</template>
);
assert.dom(".toggle-channel-membership-button.-join").exists();
await click(".toggle-channel-membership-button.-join");
assert.true(this.chatStateManager.didCloseDrawer.calledOnce);
assert.true(this.showLogin.calledWith("showLogin"));
});
});