2022-12-22 21:35:18 +08:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
2022-11-02 21:41:30 +08:00
|
|
|
import { query } from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
import hbs from "htmlbars-inline-precompile";
|
2022-12-22 21:35:18 +08:00
|
|
|
import { module, test } from "qunit";
|
|
|
|
import { render } from "@ember/test-helpers";
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
function displayName() {
|
|
|
|
return query(".chat-user-display-name").innerText.trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
module(
|
|
|
|
"Discourse Chat | Component | chat-user-display-name | prioritize username in UX",
|
|
|
|
function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("username and no name", async function (assert) {
|
|
|
|
this.siteSettings.prioritize_username_in_ux = true;
|
|
|
|
this.set("user", { username: "bob", name: null });
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<ChatUserDisplayName @user={{this.user}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.strictEqual(displayName(), "bob");
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("username and name", async function (assert) {
|
|
|
|
this.siteSettings.prioritize_username_in_ux = true;
|
|
|
|
this.set("user", { username: "bob", name: "Bobcat" });
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<ChatUserDisplayName @user={{this.user}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.strictEqual(displayName(), "bob — Bobcat");
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
module(
|
|
|
|
"Discourse Chat | Component | chat-user-display-name | prioritize name in UX",
|
|
|
|
function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("no name", async function (assert) {
|
|
|
|
this.siteSettings.prioritize_username_in_ux = false;
|
|
|
|
this.set("user", { username: "bob", name: null });
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<ChatUserDisplayName @user={{this.user}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.strictEqual(displayName(), "bob");
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("name and username", async function (assert) {
|
|
|
|
this.siteSettings.prioritize_username_in_ux = false;
|
|
|
|
this.set("user", { username: "bob", name: "Bobcat" });
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<ChatUserDisplayName @user={{this.user}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.strictEqual(displayName(), "Bobcat — bob");
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|