Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Ensure cart has contents before running tests on frontend views
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Jun 26, 2023
1 parent faada24 commit af9242f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@
import { test, expect } from '@woocommerce/e2e-playwright-utils';
import { cli } from '@woocommerce/e2e-utils';

test.afterAll( async () => {
await cli(
'npm run wp-env run tests-cli "wp option update woocommerce_cart_page_endpoint cart"'
);
await cli(
'npm run wp-env run tests-cli "wp option update woocommerce_checkout_page_endpoint checkout"'
);
} );
/**
* Internal dependencies
*/
import { goToShop, addToCart } from '../../utils';

test.describe(
'Tests permalink settings for the cart and checkout templates',
async () => {
test.afterAll( async () => {
await cli(
'npm run wp-env run tests-cli "wp option update woocommerce_cart_page_endpoint cart"'
);
await cli(
'npm run wp-env run tests-cli "wp option update woocommerce_checkout_page_endpoint checkout"'
);
} );

test.describe( 'Settings page', () => {
test( 'Load advanced settings', async ( { page } ) => {
await page.goto(
Expand All @@ -41,7 +46,13 @@ test.describe(
await expect( checkoutInput ).toBeVisible();
} );
} );

test.describe( 'Frontend templates are updated', () => {
test.beforeEach( async ( { page } ) => {
await goToShop( page );
await addToCart( page );
} );

test( 'Changing cart permalink works', async ( { page } ) => {
await page.goto(
'/wp-admin/admin.php?page=wc-settings&tab=advanced'
Expand All @@ -58,6 +69,7 @@ test.describe(
const cartText = await page.getByText( 'Proceed to checkout' );
expect( cartText ).toBeVisible();
} );

test( 'Changing checkout permalink works', async ( { page } ) => {
await page.goto(
'/wp-admin/admin.php?page=wc-settings&tab=advanced'
Expand Down
9 changes: 9 additions & 0 deletions tests/e2e-pw/utils/frontend/add-to-cart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* External dependencies
*/
import { Page } from '@playwright/test';

export const addToCart = async ( page: Page ) => {
await page.click( 'text=Add to cart' );
await page.waitForLoadState( 'networkidle' );
};
11 changes: 11 additions & 0 deletions tests/e2e-pw/utils/frontend/go-to-shop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* External dependencies
*/
import { Page } from '@playwright/test';

// Navigate to the shop page.
export const goToShop = ( page: Page ) => {
page.goto( '/shop', {
waitUntil: 'networkidle',
} );
};
2 changes: 2 additions & 0 deletions tests/e2e-pw/utils/frontend/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './get-block-by-name';
export * from './go-to-shop';
export * from './add-to-cart';
5 changes: 0 additions & 5 deletions tests/e2e-pw/utils/go-to-shop.ts

This file was deleted.

0 comments on commit af9242f

Please sign in to comment.