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 'iframed block editor settings styles' tests to Playwright #55014

Merged
merged 3 commits into from
Oct 4, 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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'iframed block editor settings styles', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activatePlugin(
Copy link
Member

Choose a reason for hiding this comment

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

The original test enables emptytheme here. Do you need to do it here too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not anymore. Since then, all editors have been iframed by default. Unless there's a v2 block or metabox fields enabled.

'gutenberg-test-iframed-enqueue-block-editor-settings'
);
} );

test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.deactivatePlugin(
'gutenberg-test-iframed-enqueue-block-editor-settings'
);
} );

test( 'should load styles added through block editor settings', async ( {
editor,
page,
} ) => {
const defaultBlock = editor.canvas.getByRole( 'button', {
name: 'Add default block',
} );

// Expect a red border (added in PHP).
await expect( defaultBlock ).toHaveCSS(
'border-color',
'rgb(255, 0, 0)'
);

await page.evaluate( () => {
const settings = window.wp.data
.select( 'core/editor' )
.getEditorSettings();
window.wp.data.dispatch( 'core/editor' ).updateEditorSettings( {
...settings,
styles: [
...settings.styles,
{
css: 'p { border-width: 2px; }',
__unstableType: 'plugin',
},
],
} );
} );

// Expect a 2px border (added in JS).
await expect( defaultBlock ).toHaveCSS( 'border-width', '2px' );
} );

test( 'should load theme styles added through block editor settings', async ( {
editor,
page,
} ) => {
const defaultBlock = editor.canvas.getByRole( 'button', {
name: 'Add default block',
} );

await page.evaluate( () => {
// Make sure that theme styles are added even if the theme styles
// preference is off.
window.wp.data
.dispatch( 'core/edit-post' )
.toggleFeature( 'themeStyles' );
const settings = window.wp.data
.select( 'core/editor' )
.getEditorSettings();
window.wp.data.dispatch( 'core/editor' ).updateEditorSettings( {
...settings,
styles: [
...settings.styles,
{
css: 'p { border-width: 2px; }',
__unstableType: 'theme',
},
],
} );
} );

// Expect a 1px border because theme styles are disabled.
await expect( defaultBlock ).toHaveCSS( 'border-width', '1px' );

await page.evaluate( () => {
// Now enable theme styles.
window.wp.data
.dispatch( 'core/edit-post' )
.toggleFeature( 'themeStyles' );
} );

// Expect a 2px border because theme styles are enabled.
await expect( defaultBlock ).toHaveCSS( 'border-width', '2px' );
} );
} );
Loading