Skip to content

Commit 0e8c299

Browse files
committed
update menu test
1 parent e9ede28 commit 0e8c299

2 files changed

Lines changed: 70 additions & 60 deletions

File tree

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,73 @@
1-
import _ from 'lodash';
1+
import faker from 'faker';
22
import React from 'react';
33
import {Simulate} from 'react-addons-test-utils';
44
import {Menu, MenuItem} from 'stardust';
55

6+
let string;
67
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();
2110
});
22-
});
2311

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);
5116
});
5217

53-
it('should have active class after click', () => {
54-
const renderedMenuItems = render(
55-
<Menu>
56-
<MenuItem name='item1' className='firstItem' />
57-
<MenuItem name='item2' className='secondItem'/>
58-
</Menu>
59-
);
60-
const firstItem = renderedMenuItems.findClass('firstItem');
61-
const secondItem = renderedMenuItems.findClass('secondItem');
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+
});
6672
});
6773
});

test/specs/collections/Message/Message-test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ describe('Message', () => {
1515
});
1616
describe('without header', () => {
1717
it('has no header', () => {
18-
render(<Message />).scryClass('sd-message-header')
18+
render(<Message />)
19+
.scryClass('sd-message-header')
1920
.should.have.a.lengthOf(0);
2021
});
2122
});
@@ -29,11 +30,13 @@ describe('Message', () => {
2930
});
3031
describe('without icon', () => {
3132
it('has no icon', () => {
32-
render(<Message />).scryClass('sd-message-icon')
33+
render(<Message />)
34+
.scryClass('sd-message-icon')
3335
.should.have.a.lengthOf(0);
3436
});
3537
it('has no "content" wrapper', () => {
36-
render(<Message />).scryClass('sd-message-content')
38+
render(<Message />)
39+
.scryClass('sd-message-content')
3740
.should.have.a.lengthOf(0);
3841
});
3942
});
@@ -54,7 +57,8 @@ describe('Message', () => {
5457
});
5558
describe('not dismissable', () => {
5659
it('has no close icon', () => {
57-
render(<Message />).scryClass('sd-message-close-icon')
60+
render(<Message />)
61+
.scryClass('sd-message-close-icon')
5862
.should.have.a.lengthOf(0);
5963
});
6064
});

0 commit comments

Comments
 (0)