This repository has been archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(list): enter and spacebar keyboard handling for List and Listitem (
#279) test roles and keyboard handlers for list and listitem
- Loading branch information
1 parent
3759e68
commit e93076c
Showing
4 changed files
with
31 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as React from 'react' | ||
import * as keyboardKey from 'keyboard-key' | ||
import { isConformant, handlesAccessibility } from 'test/specs/commonTests' | ||
import { mountWithProvider } from 'test/utils' | ||
|
||
import ListItem from 'src/components/List/ListItem' | ||
import { selectableListItemBehavior } from 'src/lib/accessibility' | ||
|
||
describe('ListItem', () => { | ||
isConformant(ListItem) | ||
handlesAccessibility(ListItem, { defaultRootRole: 'listitem' }) | ||
|
||
test('handleClick is executed when Enter is pressed for selectable list', () => { | ||
const onClick = jest.fn() | ||
const listItem = mountWithProvider( | ||
<ListItem accessibility={selectableListItemBehavior} onClick={onClick} />, | ||
).find('ListItem') | ||
listItem.simulate('keydown', { keyCode: keyboardKey.Enter }) | ||
expect(onClick).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
test('handleClick is executed when Spacebar is pressed for selectable list', () => { | ||
const onClick = jest.fn() | ||
const listItem = mountWithProvider( | ||
<ListItem accessibility={selectableListItemBehavior} onClick={onClick} />, | ||
).find('ListItem') | ||
listItem.simulate('keydown', { keyCode: keyboardKey.Spacebar }) | ||
expect(onClick).toHaveBeenCalledTimes(1) | ||
}) | ||
}) |