cronCreateAutomationCard.test.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. const schedule = describeAutomationCardSchedule(
  33. {
  34. cronExpr: automation?.cronExpr ?? "",
  35. scheduleRule: automation?.scheduleRule,
  36. },
  37. {
  38. formatMessage: ({ id }, values) =>
  39. id === "automations.schedule.customHourly"
  40. ? `每 ${values?.["interval"]} 小时的第 ${values?.["time"]} 分`
  41. : id,
  42. },
  43. );
  44. expect(schedule).toBe("每 31 小时的第 49 分");
  45. });
  46. });