forked from nodejs/nodejs.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutlineOnKeyboardNav.test.js
More file actions
35 lines (35 loc) · 1.01 KB
/
outlineOnKeyboardNav.test.js
File metadata and controls
35 lines (35 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {
handleMouseDown,
handleFocus,
handleKeyDown,
handleBlur,
} from '../../src/util/outlineOnKeyboardNav';
describe('Tests for focus and blur handlers', () => {
const FOCUS_ATTR = 'data-is-focused';
const TAB_KEYCODE = 9;
let event = {};
beforeEach(() => {
event = {
target: document.createElement('div'),
currentTarget: document.createElement('div'),
keyCode: TAB_KEYCODE,
};
});
it('hides outline for mouse focus', () => {
handleMouseDown(event);
handleFocus(event);
expect(event.target.getAttribute(FOCUS_ATTR)).toEqual('true');
});
it('doesnt hide outline for keyboard focus', () => {
handleKeyDown(event);
handleFocus(event);
expect(event.target.getAttribute(FOCUS_ATTR)).toBeNull();
});
it('Blurs after leaving focus', () => {
handleMouseDown(event);
handleFocus(event);
expect(event.target.getAttribute(FOCUS_ATTR)).toEqual('true');
handleBlur(event);
expect(event.target.getAttribute(FOCUS_ATTR)).toBeNull();
});
});