forked from microsoft/fluentui-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToggleButton.test.tsx
55 lines (47 loc) · 1.58 KB
/
ToggleButton.test.tsx
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import * as React from 'react';
import { fireEvent, render, screen, act } from '@testing-library/react';
import { Menu, MenuPopover, MenuTrigger } from '@fluentui/react-components';
import { ToggleButton } from './ToggleButton';
describe('ToggleButton', () => {
beforeEach(() => {
console.error = jest.fn();
});
it('should throw error for icon button if no title or aria-label is provided', () => {
console.error = jest.fn();
expect(() => render(<ToggleButton checked icon={<i>X</i>} />)).toThrow(
'Icon button must have a title'
);
});
it('should not throw error for icon button if aria-label is provided', () => {
console.error = jest.fn();
expect(() =>
render(<ToggleButton checked aria-label="label" icon={<i>X</i>} />)
).not.toThrow();
});
it('should render title', () => {
jest.useFakeTimers();
const { getByRole } = render(
<ToggleButton checked icon={<i>X</i>} title={'Tooltip'} />
);
const button = getByRole('button');
fireEvent.pointerEnter(button);
act(() => {
jest.runOnlyPendingTimers();
});
const title = screen.queryByText('Tooltip');
expect(title).not.toBeNull();
expect(title?.textContent).toEqual(button.getAttribute('aria-label'));
});
it('should error when attempting to wrap with a menu', () => {
expect(() =>
render(
<Menu>
<MenuTrigger>
<ToggleButton checked={false} icon={<i>X</i>} />
</MenuTrigger>
<MenuPopover></MenuPopover>
</Menu>
)
).toThrow('Icon button must have a title');
});
});