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.
93 lines
2.7 KiB
93 lines
2.7 KiB
import { describe, expect, it } from "vitest";
|
|
import { parseValue } from "./question-birthplace";
|
|
|
|
describe("QuestionBirthplace parseValue", () => {
|
|
it("parses empty and null values safely", () => {
|
|
expect(parseValue(null)).toEqual({ country: "", city: "" });
|
|
expect(parseValue(undefined)).toEqual({ country: "", city: "" });
|
|
expect(parseValue("")).toEqual({ country: "", city: "" });
|
|
});
|
|
|
|
it("parses structured objects", () => {
|
|
expect(parseValue({ country: "Iran", city: "Tehran" })).toEqual({
|
|
country: "Iran",
|
|
city: "Tehran",
|
|
});
|
|
expect(parseValue({ country: "Mashhad", city: "Iran" })).toEqual({
|
|
country: "Iran",
|
|
city: "Mashhad",
|
|
});
|
|
expect(parseValue({ country: "مشهد", city: "ایران" })).toEqual({
|
|
country: "ایران",
|
|
city: "مشهد",
|
|
});
|
|
});
|
|
|
|
it("parses standard 'Country, City' strings", () => {
|
|
expect(parseValue("Iran, Tehran")).toEqual({
|
|
country: "Iran",
|
|
city: "Tehran",
|
|
});
|
|
expect(parseValue("ایران, شیراز")).toEqual({
|
|
country: "ایران",
|
|
city: "شیراز",
|
|
});
|
|
});
|
|
|
|
it("never swaps country and city even when city equals country name", () => {
|
|
// Country selected as 'Afghanistan' and city typed as 'albania'
|
|
expect(parseValue("Afghanistan, albania")).toEqual({
|
|
country: "Afghanistan",
|
|
city: "albania",
|
|
});
|
|
|
|
// Country selected as 'Albania' and city typed as 'Albania'
|
|
expect(parseValue("Albania, Albania")).toEqual({
|
|
country: "Albania",
|
|
city: "Albania",
|
|
});
|
|
|
|
// Country selected as 'United States (US)' and city typed as 'Georgia'
|
|
expect(parseValue("United States (US), Georgia")).toEqual({
|
|
country: "United States (US)",
|
|
city: "Georgia",
|
|
});
|
|
});
|
|
|
|
it("correctly identifies country and city when formatted as 'City, Country'", () => {
|
|
expect(parseValue("Mashhad, Iran")).toEqual({
|
|
country: "Iran",
|
|
city: "Mashhad",
|
|
});
|
|
expect(parseValue("مشهد، ایران")).toEqual({
|
|
country: "ایران",
|
|
city: "مشهد",
|
|
});
|
|
expect(parseValue("Tehran, IR")).toEqual({
|
|
country: "IR",
|
|
city: "Tehran",
|
|
});
|
|
});
|
|
|
|
it("parses single country string", () => {
|
|
expect(parseValue("Iran")).toEqual({
|
|
country: "Iran",
|
|
city: "",
|
|
});
|
|
expect(parseValue("ایران")).toEqual({
|
|
country: "ایران",
|
|
city: "",
|
|
});
|
|
expect(parseValue("Afghanistan")).toEqual({
|
|
country: "Afghanistan",
|
|
city: "",
|
|
});
|
|
});
|
|
|
|
it("parses single custom city string without matching country", () => {
|
|
expect(parseValue("Rey")).toEqual({
|
|
country: "",
|
|
city: "Rey",
|
|
});
|
|
});
|
|
});
|