Skip to content

Commit

Permalink
Merge pull request #187 from goveo/development
Browse files Browse the repository at this point in the history
Country data updates
  • Loading branch information
ybrusentsov authored May 18, 2024
2 parents 27db43a + 29362b0 commit 4b7013a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
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' },
});
});
});

0 comments on commit 4b7013a

Please sign in to comment.