-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathmerchant-payment-gateways-confirmation.spec.ts
116 lines (93 loc) · 3.55 KB
/
merchant-payment-gateways-confirmation.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* External dependencies
*/
import { test, expect, Page } from '@playwright/test';
/**
* Internal dependencies
*/
import { useMerchant } from '../../utils/helpers';
// Skipping the test for now as it is flaky on GH action runs. See #8875.
test.skip( 'payment gateways disable confirmation', () => {
useMerchant();
const getToggle = ( page: Page ) =>
page.getByRole( 'link', {
name: '"WooPayments" payment method is currently',
} );
const getModalHeading = ( page: Page ) =>
page.getByRole( 'heading', { name: 'Disable WooPayments' } );
const getSaveButton = ( page: Page ) =>
page.getByRole( 'button', { name: 'Save changes' } );
const getCancelButton = ( page: Page ) =>
page.getByRole( 'button', { name: 'Cancel' } );
const getDisableButton = ( page: Page ) =>
page.getByRole( 'button', { name: 'Disable' } );
const waitForToggleLoading = ( page: Page ) =>
page
.locator( '.woocommerce-input-toggle--loading' )
.waitFor( { state: 'hidden' } );
test.beforeEach( async ( { page } ) => {
await page.goto(
'/wp-admin/admin.php?page=wc-settings&tab=checkout§ion'
);
// If WCPay enabled, disable it
if ( ( await getToggle( page ).innerText() ) === 'Yes' ) {
// Click the "Disable WCPay" toggle button
await getToggle( page ).click();
// Modal should be displayed
await expect( getModalHeading( page ) ).toBeVisible();
}
} );
test.afterAll( async ( { browser } ) => {
// Ensure WCPay is enabled after the tests, even if they fail
const page = await browser.newPage();
await page.goto(
'/wp-admin/admin.php?page=wc-settings&tab=checkout§ion'
);
if ( ( await getToggle( page ).innerText() ) === 'No' ) {
await getToggle( page ).click();
await waitForToggleLoading( page );
await getSaveButton( page ).click();
}
await expect( getToggle( page ) ).toHaveText( 'Yes' );
} );
test( 'should show the confirmation modal when disabling WCPay', async ( {
page,
} ) => {
// Clicking "Cancel" should not disable WCPay
await getCancelButton( page ).click();
// After clicking "Cancel", the modal should close and WCPay should still be enabled, even after refresh
await expect( getModalHeading( page ) ).not.toBeVisible();
await getSaveButton( page ).click();
await expect( getToggle( page ) ).toHaveText( 'Yes' );
} );
test( 'should disable WCPay after confirming, then enable again without confirming', async ( {
page,
} ) => {
// Clicking "Disable" should disable WCPay
await getDisableButton( page ).click();
// After clicking "Disable", the modal should close
await expect( getModalHeading( page ) ).not.toBeVisible();
// and refreshing the page should show WCPay become disabled
await waitForToggleLoading( page );
await getSaveButton( page ).click();
// now we can re-enable it with no issues
await getToggle( page ).click();
await waitForToggleLoading( page );
await getSaveButton( page ).click();
await expect( getToggle( page ) ).toHaveText( 'Yes' );
} );
test( 'should show the modal even after clicking the cancel button multiple times', async ( {
page,
} ) => {
// Clicking "Cancel" should not disable WCPay
await getCancelButton( page ).click();
// After clicking "Cancel", the modal should close and WCPay should still be enabled
await expect( getModalHeading( page ) ).not.toBeVisible();
await expect( getToggle( page ) ).not.toHaveClass(
'woocommerce-input-toggle--disabled'
);
// trying again to disable it - the modal should display again
await getToggle( page ).click();
await expect( getModalHeading( page ) ).toBeVisible();
} );
} );