Skip to content

Commit

Permalink
WIP: Increase component test coverage to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
acdvorak committed Feb 1, 2019
1 parent 9452569 commit 63845ba
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion test/unit/mdc-menu-surface/mdc-menu-surface.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import domEvents from 'dom-events';
import td from 'testdouble';

import {MDCMenuSurface, MDCMenuSurfaceFoundation} from '../../../packages/mdc-menu-surface/index';
import {strings, cssClasses, Corner} from '../../../packages/mdc-menu-surface/constants';
import {Corner, cssClasses, strings} from '../../../packages/mdc-menu-surface/constants';
import {getTransformPropertyName} from '../../../packages/mdc-menu-surface/util';

function getFixture(open, fixedPosition = false) {
Expand Down Expand Up @@ -493,3 +493,35 @@ test('adapter#setMaxHeight sets the maxHeight style on the menu surface element'
component.getDefaultFoundation().adapter_.setMaxHeight('100px');
assert.equal(root.style.maxHeight, '100px');
});

test('Pressing Shift+Tab on first element focuses the last menu surface element', () => {
const root = getFixture(true);
document.body.appendChild(root);
const firstItem = root.querySelectorAll(strings.FOCUSABLE_ELEMENTS)[0];
const lastItem = root.querySelectorAll(strings.FOCUSABLE_ELEMENTS)[1];
const component = new MDCMenuSurface(root);
component.open = true;

firstItem.focus();
component.getDefaultFoundation().handleKeydown({key: 'Tab', shiftKey: true, preventDefault: () => {}});
assert.equal(document.activeElement, lastItem);

component.open = false;
document.body.removeChild(root);
});

test('Pressing Tab on last element focuses the first menu surface element', () => {
const root = getFixture(true);
document.body.appendChild(root);
const firstItem = root.querySelectorAll(strings.FOCUSABLE_ELEMENTS)[0];
const lastItem = root.querySelectorAll(strings.FOCUSABLE_ELEMENTS)[1];
const component = new MDCMenuSurface(root);
component.open = true;

lastItem.focus();
component.getDefaultFoundation().handleKeydown({key: 'Tab', shiftKey: false, preventDefault: () => {}});
assert.equal(document.activeElement, firstItem);

component.open = false;
document.body.removeChild(root);
});

0 comments on commit 63845ba

Please sign in to comment.