editToolCallBlock.test.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { describe, expect, it } from "vitest";
  2. import { buildEditCodeViewerSource } from "../src/ToolCallBlocks/renderers/edit.js";
  3. import { getEditKindLabelMessageId } from "../src/ToolCallBlocks/renderers.js";
  4. describe("buildEditCodeViewerSource", () => {
  5. it("uses the real file path instead of the display directory", () => {
  6. const source = buildEditCodeViewerSource({
  7. path: "/Users/dev/Projects/z-code/packages/ui/src/i18n/locales/zh-CN.ts",
  8. actionLabel: "Edited",
  9. operationKind: "update",
  10. fileName: "zh-CN.ts",
  11. filePath: "/Users/dev/Projects/z-code/packages/ui/src/i18n/locales/",
  12. fileIconSrc: "/material-icons/typescript.svg",
  13. changeStat: { added: 1, removed: 0 },
  14. patch:
  15. "--- a/zh-CN.ts\n" +
  16. "+++ b/zh-CN.ts\n" +
  17. "@@ -513,2 +513,3 @@\n" +
  18. ' "chat.changeSummary.diffUnavailable": "暂时无法预览这份 Diff。",\n' +
  19. '+ "chat.changeSummary.openInSelectedApp": "在所选 App 中打开",\n' +
  20. ' "chat.changeSummary.rewind": "撤销",',
  21. });
  22. expect(source).toMatchObject({
  23. type: "patch",
  24. title: "zh-CN.ts",
  25. path: "/Users/dev/Projects/z-code/packages/ui/src/i18n/locales/zh-CN.ts",
  26. });
  27. });
  28. });
  29. describe("getEditKindLabelMessageId", () => {
  30. it("uses edit labels for update operations", () => {
  31. expect(getEditKindLabelMessageId(["update"], [], true)).toBe("chat.toolCall.edit.editing");
  32. expect(getEditKindLabelMessageId(["update"], [], false)).toBe("chat.toolCall.kind.edit");
  33. });
  34. it("uses stable terminal kinds for writes and deletes", () => {
  35. expect(getEditKindLabelMessageId(["write"], [], false)).toBe("chat.toolCall.kind.write");
  36. expect(getEditKindLabelMessageId(["delete"], [], false)).toBe("chat.toolCall.kind.delete");
  37. });
  38. });