From d9dd7a0df61d30b52ad33aaa2ef27ae89046e66b Mon Sep 17 00:00:00 2001 From: Niels Lange Date: Wed, 9 Mar 2022 13:23:52 +0100 Subject: [PATCH] Shopper can choose shipping option (https://github.com/woocommerce/woocommerce-blocks/pull/5844) --- .../woocommerce-blocks/bin/wp-env-config.sh | 1 + .../tests/e2e/fixtures/fixture-data.js | 24 ++++++++ .../specs/shopper/checkout-shipping.test.js | 57 +++++++++++++++++++ .../woocommerce-blocks/tests/utils/shopper.js | 19 +++++++ 4 files changed, 101 insertions(+) create mode 100644 plugins/woocommerce-blocks/tests/e2e/specs/shopper/checkout-shipping.test.js diff --git a/plugins/woocommerce-blocks/bin/wp-env-config.sh b/plugins/woocommerce-blocks/bin/wp-env-config.sh index 4e106ea27bc..27b55ecb4de 100755 --- a/plugins/woocommerce-blocks/bin/wp-env-config.sh +++ b/plugins/woocommerce-blocks/bin/wp-env-config.sh @@ -18,5 +18,6 @@ wp rewrite flush wp core version --extra wp plugin list wp theme activate storefront +wp wc customer update 1 --user=1 --billing='{"first_name":"John","last_name":"Doe","company":"Automattic","country":"US","address_1":"addr 1","address_2":"addr 2","city":"San Francisco","state":"CA","postcode":"94107","phone":"123456789"}' --shipping='{"first_name":"John","last_name":"Doe","company":"Automattic","country":"US","address_1":"addr 1","address_2":"addr 2","city":"San Francisco","state":"CA","postcode":"94107","phone":"123456789"}' exit $EXIT_CODE diff --git a/plugins/woocommerce-blocks/tests/e2e/fixtures/fixture-data.js b/plugins/woocommerce-blocks/tests/e2e/fixtures/fixture-data.js index c4109dd7532..ceb72ed35f1 100644 --- a/plugins/woocommerce-blocks/tests/e2e/fixtures/fixture-data.js +++ b/plugins/woocommerce-blocks/tests/e2e/fixtures/fixture-data.js @@ -344,6 +344,30 @@ const Shipping = () => [ }, ], }, + { + name: 'US', + locations: [ + { + code: 'US', + }, + ], + methods: [ + { + method_id: 'flat_rate', + settings: { + title: 'Normal Shipping', + cost: '20.00', + }, + }, + { + method_id: 'free_shipping', + settings: { + title: 'Free Shipping', + cost: '00.00', + }, + }, + ], + }, ]; /** diff --git a/plugins/woocommerce-blocks/tests/e2e/specs/shopper/checkout-shipping.test.js b/plugins/woocommerce-blocks/tests/e2e/specs/shopper/checkout-shipping.test.js new file mode 100644 index 00000000000..09224a94375 --- /dev/null +++ b/plugins/woocommerce-blocks/tests/e2e/specs/shopper/checkout-shipping.test.js @@ -0,0 +1,57 @@ +/** + * External dependencies + */ +import { merchant } from '@woocommerce/e2e-utils'; + +/** + * Internal dependencies + */ +import { shopper } from '../../../utils'; + +const productName = '128GB USB Stick'; +const freeShippingName = 'Free Shipping'; +const freeShippingPrice = '$0.00'; +const normalShippingName = 'Normal Shipping'; +const normalShippingPrice = '$20.00'; + +if ( process.env.WOOCOMMERCE_BLOCKS_PHASE < 2 ) + // eslint-disable-next-line jest/no-focused-tests + test.only( 'Skipping Checkout tests', () => {} ); + +describe( `Shopper → Checkout → Can choose shipping option`, () => { + beforeAll( async () => { + await merchant.login(); + } ); + + afterAll( async () => { + await merchant.logout(); + } ); + + it( 'allows customer to choose free shipping', async () => { + await shopper.goToShop(); + await shopper.addToCartFromShopPage( productName ); + await shopper.block.goToCheckout(); + await shopper.block.selectAndVerifyShippingOption( + freeShippingName, + freeShippingPrice + ); + await shopper.block.placeOrder(); + await page.waitForTimeout( 2000 ); + await expect( page ).toMatch( 'Order received' ); + await expect( page ).toMatch( freeShippingName ); + } ); + + it( 'allows customer to choose flat rate shipping', async () => { + await shopper.goToShop(); + await shopper.addToCartFromShopPage( productName ); + await shopper.block.goToCheckout(); + await shopper.block.selectAndVerifyShippingOption( + normalShippingName, + normalShippingPrice + ); + await shopper.block.placeOrder(); + await page.waitForTimeout( 2000 ); + await expect( page ).toMatch( 'Order received' ); + await expect( page ).toMatch( normalShippingName ); + } ); +} ); diff --git a/plugins/woocommerce-blocks/tests/utils/shopper.js b/plugins/woocommerce-blocks/tests/utils/shopper.js index 96ec29614ee..30a30d3919a 100644 --- a/plugins/woocommerce-blocks/tests/utils/shopper.js +++ b/plugins/woocommerce-blocks/tests/utils/shopper.js @@ -274,5 +274,24 @@ export const shopper = { page.waitForNavigation( { waitUntil: 'networkidle0' } ), ] ); }, + + selectAndVerifyShippingOption: async ( + shippingName, + shippingPrice + ) => { + await expect( page ).toClick( + '.wc-block-components-radio-control__label', + { + text: shippingName, + } + ); + await page.waitForTimeout( 1000 ); + await expect( page ).toMatchElement( + '.wc-block-components-totals-shipping .wc-block-formatted-money-amount', + { + text: shippingPrice, + } + ); + }, }, };