mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
64 lines
2 KiB
TypeScript
64 lines
2 KiB
TypeScript
|
|
import { describe, expect, it } from "vitest";
|
||
|
|
import type { WorkOrderComment } from "@/domain/work-orders/types/work-order-detail";
|
||
|
|
import { highlightedCommentIds } from "@/domain/work-orders/utils/comment-highlight";
|
||
|
|
import { encodeMentionToken } from "@/domain/work-orders/utils/comment-mentions";
|
||
|
|
|
||
|
|
function makeComment(overrides: Partial<WorkOrderComment>): WorkOrderComment {
|
||
|
|
return {
|
||
|
|
id: "c1",
|
||
|
|
createdDate: "2026-01-01T00:00:00",
|
||
|
|
commenttext: "",
|
||
|
|
commentType: "internal",
|
||
|
|
userName: "Someone Else",
|
||
|
|
authorId: "other",
|
||
|
|
commenter: null,
|
||
|
|
recordType: null,
|
||
|
|
...overrides,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
const SINCE = "2025-12-31T00:00:00Z";
|
||
|
|
|
||
|
|
describe("highlightedCommentIds", () => {
|
||
|
|
it("treats an API mentions id array as a mention even with plain @Name text", () => {
|
||
|
|
const comment = makeComment({
|
||
|
|
id: "m1",
|
||
|
|
commenttext: "Hey @Jane can you check this",
|
||
|
|
mentions: ["user-1"],
|
||
|
|
});
|
||
|
|
|
||
|
|
const mentionHit = highlightedCommentIds([comment], { since: SINCE, mentions: true }, "user-1");
|
||
|
|
expect(mentionHit.has("m1")).toBe(true);
|
||
|
|
|
||
|
|
// The same comment must NOT tint under Recent activity (comments bucket).
|
||
|
|
const commentBucket = highlightedCommentIds(
|
||
|
|
[comment],
|
||
|
|
{ since: SINCE, mentions: false },
|
||
|
|
"user-1",
|
||
|
|
);
|
||
|
|
expect(commentBucket.has("m1")).toBe(false);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("still recognises encoded @[id:name] tokens", () => {
|
||
|
|
const comment = makeComment({
|
||
|
|
id: "e1",
|
||
|
|
commenttext: `Ping ${encodeMentionToken("user-1", "Jane Doe")} please`,
|
||
|
|
});
|
||
|
|
|
||
|
|
expect(
|
||
|
|
highlightedCommentIds([comment], { since: SINCE, mentions: true }, "user-1").has("e1"),
|
||
|
|
).toBe(true);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("keeps a non-mention comment in the comments bucket", () => {
|
||
|
|
const comment = makeComment({ id: "p1", commenttext: "Status update, no mentions" });
|
||
|
|
|
||
|
|
expect(
|
||
|
|
highlightedCommentIds([comment], { since: SINCE, mentions: false }, "user-1").has("p1"),
|
||
|
|
).toBe(true);
|
||
|
|
expect(
|
||
|
|
highlightedCommentIds([comment], { since: SINCE, mentions: true }, "user-1").has("p1"),
|
||
|
|
).toBe(false);
|
||
|
|
});
|
||
|
|
});
|