editToolCallBlock.test.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { describe, expect, it } from "vitest";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { buildEditCodeViewerSource } from "../src/ToolCallBlocks/renderers/edit.js";
  4. import {
  5. getEditKindLabelMessageId,
  6. renderFileChip,
  7. } from "../src/ToolCallBlocks/renderers.js";
  8. describe("buildEditCodeViewerSource", () => {
  9. it("uses the real file path instead of the display directory", () => {
  10. const source = buildEditCodeViewerSource({
  11. path: "/Users/dev/Projects/z-code/packages/ui/src/i18n/locales/zh-CN.ts",
  12. actionLabel: "Edited",
  13. operationKind: "update",
  14. fileName: "zh-CN.ts",
  15. filePath: "/Users/dev/Projects/z-code/packages/ui/src/i18n/locales/",
  16. fileIconSrc: "/material-icons/typescript.svg",
  17. changeStat: { added: 1, removed: 0 },
  18. patch:
  19. "--- a/zh-CN.ts\n" +
  20. "+++ b/zh-CN.ts\n" +
  21. "@@ -513,2 +513,3 @@\n" +
  22. ' "chat.changeSummary.diffUnavailable": "暂时无法预览这份 Diff。",\n' +
  23. '+ "chat.changeSummary.openInSelectedApp": "在所选 App 中打开",\n' +
  24. ' "chat.changeSummary.rewind": "撤销",',
  25. });
  26. expect(source).toMatchObject({
  27. type: "patch",
  28. title: "zh-CN.ts",
  29. path: "/Users/dev/Projects/z-code/packages/ui/src/i18n/locales/zh-CN.ts",
  30. });
  31. });
  32. });
  33. describe("getEditKindLabelMessageId", () => {
  34. it("uses edit labels for update operations", () => {
  35. expect(getEditKindLabelMessageId(["update"], [], true)).toBe("chat.toolCall.edit.editing");
  36. expect(getEditKindLabelMessageId(["update"], [], false)).toBe("chat.toolCall.kind.edit");
  37. });
  38. it("uses stable terminal kinds for writes and deletes", () => {
  39. expect(getEditKindLabelMessageId(["write"], [], false)).toBe("chat.toolCall.kind.write");
  40. expect(getEditKindLabelMessageId(["delete"], [], false)).toBe("chat.toolCall.kind.delete");
  41. });
  42. });
  43. describe("renderFileChip", () => {
  44. it.each([false, true])("uses the subtle filename color (clickable=%s)", (clickable) => {
  45. const html = renderToStaticMarkup(
  46. renderFileChip({
  47. summary: {
  48. path: "/workspace/src/App.tsx",
  49. actionLabel: "Edited",
  50. operationKind: "update",
  51. fileName: "App.tsx",
  52. filePath: "/workspace/src/",
  53. fileIconSrc: "/material-icons/typescript.svg",
  54. },
  55. clickable,
  56. }),
  57. );
  58. expect(html).toContain("text-foreground-subtle");
  59. expect(html).not.toMatch(/(?:class="[^"]* )text-foreground(?: |")/u);
  60. });
  61. });