From 2e612cd799df0555bda6c4dad4e91078eea5536b Mon Sep 17 00:00:00 2001 From: Jesse Tan Date: Thu, 16 May 2024 11:38:33 +0200 Subject: [PATCH 1/5] feat: format number for The Netherlands --- src/data/countryData.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/data/countryData.ts b/src/data/countryData.ts index b97c604..177d812 100644 --- a/src/data/countryData.ts +++ b/src/data/countryData.ts @@ -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'], From a7e97500d1ad810fcb441e373f9877f260d7682d Mon Sep 17 00:00:00 2001 From: Yurii Brusentsov Date: Sat, 18 May 2024 17:23:31 +0300 Subject: [PATCH 2/5] chore: fix country data formatting --- src/data/countryData.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data/countryData.ts b/src/data/countryData.ts index 177d812..edb6d4a 100644 --- a/src/data/countryData.ts +++ b/src/data/countryData.ts @@ -216,7 +216,7 @@ export const defaultCountries: CountryData[] = [ [ 'Netherlands', 'nl', - '31', + '31', { '/^06/': '(.). .........', '/^6/': '. .........', @@ -226,7 +226,7 @@ export const defaultCountries: CountryData[] = [ '.. ........', '/^0/': '(.)... .......', default: '... .......', - } + }, ], ['New Caledonia', 'nc', '687'], ['New Zealand', 'nz', '64', '...-...-....'], From 79f7cf23c11a16ec12cfde7e1aa48af4f32321d0 Mon Sep 17 00:00:00 2001 From: Yurii Brusentsov Date: Sat, 18 May 2024 17:32:41 +0300 Subject: [PATCH 3/5] fix(country-data): add Dominican Republic formatting mask and area codes --- src/data/countryData.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/countryData.ts b/src/data/countryData.ts index edb6d4a..2657b4a 100644 --- a/src/data/countryData.ts +++ b/src/data/countryData.ts @@ -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', '....-....'], From 4b8721afd740970a92f10e3482737f673b5e1054 Mon Sep 17 00:00:00 2001 From: Yurii Brusentsov Date: Sat, 18 May 2024 17:33:41 +0300 Subject: [PATCH 4/5] fix(country-data): add Puerto Rico formatting mask --- src/data/countryData.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/countryData.ts b/src/data/countryData.ts index 2657b4a..2fb92f8 100644 --- a/src/data/countryData.ts +++ b/src/data/countryData.ts @@ -246,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'], From cd4ba2358d4d1cb723991849595a00aea61096d6 Mon Sep 17 00:00:00 2001 From: Yurii Brusentsov Date: Sat, 18 May 2024 17:48:36 +0300 Subject: [PATCH 5/5] test: fix failing tests after Dominican Republic country data updates --- src/components/PhoneInput/PhoneInput.test.tsx | 8 +++---- .../guessCountryByPartialNumber.test.ts | 22 +++++-------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/components/PhoneInput/PhoneInput.test.tsx b/src/components/PhoneInput/PhoneInput.test.tsx index 664c3e0..84144b6 100644 --- a/src/components/PhoneInput/PhoneInput.test.tsx +++ b/src/components/PhoneInput/PhoneInput.test.tsx @@ -1122,10 +1122,10 @@ describe('PhoneInput', () => { test('should use default mask if country data does not have mask', () => { // mask is undefined - const { rerender } = render(); - fireChangeEvent('+1114567'); - expect(getInput().value).toBe('+1 114567'); - expect(getCountrySelector()).toHaveAttribute('data-country', 'do'); + const { rerender } = render(); + fireChangeEvent('+93114567'); + expect(getInput().value).toBe('+93 114567'); + expect(getCountrySelector()).toHaveAttribute('data-country', 'af'); // mask is empty string rerender(); diff --git a/src/utils/countryUtils/__tests__/guessCountryByPartialNumber.test.ts b/src/utils/countryUtils/__tests__/guessCountryByPartialNumber.test.ts index 57202e9..44d5257 100644 --- a/src/utils/countryUtils/__tests__/guessCountryByPartialNumber.test.ts +++ b/src/utils/countryUtils/__tests__/guessCountryByPartialNumber.test.ts @@ -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' }, }); }); });