Skip to content

Commit 76c42e4

Browse files
committed
chore: adding test
1 parent 8e96cd2 commit 76c42e4

File tree

5 files changed

+83
-1
lines changed

5 files changed

+83
-1
lines changed

src/MenuItem.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export class MenuItem extends React.Component {
162162
role: 'option',
163163
'aria-selected': props.isSelected,
164164
};
165-
} else if (attrs.role === null) {
165+
} else if (props.role === null) {
166166
// sometimes we want to specify role inside <li/> element
167167
// <li><a role='menuitem'>Link</a></li> would be a good example
168168
delete attrs.role;

tests/Menu.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,27 @@ describe('Menu', () => {
3939
});
4040
});
4141

42+
describe('render role listbox', () => {
43+
function createMenu() {
44+
return (
45+
<Menu
46+
className="myMenu"
47+
openAnimation="fade"
48+
role="listbox"
49+
>
50+
<MenuItem key="1" role="option">1</MenuItem>
51+
<MenuItem key="2" role="option">2</MenuItem>
52+
<MenuItem key="3" role="option">3</MenuItem>
53+
</Menu>
54+
);
55+
}
56+
57+
it(`renders menu correctly`, () => {
58+
const wrapper = render(createMenu());
59+
expect(renderToJson(wrapper)).toMatchSnapshot();
60+
});
61+
});
62+
4263
it('set activeKey', () => {
4364
const wrapper = mount(
4465
<Menu activeKey="1">

tests/MenuItem.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,18 @@ describe('MenuItem', () => {
112112
expect(onClick).toHaveBeenCalledTimes(3);
113113
});
114114
});
115+
116+
describe('overwrite default role', () => {
117+
it('should set empty role', () => {
118+
const wrapper = shallow(<NakedMenuItem role={null}>test</NakedMenuItem>);
119+
120+
expect(wrapper.render()).toMatchSnapshot();
121+
});
122+
123+
it('should set specific role', () => {
124+
const wrapper = shallow(<NakedMenuItem role="option">test</NakedMenuItem>);
125+
126+
expect(wrapper.render()).toMatchSnapshot();
127+
});
128+
});
115129
});

tests/__snapshots__/Menu.spec.js.snap

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,33 @@ exports[`Menu render renders vertical menu correctly 1`] = `
267267
</li>
268268
</ul>
269269
`;
270+
271+
exports[`Menu render role listbox renders menu correctly 1`] = `
272+
<ul
273+
class="rc-menu myMenu rc-menu-root rc-menu-vertical"
274+
role="listbox"
275+
tabindex="0"
276+
>
277+
<li
278+
aria-selected="false"
279+
class="rc-menu-item"
280+
role="option"
281+
>
282+
1
283+
</li>
284+
<li
285+
aria-selected="false"
286+
class="rc-menu-item"
287+
role="option"
288+
>
289+
2
290+
</li>
291+
<li
292+
aria-selected="false"
293+
class="rc-menu-item"
294+
role="option"
295+
>
296+
3
297+
</li>
298+
</ul>
299+
`;

tests/__snapshots__/MenuItem.spec.js.snap

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`MenuItem overwrite default role should set empty role 1`] = `
4+
<li
5+
class="undefined-item"
6+
>
7+
test
8+
</li>
9+
`;
10+
11+
exports[`MenuItem overwrite default role should set specific role 1`] = `
12+
<li
13+
class="undefined-item"
14+
role="option"
15+
>
16+
test
17+
</li>
18+
`;
19+
320
exports[`MenuItem rest props can render all props to sub component 1`] = `
421
<ul
522
class="rc-menu rc-menu-root rc-menu-inline"

0 commit comments

Comments
 (0)