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.

59 lines
1.6 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 {
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),
);
});
});