dialogRadius.test.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { readFile } from "node:fs/promises";
  2. import { describe, expect, it } from "vitest";
  3. // Windows 工作区经 git autocrlf 是 CRLF,断言按 LF 编写;读取后归一化行尾,Linux 上是无操作。
  4. const read = async (file: string) =>
  5. (await readFile(new URL(`../src/${file}.tsx`, import.meta.url), "utf8")).replaceAll("\r\n", "\n");
  6. const dialogTags = (source: string) =>
  7. source.match(/<DialogContent\b[\s\S]*?(?=\n\s*>|>\n)/g) ?? [];
  8. describe("dialog shell radius", () => {
  9. for (const file of ["components/ui/dialog", "components/ui/alert-dialog"]) {
  10. it(`${file} defaults to 2xl`, async () => {
  11. const source = await read(file);
  12. expect(source).toMatch(/gap-[45] rounded-2xl border/);
  13. });
  14. }
  15. for (const file of [
  16. "ChatMediaAttachmentPreviewDialog",
  17. "feedback/FeedbackScreenshotPicker",
  18. "ToolCallBlocks/renderers/CuaScreenshotSection",
  19. ]) {
  20. it(`${file} explicitly preserves xl`, async () => {
  21. const tags = dialogTags(await read(file));
  22. expect(tags).toHaveLength(1);
  23. expect(tags[0]).toContain("rounded-xl");
  24. });
  25. }
  26. for (const file of [
  27. "GitActionMenu",
  28. "settings/AutomationEditView",
  29. // 原生购买面板已下线(购买走 webview 弹窗),不再纳入 dialog 圆角契约。
  30. "quickpick/TaskFindDialog",
  31. "components/ui/command",
  32. "components/cloud-content-dialog/CloudContentDialog",
  33. "v4/ConversationComposer",
  34. ]) {
  35. it(`${file} does not override the standard shell with xl or 3xl`, async () => {
  36. const tags = dialogTags(await read(file));
  37. expect(tags.length).toBeGreaterThan(0);
  38. for (const tag of tags) expect(tag).not.toMatch(/\brounded-(?:xl|3xl)\b/);
  39. });
  40. }
  41. });
  42. it("chat-anchored find dialog uses the same 2xl shell", async () => {
  43. const source = await read("quickpick/TaskFindDialog");
  44. expect(source).toMatch(/role="dialog"[\s\S]*?className="[^"\n]*rounded-2xl/);
  45. });