-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
71 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
|
||
let { Component, PropTypes } = React; | ||
|
||
export default class MenuItem extends Component { | ||
|
||
static propTypes = { | ||
item: PropTypes.object.isRequired | ||
}; | ||
|
||
render() { | ||
return ( | ||
<li key={'menu-item-' + this.props.item.id}>{this.props.item.label}</li> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react/addons'; | ||
import { expect } from 'chai'; | ||
|
||
import Menu from '../Menu.jsx'; | ||
import MenuItem from '../MenuItem.jsx'; | ||
|
||
// Here we create a mocked MenuItem component. | ||
class MockedMenuItem extends MenuItem { | ||
render() { | ||
return ( | ||
<li className={'mocked-menu-item'}>{this.props.item.label}</li> | ||
); | ||
} | ||
} | ||
|
||
// Here we set the mocked MenuItem component. | ||
Menu.__Rewire__('MenuItem', MockedMenuItem); | ||
|
||
describe('Menu', () => { | ||
|
||
let { TestUtils } = React.addons; | ||
|
||
let menuItems = [ | ||
{ id: 1, label: 'Option 1' }, | ||
{ id: 2, label: 'Option 2' } | ||
]; | ||
|
||
let menu = TestUtils.renderIntoDocument( | ||
<Menu items={menuItems} /> | ||
); | ||
let menuElem = React.findDOMNode(menu); | ||
|
||
it('Should render the menu items', () => { | ||
expect(menuElem.querySelectorAll('li').length).to.equal(2); | ||
expect(menuElem.querySelectorAll('li')[0].textContent.trim()).to.equal(menuItems[0].label); | ||
expect(menuElem.querySelectorAll('li')[1].textContent.trim()).to.equal(menuItems[1].label); | ||
}); | ||
|
||
it('Should render the mocked menu item', () => { | ||
expect(menuElem.querySelectorAll('li')[0].className).to.equal('mocked-menu-item'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters