discourse/plugins/chat/test/javascripts/components/chat-channel-leave-btn-test.js
Joffrey JAFFEUX 1060e4573a
DEV: allows fabricators to use faker (#26555)
The complexity of the situation is that we don't want to load faker into production by default but fabricators and styleguide are available on production.

This is made possible through app/assets/javascripts/discourse/app/lib/load-faker.js which contains a function to ensure faker is loaded asynchronously (loadFaker) and another function to access the loaded faker (getLoadedFaker).

Note 1: this commit also refactors fabricators to have access to context and use faker where possible
Note 2: this commit moves automation to admin bundle

---------

Co-authored-by: David Taylor <david@taylorhq.com>
2024-04-08 21:00:09 +02:00

59 lines
2.2 KiB
JavaScript

import { getOwner } from "@ember/application";
import { click, render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import pretender from "discourse/tests/helpers/create-pretender";
import { query } from "discourse/tests/helpers/qunit-helpers";
import I18n from "discourse-i18n";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module("Discourse Chat | Component | chat-channel-leave-btn", function (hooks) {
setupRenderingTest(hooks);
test("accepts an optional onLeaveChannel callback", async function (assert) {
this.foo = 1;
this.onLeaveChannel = () => (this.foo = 2);
this.channel = new ChatFabricators(getOwner(this)).directMessageChannel();
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);
});
test("has a specific title for direct message channel", async function (assert) {
this.channel = new ChatFabricators(getOwner(this)).directMessageChannel();
await render(hbs`<ChatChannelLeaveBtn @channel={{this.channel}} />`);
const btn = query(".chat-channel-leave-btn");
assert.strictEqual(btn.title, I18n.t("chat.direct_messages.leave"));
});
test("has a specific title for message channel", async function (assert) {
this.channel = new ChatFabricators(getOwner(this)).channel();
await render(hbs`<ChatChannelLeaveBtn @channel={{this.channel}} />`);
const btn = query(".chat-channel-leave-btn");
assert.strictEqual(btn.title, I18n.t("chat.leave"));
});
test("is not visible on mobile", async function (assert) {
this.site.desktopView = false;
this.channel = new ChatFabricators(getOwner(this)).channel();
await render(hbs`<ChatChannelLeaveBtn @channel={{this.channel}} />`);
assert.dom(".chat-channel-leave-btn").doesNotExist();
});
});