Skip to content

Commit

Permalink
E2E: Improve contrast checker e2e test with multiple scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshupathak95 committed Jan 30, 2025
1 parent 9aacc02 commit 2635c70
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions test/e2e/specs/editor/various/contrast-checker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,55 @@
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

const WARNING_TEXT = 'This color combination may be hard for people to read';

test.describe( 'ContrastChecker', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
} );

test( 'should show warning when text and background colors have low contrast', async ( {
test( 'should show warning for insufficient contrast', async ( {
editor,
page,
} ) => {
await editor.openDocumentSettingsSidebar();
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'Contrast Checker Test' },

await test.step( 'Check black text on black background', async () => {
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'Black text on Black background' },
} );

await page
.getByRole( 'button', { name: 'Text', exact: true } )
.click();
await page.getByRole( 'option', { name: 'Black' } ).click();
await page.getByRole( 'button', { name: 'Background' } ).click();
await page.getByRole( 'option', { name: 'Black' } ).click();

const lowContrastWarning = page.locator(
'.block-editor-contrast-checker'
);
await expect( lowContrastWarning ).toBeVisible();
await expect( lowContrastWarning ).toContainText( WARNING_TEXT );
} );

await page.getByRole( 'button', { name: 'Text', exact: true } ).click();
await page.getByRole( 'option', { name: 'Black' } ).click();
await test.step( 'Check white text on default background', async () => {
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'White text on Default background' },
} );

await page.getByRole( 'button', { name: 'Background' } ).click();
await page.getByRole( 'option', { name: 'Black' } ).click();
await page
.getByRole( 'button', { name: 'Text', exact: true } )
.click();
await page.getByRole( 'option', { name: 'White' } ).click();

const lowContrastWarning = page.locator(
'.block-editor-contrast-checker'
);
await expect( lowContrastWarning ).toBeVisible();
await expect( lowContrastWarning ).toContainText(
'This color combination may be hard for people to read'
);
const lowContrastWarning = page.locator(
'.block-editor-contrast-checker'
);
await expect( lowContrastWarning ).toBeVisible();
await expect( lowContrastWarning ).toContainText( WARNING_TEXT );
} );
} );
} );

0 comments on commit 2635c70

Please sign in to comment.