automationEditDirtyState.test.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. resolveChangedAutomationEditFields,
  4. type AutomationEditFieldSignatures,
  5. } from "@/settings/automationEditDirtyState.js";
  6. const initial: AutomationEditFieldSignatures = {
  7. title: "提醒吃饭",
  8. prompt: "提醒用户吃饭",
  9. schedule: '{"cronExpr":"0 */2 * * *"}',
  10. mode: "build",
  11. thoughtLevel: "xhigh",
  12. model: "provider/gpt-5.5",
  13. };
  14. describe("automation edit dirty state", () => {
  15. it("忽略用户未触碰字段的运行时归一化", () => {
  16. const current = {
  17. ...initial,
  18. schedule: '{"cronExpr":"0 */2 * * *","scheduleRule":null}',
  19. thoughtLevel: "high",
  20. };
  21. expect(
  22. resolveChangedAutomationEditFields({
  23. touchedFields: new Set(),
  24. current,
  25. baseline: initial,
  26. }),
  27. ).toEqual([]);
  28. });
  29. it("只报告用户实际修改过且值发生变化的字段", () => {
  30. const current = { ...initial, title: "新的提醒" };
  31. expect(
  32. resolveChangedAutomationEditFields({
  33. touchedFields: new Set(["title", "thoughtLevel"]),
  34. current,
  35. baseline: initial,
  36. }),
  37. ).toEqual(["title"]);
  38. });
  39. it("用户把字段改回初始值后恢复 clean", () => {
  40. expect(
  41. resolveChangedAutomationEditFields({
  42. touchedFields: new Set(["prompt"]),
  43. current: { ...initial },
  44. baseline: initial,
  45. }),
  46. ).toEqual([]);
  47. });
  48. });