Skip to content

Commit b5e96d3

Browse files
committed
test(Menu): add, update, and fix tests
1 parent f09373f commit b5e96d3

File tree

6 files changed

+42
-40
lines changed

6 files changed

+42
-40
lines changed

src/collections/Menu/MenuHeader.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function MenuHeader(props) {
1717
}
1818

1919
MenuHeader._meta = {
20-
name: 'MenuItem',
20+
name: 'MenuHeader',
2121
type: META.TYPES.COLLECTION,
2222
parent: 'Menu',
2323
}
@@ -29,10 +29,10 @@ MenuHeader.propTypes = {
2929
PropTypes.func,
3030
]),
3131

32-
/** Primary content of the MenuItem. */
32+
/** Primary content */
3333
children: PropTypes.node,
3434

35-
/** Classes that will be added to the MenuItem className. */
35+
/** Additional classes */
3636
className: PropTypes.string,
3737
}
3838

src/collections/Menu/MenuItem.js

-4
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,4 @@ MenuItem.propTypes = {
8383
position: PropTypes.oneOf(MenuItem._meta.props.position),
8484
}
8585

86-
MenuItem.defaultProps = {
87-
as: 'a',
88-
}
89-
9086
export default MenuItem
+14-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
import faker from 'faker'
21
import React from 'react'
32

43
import Menu from 'src/collections/Menu/Menu'
54
import MenuItem from 'src/collections/Menu/MenuItem'
5+
import MenuHeader from 'src/collections/Menu/MenuHeader'
6+
import MenuMenu from 'src/collections/Menu/MenuMenu'
67
import * as common from 'test/specs/commonTests'
78

89
describe('Menu', () => {
910
common.isConformant(Menu)
1011
common.hasUIClassName(Menu)
12+
common.hasSubComponents(Menu, [MenuHeader, MenuItem, MenuMenu])
13+
14+
common.propKeyOnlyToClassName(Menu, 'compact')
15+
common.propKeyOnlyToClassName(Menu, 'inverted')
16+
common.propKeyOnlyToClassName(Menu, 'pointing')
17+
common.propKeyOnlyToClassName(Menu, 'secondary')
18+
common.propKeyOnlyToClassName(Menu, 'stackable')
19+
common.propKeyOnlyToClassName(Menu, 'vertical')
20+
1121
common.rendersChildren(Menu)
12-
common.hasSubComponents(Menu, [MenuItem])
1322

14-
describe('initial state', () => {
15-
it('inherits activeItem from props', () => {
16-
const activeItem = faker.hacker.noun()
17-
shallow(<Menu activeItem={activeItem} />)
18-
.should.have.state('activeItem', activeItem)
19-
})
23+
it('renders a `div` by default', () => {
24+
shallow(<Menu />)
25+
.should.have.tagName('div')
2026
})
2127
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import MenuHeader from 'src/collections/Menu/MenuHeader'
2+
import * as common from 'test/specs/commonTests'
3+
4+
describe('MenuHeader', () => {
5+
common.isConformant(MenuHeader)
6+
common.rendersChildren(MenuHeader)
7+
})
+10-25
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React from 'react'
22

3-
import Menu from 'src/collections/Menu/Menu'
43
import MenuItem from 'src/collections/Menu/MenuItem'
54
import * as common from 'test/specs/commonTests'
6-
import { sandbox } from 'test/utils/sandbox'
5+
import { sandbox } from 'test/utils'
76

87
describe('MenuItem', () => {
98
common.isConformant(MenuItem)
@@ -18,13 +17,6 @@ describe('MenuItem', () => {
1817
.should.have.tagName('div')
1918
})
2019

21-
describe('active', () => {
22-
it('is not by default', () => {
23-
shallow(<MenuItem name='item' />)
24-
.should.not.have.className('active')
25-
})
26-
})
27-
2820
describe('name', () => {
2921
it('uses the name prop as text', () => {
3022
shallow(<MenuItem name='This is an item' />)
@@ -33,28 +25,21 @@ describe('MenuItem', () => {
3325
})
3426

3527
describe('onClick', () => {
36-
it('is called when clicked', () => {
37-
const handleClick = sandbox.spy()
28+
it('is called with (e, { name, index }) when clicked', () => {
29+
const spy = sandbox.spy()
30+
const event = { target: null }
31+
const props = { name: 'home', index: 0 }
3832

39-
const wrapper = shallow(<MenuItem onClick={handleClick} />)
40-
wrapper.simulate('click')
33+
shallow(<MenuItem onClick={spy} {...props} />)
34+
.simulate('click', event)
4135

42-
handleClick.should.have.been.called()
36+
spy.should.have.been.calledOnce()
37+
spy.should.have.been.calledWithMatch(event, props)
4338
})
39+
4440
it('renders an `a` tag', () => {
4541
shallow(<MenuItem onClick={() => null} />)
4642
.should.have.tagName('a')
4743
})
48-
it('is called when the item is clicked', () => {
49-
const props = {
50-
onClick: sandbox.spy(),
51-
}
52-
53-
// mount to get click event to propagate on click
54-
mount(<MenuItem {...props} />)
55-
.simulate('click')
56-
57-
props.onClick.should.have.been.calledOnce()
58-
})
5944
})
6045
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import MenuMenu from 'src/collections/Menu/MenuMenu'
2+
import * as common from 'test/specs/commonTests'
3+
4+
describe('MenuMenu', () => {
5+
common.isConformant(MenuMenu)
6+
common.rendersChildren(MenuMenu)
7+
common.propValueOnlyToClassName(MenuMenu, 'position')
8+
})

0 commit comments

Comments
 (0)