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

Testing: Add e2e test for basic ContrastChecker functionality #68856

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from
78 changes: 78 additions & 0 deletions test/e2e/specs/editor/various/contrast-checker.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* WordPress dependencies
*/
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 for insufficient contrast', async ( {
editor,
page,
} ) => {
await editor.openDocumentSettingsSidebar();

const lowContrastWarning = page.locator(
'.block-editor-contrast-checker'
);

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();

await expect( lowContrastWarning ).toBeVisible();
await expect( lowContrastWarning ).toContainText( WARNING_TEXT );
} );

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: 'Text', exact: true } )
.click();
await page.getByRole( 'option', { name: 'White' } ).click();

await expect( lowContrastWarning ).toBeVisible();

Check failure on line 51 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') 49 | await page.getByRole( 'option', { name: 'White' } ).click(); 50 | > 51 | await expect( lowContrastWarning ).toBeVisible(); | ^ 52 | await expect( lowContrastWarning ).toContainText( WARNING_TEXT ); 53 | } ); 54 | } ); at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/contrast-checker.spec.js:51:39 at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/contrast-checker.spec.js:40:3

Check failure on line 51 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') 49 | await page.getByRole( 'option', { name: 'White' } ).click(); 50 | > 51 | await expect( lowContrastWarning ).toBeVisible(); | ^ 52 | await expect( lowContrastWarning ).toContainText( WARNING_TEXT ); 53 | } ); 54 | } ); at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/contrast-checker.spec.js:51:39 at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/contrast-checker.spec.js:40:3

Check failure on line 51 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') 49 | await page.getByRole( 'option', { name: 'White' } ).click(); 50 | > 51 | await expect( lowContrastWarning ).toBeVisible(); | ^ 52 | await expect( lowContrastWarning ).toContainText( WARNING_TEXT ); 53 | } ); 54 | } ); at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/contrast-checker.spec.js:51:39 at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/contrast-checker.spec.js:40:3
await expect( lowContrastWarning ).toContainText( WARNING_TEXT );
} );
} );

test( 'should not show warning for sufficient contrast', async ( {
editor,
page,
} ) => {
await editor.openDocumentSettingsSidebar();

const lowContrastWarning = page.locator(
'.block-editor-contrast-checker'
);

await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'Black text on White 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: 'White' } ).click();

await expect( lowContrastWarning ).not.toBeVisible();
} );
} );
Loading