import { describe, expect, it } from "vitest"; import { selectAttachments, type SampleFile, } from "@/services/sample/mail-attachment-select"; function f(name: string): SampleFile { return { abs: `/x/${name}`, filename: name, rel: name }; } describe("selectAttachments", () => { it("mail2: packing_xlsx picks MATU 卡派 xlsx, skips screenshot", () => { const files = [ f("2邮箱.pdf"), f("柜号:MATU2745683卡派资料.xlsx"), ]; const picked = selectAttachments(files, "packing_xlsx", ["MATU2745683"]); expect(picked).toHaveLength(1); expect(picked[0].filename).toContain("MATU2745683"); }); it("mail3: business takes 卡转海 PDFs, skips 3邮箱.pdf", () => { const files = [ f("3邮箱.pdf"), f("WL103276-SBD1(1).pdf"), f("WL99583-LAX9.pdf"), ]; const picked = selectAttachments(files, "business"); expect(picked.map((x) => x.filename).sort()).toEqual([ "WL103276-SBD1(1).pdf", "WL99583-LAX9.pdf", ]); }); it("mail4: label_instruction prefers xlsx then instruction PDFs", () => { const files = [ f("4邮箱.pdf"), f("FBA19HW52S0L-76CTN-HIA1-覆盖贴1箱贴2张.pdf"), f("YT2604021091=76件换标走HIA1卡派出库操作指令.xlsx"), ]; const picked = selectAttachments(files, "label_instruction"); expect(picked[0].filename).toMatch(/\.xlsx$/i); expect(picked.some((x) => x.filename.includes("覆盖贴"))).toBe(true); expect(picked.every((x) => !/邮箱\.pdf$/i.test(x.filename))).toBe(true); }); it("none returns empty", () => { expect(selectAttachments([f("a.xlsx")], "none")).toEqual([]); }); });