Browse Source
fix(birthplace): guarantee strict country and city independence with test suite
master
fix(birthplace): guarantee strict country and city independence with test suite
master
2 changed files with 86 additions and 11 deletions
-
70src/components/Componentes/question-birthplace.test.ts
-
27src/components/Componentes/question-birthplace.tsx
@ -0,0 +1,70 @@ |
|||||
|
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", |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
it("parses standard 'City, Country' strings", () => { |
||||
|
expect(parseValue("Tehran, Iran")).toEqual({ |
||||
|
city: "Tehran", |
||||
|
country: "Iran", |
||||
|
}); |
||||
|
expect(parseValue("شیراز, ایران")).toEqual({ |
||||
|
city: "شیراز", |
||||
|
country: "ایران", |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
it("never swaps city and country even when city equals country name", () => { |
||||
|
// City typed as 'albania' and country selected as 'Afghanistan'
|
||||
|
expect(parseValue("albania, Afghanistan")).toEqual({ |
||||
|
city: "albania", |
||||
|
country: "Afghanistan", |
||||
|
}); |
||||
|
|
||||
|
// City typed as 'Albania' and country selected as 'Albania'
|
||||
|
expect(parseValue("Albania, Albania")).toEqual({ |
||||
|
city: "Albania", |
||||
|
country: "Albania", |
||||
|
}); |
||||
|
|
||||
|
// City typed as 'Georgia' and country selected as 'United States (US)'
|
||||
|
expect(parseValue("Georgia, United States (US)")).toEqual({ |
||||
|
city: "Georgia", |
||||
|
country: "United States (US)", |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
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", |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue