You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { describe, expect, it } from "vitest";
import {
buildFlockProgressPayload,
flockStageIndex,
mapFlockErrorToStage,
parseFlockProgress,
shouldOverwriteFlockFailureStage,
} from "@/lib/flock/rpa-progress";
describe("flock rpa-progress", () => {
it("build + parse roundtrip", () => {
const payload = buildFlockProgressPayload("login");
const parsed = parseFlockProgress(payload);
expect(parsed?.stage).toBe("login");
expect(parsed?.label).toContain("登录");
});
it("maps FLOCK_LOGIN_FAILED to login stage", () => {
const mapped = mapFlockErrorToStage(
"FLOCK_LOGIN_FAILED无法填写登录表单locator.waitFor: Timeout 15000ms",
);
expect(mapped.stage).toBe("login");
expect(mapped.matched).toBe(true);
expect(mapped.hint).toContain("卡在登录");
});
it("未识别错误不得默认钉在互斥锁", () => {
const mapped = mapFlockErrorToStage("不明错误 xyz");
expect(mapped.matched).toBe(false);
expect(mapped.stage).not.toBe("lock");
});
it("浏览器关闭 / 未返回报价 / 超时映射到 wait_quote", () => {
expect(mapFlockErrorToStage("Target closed").stage).toBe("wait_quote");
expect(mapFlockErrorToStage("未返回 Flock 报价档位").stage).toBe(
"wait_quote",
);
expect(mapFlockErrorToStage("Flock 询价超时,请稍后重试").stage).toBe(
"wait_quote",
);
});
it("失败写进度禁止从 wait_quote 回退到 lock", () => {
expect(
shouldOverwriteFlockFailureStage("wait_quote", {
stage: "lock",
matched: true,
}),
).toBe(false);
expect(
shouldOverwriteFlockFailureStage("lock", {
stage: "wait_quote",
matched: true,
}),
).toBe(true);
expect(
shouldOverwriteFlockFailureStage("wait_quote", {
stage: "wait_quote",
matched: false,
}),
).toBe(false);
});
it("stage index order", () => {
expect(flockStageIndex("queued")).toBeLessThan(flockStageIndex("login"));
expect(flockStageIndex("login")).toBeLessThan(flockStageIndex("fill_form"));
});
});