From c0d35f7543f22d420d67b36df61cec81e35ba498 Mon Sep 17 00:00:00 2001 From: Thomas Roberts Date: Fri, 7 Apr 2023 16:48:38 +0100 Subject: [PATCH 1/5] Allow countries not covered by postcode-validator to pass validaiton --- packages/checkout/utils/validation/is-postcode.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/checkout/utils/validation/is-postcode.ts b/packages/checkout/utils/validation/is-postcode.ts index 82ff5606916..bb3104f3d33 100644 --- a/packages/checkout/utils/validation/is-postcode.ts +++ b/packages/checkout/utils/validation/is-postcode.ts @@ -27,8 +27,10 @@ export interface IsPostcodeProps { } const isPostcode = ( { postcode, country }: IsPostcodeProps ): boolean => { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return DEFAULT_REGEXES.get( country )!.test( postcode ); + // If the country is not in the list of regexes, trying to test it would result in an error, so we skip and assume + // that it is valid. + const postcodeTest = DEFAULT_REGEXES.get( country )?.test( postcode ); + return typeof postcodeTest !== 'undefined' ? postcodeTest : true; }; export default isPostcode; From f13154feff5a3e26e0fb94d78157df052710deef Mon Sep 17 00:00:00 2001 From: Thomas Roberts Date: Fri, 7 Apr 2023 18:49:36 +0100 Subject: [PATCH 2/5] Add "skipPushCheck" option when filling billing and shipping details --- tests/utils/shopper.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/utils/shopper.js b/tests/utils/shopper.js index e1b969dce33..c5f5f6deea6 100644 --- a/tests/utils/shopper.js +++ b/tests/utils/shopper.js @@ -276,7 +276,7 @@ export const shopper = { await page.evaluate( 'document.activeElement.blur()' ); }, // prettier-ignore - fillBillingDetails: async ( customerBillingDetails ) => { + fillBillingDetails: async ( customerBillingDetails, skipPushCheck = false ) => { await page.waitForSelector( '#billing-fields' ); const companyInputField = await page.$( '#billing-company' ); @@ -290,17 +290,24 @@ export const shopper = { await expect( page ).toFill( '#billing-address_1', customerBillingDetails.addressfirstline ); await expect( page ).toFill( '#billing-address_2', customerBillingDetails.addresssecondline ); await expect( page ).toFill( '#billing-city', customerBillingDetails.city ); - await expect( page ).toFill( '#billing-state input', customerBillingDetails.state ); + + const stateInputField = await page.$( '#billing-state input' ); + if ( stateInputField ) { + await expect( page ).toFill( '#billing-state input', customerBillingDetails.state ); + } await expect( page ).toFill( '#billing-postcode', customerBillingDetails.postcode ); await expect( page ).toFill( '#billing-phone', customerBillingDetails.phone ); await expect( page ).toFill( '#email', customerBillingDetails.email ); // Blur active field to trigger customer address update, then wait for requests to finish. await page.evaluate( 'document.activeElement.blur()' ); - await checkCustomerPushCompleted( 'billing', customerBillingDetails ); + if ( ! skipPushCheck ) { + await checkCustomerPushCompleted( 'billing', customerBillingDetails ); + + } }, // prettier-ignore - fillShippingDetails: async ( customerShippingDetails ) => { + fillShippingDetails: async ( customerShippingDetails, skipPushCheck = false ) => { const companyInputField = await page.$( '#shipping-company' ); if ( companyInputField ) { @@ -313,12 +320,17 @@ export const shopper = { await expect( page ).toFill( '#shipping-address_1', customerShippingDetails.addressfirstline ); await expect( page ).toFill( '#shipping-address_2', customerShippingDetails.addresssecondline ); await expect( page ).toFill( '#shipping-city', customerShippingDetails.city ); - await expect( page ).toFill( '#shipping-state input', customerShippingDetails.state ); + const stateInputField = await page.$( '#shipping-state input' ); + if ( stateInputField ) { + await expect( page ).toFill( '#shipping-state input', customerShippingDetails.state ); + } await expect( page ).toFill( '#shipping-postcode', customerShippingDetails.postcode ); await expect( page ).toFill( '#shipping-phone', customerShippingDetails.phone ); // Blur active field to customer address update, then wait for requests to finish. await page.evaluate( 'document.activeElement.blur()' ); - await checkCustomerPushCompleted( 'shipping', customerShippingDetails ); + if ( ! skipPushCheck ) { + await checkCustomerPushCompleted( 'shipping', customerShippingDetails ); + } }, // prettier-ignore From c91fd0b4c35dec3261b916d0f57e36652e578d65 Mon Sep 17 00:00:00 2001 From: Thomas Roberts Date: Fri, 7 Apr 2023 18:49:56 +0100 Subject: [PATCH 3/5] Allow albania as a shipping/selling country --- tests/e2e/fixtures/fixture-data.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/fixtures/fixture-data.js b/tests/e2e/fixtures/fixture-data.js index 97194702bb5..1ad81f5a625 100644 --- a/tests/e2e/fixtures/fixture-data.js +++ b/tests/e2e/fixtures/fixture-data.js @@ -278,7 +278,7 @@ const Settings = () => [ }, { id: 'woocommerce_specific_allowed_countries', - value: [ 'DZ', 'CA', 'NZ', 'ES', 'GB', 'US' ], + value: [ 'AL', 'DZ', 'CA', 'NZ', 'ES', 'GB', 'US' ], }, { id: 'woocommerce_ship_to_countries', @@ -286,7 +286,7 @@ const Settings = () => [ }, { id: 'woocommerce_specific_ship_to_countries', - value: [ 'DZ', 'CA', 'NZ', 'ES', 'GB', 'US' ], + value: [ 'AL', 'DZ', 'CA', 'NZ', 'ES', 'GB', 'US' ], }, { id: 'woocommerce_enable_coupons', From fc19edd89a26116930b29a100bd90d0da44eba5f Mon Sep 17 00:00:00 2001 From: Thomas Roberts Date: Fri, 7 Apr 2023 18:50:17 +0100 Subject: [PATCH 4/5] Add test to ensure adding a postcode for a country without rules works --- .../shopper/cart-checkout/checkout.test.js | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/e2e/specs/shopper/cart-checkout/checkout.test.js b/tests/e2e/specs/shopper/cart-checkout/checkout.test.js index 99917a815a0..b2a95bab13f 100644 --- a/tests/e2e/specs/shopper/cart-checkout/checkout.test.js +++ b/tests/e2e/specs/shopper/cart-checkout/checkout.test.js @@ -197,6 +197,42 @@ describe( 'Shopper → Checkout', () => { await shopper.block.verifyShippingDetails( SHIPPING_DETAILS ); await shopper.block.verifyBillingDetails( BILLING_DETAILS ); } ); + it( 'User can add postcodes for different countries', async () => { + await shopper.block.goToShop(); + await shopper.addToCartFromShopPage( SIMPLE_PHYSICAL_PRODUCT_NAME ); + await shopper.block.goToCheckout(); + await page.waitForSelector( + '.wc-block-checkout__use-address-for-billing input[type="checkbox"]' + ); + await unsetCheckbox( + '.wc-block-checkout__use-address-for-billing input[type="checkbox"]' + ); + await shopper.block.fillShippingDetails( + { + ...SHIPPING_DETAILS, + country: 'Albania', + state: 'Berat', + postcode: '1234', + }, + true + ); + + await shopper.block.fillBillingDetails( + { + ...BILLING_DETAILS, + country: 'United Kingdom', + postcode: 'SW1 1AA', + }, + true + ); + + await expect( page ).not.toMatchElement( + '.wc-block-components-validation-error p', + { + text: 'Please enter a valid postcode', + } + ); + } ); } ); describe( 'Checkout Form Errors', () => { From e919933d5600fd5187dbef9f3f66bbe56da89517 Mon Sep 17 00:00:00 2001 From: Thomas Roberts Date: Fri, 7 Apr 2023 18:58:06 +0100 Subject: [PATCH 5/5] Remove skipPushCheck option no longer needed --- .../shopper/cart-checkout/checkout.test.js | 28 ++++++++----------- tests/utils/shopper.js | 12 +++----- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/tests/e2e/specs/shopper/cart-checkout/checkout.test.js b/tests/e2e/specs/shopper/cart-checkout/checkout.test.js index b2a95bab13f..c0cf8483e9a 100644 --- a/tests/e2e/specs/shopper/cart-checkout/checkout.test.js +++ b/tests/e2e/specs/shopper/cart-checkout/checkout.test.js @@ -207,24 +207,18 @@ describe( 'Shopper → Checkout', () => { await unsetCheckbox( '.wc-block-checkout__use-address-for-billing input[type="checkbox"]' ); - await shopper.block.fillShippingDetails( - { - ...SHIPPING_DETAILS, - country: 'Albania', - state: 'Berat', - postcode: '1234', - }, - true - ); + await shopper.block.fillShippingDetails( { + ...SHIPPING_DETAILS, + country: 'Albania', + state: 'Berat', + postcode: '1234', + } ); - await shopper.block.fillBillingDetails( - { - ...BILLING_DETAILS, - country: 'United Kingdom', - postcode: 'SW1 1AA', - }, - true - ); + await shopper.block.fillBillingDetails( { + ...BILLING_DETAILS, + country: 'United Kingdom', + postcode: 'SW1 1AA', + } ); await expect( page ).not.toMatchElement( '.wc-block-components-validation-error p', diff --git a/tests/utils/shopper.js b/tests/utils/shopper.js index c5f5f6deea6..99855e58b3d 100644 --- a/tests/utils/shopper.js +++ b/tests/utils/shopper.js @@ -276,7 +276,7 @@ export const shopper = { await page.evaluate( 'document.activeElement.blur()' ); }, // prettier-ignore - fillBillingDetails: async ( customerBillingDetails, skipPushCheck = false ) => { + fillBillingDetails: async ( customerBillingDetails ) => { await page.waitForSelector( '#billing-fields' ); const companyInputField = await page.$( '#billing-company' ); @@ -300,14 +300,12 @@ export const shopper = { await expect( page ).toFill( '#email', customerBillingDetails.email ); // Blur active field to trigger customer address update, then wait for requests to finish. await page.evaluate( 'document.activeElement.blur()' ); - if ( ! skipPushCheck ) { - await checkCustomerPushCompleted( 'billing', customerBillingDetails ); + await checkCustomerPushCompleted( 'billing', customerBillingDetails ); - } }, // prettier-ignore - fillShippingDetails: async ( customerShippingDetails, skipPushCheck = false ) => { + fillShippingDetails: async ( customerShippingDetails ) => { const companyInputField = await page.$( '#shipping-company' ); if ( companyInputField ) { @@ -328,9 +326,7 @@ export const shopper = { await expect( page ).toFill( '#shipping-phone', customerShippingDetails.phone ); // Blur active field to customer address update, then wait for requests to finish. await page.evaluate( 'document.activeElement.blur()' ); - if ( ! skipPushCheck ) { - await checkCustomerPushCompleted( 'shipping', customerShippingDetails ); - } + await checkCustomerPushCompleted( 'shipping', customerShippingDetails ); }, // prettier-ignore