Files
buzz-sheet/components/comments/comment-locale.test.tsx
T
gunshiz 9580407a90
CI / Verify (push) Successful in 1m56s
CI / Build immutable images and deploy (push) Successful in 3m12s
perf : cache
2026-10-08 23:21:34 +07:00

48 lines
2.3 KiB
TypeScript

import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it, vi } from "vitest";
import { CommentLocaleProvider } from "./comment-locale";
import { CommentBoard } from "./comment-board";
import { CommentComposer } from "./comment-composer";
import { AdminCommentInbox } from "./admin-comment-inbox";
import type { CommentItem } from "@/lib/comments/types";
vi.mock("next/navigation", () => ({ useRouter: () => ({ push: vi.fn() }) }));
const viewer = { id: "admin", admin: true, name: "Admin" };
const comment: CommentItem = {
id: "test", rootId: null, replyToId: null, replyToName: null,
authorName: "Author", authorImage: null, authorAdmin: false,
text: "ข้อความของผู้ใช้", images: [], version: 2,
createdAt: "2026-10-08T12:00:00Z", editedAt: "2026-10-08T12:00:00Z",
hidden: false, ownHidden: false, deleted: false, hearted: false,
likes: 0, reaction: 0, replyCount: 0, hasReplies: false,
canEdit: true, canInteract: true, canModerate: true,
target: "guide:test", targetName: "Test", targetImage: null, href: "/test/comment",
};
describe("comment UI language boundaries", () => {
it("keeps the public board in Thai", () => {
const html = renderToStaticMarkup(<CommentBoard target="guide:test" initial={{ items: [], nextCursor: null, viewer }} />);
expect(html).toContain("ความคิดเห็น");
expect(html).toContain("เพิ่มความคิดเห็น…");
});
it("renders the admin inbox filters and empty state in English", () => {
const html = renderToStaticMarkup(<CommentLocaleProvider locale="en">
<AdminCommentInbox initial={{ items: [], nextCursor: null, viewer }} targets={[]} />
</CommentLocaleProvider>);
expect(html).toContain("Admin replies");
expect(html).toContain("No matching comments");
expect(html).not.toMatch(/[\u0e00-\u0e7f]/);
});
it("localizes nested editing controls while preserving the draft", () => {
const html = renderToStaticMarkup(<CommentLocaleProvider locale="en">
<CommentComposer target="guide:test" editing={comment} onSaved={() => {}} />
</CommentLocaleProvider>);
expect(html).toContain("Save changes");
expect(html).toContain("Attach images");
expect(html).toContain(comment.text);
});
});