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.
109 lines
3.7 KiB
109 lines
3.7 KiB
import { describe, expect, it } from "vitest";
|
|
import {
|
|
describeWorkOrderFieldMarks,
|
|
diffWorkOrderSupplementedFields,
|
|
toWorkOrderSubmittedSnapshot,
|
|
workOrderFormFromSubmitted,
|
|
} from "@/services/parse/work-order-snapshot";
|
|
import { markInstructionImported } from "@/services/parse/instruction-execution-state";
|
|
|
|
describe("diffWorkOrderSupplementedFields", () => {
|
|
it("marks empty→filled as supplemented", () => {
|
|
const { fieldMarks, userSupplemented, supplementedFields } =
|
|
diffWorkOrderSupplementedFields(
|
|
{ F_Remark: "", F_MessageContent: "安排贴标" },
|
|
{ F_Remark: "ups默认两张", F_MessageContent: "安排贴标" },
|
|
);
|
|
expect(fieldMarks.F_Remark).toBe("supplemented");
|
|
expect(fieldMarks.F_MessageContent).toBeUndefined();
|
|
expect(userSupplemented).toBe(true);
|
|
expect(supplementedFields).toContain("F_Remark");
|
|
});
|
|
|
|
it("marks changed value as modified", () => {
|
|
const { fieldMarks } = diffWorkOrderSupplementedFields(
|
|
{ F_RefNo: "WL001", F_MessageType: "操作指令" },
|
|
{ F_RefNo: "WL002", F_MessageType: "操作指令" },
|
|
);
|
|
expect(fieldMarks.F_RefNo).toBe("modified");
|
|
expect(fieldMarks.F_MessageType).toBeUndefined();
|
|
});
|
|
|
|
it("marks cleared value as modified", () => {
|
|
const { fieldMarks } = diffWorkOrderSupplementedFields(
|
|
{ F_AttachFile: "a.pdf" },
|
|
{ F_AttachFile: "" },
|
|
);
|
|
expect(fieldMarks.F_AttachFile).toBe("modified");
|
|
});
|
|
|
|
it("returns no marks when identical", () => {
|
|
const snap = {
|
|
F_ReferCode: "TCNU4412465",
|
|
F_MessageContent: "安排卡转海",
|
|
F_Remark: "ups默认",
|
|
};
|
|
const { userSupplemented, supplementedFields } =
|
|
diffWorkOrderSupplementedFields(snap, snap);
|
|
expect(userSupplemented).toBe(false);
|
|
expect(supplementedFields).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("toWorkOrderSubmittedSnapshot / workOrderFormFromSubmitted", () => {
|
|
it("round-trips non-empty fields", () => {
|
|
const snap = toWorkOrderSubmittedSnapshot({
|
|
F_ReferCode: "TCNU4412465",
|
|
F_MessageType: "操作指令",
|
|
F_RefNo: "WL003",
|
|
F_MessageContent: "安排卡转海",
|
|
F_Remark: " ",
|
|
F_AttachFile: "",
|
|
F_UrgencyLevel: "0",
|
|
});
|
|
expect(snap.F_Remark).toBeUndefined();
|
|
expect(snap.F_ReferCode).toBe("TCNU4412465");
|
|
const form = workOrderFormFromSubmitted(snap);
|
|
expect(form.F_MessageContent).toBe("安排卡转海");
|
|
expect(form.F_Remark).toBe("");
|
|
expect(form.F_UrgencyLevel).toBe("0");
|
|
});
|
|
|
|
it("describeWorkOrderFieldMarks lists supplemented values", () => {
|
|
const lines = describeWorkOrderFieldMarks(
|
|
{ F_MessageType: "supplemented" },
|
|
{ F_MessageType: "操作指令" },
|
|
);
|
|
expect(lines).toEqual(["留言类型:操作指令"]);
|
|
});
|
|
});
|
|
|
|
describe("markInstructionImported snapshot", () => {
|
|
it("persists submitted and userSupplemented flags", () => {
|
|
const lineage = markInstructionImported({}, "wo-1", {
|
|
status: "IMPORTED",
|
|
importedAt: "2026-08-28T00:00:00.000Z",
|
|
mode: "live",
|
|
submitted: { F_MessageContent: "补全后的正文", F_Remark: "人工备注" },
|
|
supplementedFields: ["F_Remark"],
|
|
fieldMarks: { F_Remark: "supplemented" },
|
|
userSupplemented: true,
|
|
});
|
|
const entry = (
|
|
lineage as {
|
|
instruction_state: Record<
|
|
string,
|
|
{
|
|
submitted?: Record<string, string>;
|
|
userSupplemented?: boolean;
|
|
fieldMarks?: Record<string, string>;
|
|
}
|
|
>;
|
|
}
|
|
).instruction_state["wo-1"];
|
|
expect(entry.submitted?.F_Remark).toBe("人工备注");
|
|
expect(entry.userSupplemented).toBe(true);
|
|
expect(entry.fieldMarks?.F_Remark).toBe("supplemented");
|
|
});
|
|
});
|