Skip to content

Commit

Permalink
Merge branch 'develop' into update/deprecating-sofort-from-checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
FangedParakeet authored Jan 29, 2025
2 parents 514b43b + d0be258 commit 1a838da
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 128 deletions.
4 changes: 4 additions & 0 deletions changelog/dev-10074-pw-shopper-blocks-checkout-purchase
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

E2E Playwright Migration: convert shopper-wc-blocks-checkout-purchase spec
4 changes: 4 additions & 0 deletions changelog/fix-10193-form-fields-reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Update gateway form fields references to prevent errors.
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,9 @@ private function update_woopay_enabled_locations( WP_REST_Request $request ) {
}

$woopay_enabled_locations = $request->get_param( 'woopay_enabled_locations' );
$wcpay_form_fields = $this->wcpay_gateway->get_form_fields();
$all_locations = $wcpay_form_fields['payment_request_button_locations']['options'];

$all_locations = $this->wcpay_gateway->form_fields['payment_request_button_locations']['options'];
WC_Payments::woopay_tracker()->woopay_locations_updated( $all_locations, $woopay_enabled_locations );

$this->wcpay_gateway->update_option( 'platform_checkout_button_locations', $woopay_enabled_locations );
Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-payments-woopay-button-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public function init() {

// Create WooPay button location option if it doesn't exist and enable all locations by default.
if ( ! array_key_exists( self::BUTTON_LOCATIONS, get_option( 'woocommerce_woocommerce_payments_settings' ) ) ) {
if ( isset( $this->gateway->form_fields[ self::BUTTON_LOCATIONS ]['options'] ) ) {
$all_locations = $this->gateway->form_fields[ self::BUTTON_LOCATIONS ]['options'];
if ( isset( $this->gateway->get_form_fields()[ self::BUTTON_LOCATIONS ]['options'] ) ) {
$all_locations = $this->gateway->get_form_fields()[ self::BUTTON_LOCATIONS ]['options'];

$this->gateway->update_option( self::BUTTON_LOCATIONS, array_keys( $all_locations ) );
WC_Payments::woopay_tracker()->woopay_locations_updated( $all_locations, array_keys( $all_locations ) );
Expand Down
22 changes: 11 additions & 11 deletions tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ test.describe( 'Shopper Multi-Currency widget', () => {
).toBeVisible();

Check failure on line 42 in tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[shopper] › shopper/shopper-multi-currency-widget.spec.ts:36:6 › Shopper Multi-Currency widget › should display currency switcher widget if multi-currency is enabled

1) [shopper] › shopper/shopper-multi-currency-widget.spec.ts:36:6 › Shopper Multi-Currency widget › should display currency switcher widget if multi-currency is enabled Error: Timed out 20000ms waiting for expect(locator).toBeVisible() Locator: locator('.widget select[name=currency]') Expected: visible Received: hidden Call log: - expect.toBeVisible with timeout 20000ms - waiting for locator('.widget select[name=currency]') 40 | await expect( 41 | shopperPage.locator( '.widget select[name=currency]' ) > 42 | ).toBeVisible(); | ^ 43 | } ); 44 | 45 | test.describe( 'Should allow shopper to switch currency', () => { at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts:42:5

Check failure on line 42 in tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[shopper] › shopper/shopper-multi-currency-widget.spec.ts:36:6 › Shopper Multi-Currency widget › should display currency switcher widget if multi-currency is enabled

1) [shopper] › shopper/shopper-multi-currency-widget.spec.ts:36:6 › Shopper Multi-Currency widget › should display currency switcher widget if multi-currency is enabled Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 20000ms waiting for expect(locator).toBeVisible() Locator: locator('.widget select[name=currency]') Expected: visible Received: hidden Call log: - expect.toBeVisible with timeout 20000ms - waiting for locator('.widget select[name=currency]') 40 | await expect( 41 | shopperPage.locator( '.widget select[name=currency]' ) > 42 | ).toBeVisible(); | ^ 43 | } ); 44 | 45 | test.describe( 'Should allow shopper to switch currency', () => { at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts:42:5

Check failure on line 42 in tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[shopper] › shopper/shopper-multi-currency-widget.spec.ts:36:6 › Shopper Multi-Currency widget › should display currency switcher widget if multi-currency is enabled

1) [shopper] › shopper/shopper-multi-currency-widget.spec.ts:36:6 › Shopper Multi-Currency widget › should display currency switcher widget if multi-currency is enabled Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 20000ms waiting for expect(locator).toBeVisible() Locator: locator('.widget select[name=currency]') Expected: visible Received: hidden Call log: - expect.toBeVisible with timeout 20000ms - waiting for locator('.widget select[name=currency]') 40 | await expect( 41 | shopperPage.locator( '.widget select[name=currency]' ) > 42 | ).toBeVisible(); | ^ 43 | } ); 44 | 45 | test.describe( 'Should allow shopper to switch currency', () => { at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts:42:5
} );

test( 'should not display currency switcher widget if multi-currency is disabled', async () => {
await merchant.deactivateMulticurrency( merchantPage );

await navigation.goToShop( shopperPage );
await expect(
shopperPage.locator( '.widget select[name=currency]' )
).not.toBeVisible();

await merchant.activateMulticurrency( merchantPage );
} );

test.describe( 'Should allow shopper to switch currency', () => {
test.afterEach( async () => {

Check failure on line 46 in tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[shopper] › shopper/shopper-multi-currency-widget.spec.ts:57:7 › Shopper Multi-Currency widget › Should allow shopper to switch currency › at the product page

2) [shopper] › shopper/shopper-multi-currency-widget.spec.ts:57:7 › Shopper Multi-Currency widget › Should allow shopper to switch currency › at the product page Test timeout of 120000ms exceeded while running "afterEach" hook. 44 | 45 | test.describe( 'Should allow shopper to switch currency', () => { > 46 | test.afterEach( async () => { | ^ 47 | await shopperPage.selectOption( 48 | '.widget select[name=currency]', 49 | 'EUR' at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts:46:8

Check failure on line 46 in tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[shopper] › shopper/shopper-multi-currency-widget.spec.ts:57:7 › Shopper Multi-Currency widget › Should allow shopper to switch currency › at the product page

2) [shopper] › shopper/shopper-multi-currency-widget.spec.ts:57:7 › Shopper Multi-Currency widget › Should allow shopper to switch currency › at the product page Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Test timeout of 120000ms exceeded while running "afterEach" hook. 44 | 45 | test.describe( 'Should allow shopper to switch currency', () => { > 46 | test.afterEach( async () => { | ^ 47 | await shopperPage.selectOption( 48 | '.widget select[name=currency]', 49 | 'EUR' at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts:46:8

Check failure on line 46 in tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[shopper] › shopper/shopper-multi-currency-widget.spec.ts:57:7 › Shopper Multi-Currency widget › Should allow shopper to switch currency › at the product page

2) [shopper] › shopper/shopper-multi-currency-widget.spec.ts:57:7 › Shopper Multi-Currency widget › Should allow shopper to switch currency › at the product page Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Test timeout of 120000ms exceeded while running "afterEach" hook. 44 | 45 | test.describe( 'Should allow shopper to switch currency', () => { > 46 | test.afterEach( async () => { | ^ 47 | await shopperPage.selectOption( 48 | '.widget select[name=currency]', 49 | 'EUR' at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts:46:8

Check failure on line 46 in tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[shopper] › shopper/shopper-multi-currency-widget.spec.ts:61:7 › Shopper Multi-Currency widget › Should allow shopper to switch currency › at the cart page

3) [shopper] › shopper/shopper-multi-currency-widget.spec.ts:61:7 › Shopper Multi-Currency widget › Should allow shopper to switch currency › at the cart page Test timeout of 120000ms exceeded while running "afterEach" hook. 44 | 45 | test.describe( 'Should allow shopper to switch currency', () => { > 46 | test.afterEach( async () => { | ^ 47 | await shopperPage.selectOption( 48 | '.widget select[name=currency]', 49 | 'EUR' at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts:46:8
await shopperPage.selectOption(

Check failure on line 47 in tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[shopper] › shopper/shopper-multi-currency-widget.spec.ts:57:7 › Shopper Multi-Currency widget › Should allow shopper to switch currency › at the product page

2) [shopper] › shopper/shopper-multi-currency-widget.spec.ts:57:7 › Shopper Multi-Currency widget › Should allow shopper to switch currency › at the product page Error: page.selectOption: Test ended. Call log: - waiting for locator('.widget select[name=currency]') 45 | test.describe( 'Should allow shopper to switch currency', () => { 46 | test.afterEach( async () => { > 47 | await shopperPage.selectOption( | ^ 48 | '.widget select[name=currency]', 49 | 'EUR' 50 | ); at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts:47:22

Check failure on line 47 in tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[shopper] › shopper/shopper-multi-currency-widget.spec.ts:57:7 › Shopper Multi-Currency widget › Should allow shopper to switch currency › at the product page

2) [shopper] › shopper/shopper-multi-currency-widget.spec.ts:57:7 › Shopper Multi-Currency widget › Should allow shopper to switch currency › at the product page Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: page.selectOption: Test ended. Call log: - waiting for locator('.widget select[name=currency]') 45 | test.describe( 'Should allow shopper to switch currency', () => { 46 | test.afterEach( async () => { > 47 | await shopperPage.selectOption( | ^ 48 | '.widget select[name=currency]', 49 | 'EUR' 50 | ); at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts:47:22

Check failure on line 47 in tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[shopper] › shopper/shopper-multi-currency-widget.spec.ts:57:7 › Shopper Multi-Currency widget › Should allow shopper to switch currency › at the product page

2) [shopper] › shopper/shopper-multi-currency-widget.spec.ts:57:7 › Shopper Multi-Currency widget › Should allow shopper to switch currency › at the product page Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: page.selectOption: Test ended. Call log: - waiting for locator('.widget select[name=currency]') 45 | test.describe( 'Should allow shopper to switch currency', () => { 46 | test.afterEach( async () => { > 47 | await shopperPage.selectOption( | ^ 48 | '.widget select[name=currency]', 49 | 'EUR' 50 | ); at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/shopper/shopper-multi-currency-widget.spec.ts:47:22
Expand Down Expand Up @@ -124,4 +113,15 @@ test.describe( 'Shopper Multi-Currency widget', () => {
merchantPage.locator( '.widget select[name=currency]' )
).not.toBeVisible();
} );

test( 'should not display currency switcher widget if multi-currency is disabled', async () => {
await merchant.deactivateMulticurrency( merchantPage );

await navigation.goToShop( shopperPage );
await expect(
shopperPage.locator( '.widget select[name=currency]' )
).not.toBeVisible();

await merchant.activateMulticurrency( merchantPage );
} );
} );
28 changes: 16 additions & 12 deletions tests/e2e-pw/specs/shopper/shopper-myaccount-saved-cards.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,27 @@ test.describe( 'Shopper can save and delete cards', () => {
// Otherwise, you will get the error message,
// "You cannot add a new payment method so soon after the previous one."
// Source: /docker/wordpress/wp-content/plugins/woocommerce/includes/class-wc-form-handler.php#L509-L521

// Be careful that this is only needed for a successful card addition, so call it only where it's needed the most, to prevent unnecessary delays.
const timeTestFinished = Date.now();
const elapsedWaitTime = timeTestFinished - timeAdded;
const remainingWaitTime =
20000 > elapsedWaitTime ? 20000 - elapsedWaitTime : 0;

await page.waitForTimeout( remainingWaitTime );
if ( remainingWaitTime > 0 ) {
await page.waitForTimeout( remainingWaitTime );
}
}

// No need to run this test for all card types.
test( 'prevents adding another card for 20 seconds after a card is added', async () => {
await goToMyAccount( shopperPage, 'payment-methods' );
// Take note of the time when we added this card

// Make sure that at least 20s had already elapsed since the last card was added.
await waitTwentySecondsSinceLastCardAdded( shopperPage );

await addSavedCard( shopperPage, config.cards.basic, 'US', '94110' );
// Take note of the time when we added this card
timeAdded = +Date.now();

await expect(
Expand All @@ -108,7 +116,6 @@ test.describe( 'Shopper can save and delete cards', () => {
)
).not.toBeVisible();

await waitTwentySecondsSinceLastCardAdded( shopperPage );
// cleanup for the next tests
await goToMyAccount( shopperPage, 'payment-methods' );
await deleteSavedCard( shopperPage, config.cards.basic );
Expand All @@ -128,6 +135,9 @@ test.describe( 'Shopper can save and delete cards', () => {
test.describe( 'Testing card: ' + cardName, () => {
test( `should add the ${ cardName } card as a new payment method`, async () => {
await goToMyAccount( shopperPage, 'payment-methods' );
// Make sure that at least 20s had already elapsed since the last card was added.
await waitTwentySecondsSinceLastCardAdded( shopperPage );

await addSavedCard(
shopperPage,
card,
Expand Down Expand Up @@ -159,8 +169,6 @@ test.describe( 'Shopper can save and delete cards', () => {
`${ card.expires.month }/${ card.expires.year }`
)
).toBeVisible();

await waitTwentySecondsSinceLastCardAdded( shopperPage );
} );

test( `should be able to purchase with the saved ${ cardName } card`, async () => {
Expand All @@ -180,6 +188,9 @@ test.describe( 'Shopper can save and delete cards', () => {

test( `should be able to set the ${ cardName } card as default payment method`, async () => {
await goToMyAccount( shopperPage, 'payment-methods' );
// Make sure that at least 20s had already elapsed since the last card was added.
await waitTwentySecondsSinceLastCardAdded( shopperPage );

await addSavedCard( shopperPage, card2, 'US', '94110' );
// Take note of the time when we added this card
timeAdded = +Date.now();
Expand Down Expand Up @@ -214,13 +225,6 @@ test.describe( 'Shopper can save and delete cards', () => {
shopperPage.getByText( 'No saved methods found.' )
).toBeVisible();
} );

test.afterAll( async () => {
const cardKeys = Object.keys( cards );
if ( cardName !== cardKeys[ cardKeys.length - 1 ] ) {
waitTwentySecondsSinceLastCardAdded( shopperPage );
}
} );
} );
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* External dependencies
*/
import { test, expect, Page } from '@playwright/test';

/**
* Internal dependencies
*/
import {
checkPageExists,
describeif,
getMerchant,
getShopper,
} from '../../utils/helpers';
import { shouldRunWCBlocksTests } from '../../utils/constants';
import { addWCBCheckoutPage } from '../../utils/merchant';
import { goToCheckoutWCB } from '../../utils/shopper-navigation';
import {
addCartProduct,
confirmCardAuthentication,
fillBillingAddressWCB,
fillCardDetailsWCB,
} from '../../utils/shopper';
import { config } from '../../config/default';

describeif( shouldRunWCBlocksTests )(
'WooCommerce Blocks > Successful purchase',
() => {
let shopperPage: Page;

test.beforeAll( async ( { browser }, { project } ) => {
shopperPage = ( await getShopper( browser ) ).shopperPage;
if (
! ( await checkPageExists(
shopperPage,
project.use.baseURL + '/checkout-wcb'
) )
) {
const { merchantPage } = await getMerchant( browser );
await addWCBCheckoutPage( merchantPage );
}
} );

test( 'using a basic card', async () => {
await addCartProduct( shopperPage );
await goToCheckoutWCB( shopperPage );
await fillBillingAddressWCB(
shopperPage,
config.addresses.customer.billing
);
await fillCardDetailsWCB( shopperPage, config.cards.basic );
await shopperPage
.getByRole( 'button', { name: 'Place Order' } )
.click();
await expect(
shopperPage.getByRole( 'heading', {
name: 'Order received',
} )
).toBeVisible();
} );

test( 'using a 3DS card', async () => {
await addCartProduct( shopperPage );
await goToCheckoutWCB( shopperPage );
await fillBillingAddressWCB(
shopperPage,
config.addresses.customer.billing
);
await fillCardDetailsWCB( shopperPage, config.cards[ '3ds' ] );
await shopperPage
.getByRole( 'button', { name: 'Place Order' } )
.click();
await confirmCardAuthentication( shopperPage );
await expect(
shopperPage.getByRole( 'heading', {
name: 'Order received',
} )
).toBeVisible();
} );
}
);

This file was deleted.

0 comments on commit 1a838da

Please sign in to comment.