-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new e2e test for creating a pattern (#54855)
- Loading branch information
1 parent
c35b6d0
commit 7b19836
Showing
1 changed file
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
test.describe( 'Patterns', () => { | ||
test.beforeAll( async ( { requestUtils } ) => { | ||
await requestUtils.activateTheme( 'emptytheme' ); | ||
await requestUtils.deleteAllBlocks(); | ||
} ); | ||
test.afterAll( async ( { requestUtils } ) => { | ||
await requestUtils.activateTheme( 'twentytwentyone' ); | ||
} ); | ||
|
||
test.afterEach( async ( { requestUtils } ) => { | ||
await requestUtils.deleteAllBlocks(); | ||
} ); | ||
|
||
test( 'create a new pattern', async ( { page, editor, admin } ) => { | ||
await admin.visitSiteEditor(); | ||
|
||
const navigation = page.getByRole( 'region', { name: 'Navigation' } ); | ||
const patternsContent = page.getByRole( 'region', { | ||
name: 'Patterns content', | ||
} ); | ||
|
||
await navigation.getByRole( 'button', { name: 'Patterns' } ).click(); | ||
|
||
await expect( | ||
navigation.getByRole( 'heading', { name: 'Patterns', level: 1 } ) | ||
).toBeVisible(); | ||
await expect( patternsContent ).toContainText( 'No patterns found.' ); | ||
|
||
await navigation | ||
.getByRole( 'button', { name: 'Create pattern' } ) | ||
.click(); | ||
|
||
const createPatternMenu = page.getByRole( 'menu', { | ||
name: 'Create pattern', | ||
} ); | ||
await expect( | ||
createPatternMenu.getByRole( 'menuitem', { | ||
name: 'Create pattern', | ||
} ) | ||
).toBeFocused(); | ||
await createPatternMenu | ||
.getByRole( 'menuitem', { name: 'Create pattern' } ) | ||
.click(); | ||
|
||
const createPatternDialog = page.getByRole( 'dialog', { | ||
name: 'Create pattern', | ||
} ); | ||
await createPatternDialog | ||
.getByRole( 'textbox', { name: 'Name' } ) | ||
.fill( 'My pattern' ); | ||
await page.keyboard.press( 'Enter' ); | ||
await expect( | ||
createPatternDialog.getByRole( 'button', { name: 'Create' } ) | ||
).toBeDisabled(); | ||
|
||
await expect( page ).toHaveTitle( /^My pattern/ ); | ||
await expect( | ||
page | ||
.getByRole( 'region', { name: 'Editor top bar' } ) | ||
.getByRole( 'heading', { name: 'My pattern', level: 1 } ) | ||
).toBeVisible(); | ||
|
||
await editor.canvas | ||
.getByRole( 'button', { name: 'Add default block' } ) | ||
.click(); | ||
await page.keyboard.type( 'My pattern' ); | ||
|
||
await page | ||
.getByRole( 'region', { name: 'Editor top bar' } ) | ||
.getByRole( 'button', { name: 'Save' } ) | ||
.click(); | ||
await page | ||
.getByRole( 'region', { name: 'Save panel' } ) | ||
.getByRole( 'button', { name: 'Save' } ) | ||
.click(); | ||
await expect( | ||
page.getByRole( 'button', { name: 'Dismiss this notice' } ) | ||
).toContainText( 'Site updated' ); | ||
|
||
await page.getByRole( 'button', { name: 'Open navigation' } ).click(); | ||
await navigation.getByRole( 'button', { name: 'Back' } ).click(); | ||
// TODO: await expect( page ).toHaveTitle( /^Patterns/ ); | ||
|
||
await expect( | ||
navigation.getByRole( 'button', { name: 'All patterns' } ) | ||
).toBeVisible(); | ||
await expect( | ||
navigation.getByRole( 'button', { name: 'My patterns' } ) | ||
).toBeVisible(); | ||
await expect( | ||
navigation.getByRole( 'button', { name: 'Uncategorized' } ) | ||
).toBeVisible(); | ||
|
||
await expect( | ||
patternsContent.getByRole( 'heading', { | ||
name: 'All patterns', | ||
level: 2, | ||
} ) | ||
).toBeVisible(); | ||
await expect( | ||
patternsContent | ||
.getByRole( 'listbox', { name: 'All patterns' } ) | ||
// TODO: should be `getByRole( 'option', { name: 'My pattern' } )` | ||
.getByRole( 'button', { name: 'My pattern', exact: true } ) | ||
// TODO: Shouldn't need this. | ||
.nth( 0 ) | ||
).toBeVisible(); | ||
} ); | ||
} ); |