Browse Source
feat: implement phone input component with Flutter-based geolocation, country-specific formatting, and validation testing
master
feat: implement phone input component with Flutter-based geolocation, country-specific formatting, and validation testing
master
9 changed files with 996 additions and 84 deletions
-
27src/components/Componentes/question-birthplace.tsx
-
48src/components/Componentes/question-phone.test.tsx
-
102src/components/Componentes/question-phone.tsx
-
76src/components/Componentes/question-sheet.test.tsx
-
89src/components/Componentes/question-sheet.tsx
-
88src/data/countries.test.ts
-
411src/data/countries.ts
-
59src/data/languages.test.ts
-
174src/data/languages.ts
@ -0,0 +1,88 @@ |
|||
import { describe, expect, it } from "vitest"; |
|||
import { |
|||
COUNTRIES_EN, |
|||
COUNTRIES_FA, |
|||
getCountryIsoCode, |
|||
getCountryList, |
|||
isKnownCountry, |
|||
resolveCountryName, |
|||
filterCountryOptions, |
|||
} from "./countries"; |
|||
|
|||
describe("countries data and localization", () => { |
|||
it("resolves ISO codes correctly", () => { |
|||
expect(getCountryIsoCode("Afghanistan")).toBe("AF"); |
|||
expect(getCountryIsoCode("Albania")).toBe("AL"); |
|||
expect(getCountryIsoCode("Iran")).toBe("IR"); |
|||
expect(getCountryIsoCode("افغانستان")).toBe("AF"); |
|||
expect(getCountryIsoCode("ایران")).toBe("IR"); |
|||
expect(getCountryIsoCode("US")).toBe("US"); |
|||
}); |
|||
|
|||
it("resolves country names in Russian", () => { |
|||
expect(resolveCountryName("Afghanistan", "ru")).toBe("Афганистан"); |
|||
expect(resolveCountryName("Albania", "ru")).toBe("Албания"); |
|||
expect(resolveCountryName("Algeria", "ru")).toBe("Алжир"); |
|||
expect(resolveCountryName("Australia", "ru")).toBe("Австралия"); |
|||
expect(resolveCountryName("Germany", "ru")).toBe("Германия"); |
|||
}); |
|||
|
|||
it("resolves country names in Arabic", () => { |
|||
expect(resolveCountryName("Afghanistan", "ar")).toBe("أفغانستان"); |
|||
expect(resolveCountryName("Germany", "ar")).toBe("ألمانيا"); |
|||
}); |
|||
|
|||
it("resolves country names in Persian", () => { |
|||
expect(resolveCountryName("Afghanistan", "fa")).toBe("افغانستان"); |
|||
expect(resolveCountryName("Germany", "fa")).toBe("آلمان"); |
|||
expect(resolveCountryName("United States", "fa")).toBe("ایالات متحده آمریکا (US)"); |
|||
}); |
|||
|
|||
it("resolves country names in Turkish", () => { |
|||
expect(resolveCountryName("Afghanistan", "tr")).toBe("Afganistan"); |
|||
expect(resolveCountryName("Germany", "tr")).toBe("Almanya"); |
|||
}); |
|||
|
|||
it("getCountryList returns localized lists", () => { |
|||
const listFa = getCountryList("fa"); |
|||
expect(listFa[0]).toBe("افغانستان"); |
|||
|
|||
const listRu = getCountryList("ru"); |
|||
expect(listRu[0]).toBe("Афганистан"); |
|||
expect(listRu[1]).toBe("Албания"); |
|||
|
|||
const listEn = getCountryList("en"); |
|||
expect(listEn[0]).toBe("Afghanistan"); |
|||
}); |
|||
|
|||
it("identifies known countries", () => { |
|||
expect(isKnownCountry("Afghanistan")).toBe(true); |
|||
expect(isKnownCountry("افغانستان")).toBe(true); |
|||
expect(isKnownCountry("AF")).toBe(true); |
|||
expect(isKnownCountry("UnknownCountry123")).toBe(false); |
|||
}); |
|||
|
|||
it("filters country options across multiple languages and aliases", () => { |
|||
const listFa = getCountryList("fa"); |
|||
// Search in English on Persian list
|
|||
const matchedIran = filterCountryOptions(listFa, "iran", "fa"); |
|||
expect(matchedIran[0]).toBe("ایران"); |
|||
|
|||
const matchedGermany = filterCountryOptions(listFa, "germany", "fa"); |
|||
expect(matchedGermany[0]).toBe("آلمان"); |
|||
|
|||
const matchedUsa = filterCountryOptions(listFa, "usa", "fa"); |
|||
expect(matchedUsa[0]).toBe("ایالات متحده آمریکا (US)"); |
|||
|
|||
const matchedTajikistan = filterCountryOptions(listFa, "tajikistan", "fa"); |
|||
expect(matchedTajikistan[0]).toBe("تاجیکستان"); |
|||
|
|||
// Search in Persian on English list
|
|||
const listEn = getCountryList("en"); |
|||
const matchedIranEn = filterCountryOptions(listEn, "ایران", "en"); |
|||
expect(matchedIranEn[0]).toBe("Iran"); |
|||
|
|||
const matchedGermanyEn = filterCountryOptions(listEn, "آلمان", "en"); |
|||
expect(matchedGermanyEn[0]).toBe("Germany"); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,59 @@ |
|||
import { describe, expect, it } from "vitest"; |
|||
import { |
|||
LANGUAGES_EN, |
|||
LANGUAGES_FA, |
|||
getLanguageCode, |
|||
getLanguageList, |
|||
resolveLanguageName, |
|||
} from "./languages"; |
|||
|
|||
describe("languages data and localization", () => { |
|||
it("resolves language codes correctly", () => { |
|||
expect(getLanguageCode("Afrikaans")).toBe("af"); |
|||
expect(getLanguageCode("Arabic")).toBe("ar"); |
|||
expect(getLanguageCode("Russian")).toBe("ru"); |
|||
expect(getLanguageCode("فارسی")).toBe("fa"); |
|||
expect(getLanguageCode("عربی")).toBe("ar"); |
|||
expect(getLanguageCode("en")).toBe("en"); |
|||
}); |
|||
|
|||
it("resolves language names in Russian", () => { |
|||
expect(resolveLanguageName("Afrikaans", "ru")).toBe("Африкаанс"); |
|||
expect(resolveLanguageName("Arabic", "ru")).toBe("Арабский"); |
|||
expect(resolveLanguageName("Russian", "ru")).toBe("Русский"); |
|||
expect(resolveLanguageName("English", "ru")).toBe("Английский"); |
|||
expect(resolveLanguageName("Persian", "ru")).toBe("Персидский"); |
|||
expect(resolveLanguageName("Other", "ru")).toBe("Другое"); |
|||
}); |
|||
|
|||
it("resolves language names in Arabic", () => { |
|||
expect(resolveLanguageName("Arabic", "ar")).toBe("العربية"); |
|||
expect(resolveLanguageName("English", "ar")).toBe("الإنجليزية"); |
|||
expect(resolveLanguageName("Other", "ar")).toBe("أخرى"); |
|||
}); |
|||
|
|||
it("resolves language names in Persian", () => { |
|||
expect(resolveLanguageName("Arabic", "fa")).toBe("عربی"); |
|||
expect(resolveLanguageName("English", "fa")).toBe("انگلیسی"); |
|||
expect(resolveLanguageName("Russian", "fa")).toBe("روسی"); |
|||
expect(resolveLanguageName("Other", "fa")).toBe("سایر"); |
|||
}); |
|||
|
|||
it("resolves language names in Turkish", () => { |
|||
expect(resolveLanguageName("Arabic", "tr")).toBe("Arapça"); |
|||
expect(resolveLanguageName("English", "tr")).toBe("İngilizce"); |
|||
expect(resolveLanguageName("Russian", "tr")).toBe("Rusça"); |
|||
expect(resolveLanguageName("Other", "tr")).toBe("Diğer"); |
|||
}); |
|||
|
|||
it("getLanguageList returns localized lists", () => { |
|||
const listFa = getLanguageList("fa"); |
|||
expect(listFa[0]).toBe("آذربایجانی"); |
|||
|
|||
const listRu = getLanguageList("ru"); |
|||
expect(listRu[0]).toBe("Африкаанс"); |
|||
|
|||
const listEn = getLanguageList("en"); |
|||
expect(listEn[0]).toBe("Afrikaans"); |
|||
}); |
|||
}); |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue