-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
page-loads.spec.js
115 lines (106 loc) · 3.51 KB
/
page-loads.spec.js
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
const { test, expect } = require( '@playwright/test' );
const { features } = require( '../../utils' );
const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default;
// a representation of the menu structure for WC
const wcPages = [
{
name: 'WooCommerce',
subpages: [
{ name: 'Home', heading: 'Home' },
{ name: 'Orders', heading: 'Orders' },
{ name: 'Customers', heading: 'Customers' },
{ name: 'Coupons', heading: 'Coupons' },
{ name: 'Reports', heading: 'Orders' },
{ name: 'Settings', heading: 'General' },
{ name: 'Status', heading: 'System status' },
],
},
{
name: 'Products',
subpages: [
{ name: 'All Products', heading: 'Products' },
{ name: 'Add New', heading: 'Add New' },
{ name: 'Categories', heading: 'Product categories' },
{ name: 'Tags', heading: 'Product tags' },
{ name: 'Attributes', heading: 'Attributes' },
],
},
// analytics is handled through a separate test
{
name: 'Marketing',
subpages: [
{ name: 'Overview', heading: 'Overview' },
{ name: 'Coupons', heading: 'Coupons' },
],
},
];
for ( const currentPage of wcPages ) {
test.describe( `WooCommerce Page Load > Load ${ currentPage.name } sub pages`, () => {
test.use( { storageState: process.env.ADMINSTATE } );
const coreProfilerEnabled = features.is_enabled( 'core-profiler' );
test.beforeEach( async ( { page, baseURL } ) => {
if ( currentPage.name === 'WooCommerce' ) {
await page.goto( 'wp-admin/admin.php?page=wc-admin' );
} else if ( currentPage.name === 'Products' ) {
await page.goto( 'wp-admin/edit.php?post_type=product' );
} else if ( currentPage.name === 'Marketing' ) {
await page.goto(
'wp-admin/admin.php?page=wc-admin&path=%2Fmarketing'
);
} else if ( currentPage.name === 'Home' && coreProfilerEnabled ) {
await new wcApi( {
url: baseURL,
consumerKey: process.env.CONSUMER_KEY,
consumerSecret: process.env.CONSUMER_SECRET,
version: 'wc-admin',
} ).post( 'onboarding/profile', {
skipped: true,
} );
await page.goto( 'wp-admin/admin.php?page=wc-admin' );
}
} );
for ( let i = 0; i < currentPage.subpages.length; i++ ) {
test( `Can load ${ currentPage.subpages[ i ].name }`, async ( {
page,
} ) => {
// deal with the onboarding wizard
if ( currentPage.subpages[ i ].name === 'Home' ) {
if ( ! coreProfilerEnabled ) {
await page.goto(
'wp-admin/admin.php?page=wc-admin&path=/setup-wizard'
);
await page
.locator( 'text=Skip setup store details' )
.click();
await page
.locator( 'button >> text=No thanks' )
.click();
await page.waitForLoadState( 'networkidle' );
await page.goto( 'wp-admin/admin.php?page=wc-admin' );
}
}
// deal with cases where the 'Coupons' legacy menu had already been removed.
if ( currentPage.subpages[ i ].name === 'Coupons' ) {
const couponsMenuVisible = await page
.locator(
`li.wp-menu-open > ul.wp-submenu > li:has-text("${ currentPage.subpages[ i ].name }")`
)
.isVisible();
test.skip(
! couponsMenuVisible,
'Skipping this test because the legacy Coupons menu was not found and may have already been removed.'
);
}
await page
.locator(
`li.wp-menu-open > ul.wp-submenu > li:has-text("${ currentPage.subpages[ i ].name }")`,
{ waitForLoadState: 'networkidle' }
)
.click();
await expect(
page.locator( 'h1.components-text' )
).toContainText( currentPage.subpages[ i ].heading );
} );
}
} );
}