diff --git a/packages/block-editor/src/components/iframe/index.js b/packages/block-editor/src/components/iframe/index.js index 3ae01525a80109..8411430dfbdadd 100644 --- a/packages/block-editor/src/components/iframe/index.js +++ b/packages/block-editor/src/components/iframe/index.js @@ -131,8 +131,23 @@ function Iframe( { function preventFileDropDefault( event ) { event.preventDefault(); } + + const { ownerDocument } = node; + + // Ideally ALL classes that are added through get_body_class should + // be added in the editor too, which we'll somehow have to get from + // the server in the future (which will run the PHP filters). + setBodyClasses( + Array.from( ownerDocument.body.classList ).filter( + ( name ) => + name.startsWith( 'admin-color-' ) || + name.startsWith( 'post-type-' ) || + name === 'wp-embed-responsive' + ) + ); + function onLoad() { - const { contentDocument, ownerDocument } = node; + const { contentDocument } = node; const { documentElement } = contentDocument; iFrameDocument = contentDocument; @@ -140,18 +155,6 @@ function Iframe( { clearerRef( documentElement ); - // Ideally ALL classes that are added through get_body_class should - // be added in the editor too, which we'll somehow have to get from - // the server in the future (which will run the PHP filters). - setBodyClasses( - Array.from( ownerDocument.body.classList ).filter( - ( name ) => - name.startsWith( 'admin-color-' ) || - name.startsWith( 'post-type-' ) || - name === 'wp-embed-responsive' - ) - ); - contentDocument.dir = ownerDocument.dir; for ( const compatStyle of getCompatibilityStyles() ) { diff --git a/test/e2e/specs/editor/various/block-editor-dark-background.spec.js b/test/e2e/specs/editor/various/block-editor-dark-background.spec.js new file mode 100644 index 00000000000000..dc333f31c7ed9d --- /dev/null +++ b/test/e2e/specs/editor/various/block-editor-dark-background.spec.js @@ -0,0 +1,52 @@ +/** + * WordPress dependencies + */ +const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); + +test.describe( 'Block editor with dark background theme', () => { + test.beforeAll( async ( { requestUtils } ) => { + await requestUtils.activateTheme( 'darktheme' ); + } ); + + test.beforeEach( async ( { admin } ) => { + await admin.createNewPost(); + } ); + + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.activateTheme( 'twentytwentyone' ); + } ); + + test.describe( 'Block editor iframe body', () => { + test( 'Should have the is-dark-theme CSS class', async ( { + editor, + } ) => { + const canvasBody = editor.canvas.locator( 'body' ); + + await expect( canvasBody ).toHaveClass( /is-dark-theme/ ); + } ); + } ); +} ); + +test.describe( 'Block editor with light background theme', () => { + test.beforeAll( async ( { requestUtils } ) => { + await requestUtils.activateTheme( 'twentytwentyfour' ); + } ); + + test.beforeEach( async ( { admin } ) => { + await admin.createNewPost(); + } ); + + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.activateTheme( 'twentytwentyone' ); + } ); + + test.describe( 'Block editor iframe body', () => { + test( 'Should not have the is-dark-theme CSS class', async ( { + editor, + } ) => { + const canvasBody = editor.canvas.locator( 'body' ); + + await expect( canvasBody ).not.toHaveClass( /is-dark-theme/ ); + } ); + } ); +} ); diff --git a/test/e2e/specs/site-editor/site-editor-dark-background.spec.js b/test/e2e/specs/site-editor/site-editor-dark-background.spec.js new file mode 100644 index 00000000000000..1bf49c196bdfc6 --- /dev/null +++ b/test/e2e/specs/site-editor/site-editor-dark-background.spec.js @@ -0,0 +1,75 @@ +/** + * WordPress dependencies + */ +const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); + +test.describe( 'Site editor with dark background theme', () => { + test.beforeAll( async ( { requestUtils } ) => { + await requestUtils.activateTheme( 'darktheme' ); + } ); + + test.beforeEach( async ( { admin } ) => { + await admin.visitSiteEditor(); + } ); + + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.activateTheme( 'twentytwentyone' ); + } ); + + test.describe( 'Site editor iframe body', () => { + test( 'Should have the is-dark-theme CSS class', async ( { + editor, + } ) => { + const canvasBody = editor.canvas.locator( 'body' ); + + await expect( canvasBody ).toHaveClass( /is-dark-theme/ ); + } ); + } ); +} ); + +test.describe( 'Site editor with light background theme and theme variations', () => { + test.beforeAll( async ( { requestUtils } ) => { + await requestUtils.activateTheme( 'twentytwentyfour' ); + } ); + + test.beforeEach( async ( { admin } ) => { + await admin.visitSiteEditor(); + } ); + + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.activateTheme( 'twentytwentyone' ); + } ); + + test.describe( 'Site editor iframe body', () => { + test( 'Should not have the is-dark-theme CSS class', async ( { + editor, + } ) => { + const canvasBody = editor.canvas.locator( 'body' ); + + await expect( canvasBody ).not.toHaveClass( /is-dark-theme/ ); + } ); + + test( 'Should add and remove the is-dark-theme CSS class with dark and light theme variation', async ( { + page, + editor, + } ) => { + // Click "Styles" + await page.getByRole( 'button', { name: 'Styles' } ).click(); + + // Click "Browse styles" + await page.getByRole( 'button', { name: 'Browse styles' } ).click(); + + const canvasBody = editor.canvas.locator( 'body' ); + + // Activate "Maelstrom" Theme Variation. + await page.getByRole( 'button', { name: 'Maelstrom' } ).click(); + + await expect( canvasBody ).toHaveClass( /is-dark-theme/ ); + + // Activate "Ember" Theme Variation. + await page.getByRole( 'button', { name: 'Ember' } ).click(); + + await expect( canvasBody ).not.toHaveClass( /is-dark-theme/ ); + } ); + } ); +} ); diff --git a/test/gutenberg-test-themes/darktheme/block-templates/index.html b/test/gutenberg-test-themes/darktheme/block-templates/index.html new file mode 100644 index 00000000000000..0283daeb54c6f4 --- /dev/null +++ b/test/gutenberg-test-themes/darktheme/block-templates/index.html @@ -0,0 +1,11 @@ + +
+ + + + +
+ + +

My awesome paragraph

+ diff --git a/test/gutenberg-test-themes/darktheme/block-templates/singular.html b/test/gutenberg-test-themes/darktheme/block-templates/singular.html new file mode 100644 index 00000000000000..cd05d5fe917fea --- /dev/null +++ b/test/gutenberg-test-themes/darktheme/block-templates/singular.html @@ -0,0 +1,2 @@ + + diff --git a/test/gutenberg-test-themes/darktheme/index.php b/test/gutenberg-test-themes/darktheme/index.php new file mode 100644 index 00000000000000..0c6530acc1aaff --- /dev/null +++ b/test/gutenberg-test-themes/darktheme/index.php @@ -0,0 +1,9 @@ +