2024-07-25 21:09:06 +08:00
|
|
|
import { getOwner } from "@ember/owner";
|
2022-11-02 21:41:30 +08:00
|
|
|
import { render } from "@ember/test-helpers";
|
2023-10-11 02:38:59 +08:00
|
|
|
import hbs from "htmlbars-inline-precompile";
|
|
|
|
import { module, test } from "qunit";
|
2022-11-02 21:41:30 +08:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
|
|
import { query } from "discourse/tests/helpers/qunit-helpers";
|
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 | Unit | Helpers | format-chat-date", function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
|
|
test("link to chat message", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
const channel = new ChatFabricators(getOwner(this)).channel();
|
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({ channel });
|
2023-03-03 20:09:25 +08:00
|
|
|
|
2023-02-15 15:27:09 +08:00
|
|
|
await render(hbs`{{format-chat-date this.message}}`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2023-05-17 23:49:52 +08:00
|
|
|
assert.equal(
|
|
|
|
query(".chat-time").getAttribute("href"),
|
|
|
|
`/chat/c/-/${channel.id}/${this.message.id}`
|
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
2024-03-08 16:09:42 +08:00
|
|
|
|
|
|
|
test("link to chat message thread", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
const channel = new ChatFabricators(getOwner(this)).channel();
|
|
|
|
const thread = new ChatFabricators(getOwner(this)).thread();
|
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
|
|
|
channel,
|
|
|
|
thread,
|
|
|
|
});
|
2024-03-08 16:09:42 +08:00
|
|
|
|
|
|
|
await render(
|
|
|
|
hbs`{{format-chat-date this.message (hash threadContext=true)}}`
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
query(".chat-time").getAttribute("href"),
|
|
|
|
`/chat/c/-/${channel.id}/t/${thread.id}/${this.message.id}`
|
|
|
|
);
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|