Skip to content

Commit

Permalink
E2E: Fix skipping of core profiler in page-loads.spec.js (#39084)
Browse files Browse the repository at this point in the history
* Add changelog

* Move skip action to beforeAll hook
  • Loading branch information
rodelgc committed Jul 5, 2023
1 parent 98b9670 commit ed1ace1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/e2e-skip-core-profiler
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Fix skipping of core profiler in page-loads.spec.js.
53 changes: 24 additions & 29 deletions plugins/woocommerce/tests/e2e-pw/tests/merchant/page-loads.spec.js
Expand Up @@ -40,51 +40,46 @@ 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.beforeAll( async ( { baseURL } ) => {
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( {
if ( coreProfilerEnabled ) {
const response = await new wcApi( {
url: baseURL,
consumerKey: process.env.CONSUMER_KEY,
consumerSecret: process.env.CONSUMER_SECRET,
version: 'wc-admin',
} ).post( 'onboarding/profile', {
skipped: true,
} );

const httpStatus = response.status;
const { status, message } = response.data;

expect( httpStatus ).toEqual( 200 );
expect( status ).toEqual( 'success' );
expect( message ).toEqual(
'Onboarding profile data has been updated.'
);
}
} );

test.beforeEach( async ( { page } ) => {
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'
);
}
} );

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
Expand Down

0 comments on commit ed1ace1

Please sign in to comment.