automationEditSaveAndRun.test.ts 821 B

1234567891011121314151617181920212223242526
  1. import { describe, expect, it, vi } from "vitest";
  2. import { saveAndRunAutomation } from "@/settings/AutomationEditView.js";
  3. describe("AutomationEditView save and run", () => {
  4. it("保存当前表单成功后才立即运行", async () => {
  5. const order: string[] = [];
  6. const save = vi.fn(async () => {
  7. order.push("save");
  8. return true;
  9. });
  10. const run = vi.fn(async () => {
  11. order.push("run");
  12. });
  13. await expect(saveAndRunAutomation(save, run)).resolves.toBe(true);
  14. expect(order).toEqual(["save", "run"]);
  15. });
  16. it("保存失败时不立即运行", async () => {
  17. const save = vi.fn(async () => false);
  18. const run = vi.fn(async () => undefined);
  19. await expect(saveAndRunAutomation(save, run)).resolves.toBe(false);
  20. expect(run).not.toHaveBeenCalled();
  21. });
  22. });