2024-07-25 21:09:06 +08:00
|
|
|
import { getOwner } from "@ember/owner";
|
2022-12-22 21:35:18 +08:00
|
|
|
import { click, render } from "@ember/test-helpers";
|
2022-11-02 21:41:30 +08:00
|
|
|
import hbs from "htmlbars-inline-precompile";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { module, test } from "qunit";
|
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
2022-11-02 21:41:30 +08:00
|
|
|
import pretender from "discourse/tests/helpers/create-pretender";
|
2024-03-19 06:29:42 +08:00
|
|
|
import { query } from "discourse/tests/helpers/qunit-helpers";
|
2023-10-18 18:07:09 +08:00
|
|
|
import I18n from "discourse-i18n";
|
2024-04-09 03:00:09 +08:00
|
|
|
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
module("Discourse Chat | Component | chat-channel-leave-btn", function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("accepts an optional onLeaveChannel callback", async function (assert) {
|
2023-05-09 00:24:41 +08:00
|
|
|
this.foo = 1;
|
|
|
|
this.onLeaveChannel = () => (this.foo = 2);
|
2024-04-09 03:00:09 +08:00
|
|
|
this.channel = new ChatFabricators(getOwner(this)).directMessageChannel();
|
2022-12-22 21:35:18 +08:00
|
|
|
|
|
|
|
await render(
|
|
|
|
hbs`<ChatChannelLeaveBtn @channel={{this.channel}} @onLeaveChannel={{this.onLeaveChannel}} />`
|
|
|
|
);
|
|
|
|
|
|
|
|
pretender.post("/chat/chat_channels/:chatChannelId/unfollow", () => {
|
|
|
|
return [200, { current_user_membership: { following: false } }, {}];
|
|
|
|
});
|
|
|
|
assert.strictEqual(this.foo, 1);
|
|
|
|
|
|
|
|
await click(".chat-channel-leave-btn");
|
|
|
|
assert.strictEqual(this.foo, 2);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("has a specific title for direct message channel", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.channel = new ChatFabricators(getOwner(this)).directMessageChannel();
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<ChatChannelLeaveBtn @channel={{this.channel}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
const btn = query(".chat-channel-leave-btn");
|
|
|
|
assert.strictEqual(btn.title, I18n.t("chat.direct_messages.leave"));
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("has a specific title for message channel", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.channel = new ChatFabricators(getOwner(this)).channel();
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<ChatChannelLeaveBtn @channel={{this.channel}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
const btn = query(".chat-channel-leave-btn");
|
|
|
|
assert.strictEqual(btn.title, I18n.t("chat.leave"));
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("is not visible on mobile", async function (assert) {
|
2024-03-19 06:29:42 +08:00
|
|
|
this.site.desktopView = false;
|
2024-04-09 03:00:09 +08:00
|
|
|
this.channel = new ChatFabricators(getOwner(this)).channel();
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<ChatChannelLeaveBtn @channel={{this.channel}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2024-03-19 06:29:42 +08:00
|
|
|
assert.dom(".chat-channel-leave-btn").doesNotExist();
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
});
|