-
Notifications
You must be signed in to change notification settings - Fork 66
Add basic e2e tests #811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic e2e tests #811
Changes from all commits
956389e
258bcd8
0758c9e
4930735
74153fb
143c1b6
6ff0c91
f3d0599
250a976
648bf23
d0aefc3
f76d4d9
4665e2e
6bf9046
040ed22
48e1fd6
b0e688f
48b6813
2071d1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,3 +37,6 @@ build/ | |
| *.result.* | ||
|
|
||
| dev-env/ | ||
|
|
||
| # Playwright e2e test artifacts (screenshots, traces, test results) | ||
| artifacts/ | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| process.env.WP_BASE_URL ??= 'http://localhost:8989'; | ||
| module.exports = require( '@wordpress/scripts/config/playwright.config' ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
|
||
| test.describe( 'Create Block Theme — Site Editor Sidebar', () => { | ||
| test( 'plugin sidebar button is present in the editor toolbar', async ( { | ||
| admin, | ||
| page, | ||
| } ) => { | ||
| await admin.visitSiteEditor( { canvas: 'edit' } ); | ||
| await expect( | ||
| page.getByRole( 'button', { name: 'Create Block Theme' } ) | ||
| ).toBeVisible(); | ||
|
mikachan marked this conversation as resolved.
|
||
| } ); | ||
|
|
||
| test( 'clicking the toolbar button opens the plugin sidebar', async ( { | ||
| admin, | ||
| page, | ||
| } ) => { | ||
| await admin.visitSiteEditor( { canvas: 'edit' } ); | ||
| await page | ||
| .getByRole( 'button', { name: 'Create Block Theme' } ) | ||
| .click(); | ||
| await expect( | ||
| page.getByRole( 'button', { name: 'Save Changes to Theme' } ) | ||
| ).toBeVisible(); | ||
| } ); | ||
| } ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| const { execSync } = require( 'child_process' ); | ||
|
|
||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
|
||
| const E2E_THEME_SLUG = 'e2e-test-theme'; | ||
|
|
||
| test.describe( 'Create Block Theme — Admin Landing Page', () => { | ||
| let originalThemeSlug; | ||
|
|
||
| test.beforeAll( async ( { requestUtils } ) => { | ||
| const themes = await requestUtils.rest( { path: '/wp/v2/themes' } ); | ||
| const active = themes.find( ( { status } ) => status === 'active' ); | ||
| originalThemeSlug = active?.stylesheet; | ||
|
|
||
| if ( | ||
| themes.some( ( { stylesheet } ) => stylesheet === E2E_THEME_SLUG ) | ||
| ) { | ||
| execSync( | ||
| `npx wp-env run tests-cli wp theme delete ${ E2E_THEME_SLUG }`, | ||
| { stdio: 'ignore' } | ||
| ); | ||
| } | ||
| } ); | ||
|
|
||
| test.afterAll( async ( { requestUtils } ) => { | ||
| if ( originalThemeSlug ) { | ||
| await requestUtils.activateTheme( originalThemeSlug ); | ||
| } | ||
|
|
||
| const themes = await requestUtils.rest( { path: '/wp/v2/themes' } ); | ||
| if ( | ||
| themes.some( ( { stylesheet } ) => stylesheet === E2E_THEME_SLUG ) | ||
| ) { | ||
| execSync( | ||
| `npx wp-env run tests-cli wp theme delete ${ E2E_THEME_SLUG }`, | ||
| { stdio: 'ignore' } | ||
|
Comment on lines
+40
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't seen a need for this before. Could you explain why this is needed? Is there a precedence for this in Gutenberg already?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no
|
||
| ); | ||
| } | ||
| } ); | ||
|
|
||
| test( 'page loads and shows main heading', async ( { admin, page } ) => { | ||
| await admin.visitAdminPage( | ||
| 'themes.php', | ||
| 'page=create-block-theme-landing' | ||
| ); | ||
| await expect( | ||
| page.getByRole( 'heading', { name: 'What would you like to do?' } ) | ||
| ).toBeVisible(); | ||
| } ); | ||
|
|
||
| test( 'clicking export downloads a zip file', async ( { admin, page } ) => { | ||
| await admin.visitAdminPage( | ||
| 'themes.php', | ||
| 'page=create-block-theme-landing' | ||
| ); | ||
| const [ download ] = await Promise.all( [ | ||
| page.waitForEvent( 'download' ), | ||
| page.getByRole( 'button', { name: /Export/ } ).click(), | ||
| ] ); | ||
| expect( download.suggestedFilename() ).toMatch( /\.zip$/ ); | ||
| } ); | ||
|
|
||
| test( 'create blank theme modal opens with name field', async ( { | ||
| admin, | ||
| page, | ||
| } ) => { | ||
| await admin.visitAdminPage( | ||
| 'themes.php', | ||
| 'page=create-block-theme-landing' | ||
| ); | ||
| await page | ||
| .getByRole( 'button', { name: /Create a new Blank Theme/i } ) | ||
| .click(); | ||
| await expect( page.getByLabel( /Theme name/i ) ).toBeVisible(); | ||
| } ); | ||
|
|
||
| test( 'create blank theme end-to-end', async ( { | ||
| admin, | ||
| page, | ||
| requestUtils, | ||
| } ) => { | ||
| await admin.visitAdminPage( | ||
| 'themes.php', | ||
| 'page=create-block-theme-landing' | ||
| ); | ||
|
|
||
| // Accept the alert dialog that fires on successful theme creation. | ||
| page.once( 'dialog', ( dialog ) => dialog.accept() ); | ||
|
|
||
| await page | ||
| .getByRole( 'button', { name: /Create a new Blank Theme/i } ) | ||
| .click(); | ||
| await page.getByLabel( /Theme name/i ).fill( 'E2E Test Theme' ); | ||
| await page | ||
| .getByRole( 'button', { | ||
| name: 'Create and Activate Blank Theme', | ||
| } ) | ||
| .click(); | ||
|
|
||
| await page.waitForURL( /site-editor/, { waitUntil: 'commit' } ); | ||
|
|
||
| const themes = await requestUtils.rest( { path: '/wp/v2/themes' } ); | ||
| const active = themes.find( ( { status } ) => status === 'active' ); | ||
| expect( active?.stylesheet ).toBe( E2E_THEME_SLUG ); | ||
| } ); | ||
| } ); | ||
Uh oh!
There was an error while loading. Please reload this page.