Skip to content
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 'sidebar permalink' e2e tests to Playwright #56253

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

81 changes: 81 additions & 0 deletions test/e2e/specs/editor/various/sidebar-permalink.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

// This tests are not together with the remaining sidebar tests,
// because we need to publish/save a post, to correctly test the permalink row.
// The sidebar test suit enforces that focus is never lost, but during save operations
// the focus is lost and a new element is focused once the save is completed.
test.describe( 'Sidebar Permalink', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activatePlugin( 'gutenberg-test-custom-post-types' );
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.deactivatePlugin(
'gutenberg-test-custom-post-types'
);
} );

test( 'should not render URL when post is publicly queryable but not public', async ( {
admin,
editor,
page,
} ) => {
await admin.createNewPost( { postType: 'public_q_not_public' } );
await editor.openDocumentSettingsSidebar();
await editor.canvas
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'aaaaa' );
await editor.publishPost();
// Start editing again.
await editor.canvas
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'aaaa (Updated)' );
await expect(
page.getByRole( 'button', { name: 'Change URL' } )
).toBeHidden();
Comment on lines +26 to +38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we ensure this button is visible before the post-publish editing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we ensure this button is visible before the post-publish editing?

I don't think we need to do that.

The button should be rendered at all. Not sure why publishing step was included in the first place. Probably testing some regression.

} );

test( 'should not render URL when post is public but not publicly queryable', async ( {
admin,
editor,
page,
} ) => {
await admin.createNewPost( { postType: 'not_public_q_public' } );
await editor.openDocumentSettingsSidebar();
await editor.canvas
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'aaaaa' );
await editor.saveDraft();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The editor.publishPost() helper could fail for specific post-type configurations when the post-publish panel isn't displayed. I will double-check if not displaying the panel is intentional and fix the code accordingly.

Failing locator

const urlString = await this.page
.getByRole( 'region', { name: 'Editor publish' } )
.getByRole( 'textbox', { name: 'address' } )
.inputValue();

// Start editing again.
await editor.canvas
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'aaaa (Updated)' );
await expect(
page.getByRole( 'button', { name: 'Change URL' } )
).toBeHidden();
Comment on lines +56 to +58
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above!

} );

test( 'should render URL when post is public and publicly queryable', async ( {
admin,
editor,
page,
} ) => {
await admin.createNewPost( { postType: 'public_q_public' } );
await editor.openDocumentSettingsSidebar();
await editor.canvas
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'aaaaa' );
await editor.publishPost();

// Start editing again.
await editor.canvas
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'aaaa (Updated)' );
await expect(
page.getByRole( 'button', { name: 'Change URL' } )
).toBeVisible();
Comment on lines +77 to +79
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, but the other way round 😄

} );
} );
Loading