cronCreateAutomationCard.test.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { describe, expect, it } from "vitest";
  2. import { readCronCreateAutomationOutputSummary } from "@/ToolCallBlocks/renderers/cron-create.js";
  3. import { describeAutomationCardSchedule } from "@/settings/automationCardSchedule.js";
  4. describe("CronCreateAutomationCard output", () => {
  5. it("保留 scheduleRule,使长小时间隔不会按兼容 cron 展示为每小时", () => {
  6. const automation = readCronCreateAutomationOutputSummary(
  7. JSON.stringify({
  8. automation: {
  9. automation_id: "automation-31-hours",
  10. title: "每 31 小时执行",
  11. cron_expr: "49 * * * *",
  12. scheduleRule: {
  13. unit: "hourly",
  14. interval: 31,
  15. hour: 0,
  16. minute: 49,
  17. anchorAt: new Date(2026, 7, 5, 17, 49).getTime(),
  18. },
  19. },
  20. }),
  21. );
  22. expect(automation).toMatchObject({
  23. automationId: "automation-31-hours",
  24. title: "每 31 小时执行",
  25. cronExpr: "49 * * * *",
  26. scheduleRule: {
  27. unit: "hourly",
  28. interval: 31,
  29. minute: 49,
  30. },
  31. });
  32. expect(automation?.scheduleRule).toBeDefined();
  33. const schedule = describeAutomationCardSchedule(
  34. {
  35. cronExpr: automation?.cronExpr ?? "",
  36. scheduleRule: automation?.scheduleRule,
  37. },
  38. {
  39. formatMessage: ({ id }, values) =>
  40. id === "automations.schedule.customHourly"
  41. ? `每 ${values?.["interval"]} 小时的第 ${values?.["time"]} 分`
  42. : id,
  43. },
  44. );
  45. expect(schedule).toBe("每 31 小时的第 49 分");
  46. });
  47. });