2024-11-04 04:04:38 +08:00
|
|
|
import { hash } from "@ember/helper";
|
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 { module, test } from "qunit";
|
2022-11-02 21:41:30 +08:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
2024-11-04 04:04:38 +08:00
|
|
|
import formatChatDate from "discourse/plugins/chat/discourse/helpers/format-chat-date";
|
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();
|
2024-11-04 04:04:38 +08:00
|
|
|
const message = new ChatFabricators(getOwner(this)).message({ channel });
|
2023-03-03 20:09:25 +08:00
|
|
|
|
2024-11-04 04:04:38 +08:00
|
|
|
await render(<template>{{formatChatDate message}}</template>);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2024-11-04 04:04:38 +08:00
|
|
|
assert
|
|
|
|
.dom(".chat-time")
|
|
|
|
.hasAttribute("href", `/chat/c/-/${channel.id}/${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();
|
2024-11-04 04:04:38 +08:00
|
|
|
const message = new ChatFabricators(getOwner(this)).message({
|
2024-04-09 03:00:09 +08:00
|
|
|
channel,
|
|
|
|
thread,
|
|
|
|
});
|
2024-03-08 16:09:42 +08:00
|
|
|
|
2024-11-04 04:04:38 +08:00
|
|
|
await render(<template>
|
|
|
|
{{formatChatDate message (hash threadContext=true)}}
|
|
|
|
</template>);
|
2024-03-08 16:09:42 +08:00
|
|
|
|
2024-11-04 04:04:38 +08:00
|
|
|
assert
|
|
|
|
.dom(".chat-time")
|
|
|
|
.hasAttribute(
|
|
|
|
"href",
|
|
|
|
`/chat/c/-/${channel.id}/t/${thread.id}/${message.id}`
|
|
|
|
);
|
2024-03-08 16:09:42 +08:00
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|