mirror of
https://github.com/discourse/discourse.git
synced 2024-12-22 01:03:43 +08:00
c34f8b65cb
As of #23867 this is now a real package, so updating the imports to use the real package name, rather than relying on the alias. The name change in the package name is because `I18n` is not a valid name as NPM packages must be all lowercase. This commit also introduces an eslint rule to prevent importing from the old I18n path. For themes/plugins, the old 'i18n' name remains functional.
58 lines
2.1 KiB
JavaScript
58 lines
2.1 KiB
JavaScript
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 { exists, query } from "discourse/tests/helpers/qunit-helpers";
|
|
import I18n from "discourse-i18n";
|
|
import fabricators 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 = fabricators.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 = fabricators.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 = fabricators.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.mobileView = true;
|
|
this.channel = fabricators.channel();
|
|
|
|
await render(hbs`<ChatChannelLeaveBtn @channel={{this.channel}} />`);
|
|
|
|
assert.false(exists(".chat-channel-leave-btn"));
|
|
});
|
|
});
|