forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBottomNavigationAction.test.js
More file actions
106 lines (82 loc) · 3.52 KB
/
BottomNavigationAction.test.js
File metadata and controls
106 lines (82 loc) · 3.52 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import { createRenderer, within, screen } from '@mui/internal-test-utils';
import BottomNavigationAction, {
bottomNavigationActionClasses as classes,
} from '@mui/material/BottomNavigationAction';
import ButtonBase from '@mui/material/ButtonBase';
import describeConformance from '../../test/describeConformance';
const CustomButtonBase = React.forwardRef(({ focusRipple, ...props }, ref) => (
<ButtonBase ref={ref} {...props} />
));
describe('<BottomNavigationAction />', () => {
const { render } = createRenderer();
describeConformance(<BottomNavigationAction />, () => ({
classes,
inheritComponent: ButtonBase,
render,
muiName: 'MuiBottomNavigationAction',
refInstanceof: window.HTMLButtonElement,
testVariantProps: { showLabel: true },
testDeepOverrides: { slotName: 'label', slotClassName: classes.label },
skip: ['componentProp'],
slots: {
root: {
expectedClassName: classes.root,
testWithElement: CustomButtonBase,
},
label: {
expectedClassName: classes.label,
},
},
}));
it('adds a `selected` class when selected', () => {
render(<BottomNavigationAction selected />);
expect(screen.getByRole('button')).to.have.class(classes.selected);
});
it('should render label with the selected class when selected', () => {
const { container } = render(<BottomNavigationAction selected />);
expect(container.querySelector(`.${classes.label}`)).to.have.class(classes.selected);
});
it('adds a `iconOnly` class by default', () => {
render(<BottomNavigationAction />);
expect(screen.getByRole('button')).to.have.class(classes.iconOnly);
});
it('should render label with the `iconOnly` class', () => {
const { container } = render(<BottomNavigationAction />);
expect(container.querySelector(`.${classes.label}`)).to.have.class(classes.iconOnly);
});
it('removes the `iconOnly` class when `selected`', () => {
render(<BottomNavigationAction selected />);
expect(screen.getByRole('button')).not.to.have.class(classes.iconOnly);
});
it('removes the `iconOnly` class when `showLabel`', () => {
render(<BottomNavigationAction showLabel />);
expect(screen.getByRole('button')).not.to.have.class(classes.iconOnly);
});
it('should render the passed `icon`', () => {
render(<BottomNavigationAction icon={<div data-testid="icon" />} />);
expect(within(screen.getByRole('button')).getByTestId('icon')).not.to.equal(null);
});
describe('prop: onClick', () => {
it('should be called when a click is triggered', () => {
const handleClick = spy();
render(<BottomNavigationAction onClick={handleClick} />);
screen.getByRole('button').click();
expect(handleClick.callCount).to.equal(1);
});
});
it('forwards nativeButton={false} through useSlot to ButtonBase', () => {
const CustomSpan = React.forwardRef((props, ref) => <span ref={ref} {...props} />);
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
render(<BottomNavigationAction component={CustomSpan} nativeButton={false} />);
const action = screen.getByRole('button');
expect(action).to.have.tagName('SPAN');
expect(action).not.to.have.attribute('type');
// Proves nativeButton={false} was forwarded — without it, ButtonBase
// would warn about a non-button host with nativeButton omitted.
expect(errorSpy.mock.calls.length).to.equal(0);
errorSpy.mockRestore();
});
});