forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBottomNavigation.test.js
More file actions
executable file
·109 lines (99 loc) · 3.96 KB
/
BottomNavigation.test.js
File metadata and controls
executable file
·109 lines (99 loc) · 3.96 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
107
108
109
import { expect } from 'chai';
import { spy } from 'sinon';
import { createRenderer, fireEvent, screen } from '@mui/internal-test-utils';
import BottomNavigation, {
bottomNavigationClasses as classes,
} from '@mui/material/BottomNavigation';
import BottomNavigationAction, {
bottomNavigationActionClasses as actionClasses,
} from '@mui/material/BottomNavigationAction';
import Icon from '@mui/material/Icon';
import describeConformance from '../../test/describeConformance';
describe('<BottomNavigation />', () => {
const { render } = createRenderer();
const icon = <Icon>restore</Icon>;
const getBottomNavigation = (container) => container.firstChild;
describeConformance(
<BottomNavigation>
<BottomNavigationAction label="One" />
</BottomNavigation>,
() => ({
classes,
inheritComponent: 'div',
render,
muiName: 'MuiBottomNavigation',
refInstanceof: window.HTMLDivElement,
testComponentPropWith: 'span',
skip: ['themeVariants'],
}),
);
it('renders with a null child', () => {
const { container } = render(
<BottomNavigation showLabels value={0}>
<BottomNavigationAction label="One" />
{null}
<BottomNavigationAction label="Three" />
</BottomNavigation>,
);
expect(getBottomNavigation(container).childNodes.length).to.equal(2);
});
it('should pass selected prop to children', () => {
const { container } = render(
<BottomNavigation showLabels value={1}>
<BottomNavigationAction icon={icon} />
<BottomNavigationAction icon={icon} />
</BottomNavigation>,
);
expect(getBottomNavigation(container).childNodes[0]).not.to.have.class(actionClasses.selected);
expect(getBottomNavigation(container).childNodes[1]).to.have.class(actionClasses.selected);
});
it('should overwrite parent showLabel prop adding class iconOnly', () => {
render(
<BottomNavigation showLabels>
<BottomNavigationAction icon={icon} data-testid="withLabel" />
<BottomNavigationAction icon={icon} showLabel={false} data-testid="withoutLabel" />
</BottomNavigation>,
);
expect(screen.getByTestId('withLabel')).not.to.have.class(actionClasses.iconOnly);
expect(screen.getByTestId('withoutLabel')).to.have.class(actionClasses.iconOnly);
});
it('should forward the click', () => {
const handleChange = spy();
const { container } = render(
<BottomNavigation showLabels value={0} onChange={handleChange}>
<BottomNavigationAction icon={icon} />
<BottomNavigationAction icon={icon} />
</BottomNavigation>,
);
fireEvent.click(getBottomNavigation(container).childNodes[1]);
expect(handleChange.callCount).to.equal(1);
expect(handleChange.args[0][1]).to.equal(1);
});
it('should use custom action values', () => {
const handleChange = spy();
const { container } = render(
<BottomNavigation showLabels value={'first'} onChange={handleChange}>
<BottomNavigationAction value="first" icon={icon} />
<BottomNavigationAction value="second" icon={icon} />
</BottomNavigation>,
);
fireEvent.click(getBottomNavigation(container).childNodes[1]);
expect(handleChange.args[0][1]).to.equal('second', 'should have been called with value second');
});
it('should handle also empty action value', () => {
const handleChange = spy();
const { container } = render(
<BottomNavigation showLabels value="val" onChange={handleChange}>
<BottomNavigationAction value="" icon={icon} />
<BottomNavigationAction icon={icon} />
<BottomNavigationAction value={null} icon={icon} />
</BottomNavigation>,
);
fireEvent.click(getBottomNavigation(container).childNodes[0]);
expect(handleChange.args[0][1], '');
fireEvent.click(getBottomNavigation(container).childNodes[1]);
expect(handleChange.args[1][1], 1);
fireEvent.click(getBottomNavigation(container).childNodes[2]);
expect(handleChange.args[2][1], '');
});
});