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 d85916d commit d20c61f
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();

Check failure on line 53 in test/e2e/specs/editor/various/contrast-checker.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › editor/various/contrast-checker.spec.js:13:2 › ContrastChecker › should show warning for insufficient contrast

1) [chromium] › editor/various/contrast-checker.spec.js:13:2 › ContrastChecker › should show warning for insufficient contrast › Check white text on default background Error: Timed out 5000ms waiting for expect(locator).toBeVisible() Locator: locator('.block-editor-contrast-checker') Expected: visible Received: <element(s) not found> Call log: - expect.toBeVisible with timeout 5000ms - waiting for locator('.block-editor-contrast-checker') 51 | '.block-editor-contrast-checker' 52 | ); > 53 | await expect( lowContrastWarning ).toBeVisible(); | ^ 54 | await expect( lowContrastWarning ).toContainText( WARNING_TEXT ); 55 | } ); 56 | } ); at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/contrast-checker.spec.js:53:39 at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/contrast-checker.spec.js:39:3

Check failure on line 53 in test/e2e/specs/editor/various/contrast-checker.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › editor/various/contrast-checker.spec.js:13:2 › ContrastChecker › should show warning for insufficient contrast

1) [chromium] › editor/various/contrast-checker.spec.js:13:2 › ContrastChecker › should show warning for insufficient contrast › Check white text on default background Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toBeVisible() Locator: locator('.block-editor-contrast-checker') Expected: visible Received: <element(s) not found> Call log: - expect.toBeVisible with timeout 5000ms - waiting for locator('.block-editor-contrast-checker') 51 | '.block-editor-contrast-checker' 52 | ); > 53 | await expect( lowContrastWarning ).toBeVisible(); | ^ 54 | await expect( lowContrastWarning ).toContainText( WARNING_TEXT ); 55 | } ); 56 | } ); at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/contrast-checker.spec.js:53:39 at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/contrast-checker.spec.js:39:3

Check failure on line 53 in test/e2e/specs/editor/various/contrast-checker.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › editor/various/contrast-checker.spec.js:13:2 › ContrastChecker › should show warning for insufficient contrast

1) [chromium] › editor/various/contrast-checker.spec.js:13:2 › ContrastChecker › should show warning for insufficient contrast › Check white text on default background Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toBeVisible() Locator: locator('.block-editor-contrast-checker') Expected: visible Received: <element(s) not found> Call log: - expect.toBeVisible with timeout 5000ms - waiting for locator('.block-editor-contrast-checker') 51 | '.block-editor-contrast-checker' 52 | ); > 53 | await expect( lowContrastWarning ).toBeVisible(); | ^ 54 | await expect( lowContrastWarning ).toContainText( WARNING_TEXT ); 55 | } ); 56 | } ); at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/contrast-checker.spec.js:53:39 at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/contrast-checker.spec.js:39:3
await expect( lowContrastWarning ).toContainText( WARNING_TEXT );
} );
} );
} );

0 comments on commit d20c61f

Please sign in to comment.