Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Country data updates #187

Merged
merged 7 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/components/PhoneInput/PhoneInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1122,10 +1122,10 @@ describe('PhoneInput', () => {

test('should use default mask if country data does not have mask', () => {
// mask is undefined
const { rerender } = render(<PhoneInput defaultCountry="do" />);
fireChangeEvent('+1114567');
expect(getInput().value).toBe('+1 114567');
expect(getCountrySelector()).toHaveAttribute('data-country', 'do');
const { rerender } = render(<PhoneInput defaultCountry="af" />);
fireChangeEvent('+93114567');
expect(getInput().value).toBe('+93 114567');
expect(getCountrySelector()).toHaveAttribute('data-country', 'af');

// mask is empty string
rerender(<PhoneInput defaultCountry="gr" />);
Expand Down
20 changes: 17 additions & 3 deletions src/data/countryData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const defaultCountries: CountryData[] = [
['Denmark', 'dk', '45', '.. .. .. ..'],
['Djibouti', 'dj', '253'],
['Dominica', 'dm', '1767'],
['Dominican Republic', 'do', '1', '', 2],
['Dominican Republic', 'do', '1', '(...) ...-....', 2, ['809', '829', '849']],
['Ecuador', 'ec', '593'],
['Egypt', 'eg', '20'],
['El Salvador', 'sv', '503', '....-....'],
Expand Down Expand Up @@ -213,7 +213,21 @@ export const defaultCountries: CountryData[] = [
['Namibia', 'na', '264'],
['Nauru', 'nr', '674'],
['Nepal', 'np', '977'],
['Netherlands', 'nl', '31', '.. ........'],
[
'Netherlands',
'nl',
'31',
{
'/^06/': '(.). .........',
'/^6/': '. .........',
'/^0(10|13|14|15|20|23|24|26|30|33|35|36|38|40|43|44|45|46|50|53|55|58|70|71|72|73|74|75|76|77|78|79|82|84|85|87|88|91)/':
'(.).. ........',
'/^(10|13|14|15|20|23|24|26|30|33|35|36|38|40|43|44|45|46|50|53|55|58|70|71|72|73|74|75|76|77|78|79|82|84|85|87|88|91)/':
'.. ........',
'/^0/': '(.)... .......',
default: '... .......',
},
],
['New Caledonia', 'nc', '687'],
['New Zealand', 'nz', '64', '...-...-....'],
['Nicaragua', 'ni', '505'],
Expand All @@ -232,7 +246,7 @@ export const defaultCountries: CountryData[] = [
['Philippines', 'ph', '63', '.... .......'],
['Poland', 'pl', '48', '...-...-...'],
['Portugal', 'pt', '351'],
['Puerto Rico', 'pr', '1', '', 3, ['787', '939']],
['Puerto Rico', 'pr', '1', '(...) ...-....', 3, ['787', '939']],
['Qatar', 'qa', '974'],
['Réunion', 're', '262'],
['Romania', 'ro', '40'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,32 +153,22 @@ describe('guessCountryByPartialNumber', () => {
test('should return the current country if the dial code matches', () => {
expect(
guessCountryByPartialNumber({
phone: '+1 234567890',
phone: '+39 1234567890',
countries: defaultCountries,
currentCountryIso2: 'us',
currentCountryIso2: 'it',
}),
).toMatchObject({
country: { dialCode: '1', iso2: 'us' },
country: { dialCode: '39', iso2: 'it' },
});

expect(
guessCountryByPartialNumber({
phone: '+1 204567890', // Canada area code
phone: '+39 1234567890',
countries: defaultCountries,
currentCountryIso2: 'do',
currentCountryIso2: 'va',
}),
).toMatchObject({
country: { dialCode: '1', iso2: 'ca' },
});

expect(
guessCountryByPartialNumber({
phone: '+1 111567890',
countries: defaultCountries,
currentCountryIso2: 'do',
}),
).toMatchObject({
country: { dialCode: '1', iso2: 'do' },
country: { dialCode: '39', iso2: 'va' },
});
});
});
Loading