woocommerce/plugins/woocommerce-blocks/tests/e2e
Alex Florisca 7dc8dd63ba
Update Order Summary Design (#45767)
* Add border around order summary on cart & checkout

* Group subtotal, discount, fees, taxes and shiping block

* Move the coupon form in order summary

* Move the coupon form in order summary

* Manage state externally in Panel component and refactor Coupon form to use the Panel component

* Remove descriptions from order summary items

* increase font weight of order summary title

* Tidy up design for desktop and add separator back in for blocks on checkout order summary

* Remove border around order summary on mobile

* Revert "Move the coupon form in order summary"

This reverts commit 4a8044cdcf.

* Change heading styles for cart

* Change font weight to 500 of order summary heading on checkout block

* Remove padding and border between order summary totals items

* Refactor css for cart & checkout totals to work in the editor

* Adjust cart totals heading in the editor

* Last adjustment to checkout totals style to work in editor

* Add changelog

* Change the cursor to pointer for the panel component

* remove unused short and full description from OrderSummaryItem

* Fix failing e2e tests

* Fix lint issues

* Vertically align order summary title in the editor

* Fix e2e tests

* Fix linting issues

* Fix unit tests

* Remove changes from woocommerce.php

* Fix checkout block test

* fix eslint errors in checkout block test

---------

Co-authored-by: Niels Lange <info@nielslange.de>
2024-04-25 12:03:31 +07:00
..
bin Blocks - E2E: Fix visibility store (#46521) 2024-04-12 11:26:12 +00:00
mocks/custom-plugins Update @wordpress/env to 8.1.1 and re-enable PHP Unit Tests for PHP v 8.1 and 8.2 (https://github.com/woocommerce/woocommerce-blocks/pull/9875) 2023-09-01 16:07:55 +07:00
playwright-utils Fix E2E tests for WordPress 6.5 (#44593) 2024-03-27 10:54:44 +01:00
test-data/data Refactor review blocks e2e tests to remove redundant html templates and add more scenarios (#44880) 2024-02-29 15:43:59 +13:00
tests Update Order Summary Design (#45767) 2024-04-25 12:03:31 +07:00
types Rename commands and directories for Playwright and JEST e2e tests (https://github.com/woocommerce/woocommerce-blocks/pull/10493) 2023-08-08 17:58:12 +01:00
utils Create update_template_data util and formatting improvements (#46408) 2024-04-24 14:57:18 +02:00
wc-blocks-eslint-rules Playwright: Add eslint rule to prevent import `test` or `expect` from playwright library (https://github.com/woocommerce/woocommerce-blocks/pull/11475) 2023-10-30 11:23:40 -03:00
.eslintrc.js Playwright: Add eslint rule to prevent import `test` or `expect` from playwright library (https://github.com/woocommerce/woocommerce-blocks/pull/11475) 2023-10-30 11:23:40 -03:00
README.md Blocks Playwright tests: Add tests for the new attribute filter block (#45333) 2024-03-13 00:15:05 +13:00
block-theme-with-templates.setup.ts Fix E2E tests for WordPress 6.5 (#44593) 2024-03-27 10:54:44 +01:00
block-theme.setup.ts [E2E] Setup block theme without opening browser (#44702) 2024-02-20 16:52:53 +01:00
classic-theme.setup.ts Update @wordpress/env to 8.1.1 and re-enable PHP Unit Tests for PHP v 8.1 and 8.2 (https://github.com/woocommerce/woocommerce-blocks/pull/9875) 2023-09-01 16:07:55 +07:00
global-setup.ts Fix E2E tests for WordPress 6.5 (#44593) 2024-03-27 10:54:44 +01:00
global-teardown.ts Rename commands and directories for Playwright and JEST e2e tests (https://github.com/woocommerce/woocommerce-blocks/pull/10493) 2023-08-08 17:58:12 +01:00
playwright.block-theme-with-templates.config.ts Add e2e tests to verify block templates can be customized if the theme has its own custom templates (#43650) 2024-01-18 11:39:24 +01:00
playwright.classic-theme.config.ts Playwright test workflow migration from Blocks repo (#42804) 2023-12-15 09:34:29 -08:00
playwright.config.ts Fix E2E tests for WordPress 6.5 (#44593) 2024-03-27 10:54:44 +01:00
playwright.performance.config.ts Blocks: Isolate performance tests from e2e tests (#46773) 2024-04-23 13:11:46 +02:00
playwright.side-effects.config.ts Playwright test workflow migration from Blocks repo (#42804) 2023-12-15 09:34:29 -08:00
tsconfig.json Rename commands and directories for Playwright and JEST e2e tests (https://github.com/woocommerce/woocommerce-blocks/pull/10493) 2023-08-08 17:58:12 +01:00

README.md

WooCommerce Blocks Playwright End to End Tests

This is the documentation for the new E2E testing setup based on Playwright and wp-env. Over time, these playwright E2E tests should replace the current Puppeteer E2E tests.

Table of contents

Pre-requisites

Note, that if you are on Mac and you install docker through other methods such as homebrew, for example, your steps to set it up might be different. The commands listed in steps below may also vary.

If you are using Windows, we recommend using Windows Subsystem for Linux (WSL) for running E2E tests. Follow the WSL Setup Instructions first before proceeding with the steps below.

Introduction

End-to-end tests are powered by Playwright. The test site is spun up using wp-env (recommended), but we will continue to support e2e-environment in the meantime.

Running tests for the first time

In the root directory, run:

nvm use
pnpm install

Now change directory to plugins/woocommerce-blocks/:

cd plugins/woocommerce-blocks/

Ensure necessary browsers are installed:

npx playwright install
pnpm run env:start
pnpm run test:e2e

If you have any problems running the tests, check out the Troubleshooting section for help.

To run the test again, re-create the environment to start with a fresh state

pnpm run env:restart
pnpm run test:e2e

Adding posts for testing block content

During test setup posts are automatically created from all the html files contained in ./bin/posts. All posts are given a title like File Name Block which generates a url like file-name-block.

e.g. my-test.html will generate a post with the title My Test Block and permalink my-test-block. You'll be able to navigate to that page in your test like:

await page.goto( '/my-test-block/' );

Please also note that the posts are generated during initial environment setup, so if you add or edit a post file you'll need to restart the environment to see the changes.

Tests with side effects

We call tests that affect other tests (ones that modify the site settings, using custom plugins) are tests with side effects and we split those tests to a separate test suite:

pnpm run test:e2e:side-effects

Note: All command parameters of test:e2e can be used for test:e2e:side-effects.

Tests with a classic theme and a block theme with custom templates

By default, e2e tests run in a non-customized block theme. However, we also have some e2e tests which run specifically in a classic theme and in a block theme with custom templates. They can be run like this:

pnpm run test:e2e:classic-theme
pnpm run test:e2e:block-theme-with-templates

_Note: All command parameters of test:e2e can be used for these commands too.

Other ways of running tests

Headless mode:

pnpm run test:e2e

Interactive UI mode:

pnpm run test:e2e --ui

Headed mode:

pnpm run test:e2e --headed

Debug mode:

pnpm run test:e2e --debug

Running a single test:

pnpm run test:e2e ./tests/e2e/tests/example.spec.ts

To see all options, run the following command:

npx playwright test --help

Generating dynamic posts to test block variations

Testing a single block can be daunting considering all the different attribute combinations that could be considered valid for a single block. The basic templating system available in this test suite allows for the generation of dynamic posts that can be used to test block variations.

Templates use the Handlebars templating system and you can put them anywhere. It's simplest to co-locate them with the test. You can easily pass custom attributes to a block in your template using the wp-block helper we've defined.

It looks like this in the template:

{{#> wp-block name="woocommerce/featured-category" attributes=attributes /}}
    You can nest content here if you want to test the block with some content.
{{/wp-block}}

In your tests you can use createPostFromTemplate to create a post containing your template. If you use it more than once in your test you can extend the test suite and provide the posts as fixtures, like in the example below

import { test as base } from '@playwright/test';

const test = base.extend< {
	dropdownBlockPost: Post;
	defaultBlockPost: Post;
} >( {
	defaultBlockPost: async ( { requestUtils }, use ) => {
		const testingPost = await requestUtils.createPostFromTemplate(
			requestUtils,
			{ title: 'Product Filter Stock Status Block' },
			TEMPLATE_PATH,
			{}
		);

		await use( testingPost );
		await requestUtils.deletePost( post.id );
	},

	dropdownBlockPost: async ( { requestUtils }, use ) => {
		const testingPost = await requestUtils.createPostFromTemplate(
			requestUtils,
			{ title: 'Product Filter Stock Status Block' },
			TEMPLATE_PATH,
			{
				attributes: {
					displayStyle: 'dropdown',
				},
			}
		);

		await use( testingPost );
		await requestUtils.deletePost( post.id );
	},
} );

In your test you can navigate to the page. You won't need to clean it up, because the fixture will take care of that for you.

test( 'Test the block', async ( { page, defaultBlockPost } ) => {
	await page.goto( defaultBlockPost.link );
	// do your tests here
} );

Troubleshooting

If you run into problems the first time you try to run the tests, please run the following command before starting the test suite:

pnpm wp-env:config

This helps set up your environment correctly and can prevent some of the usual issues from happening.