Skip to content

Commit

Permalink
Merge pull request #171 from woocommerce/fix/e2e-tests
Browse files Browse the repository at this point in the history
Fix e2e tests: Update default behavior to use a block-based cart and checkout
  • Loading branch information
dkotter authored Nov 10, 2023
2 parents 9b9ab19 + 2dd62b7 commit 570013a
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 160 deletions.
4 changes: 3 additions & 1 deletion tests/e2e/bin/initialize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ wp-env run tests-cli wp user create customer [email protected] -
wp-env run tests-cli wp wc tax create -- --country="*" --state="*" --postcode="*" --city="*" --rate=20 --name="General Tax" --user=1
wp-env run tests-cli wp wc product create -- --name="Simple Product" --slug="simple-product" --user=1 --regular_price=10 --virtual=true
wp-env run tests-cli wp wc product create -- --name="Simple Subscription Product" --slug="simple-subscription-product" --user=1 --regular_price=10 --type=subscription --virtual=true --meta_data='[{"key":"_subscription_price","value":"10"},{"key":"_subscription_period","value":"month"},{"key":"_subscription_period_interval","value":"1"}]'
wp-env run tests-cli wp post create ./wp-content/plugins/woocommerce-gateway-payfast/tests/e2e/config/checkout-block-page.txt --post_title='Checkout Block' --post_type=page --post_status=publish --post_author=1

# Add Shortcode checkout page.
wp-env run tests-cli wp post create --post_title='Shortcode Checkout' --post_type=page --post_status=publish --post_author=1 --post_content='<!-- wp:shortcode -->[woocommerce_checkout]<!-- /wp:shortcode -->'
79 changes: 0 additions & 79 deletions tests/e2e/config/checkout-block-page.txt

This file was deleted.

8 changes: 4 additions & 4 deletions tests/e2e/specs/admin/edit-settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test.describe( 'Verify payfast setting - @foundational', async () => {

test( 'Checkout Block: Payment method should not available when disabled', async () => {
await addProductToCart( {page: checkoutBlockPage, productUrl: '/product/simple-product/'} );
await checkoutBlockPage.goto( '/checkout-block/' );
await checkoutBlockPage.goto( '/checkout/' );

const paymentMethodLocator = await checkoutBlockPage.locator( 'label.wc-block-components-radio-control__option', {
has: checkoutBlockPage.locator( 'input[value="payfast"]' )
Expand All @@ -55,7 +55,7 @@ test.describe( 'Verify payfast setting - @foundational', async () => {

test( 'Checkout Page: Payment method should not available when disabled', async () => {
await addProductToCart( {page: checkoutPage, productUrl: '/product/simple-product/'} );
await checkoutPage.goto( '/checkout/' );
await checkoutPage.goto( '/shortcode-checkout/' );

const paymentMethodLocator = await checkoutPage.locator( '.wc_payment_method', {
has: checkoutPage.locator( 'input[value="payfast"]' )
Expand All @@ -78,7 +78,7 @@ test.describe( 'Verify payfast setting - @foundational', async () => {

test( 'Checkout Block: Verify method title & description', async () => {
await addProductToCart( {page: checkoutBlockPage, productUrl: '/product/simple-product/'} );
await checkoutBlockPage.goto( '/checkout-block/' );
await checkoutBlockPage.goto( '/checkout/' );

const paymentMethodLocator = await checkoutBlockPage.locator(
'label[for="radio-control-wc-payment-method-options-payfast"]' );
Expand All @@ -92,7 +92,7 @@ test.describe( 'Verify payfast setting - @foundational', async () => {

test( 'Checkout Page: Verify method title & description', async () => {
await addProductToCart( {page: checkoutPage, productUrl: '/product/simple-product/'} );
await checkoutPage.goto( '/checkout/' );
await checkoutPage.goto( '/shortcode-checkout/' );

const paymentMethodLocator = await checkoutPage.locator( '.wc_payment_method.payment_method_payfast' );
await expect( paymentMethodLocator ).toHaveText( /Payfast/ );
Expand Down
26 changes: 7 additions & 19 deletions tests/e2e/specs/payment-flow/cancelled-one-time-payment.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Internal dependencies
*/
import {addProductToCart, changeCurrency, editPayfastSetting, goToOrderEditPage} from '../../utils';
import {addProductToCart, changeCurrency, editPayfastSetting, fillBillingDetails, goToOrderEditPage} from '../../utils';
import {customer, payfastSandboxCredentials} from "../../config";

/**
Expand Down Expand Up @@ -42,17 +42,11 @@ test.describe( 'Verify Payfast Cancelled One-Time Payment Process - @foundationa

const page = checkoutBlock;
await addProductToCart( {page, productUrl:'/product/simple-product/'} );
await page.goto('/checkout-block/');

await page.getByLabel('First name').fill( customer.billing.firstname );
await page.getByLabel('Last name').fill( customer.billing.lastname );
await page.getByLabel('Address', {exact: true}).fill( customer.billing.addressfirstline );
await page.getByLabel('City').fill( customer.billing.city );
await page.getByLabel('Zip Code').fill( customer.billing.postcode );
await page.getByLabel('Phone (optional)').fill( customer.billing.phone );
await page.goto('/checkout/');
await fillBillingDetails(page, customer.billing, true);

// Check if Payfast payment method is visible & place order
const payfastCheckoutPage = page.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ );
const payfastCheckoutPage = page.waitForURL( /\/sandbox.payfast.co.za\/eng/ );
const payfastPaymentMethod = await page.locator( 'label[for="radio-control-wc-payment-method-options-payfast"]' );
await payfastPaymentMethod.click();
await page.getByRole( 'button', {name: 'Place order'} ).click();
Expand Down Expand Up @@ -81,17 +75,11 @@ test.describe( 'Verify Payfast Cancelled One-Time Payment Process - @foundationa
const page = checkoutPage;

await addProductToCart( {page, productUrl: '/product/simple-product/'} );
await page.goto( '/checkout/' );

await page.getByLabel( 'First name' ).fill( customer.billing.firstname );
await page.getByLabel( 'Last name' ).fill( customer.billing.lastname );
await page.getByLabel( 'Street address' ).fill( customer.billing.addressfirstline );
await page.getByLabel( 'Town / City' ).fill( customer.billing.city );
await page.getByLabel( 'Zip Code' ).fill( customer.billing.postcode );
await page.getByLabel( 'Phone' ).fill( customer.billing.phone );
await page.goto( '/shortcode-checkout/' );
await fillBillingDetails(page, customer.billing);

// Check if Payfast payment method is visible & place order
const payfastCheckoutPage = page.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ );
const payfastCheckoutPage = page.waitForURL( /\/sandbox.payfast.co.za\/eng/ );
const payfastPaymentMethod = await page.locator( '.wc_payment_method.payment_method_payfast' );
await payfastPaymentMethod.click();
await page.getByRole( 'button', {name: 'Place order'} ).click();
Expand Down
26 changes: 7 additions & 19 deletions tests/e2e/specs/payment-flow/one-time-payment.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Internal dependencies
*/
import {addProductToCart, changeCurrency, clearEmailLogs, editPayfastSetting, goToOrderEditPage} from '../../utils';
import {addProductToCart, changeCurrency, clearEmailLogs, editPayfastSetting, fillBillingDetails, goToOrderEditPage} from '../../utils';
import {customer, payfastSandboxCredentials} from "../../config";

/**
Expand Down Expand Up @@ -45,17 +45,11 @@ test.describe( 'Verify Payfast One-Time Payment Process - @foundational', async
await clearEmailLogs( {page: adminPage} );

await addProductToCart( {page: checkoutBlock, productUrl:'/product/simple-product/'} );
await checkoutBlock.goto('/checkout-block/');

await checkoutBlock.getByLabel('First name').fill( customer.billing.firstname );
await checkoutBlock.getByLabel('Last name').fill( customer.billing.lastname );
await checkoutBlock.getByLabel('Address', {exact: true}).fill( customer.billing.addressfirstline );
await checkoutBlock.getByLabel('City').fill( customer.billing.city );
await checkoutBlock.getByLabel('Zip Code').fill( customer.billing.postcode );
await checkoutBlock.getByLabel('Phone (optional)').fill( customer.billing.phone );
await checkoutBlock.goto('/checkout/');
await fillBillingDetails(checkoutBlock, customer.billing, true);

// Check if Payfast payment method is visible & place order
waitForURL = checkoutBlock.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ );
waitForURL = checkoutBlock.waitForURL( /\/sandbox.payfast.co.za\/eng/ );
const payfastPaymentMethod = await checkoutBlock.locator( 'label[for="radio-control-wc-payment-method-options-payfast"]' );
await payfastPaymentMethod.click();
await checkoutBlock.getByRole( 'button', {name: 'Place order'} ).click();
Expand Down Expand Up @@ -89,17 +83,11 @@ test.describe( 'Verify Payfast One-Time Payment Process - @foundational', async
let waitForURL;

await addProductToCart( {page: checkoutPage, productUrl: '/product/simple-product/'} );
await checkoutPage.goto( '/checkout/' );

await checkoutPage.getByLabel( 'First name' ).fill( customer.billing.firstname );
await checkoutPage.getByLabel( 'Last name' ).fill( customer.billing.lastname );
await checkoutPage.getByLabel( 'Street address' ).fill( customer.billing.addressfirstline );
await checkoutPage.getByLabel( 'Town / City' ).fill( customer.billing.city );
await checkoutPage.getByLabel( 'Zip Code' ).fill( customer.billing.postcode );
await checkoutPage.getByLabel( 'Phone' ).fill( customer.billing.phone );
await checkoutPage.goto( '/shortcode-checkout/' );
await fillBillingDetails(checkoutPage, customer.billing);

// Check if Payfast payment method is visible & place order
waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ );
waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng/ );
const payfastPaymentMethod = await checkoutPage.locator( '.wc_payment_method.payment_method_payfast' );
await payfastPaymentMethod.click();
await checkoutPage.getByRole( 'button', {name: 'Place order'} ).click();
Expand Down
29 changes: 9 additions & 20 deletions tests/e2e/specs/payment-flow/subscription-payment.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Internal dependencies
*/
import {changeCurrency, editPayfastSetting, goToOrderEditPage} from '../../utils';
import {changeCurrency, editPayfastSetting, fillBillingDetails, goToOrderEditPage} from '../../utils';
import {customer, payfastSandboxCredentials} from "../../config";

/**
Expand Down Expand Up @@ -44,17 +44,11 @@ test.describe( 'Verify Payfast Subscription Payment Process - @foundational', as

await checkoutBlock.goto( '/product/simple-subscription-product/' );
await checkoutBlock.click( 'text=Sign up now' );
await checkoutBlock.goto( '/checkout-block/' );

await checkoutBlock.getByLabel( 'First name' ).fill( customer.billing.firstname );
await checkoutBlock.getByLabel( 'Last name' ).fill( customer.billing.lastname );
await checkoutBlock.getByLabel( 'Address', {exact: true} ).fill( customer.billing.addressfirstline );
await checkoutBlock.getByLabel( 'City' ).fill( customer.billing.city );
await checkoutBlock.getByLabel( 'Zip Code' ).fill( customer.billing.postcode );
await checkoutBlock.getByLabel( 'Phone (optional)' ).fill( customer.billing.phone );
await checkoutBlock.goto( '/checkout/' );
await fillBillingDetails(checkoutBlock, customer.billing, true);

// Check if Payfast payment method is visible & place order
waitForURL = checkoutBlock.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ );
waitForURL = checkoutBlock.waitForURL( /\/sandbox.payfast.co.za\/eng/ );
const payfastPaymentMethod = await checkoutBlock.locator(
'label[for="radio-control-wc-payment-method-options-payfast"]' );
await payfastPaymentMethod.click();
Expand Down Expand Up @@ -91,17 +85,11 @@ test.describe( 'Verify Payfast Subscription Payment Process - @foundational', as

await checkoutPage.goto( '/product/simple-subscription-product/' );
await checkoutPage.click( 'text=Sign up now' );
await checkoutPage.goto( '/checkout/' );

await checkoutPage.getByLabel( 'First name' ).fill( customer.billing.firstname );
await checkoutPage.getByLabel( 'Last name' ).fill( customer.billing.lastname );
await checkoutPage.getByLabel( 'Street address' ).fill( customer.billing.addressfirstline );
await checkoutPage.getByLabel( 'Town / City' ).fill( customer.billing.city );
await checkoutPage.getByLabel( 'Zip Code' ).fill( customer.billing.postcode );
await checkoutPage.getByLabel( 'Phone' ).fill( customer.billing.phone );
await checkoutPage.goto( '/shortcode-checkout/' );
await fillBillingDetails(checkoutPage, customer.billing);

// Check if Payfast payment method is visible & place order
waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ );
waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng/ );
const payfastPaymentMethod = await checkoutPage.locator( '.wc_payment_method.payment_method_payfast' );
await payfastPaymentMethod.click();
await checkoutPage.getByRole( 'button', {name: 'Sign up now'} ).click();
Expand Down Expand Up @@ -153,7 +141,8 @@ test.describe( 'Verify Payfast Subscription Payment Process - @foundational', as
await checkoutPage.getByRole( 'link', {name: 'Renew now'} ).click();

// Check if Payfast payment method is visible & place order
waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng\/process\/payment/ );
await checkoutPage.goto( '/shortcode-checkout/' );
waitForURL = checkoutPage.waitForURL( /\/sandbox.payfast.co.za\/eng/ );
const payfastPaymentMethod = await checkoutPage.locator( '.wc_payment_method.payment_method_payfast' );
await payfastPaymentMethod.click();
await checkoutPage.getByRole( 'button', {name: 'Renew Subscription'} ).click();
Expand Down
Loading

0 comments on commit 570013a

Please sign in to comment.