diff --git a/client/src/core-components/__tests__/menu-test.js b/client/src/core-components/__tests__/menu-test.js new file mode 100644 index 00000000..b02961cb --- /dev/null +++ b/client/src/core-components/__tests__/menu-test.js @@ -0,0 +1,66 @@ +// LIBS +const _ = require('lodash'); + +// MOCKS +const Icon = ReactMock(); + +// COMPONENTS +const Menu = requireUnit('core-components/menu', { + 'core-components/icon': Icon +}); + +describe('Menu component', function () { + let menu, items, icons; + + function renderMenu(props) { + let defaultProps = { + items: [ + {content: 'First Item', icon: 'ICON_1'}, + {content: 'Second Item', icon: 'ICON_2'}, + {content: 'Third Item', icon: 'ICON_3'}, + {content: 'Fourth Item', icon: 'ICON_4'} + ] + }; + + + menu = TestUtils.renderIntoDocument( +
+ ); + items = TestUtils.scryRenderedDOMComponentsWithTag(menu, 'li'); + icons = TestUtils.scryRenderedComponentsWithType(menu, Icon); + } + + it('should render items with icons', function () { + renderMenu({ + items: [ + {content: 'First Item', icon: 'ICON_1'}, + {content: 'Second Item', icon: 'ICON_2'}, + {content: 'Third Item', icon: 'ICON_3'}, + {content: 'Fourth Item', icon: 'ICON_4'} + ] + }); + + expect(items.length).to.equal(4); + expect(items[0].textContent).to.equal('First Item'); + expect(items[1].textContent).to.equal('Second Item'); + expect(items[2].textContent).to.equal('Third Item'); + expect(items[3].textContent).to.equal('Fourth Item'); + + items.forEach((item, index) => { + expect(item.className).to.contain('menu__list-item'); + expect(item.childNodes[0]).to.equal(ReactDOM.findDOMNode(icons[index])); + }); + }); + + it('should add custom class if passsed', function () { + + }); + + it('should add selected class to selected index', function () { + + }); + + it('should call onItemClick if an item is clicked', function () { + + }) +}); diff --git a/client/src/core-components/menu.js b/client/src/core-components/menu.js index 3b144174..22a86606 100644 --- a/client/src/core-components/menu.js +++ b/client/src/core-components/menu.js @@ -31,27 +31,19 @@ const Menu = React.createClass({ }, renderListItem(item, index) { + let iconNode = null; + + if (item.icon) { + iconNode =