|
1 | | -import _ from 'lodash'; |
| 1 | +import faker from 'faker'; |
2 | 2 | import React from 'react'; |
3 | 3 | import {Simulate} from 'react-addons-test-utils'; |
4 | 4 | import {Menu, MenuItem} from 'stardust'; |
5 | 5 |
|
| 6 | +let string; |
6 | 7 | describe('Menu', () => { |
7 | | - it('should render children', () => { |
8 | | - const renderedMenu = render( |
9 | | - <Menu> |
10 | | - <span className='sd-test-span'>Hello</span> |
11 | | - </Menu> |
12 | | - ).findClass('sd-menu'); |
13 | | - renderedMenu.props.children.should.be.ok; |
14 | | - let childComponentClass; |
15 | | - React.Children.forEach(renderedMenu.props.children, (child, i) => { |
16 | | - if (i === 0) { |
17 | | - childComponentClass = child.props.className; |
18 | | - } |
19 | | - }); |
20 | | - childComponentClass.should.equal('sd-test-span'); |
| 8 | + beforeEach(() => { |
| 9 | + string = faker.hacker.phrase(); |
21 | 10 | }); |
22 | | -}); |
23 | 11 |
|
24 | | -describe('MenuItem', () => { |
25 | | - it('should have name property', () => { |
26 | | - const renderedMenuItem = render(<MenuItem name='This is an item' />).findClass('sd-menu-item'); |
27 | | - _.includes(renderedMenuItem.props.children, 'This is an item').should.be.true; |
28 | | - }); |
29 | | - it('should not have a label by default', () => { |
30 | | - const renderedMenuLabel = render(<MenuItem name='item' />).scryClass('sd-menu-label'); |
31 | | - _.isEmpty(renderedMenuLabel).should.be.true; |
32 | | - }); |
33 | | - it('should not have active class by default', () => { |
34 | | - const renderedMenuItem = render(<MenuItem name='item' />).scryClass('active'); |
35 | | - _.isEmpty(renderedMenuItem).should.be.true; |
36 | | - }); |
37 | | - it('should render a label if prop given', () => { |
38 | | - const renderedMenuLabel = render(<MenuItem name='item' label='37' />).findClass('sd-menu-label'); |
39 | | - renderedMenuLabel.should.be.ok; |
40 | | - renderedMenuLabel.props.children.should.equal('37'); |
41 | | - }); |
42 | | - it('should have active class if first child', () => { |
43 | | - const renderedMenuItems = render( |
44 | | - <Menu> |
45 | | - <MenuItem name='item1' /> |
46 | | - <MenuItem name='item2' /> |
47 | | - </Menu> |
48 | | - ).scryClass('sd-menu-item'); |
49 | | - _.first(renderedMenuItems).props.className.should.contain('active'); |
50 | | - _.last(renderedMenuItems).props.className.should.not.contain('active'); |
| 12 | + it('should render children', () => { |
| 13 | + // TODO: Menu does not render child text without a containing element |
| 14 | + render(<Menu><i>{string}</i></Menu>) |
| 15 | + .assertText(string); |
51 | 16 | }); |
52 | 17 |
|
53 | | - it('should have active class after click', () => { |
54 | | - const renderedMenuItems = render( |
55 | | - <Menu> |
56 | | - <MenuItem name='item1' /> |
57 | | - <MenuItem name='item2' /> |
58 | | - </Menu> |
59 | | - ); |
60 | | - const firstItem = renderedMenuItems.findText('item1'); |
61 | | - const secondItem = renderedMenuItems.findText('item2'); |
62 | | - const secondNode = secondItem.getDOMNode(); |
63 | | - Simulate.click(secondNode); |
64 | | - firstItem.props.className.should.not.contain('active'); |
65 | | - secondItem.props.className.should.contain('active'); |
| 18 | + describe('MenuItem', () => { |
| 19 | + it('uses the name prop as text', () => { |
| 20 | + render(<MenuItem name='This is an item' />) |
| 21 | + .assertText('This is an item'); |
| 22 | + }); |
| 23 | + it('should not have a label by default', () => { |
| 24 | + render(<MenuItem name='item' />) |
| 25 | + .scryClass('sd-menu-label') |
| 26 | + .should.have.length(0); |
| 27 | + }); |
| 28 | + it('should not have active class by default', () => { |
| 29 | + render(<MenuItem name='item' />) |
| 30 | + .scryClass('active') |
| 31 | + .should.have.length(0); |
| 32 | + }); |
| 33 | + it('should render a label if prop given', () => { |
| 34 | + render(<MenuItem name='item' label='37' />) |
| 35 | + .findClass('sd-menu-label') |
| 36 | + .textContent |
| 37 | + .should.equal('37'); |
| 38 | + }); |
| 39 | + it('should have active class if first child', () => { |
| 40 | + const [firstItem, secondItem] = render( |
| 41 | + <Menu> |
| 42 | + <MenuItem name='item1' /> |
| 43 | + <MenuItem name='item2' /> |
| 44 | + </Menu> |
| 45 | + ).scryClass('sd-menu-item'); |
| 46 | + |
| 47 | + firstItem |
| 48 | + .getAttribute('class') |
| 49 | + .should.contain('active'); |
| 50 | + secondItem |
| 51 | + .getAttribute('class') |
| 52 | + .should.not.contain('active'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should have active class after click', () => { |
| 56 | + const [firstItem, secondItem] = render( |
| 57 | + <Menu> |
| 58 | + <MenuItem name='item1' /> |
| 59 | + <MenuItem name='item2' /> |
| 60 | + </Menu> |
| 61 | + ).scryClass('sd-menu-item'); |
| 62 | + |
| 63 | + Simulate.click(secondItem); |
| 64 | + |
| 65 | + firstItem |
| 66 | + .getAttribute('class') |
| 67 | + .should.not.contain('active'); |
| 68 | + secondItem |
| 69 | + .getAttribute('class') |
| 70 | + .should.contain('active'); |
| 71 | + }); |
66 | 72 | }); |
67 | 73 | }); |
0 commit comments