Skip to content

Commit

Permalink
Add CaptureLater functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepearson committed Jan 21, 2025
1 parent 00599cd commit 5b28c7b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
30 changes: 12 additions & 18 deletions tests/e2e-pw/specs/merchant/merchant-orders-manual-capture.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
goToOrder,
goToWooPaymentsSettings,

Check warning on line 12 in tests/e2e-pw/specs/merchant/merchant-orders-manual-capture.spec.ts

View workflow job for this annotation

GitHub Actions / JS linting

'goToWooPaymentsSettings' is defined but never used
} from '../../utils/merchant-navigation';
import { saveWooPaymentsSettings } from '../../utils/merchant';
import {
activateCaptureLater,
deactivateCaptureLater,
} from '../../utils/merchant';
import {
emptyCart,
fillCardDetails,
Expand All @@ -27,15 +30,12 @@ import { goToShop } from '../../utils/shopper-navigation';
let orderId;

test.describe( 'Order > Manual Capture', () => {
test.beforeEach( async ( { browser } ) => {
let merchantPage;

test.beforeAll( async ( { browser } ) => {
// Merchant go to settings, enable capture later, and then save.
const { merchantPage } = await getMerchant( browser );
await goToWooPaymentsSettings( merchantPage );
await merchantPage.getByTestId( 'capture-later-checkbox' ).click();
await merchantPage
.getByRole( 'button', { name: 'Enable manual capture' } )
.click();
await saveWooPaymentsSettings( merchantPage );
merchantPage = ( await getMerchant( browser ) ).merchantPage;
await activateCaptureLater( merchantPage );

// Shopper add items to cart, fill in the checkout, place an order.
const { shopperPage } = await getShopper( browser );
Expand All @@ -59,19 +59,13 @@ test.describe( 'Order > Manual Capture', () => {
orderId = await orderIdField.innerText();
} );

test.afterEach( async ( { browser } ) => {
test.afterAll( async () => {

Check failure on line 62 in tests/e2e-pw/specs/merchant/merchant-orders-manual-capture.spec.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[merchant] › merchant/merchant-orders-manual-capture.spec.ts:67:6 › Order > Manual Capture › should create an "On hold" order then capture the charge

1) [merchant] › merchant/merchant-orders-manual-capture.spec.ts:67:6 › Order > Manual Capture › should create an "On hold" order then capture the charge "afterAll" hook timeout of 120000ms exceeded. 60 | } ); 61 | > 62 | test.afterAll( async () => { | ^ 63 | // Merchant go to settings, disable capture later, and then save. 64 | await deactivateCaptureLater( merchantPage ); 65 | } ); at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/merchant/merchant-orders-manual-capture.spec.ts:62:7

Check failure on line 62 in tests/e2e-pw/specs/merchant/merchant-orders-manual-capture.spec.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[merchant] › merchant/merchant-orders-manual-capture.spec.ts:67:6 › Order > Manual Capture › should create an "On hold" order then capture the charge

1) [merchant] › merchant/merchant-orders-manual-capture.spec.ts:67:6 › Order > Manual Capture › should create an "On hold" order then capture the charge "afterAll" hook timeout of 120000ms exceeded. 60 | } ); 61 | > 62 | test.afterAll( async () => { | ^ 63 | // Merchant go to settings, disable capture later, and then save. 64 | await deactivateCaptureLater( merchantPage ); 65 | } ); at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/merchant/merchant-orders-manual-capture.spec.ts:62:7

Check failure on line 62 in tests/e2e-pw/specs/merchant/merchant-orders-manual-capture.spec.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[merchant] › merchant/merchant-orders-manual-capture.spec.ts:67:6 › Order > Manual Capture › should create an "On hold" order then capture the charge

1) [merchant] › merchant/merchant-orders-manual-capture.spec.ts:67:6 › Order > Manual Capture › should create an "On hold" order then capture the charge Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── "afterAll" hook timeout of 120000ms exceeded. 60 | } ); 61 | > 62 | test.afterAll( async () => { | ^ 63 | // Merchant go to settings, disable capture later, and then save. 64 | await deactivateCaptureLater( merchantPage ); 65 | } ); at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/merchant/merchant-orders-manual-capture.spec.ts:62:7

Check failure on line 62 in tests/e2e-pw/specs/merchant/merchant-orders-manual-capture.spec.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[merchant] › merchant/merchant-orders-manual-capture.spec.ts:67:6 › Order > Manual Capture › should create an "On hold" order then capture the charge

1) [merchant] › merchant/merchant-orders-manual-capture.spec.ts:67:6 › Order > Manual Capture › should create an "On hold" order then capture the charge Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── "afterAll" hook timeout of 120000ms exceeded. 60 | } ); 61 | > 62 | test.afterAll( async () => { | ^ 63 | // Merchant go to settings, disable capture later, and then save. 64 | await deactivateCaptureLater( merchantPage ); 65 | } ); at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/merchant/merchant-orders-manual-capture.spec.ts:62:7
// Merchant go to settings, disable capture later, and then save.
const { merchantPage } = await getMerchant( browser );
await goToWooPaymentsSettings( merchantPage );
await merchantPage.getByTestId( 'capture-later-checkbox' ).click();
await saveWooPaymentsSettings( merchantPage );
await deactivateCaptureLater( merchantPage );
} );

test( 'should create an "On hold" order then capture the charge', async ( {
browser,
} ) => {
test( 'should create an "On hold" order then capture the charge', async () => {
// Merchant go to the order.
const { merchantPage } = await getMerchant( browser );
await goToOrder( merchantPage, orderId );

// Confirm order status is 'On hold', and that there's an 'authorized' note.
Expand Down
31 changes: 31 additions & 0 deletions tests/e2e-pw/utils/merchant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,34 @@ export const deactivateWooPay = async ( page: Page ) => {
await page.getByTestId( 'woopay-toggle' ).uncheck();
await saveWooPaymentsSettings( page );
};

export const isCaptureLaterEnabled = async ( page: Page ) => {
await navigation.goToWooPaymentsSettings( page );

const checkboxTestId = 'capture-later-checkbox';
const isEnabled = await page.getByTestId( checkboxTestId ).isChecked();

return isEnabled;
};

export const activateCaptureLater = async ( page: Page ) => {
await navigation.goToWooPaymentsSettings( page );

const checkboxTestId = 'capture-later-checkbox';
const wasInitiallyEnabled = await isCaptureLaterEnabled( page );

if ( ! wasInitiallyEnabled ) {
await page.getByTestId( checkboxTestId ).check();

Check failure on line 354 in tests/e2e-pw/utils/merchant.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[merchant] › merchant/merchant-orders-manual-capture.spec.ts:67:6 › Order > Manual Capture › should create an "On hold" order then capture the charge

1) [merchant] › merchant/merchant-orders-manual-capture.spec.ts:67:6 › Order > Manual Capture › should create an "On hold" order then capture the charge Error: locator.check: Clicking the checkbox did not change its state Call log: - waiting for getByTestId('capture-later-checkbox') - locator resolved to <input value="1" type="checkbox" id="inspector-checkbox…/> - attempting click action - waiting for element to be visible, enabled and stable - element is visible, enabled and stable - scrolling into view if needed - done scrolling - performing click action - click action done - waiting for scheduled navigations to finish - navigations have finished at ../utils/merchant.ts:354 352 | 353 | if ( ! wasInitiallyEnabled ) { > 354 | await page.getByTestId( checkboxTestId ).check(); | ^ 355 | await page 356 | .getByRole( 'button', { name: 'Enable manual capture' } ) 357 | .click(); at activateCaptureLater (/home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/utils/merchant.ts:354:44) at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/merchant/merchant-orders-manual-capture.spec.ts:38:3

Check failure on line 354 in tests/e2e-pw/utils/merchant.ts

View workflow job for this annotation

GitHub Actions / WC - latest

[merchant] › merchant/merchant-orders-manual-capture.spec.ts:67:6 › Order > Manual Capture › should create an "On hold" order then capture the charge

1) [merchant] › merchant/merchant-orders-manual-capture.spec.ts:67:6 › Order > Manual Capture › should create an "On hold" order then capture the charge Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: locator.check: Clicking the checkbox did not change its state Call log: - waiting for getByTestId('capture-later-checkbox') - locator resolved to <input value="1" type="checkbox" id="inspector-checkbox…/> - attempting click action - waiting for element to be visible, enabled and stable - element is visible, enabled and stable - scrolling into view if needed - done scrolling - performing click action - click action done - waiting for scheduled navigations to finish - navigations have finished at ../utils/merchant.ts:354 352 | 353 | if ( ! wasInitiallyEnabled ) { > 354 | await page.getByTestId( checkboxTestId ).check(); | ^ 355 | await page 356 | .getByRole( 'button', { name: 'Enable manual capture' } ) 357 | .click(); at activateCaptureLater (/home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/utils/merchant.ts:354:44) at /home/runner/work/woocommerce-payments/woocommerce-payments/tests/e2e-pw/specs/merchant/merchant-orders-manual-capture.spec.ts:38:3
await page
.getByRole( 'button', { name: 'Enable manual capture' } )
.click();
await saveWooPaymentsSettings( page );
}
return wasInitiallyEnabled;
};

export const deactivateCaptureLater = async ( page: Page ) => {
await navigation.goToWooPaymentsSettings( page );
await page.getByTestId( 'capture-later-checkbox' ).uncheck();
await saveWooPaymentsSettings( page );
};

0 comments on commit 5b28c7b

Please sign in to comment.