Skip to content

Commit 41b213f

Browse files
committed
Add a handful of new tests
1 parent 9ad900b commit 41b213f

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/use-dropdown-menu.test.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,36 @@ it('moves the focus to the first menu item after pressing enter while focused on
1818
expect(document.activeElement?.id).toBe('menu-item-1');
1919
});
2020

21+
it('moves the focus to the first menu item after pressing space while focused on the menu button', () => {
22+
const component = mount(<TestComponent />);
23+
const button = component.find('#menu-button');
24+
25+
button.getDOMNode<HTMLButtonElement>().focus();
26+
button.simulate('keydown', { key: ' ' });
27+
28+
expect(document.activeElement?.id).toBe('menu-item-1');
29+
});
30+
31+
it('moves the focus to the first menu item after clicking the menu to open it, then pressing tab while focused on the menu button', () => {
32+
const component = mount(<TestComponent />);
33+
const button = component.find('#menu-button');
34+
35+
button.simulate('click');
36+
button.simulate('keydown', { key: 'Tab' });
37+
38+
expect(document.activeElement?.id).toBe('menu-item-1');
39+
});
40+
41+
it('moves the focus to the first menu item after clicking the menu to open it, then pressing arrow down while focused on the menu button', () => {
42+
const component = mount(<TestComponent />);
43+
const button = component.find('#menu-button');
44+
45+
button.simulate('click');
46+
button.simulate('keydown', { key: 'ArrowDown' });
47+
48+
expect(document.activeElement?.id).toBe('menu-item-1');
49+
});
50+
2151
it('sets isOpen to true after pressing enter while focused on the menu button', () => {
2252
const component = mount(<TestComponent />);
2353
const button = component.find('#menu-button');
@@ -29,6 +59,17 @@ it('sets isOpen to true after pressing enter while focused on the menu button',
2959
expect(span.text()).toBe('true');
3060
});
3161

62+
it('sets isOpen to true after pressing space while focused on the menu button', () => {
63+
const component = mount(<TestComponent />);
64+
const button = component.find('#menu-button');
65+
const span = component.find('#is-open-indicator');
66+
67+
button.getDOMNode<HTMLButtonElement>().focus();
68+
button.simulate('keydown', { key: ' ' });
69+
70+
expect(span.text()).toBe('true');
71+
});
72+
3273
it('moves the focus to the next element in the menu after pressing the down arrow', () => {
3374
const component = mount(<TestComponent />);
3475
const button = component.find('#menu-button');

0 commit comments

Comments
 (0)