Skip to content

Commit 936b878

Browse files
authored
Convert Shopper Multi Currency Widget spec to Playwright (#10204)
1 parent 65c0450 commit 936b878

File tree

7 files changed

+161
-207
lines changed

7 files changed

+161
-207
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: dev
3+
4+
Convert shopper-multi-currency-widget spec from Puppeteer to Playwright

tests/e2e-pw/specs/shopper/multi-currency-checkout.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
activateMulticurrency,
1111
addCurrency,
1212
deactivateMulticurrency,
13-
removeCurrency,
13+
restoreCurrencies,
1414
} from '../../utils/merchant';
1515
import { emptyCart, placeOrderWithCurrency } from '../../utils/shopper';
1616
import * as navigation from '../../utils/shopper-navigation';
@@ -33,7 +33,7 @@ test.describe( 'Multi-currency checkout', () => {
3333
} );
3434

3535
test.afterAll( async () => {
36-
await removeCurrency( merchantPage, 'EUR' );
36+
await restoreCurrencies( merchantPage );
3737
await emptyCart( shopperPage );
3838

3939
if ( ! wasMulticurrencyEnabled ) {

tests/e2e-pw/specs/shopper/shopper-bnpls-checkout.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,26 @@ const bnplProviders = [ 'Affirm', 'Afterpay' ];
1818
test.describe( 'BNPL checkout', () => {
1919
let merchantPage: Page;
2020
let shopperPage: Page;
21+
let wasMulticurrencyEnabled: boolean;
2122

2223
test.beforeAll( async ( { browser } ) => {
2324
shopperPage = ( await getShopper( browser ) ).shopperPage;
2425
merchantPage = ( await getMerchant( browser ) ).merchantPage;
26+
wasMulticurrencyEnabled = await merchant.isMulticurrencyEnabled(
27+
merchantPage
28+
);
2529

2630
await merchant.enablePaymentMethods( merchantPage, bnplProviders );
31+
if ( wasMulticurrencyEnabled ) {
32+
await merchant.deactivateMulticurrency( merchantPage );
33+
}
2734
} );
2835

2936
test.afterAll( async () => {
3037
await merchant.disablePaymentMethods( merchantPage, bnplProviders );
38+
if ( wasMulticurrencyEnabled ) {
39+
await merchant.activateMulticurrency( merchantPage );
40+
}
3141
} );
3242

3343
for ( const ctpEnabled of cardTestingProtectionStates ) {
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { test, expect, Page } from '@playwright/test';
5+
/**
6+
* Internal dependencies
7+
*/
8+
import * as merchant from '../../utils/merchant';
9+
import * as shopper from '../../utils/shopper';
10+
import * as navigation from '../../utils/shopper-navigation';
11+
import { goToOrder } from '../../utils/merchant-navigation';
12+
import RestAPI from '../../utils/rest-api';
13+
import { getMerchant, getShopper } from '../../utils/helpers';
14+
15+
test.describe( 'Shopper Multi-Currency widget', () => {
16+
let merchantPage: Page;
17+
let shopperPage: Page;
18+
let wasMulticurrencyEnabled: boolean;
19+
20+
test.beforeAll( async ( { browser } ) => {
21+
shopperPage = ( await getShopper( browser ) ).shopperPage;
22+
merchantPage = ( await getMerchant( browser ) ).merchantPage;
23+
wasMulticurrencyEnabled = await merchant.activateMulticurrency(
24+
merchantPage
25+
);
26+
await merchant.restoreCurrencies( merchantPage );
27+
} );
28+
29+
test.afterAll( async () => {
30+
if ( ! wasMulticurrencyEnabled ) {
31+
await merchant.deactivateMulticurrency( merchantPage );
32+
}
33+
} );
34+
35+
test( 'should display currency switcher widget if multi-currency is enabled', async () => {
36+
await merchant.addMulticurrencyWidget( merchantPage );
37+
38+
await navigation.goToShop( shopperPage );
39+
await expect(
40+
shopperPage.locator( '.widget select[name=currency]' )
41+
).toBeVisible();
42+
} );
43+
44+
test( 'should not display currency switcher widget if multi-currency is disabled', async () => {
45+
await merchant.deactivateMulticurrency( merchantPage );
46+
47+
await navigation.goToShop( shopperPage );
48+
await expect(
49+
shopperPage.locator( '.widget select[name=currency]' )
50+
).not.toBeVisible();
51+
52+
await merchant.activateMulticurrency( merchantPage );
53+
} );
54+
55+
test.describe( 'Should allow shopper to switch currency', () => {
56+
test.afterEach( async () => {
57+
await shopperPage.selectOption(
58+
'.widget select[name=currency]',
59+
'EUR'
60+
);
61+
await expect( shopperPage ).toHaveURL( /.*currency=EUR/ );
62+
63+
// Change it back to USD for the other tests.
64+
await navigation.goToShopWithCurrency( shopperPage, 'USD' );
65+
} );
66+
67+
test( 'at the product page', async () => {
68+
await navigation.goToProductPageBySlug( shopperPage, 'beanie' );
69+
} );
70+
71+
test( 'at the cart page', async () => {
72+
await navigation.goToCart( shopperPage );
73+
} );
74+
75+
test( 'at the checkout page', async () => {
76+
await navigation.goToCheckout( shopperPage );
77+
} );
78+
} );
79+
80+
test.describe( 'Should not affect prices', () => {
81+
let orderId: string;
82+
83+
test.afterEach( async () => {
84+
await shopperPage.selectOption(
85+
'.widget select[name=currency]',
86+
'EUR'
87+
);
88+
89+
await expect(
90+
shopperPage.getByText( '$18.00 USD' ).first()
91+
).toBeVisible();
92+
93+
await navigation.goToShopWithCurrency( shopperPage, 'USD' );
94+
} );
95+
96+
test( 'at the order received page', async () => {
97+
orderId = await shopper.placeOrderWithCurrency(
98+
shopperPage,
99+
'USD'
100+
);
101+
} );
102+
103+
test( 'at My account > Orders', async () => {
104+
await navigation.goToOrders( shopperPage );
105+
await expect(
106+
shopperPage.getByLabel( `View order number ${ orderId }` )
107+
).toBeVisible();
108+
} );
109+
} );
110+
111+
test( 'should not display currency switcher on pay for order page', async ( {}, {
112+
project,
113+
} ) => {
114+
const restApi = new RestAPI( project.use.baseURL );
115+
const orderId = await restApi.createOrder();
116+
117+
await goToOrder( merchantPage, orderId );
118+
await merchantPage
119+
.getByRole( 'link', { name: 'Customer payment page' } )
120+
.click();
121+
122+
await expect(
123+
merchantPage.locator( '.widget select[name=currency]' )
124+
).not.toBeVisible();
125+
} );
126+
} );

tests/e2e-pw/utils/merchant.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,16 @@ export const deactivateMulticurrency = async ( page: Page ) => {
9393
export const addMulticurrencyWidget = async ( page: Page ) => {
9494
await navigation.goToWidgets( page );
9595
// Wait for all widgets to load. This is important to prevent flakiness.
96+
await page.locator( '.components-spinner' ).first().waitFor();
9697
await expect( page.locator( '.components-spinner' ) ).toHaveCount( 0 );
9798

9899
if ( await page.getByRole( 'button', { name: 'Close' } ).isVisible() ) {
99100
await page.getByRole( 'button', { name: 'Close' } ).click();
100101
}
101102

102103
const isWidgetAdded = await page
103-
.getByRole( 'heading', { name: 'Currency Switcher Widget' } )
104+
.locator( 'iframe[srcdoc*=currency]' )
105+
.first()
104106
.isVisible();
105107

106108
if ( ! isWidgetAdded ) {

tests/e2e-pw/utils/rest-api.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { HTTPClientFactory } from '@woocommerce/api';
99
import { config } from '../config/default';
1010

1111
const userEndpoint = '/wp/v2/users';
12+
const ordersEndpoint = '/wc/v3/orders';
1213

1314
class RestAPI {
1415
private baseUrl: string;
@@ -63,6 +64,21 @@ class RestAPI {
6364
}
6465
}
6566
}
67+
68+
async createOrder(): Promise< string > {
69+
const client = this.getAdminClient();
70+
71+
const order = await client.post( ordersEndpoint, {
72+
line_items: [
73+
{
74+
product_id: 16,
75+
quantity: 1,
76+
},
77+
],
78+
} );
79+
80+
return `${ order.data.id }`;
81+
}
6682
}
6783

6884
export default RestAPI;

0 commit comments

Comments
 (0)