Skip to content

Commit

Permalink
E2E Tests: a11y: Test focus retention in modals
Browse files Browse the repository at this point in the history
Checks edge cases in withConstrainedTabbing.
  • Loading branch information
mcsf committed Oct 1, 2018
1 parent 4d21ead commit 2ee25cc
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions test/e2e/specs/a11y.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
/**
* Internal dependencies
*/
import { newPost, pressWithModifier } from '../support/utils';
import {
ACCESS_MODIFIER_KEYS,
newPost,
pressWithModifier,
} from '../support/utils';

function isCloseButtonFocused() {
return page.$eval( ':focus', ( focusedElement ) => {
return focusedElement.getAttribute( 'aria-label' ) === 'Close dialog';
} );
}

describe( 'a11y', () => {
beforeAll( async () => {
beforeEach( async () => {
await newPost();
} );

Expand All @@ -19,4 +29,43 @@ describe( 'a11y', () => {

expect( isFocusedToggle ).toBe( true );
} );

it( 'constrains focus to a modal when tabbing', async () => {
// Open help modal
await pressWithModifier( ACCESS_MODIFIER_KEYS, 'h' );

// Test that the Close button of the modal is focused when the
// latter is opened.
expect( await isCloseButtonFocused() ).toBe( true );

await page.keyboard.press( 'Tab' );

// Test that the Close button of the modal is focused when the
// latter is opened.
expect( await isCloseButtonFocused() ).toBe( true );
} );

it( 'returns focus to the first tabbable in a modal after blurring a tabbable', async () => {
await pressWithModifier( ACCESS_MODIFIER_KEYS, 'h' );

// Click to move focus to an element after the last tabbable within the
// modal.
await page.click( '.components-modal__content' );

await page.keyboard.press( 'Tab' );

expect( await isCloseButtonFocused() ).toBe( true );
} );

it( 'returns focus to the last tabbable in a modal after blurring a tabbable and tabbing in reverse direction', async () => {
await pressWithModifier( ACCESS_MODIFIER_KEYS, 'h' );

// Click to move focus to an element before the first tabbable within
// the modal.
await page.click( '.components-modal__header-heading' );

await pressWithModifier( 'Shift', 'Tab' );

expect( await isCloseButtonFocused() ).toBe( true );
} );
} );

0 comments on commit 2ee25cc

Please sign in to comment.