Skip to content

Commit 65c0450

Browse files
ismaeldcomtpaksu
andauthored
Convert the Order Full Refund spec to Playwright (#10151)
Co-authored-by: Taha Paksu <[email protected]>
1 parent b8d12c1 commit 65c0450

File tree

3 files changed

+124
-135
lines changed

3 files changed

+124
-135
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Significance: patch
2+
Type: dev
3+
Comment: Convert merchant-orders-full-refund spec from Puppeteer to Playwright
4+
5+
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { test, expect, Page } from '@playwright/test';
5+
6+
/**
7+
* Internal dependencies
8+
*/
9+
import { getMerchant, getShopper } from '../../utils/helpers';
10+
import {
11+
deactivateMulticurrency,
12+
isMulticurrencyEnabled,
13+
} from '../../utils/merchant';
14+
import * as shopper from '../../utils/shopper';
15+
import { goToOrder, goToPaymentDetails } from '../../utils/merchant-navigation';
16+
17+
test.describe( 'WooCommerce Payments - Full Refund', () => {
18+
let merchantPage: Page;
19+
let shopperPage: Page;
20+
let orderId: string;
21+
let orderAmount: string;
22+
23+
test.beforeAll( async ( { browser } ) => {
24+
merchantPage = ( await getMerchant( browser ) ).merchantPage;
25+
shopperPage = ( await getShopper( browser ) ).shopperPage;
26+
27+
// Disable multi-currency in the merchant settings. This step is important because local environment setups
28+
// might have multi-currency enabled. We need to ensure a consistent environment for the test.
29+
if ( await isMulticurrencyEnabled( merchantPage ) ) {
30+
await deactivateMulticurrency( merchantPage );
31+
}
32+
} );
33+
34+
test( 'should process a full refund for an order', async () => {
35+
// Place an order to refund later and get the order ID so we can open it in the merchant view
36+
orderId = await shopper.placeOrderWithCurrency( shopperPage, 'USD' );
37+
38+
// Get the order total so we can verify the refund amount
39+
orderAmount = await shopperPage
40+
.locator(
41+
'.woocommerce-order-overview__total .woocommerce-Price-amount'
42+
)
43+
.textContent();
44+
45+
// Open the order
46+
await goToOrder( merchantPage, orderId );
47+
48+
// Click refund button
49+
await merchantPage
50+
.getByRole( 'button', {
51+
name: 'Refund',
52+
} )
53+
.click();
54+
55+
// Fill refund details
56+
await merchantPage.getByLabel( 'Refund amount' ).fill( orderAmount );
57+
// await merchantPage.fill( '.refund_line_total', orderAmount );
58+
await merchantPage
59+
.getByLabel( 'Reason for refund' )
60+
.fill( 'No longer wanted' );
61+
62+
const refundButton = await merchantPage.getByRole( 'button', {
63+
name: `Refund ${ orderAmount } via WooPayments`,
64+
} );
65+
66+
await expect( refundButton ).toBeVisible();
67+
68+
// TODO: This visual regression test is not flaky, but we should revisit the approach.
69+
// await expect( merchantPage ).toHaveScreenshot();
70+
71+
// Click refund and handle confirmation dialog
72+
merchantPage.on( 'dialog', ( dialog ) => dialog.accept() );
73+
await refundButton.click();
74+
75+
// Wait for refund to process
76+
await merchantPage.waitForLoadState( 'networkidle' );
77+
78+
// Verify refund details
79+
await expect(
80+
merchantPage.getByRole( 'cell', {
81+
name: `-${ orderAmount }`,
82+
} )
83+
).toHaveCount( 2 );
84+
await expect(
85+
merchantPage.getByText(
86+
`A refund of ${ orderAmount } was successfully processed using WooPayments. Reason: No longer wanted`
87+
)
88+
).toBeVisible();
89+
90+
// TODO: This visual regression test is not flaky, but we should revisit the approach.
91+
// await expect( merchantPage ).toHaveScreenshot();
92+
} );
93+
94+
test( 'should be able to view a refunded transaction', async () => {
95+
// Get and navigate to payment details
96+
const paymentIntentId = await merchantPage
97+
.locator( '#order_data' )
98+
.getByRole( 'link', {
99+
name: /pi_/,
100+
} )
101+
.innerText();
102+
103+
await goToPaymentDetails( merchantPage, paymentIntentId );
104+
105+
// Verify timeline events
106+
await expect(
107+
merchantPage.getByText(
108+
`A payment of ${ orderAmount } was successfully refunded.`
109+
)
110+
).toBeVisible();
111+
112+
await expect(
113+
merchantPage.getByText( 'Payment status changed to Refunded.' )
114+
).toBeVisible();
115+
116+
// TODO: This visual regression test is not flaky, but we should revisit the approach.
117+
// await expect( merchantPage ).toHaveScreenshot();
118+
} );
119+
} );

tests/e2e/specs/wcpay/merchant/merchant-orders-full-refund.spec.js

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)