-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Migrate Site Editor 'settings sidebar' e2e tests to Playwright #57392
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
122 changes: 0 additions & 122 deletions
122
packages/e2e-tests/specs/site-editor/settings-sidebar.test.js
This file was deleted.
Oops, something went wrong.
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,148 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
test.describe( 'Settings sidebar', () => { | ||
test.beforeAll( async ( { requestUtils } ) => { | ||
await Promise.all( [ | ||
requestUtils.activateTheme( 'emptytheme' ), | ||
requestUtils.deleteAllTemplates( 'wp_template' ), | ||
requestUtils.deleteAllTemplates( 'wp_template_part' ), | ||
] ); | ||
} ); | ||
|
||
test.beforeEach( async ( { admin } ) => { | ||
await admin.visitSiteEditor( { | ||
postId: 'emptytheme//index', | ||
postType: 'wp_template', | ||
canvas: 'edit', | ||
} ); | ||
} ); | ||
|
||
test.afterAll( async ( { requestUtils } ) => { | ||
await Promise.all( [ | ||
requestUtils.activateTheme( 'twentytwentyone' ), | ||
requestUtils.deleteAllTemplates( 'wp_template' ), | ||
requestUtils.deleteAllTemplates( 'wp_template_part' ), | ||
] ); | ||
} ); | ||
|
||
test.describe( 'Template tab', () => { | ||
test( 'should open template tab by default if no block is selected', async ( { | ||
editor, | ||
page, | ||
} ) => { | ||
await editor.openDocumentSettingsSidebar(); | ||
|
||
await expect( | ||
page | ||
.getByRole( 'region', { name: 'Editor settings' } ) | ||
.getByRole( 'button', { name: 'Template (selected)' } ) | ||
).toHaveClass( /is-active/ ); | ||
} ); | ||
|
||
test( `should show the currently selected template's title and description`, async ( { | ||
admin, | ||
editor, | ||
page, | ||
} ) => { | ||
await editor.openDocumentSettingsSidebar(); | ||
|
||
const settingsSideber = page.getByRole( 'region', { | ||
name: 'Editor settings', | ||
} ); | ||
const templateTitle = settingsSideber.locator( | ||
'.edit-site-sidebar-card__title' | ||
); | ||
const templateDescription = settingsSideber.locator( | ||
'.edit-site-sidebar-card__description' | ||
); | ||
Comment on lines
+55
to
+60
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. Had to use the class locator here. |
||
|
||
await expect( templateTitle ).toHaveText( 'Index' ); | ||
await expect( templateDescription ).toHaveText( | ||
'Used as a fallback template for all pages when a more specific template is not defined.' | ||
); | ||
|
||
await admin.visitSiteEditor( { | ||
postId: 'emptytheme//singular', | ||
postType: 'wp_template', | ||
canvas: 'edit', | ||
} ); | ||
|
||
await expect( templateTitle ).toHaveText( 'Single Entries' ); | ||
await expect( templateDescription ).toHaveText( | ||
'Displays any single entry, such as a post or a page. This template will serve as a fallback when a more specific template (e.g. Single Post, Page, or Attachment) cannot be found.' | ||
); | ||
} ); | ||
} ); | ||
|
||
test.describe( 'Block tab', () => { | ||
test( 'should open block tab by default if a block is selected', async ( { | ||
editor, | ||
page, | ||
} ) => { | ||
await editor.selectBlocks( | ||
editor.canvas.getByRole( 'document', { name: 'Block' } ).first() | ||
); | ||
await editor.openDocumentSettingsSidebar(); | ||
|
||
await expect( | ||
page | ||
.getByRole( 'region', { name: 'Editor settings' } ) | ||
.getByRole( 'button', { name: 'Block (selected)' } ) | ||
).toHaveClass( /is-active/ ); | ||
} ); | ||
} ); | ||
|
||
test.describe( 'Tab switch based on selection', () => { | ||
test( 'should switch to block tab if we select a block, when Template is selected', async ( { | ||
editor, | ||
page, | ||
} ) => { | ||
await editor.openDocumentSettingsSidebar(); | ||
|
||
await expect( | ||
page | ||
.getByRole( 'region', { name: 'Editor settings' } ) | ||
.getByRole( 'button', { name: 'Template (selected)' } ) | ||
).toHaveClass( /is-active/ ); | ||
|
||
// By inserting the block is also selected. | ||
await editor.insertBlock( { name: 'core/heading' } ); | ||
await expect( | ||
page | ||
.getByRole( 'region', { name: 'Editor settings' } ) | ||
.getByRole( 'button', { name: 'Block (selected)' } ) | ||
).toHaveClass( /is-active/ ); | ||
} ); | ||
|
||
test( 'should switch to Template tab when a block was selected and we select the Template', async ( { | ||
editor, | ||
page, | ||
} ) => { | ||
await editor.selectBlocks( | ||
editor.canvas.getByRole( 'document', { name: 'Block' } ).first() | ||
); | ||
await editor.openDocumentSettingsSidebar(); | ||
|
||
await expect( | ||
page | ||
.getByRole( 'region', { name: 'Editor settings' } ) | ||
.getByRole( 'button', { name: 'Block (selected)' } ) | ||
).toHaveClass( /is-active/ ); | ||
|
||
await page.evaluate( () => { | ||
window.wp.data | ||
.dispatch( 'core/block-editor' ) | ||
.clearSelectedBlock(); | ||
} ); | ||
|
||
await expect( | ||
page | ||
.getByRole( 'region', { name: 'Editor settings' } ) | ||
.getByRole( 'button', { name: 'Template (selected)' } ) | ||
).toHaveClass( /is-active/ ); | ||
} ); | ||
} ); | ||
} ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can improve active tab assertions after #56959 is merged.
Untested example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The active tab assertions work like a charm - https://github.com/WordPress/gutenberg/pull/57446/files.