mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-01 12:03:11 +00:00
Re-apply the requested slide-over tab on every open via an open counter, so a second comment/mention notification for the work order already on screen still switches to Comments and re-scrolls to the highlighted comment. Treat a board comment's mentions id array (plain @Name text) as a mention alongside encoded @[id:name] tokens so mention items highlight and comment items exclude them. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
63 lines
2 KiB
TypeScript
63 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);
|
|
});
|
|
});
|