Skip to content

Commit

Permalink
Add tests for the site editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed Feb 17, 2025
1 parent 147cb34 commit 9e8dfb5
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ test.describe( 'Block editor with dark background theme', () => {
await requestUtils.activateTheme( 'twentytwentyone' );
} );

test.describe( 'block editor iframe body', () => {
test( 'should have the is-dark-theme CSS class', async ( {
test.describe( 'Block editor iframe body', () => {
test( 'Should have the is-dark-theme CSS class', async ( {
editor,
} ) => {
const canvasBody = editor.canvas.locator( 'body' );
Expand All @@ -40,8 +40,8 @@ test.describe( 'Block editor with light background theme', () => {
await requestUtils.activateTheme( 'twentytwentyone' );
} );

test.describe( 'block editor iframe body', () => {
test( 'should not have the is-dark-theme CSS class', async ( {
test.describe( 'Block editor iframe body', () => {
test( 'Should not have the is-dark-theme CSS class', async ( {
editor,
} ) => {
const canvasBody = editor.canvas.locator( 'body' );
Expand Down
75 changes: 75 additions & 0 deletions test/e2e/specs/site-editor/site-editor-dark-background.spec.js
Original file line number Diff line number Diff line change
@@ -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/ );
} );
} );
} );

0 comments on commit 9e8dfb5

Please sign in to comment.