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

Commit

Permalink
Move cart widget tests to playwright and ensure classic/block theme c…
Browse files Browse the repository at this point in the history
…onfigs are executed correctly (#10669)
  • Loading branch information
opr authored Aug 28, 2023
1 parent 6f58d5a commit 4531790
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 62 deletions.
1 change: 1 addition & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
matrix:
config: [
{ name: Normal, file: playwright.config.ts, resultPath: test-results },
{ name: Classic, file: playwright.classic-theme.config.ts, resultPath: test-results-classic-theme },
{ name: SideEffects, file: playwright.side-effects.config.ts, resultPath: test-results-side-effects },
]
steps:
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
"test:e2e:report": "sh ./bin/check-env.sh && npx playwright test --config=tests/e2e/playwright.config.ts --reporter=html",
"test:e2e:side-effects": "npm run test:e2e -- --config=tests/e2e/playwright.side-effects.config.ts",
"test:e2e:side-effects:report": "npm run test:e2e:report -- --config=tests/e2e/playwright.side-effects.config.ts",
"test:e2e:classic-theme": "npm run test:e2e -- --config=tests/e2e/playwright.classic-theme.config.ts",
"test:e2e:classic-theme:report": "npm run test:e2e:report -- --config=tests/e2e/playwright.classic-theme.config.ts",
"test:e2e:jest": "npm run wp-env:config && cross-env JEST_PUPPETEER_CONFIG=tests/e2e-jest/config/jest-puppeteer.config.js NODE_CONFIG_DIR=tests/e2e-jest/config wp-scripts test-e2e --config tests/e2e-jest/config/jest.config.js",
"test:e2e:jest:dev": "npm run wp-env:config && cross-env JEST_PUPPETEER_CONFIG=tests/e2e-jest/config/jest-puppeteer.config-dev.js NODE_CONFIG_DIR=tests/e2e-jest/config wp-scripts test-e2e --config tests/e2e-jest/config/jest.config.js",
"test:e2e:jest:dev-watch": "npm run wp-env:config && cross-env JEST_PUPPETEER_CONFIG=tests/e2e-jest/config/jest-puppeteer.config-dev.js NODE_CONFIG_DIR=tests/e2e-jest/config wp-scripts test-e2e --config tests/e2e-jest/config/jest.config.js --watch",
Expand Down
46 changes: 0 additions & 46 deletions tests/e2e-jest/specs/backend/cart.test.js

This file was deleted.

17 changes: 15 additions & 2 deletions tests/e2e/block-theme.setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
/**
* External dependencies
*/
import { BLOCK_THEME_SLUG, cli } from '@woocommerce/e2e-utils';
import {
BLOCK_THEME_NAME,
BLOCK_THEME_SLUG,
cli,
} from '@woocommerce/e2e-utils';
import { test as setup, expect } from '@woocommerce/e2e-playwright-utils';

cli( `npm run wp-env run tests-cli "wp theme activate ${ BLOCK_THEME_SLUG }` );
setup( 'Sets up the block theme', async ( { admin } ) => {
await cli(
`npm run wp-env run tests-cli "wp theme install ${ BLOCK_THEME_SLUG } --activate"`
);
await admin.page.goto( '/wp-admin/themes.php' );
await expect(
admin.page.getByText( `Active: ${ BLOCK_THEME_NAME }` )
).toBeVisible();
} );
19 changes: 15 additions & 4 deletions tests/e2e/classic-theme.setup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
/**
* External dependencies
*/
import { CLASSIC_THEME_SLUG, cli } from '@woocommerce/e2e-utils';
import {
CLASSIC_THEME_NAME,
CLASSIC_THEME_SLUG,
cli,
} from '@woocommerce/e2e-utils';
import { test as setup, expect } from '@woocommerce/e2e-playwright-utils';

cli(
`npm run wp-env run tests-cli "wp theme activate ${ CLASSIC_THEME_SLUG }`
);
setup( 'Sets up the classic theme', async ( { admin } ) => {
await cli(
`npm run wp-env run tests-cli "wp theme install ${ CLASSIC_THEME_SLUG } --activate"`
);
await admin.page.goto( '/wp-admin/themes.php' );
await expect(
admin.page.getByText( `Active: ${ CLASSIC_THEME_NAME }` )
).toBeVisible();
} );
32 changes: 32 additions & 0 deletions tests/e2e/playwright.classic-theme.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* External dependencies
*/
import { defineConfig } from '@playwright/test';
import path from 'path';

/**
* Internal dependencies
*/
import config from './playwright.config';

export default defineConfig( {
...config,
outputDir: path.join(
process.cwd(),
'artifacts/test-results-side-effects'
),
fullyParallel: false,
workers: 1,
projects: [
{
name: 'classicThemeConfiguration',
testDir: '.',
testMatch: /classic-theme.setup.ts/,
},
{
name: 'classicTheme',
testMatch: /.*.classic_theme.spec.ts/,
dependencies: [ 'classicThemeConfiguration' ],
},
],
} );
10 changes: 1 addition & 9 deletions tests/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,14 @@ const config: ExtendedPlaywrightTestConfig = {
projects: [
{
name: 'blockThemeConfiguration',
testDir: '.',
testMatch: /block-theme.setup.ts/,
},
{
name: 'blockTheme',
testMatch: /.*.block_theme.spec.ts/,
dependencies: [ 'blockThemeConfiguration' ],
},
{
name: 'classicThemeConfiguration',
testMatch: /classic-theme.setup.ts/,
},
{
name: 'classicTheme',
testMatch: /.*.classic_theme.spec.ts/,
dependencies: [ 'classicThemeConfiguration' ],
},
],
};

Expand Down
1 change: 1 addition & 0 deletions tests/e2e/playwright.side-effects.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default defineConfig( {
projects: [
{
name: 'blockThemeConfiguration',
testDir: '.',
testMatch: /block-theme.setup.ts/,
},
{
Expand Down
26 changes: 26 additions & 0 deletions tests/e2e/tests/cart/cart-block.merchant.classic_theme.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* External dependencies
*/
import { test, expect } from '@woocommerce/e2e-playwright-utils';

test.describe( 'Merchant → Cart', () => {
test.describe( 'in widget editor', () => {
test( "can't be inserted in a widget area", async ( {
editorUtils,
page,
} ) => {
await page.goto( '/wp-admin/widgets.php' );
await editorUtils.closeModalByName( 'Welcome to block Widgets' );

await editorUtils.openGlobalBlockInserter();
await editorUtils.page
.getByLabel( 'Search for blocks and patterns' )
.fill( 'woocommerce/cart' );
const cartButton = editorUtils.page.getByRole( 'option', {
name: 'Cart',
exact: true,
} );
await expect( cartButton ).toBeHidden();
} );
} );
} );
4 changes: 3 additions & 1 deletion tests/e2e/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import path from 'path';

export const BLOCK_THEME_SLUG = 'twentytwentythree';
export const CLASSIC_THEME_SLUG = 'twentytwentyone';
export const BLOCK_THEME_NAME = 'Twenty Twenty-Three';
export const CLASSIC_THEME_SLUG = 'storefront';
export const CLASSIC_THEME_NAME = 'Storefront';
export const BASE_URL = 'http://localhost:8889';
export const STORAGE_STATE_PATH = path.join(
process.cwd(),
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/utils/editor/editor-utils.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ export class EditorUtils {
);
}

async closeModalByName( name: string ) {
const isModalOpen = await this.page.getByLabel( name ).isVisible();

// eslint-disable-next-line playwright/no-conditional-in-test
if ( isModalOpen ) {
await this.page
.getByLabel( name )
.getByRole( 'button', { name: 'Close' } )
.click();
}
}
async replaceBlockByBlockName( name: string, nameToInsert: string ) {
await this.page.evaluate(
( { name: _name, nameToInsert: _nameToInsert } ) => {
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/utils/frontend/frontend-utils.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class FrontendUtils {
}

async addToCart( itemName = '' ) {
await this.page.waitForLoadState( 'domcontentloaded' );
if ( itemName !== '' ) {
await this.page
.getByLabel( `Add “${ itemName }” to your cart` )
Expand Down

0 comments on commit 4531790

Please sign in to comment.