import { describe, expect, it } from "vitest"; import { expandDirectionalStreet, parseStreetDirection, scoreMothershipCandidateForDraft, sortMothershipCandidatesForDraft, } from "@/lib/address/street-normalize"; import type { MothershipAddressCandidate } from "@/modules/address/types"; function cand( street: string, display: string, ): MothershipAddressCandidate { return { option_id: `id-${street.replace(/\s+/g, "-")}`, display_label: display, formatted_address: display, street, city: "Pomona", state: "CA", zip: "", }; } describe("street-normalize", () => { it("expandDirectionalStreet 展开 W 7th St", () => { expect(expandDirectionalStreet("600 W 7th St")).toBe( "600 West 7th Street", ); expect(parseStreetDirection("600 W 7th St")).toBe("W"); expect(parseStreetDirection("600 East 7th Street")).toBe("E"); }); it("600 W 7th St 草稿优先 West 7th,惩罚 East", () => { const draft = { street: "600 W 7th St", city: "Pomona", state: "CA" }; const west = cand( "600 West 7th Street", "600 West 7th Street, Pomona, California, USA", ); const abbrev = cand( "600 W 7th St", "600 W 7th St, Pomona, California, USA", ); const east = cand( "600 East 7th Street", "600 East 7th Street, Pomona, California, USA", ); const sorted = sortMothershipCandidatesForDraft( [abbrev, east, west], draft, ); expect(sorted[0]?.street).toBe("600 West 7th Street"); expect(scoreMothershipCandidateForDraft(east, draft)).toBeLessThan( scoreMothershipCandidateForDraft(west, draft), ); }); });