Skip to content

Commit f887fa4

Browse files
committed
Merge pull request #90 from TechnologyAdvice/feature/fix-test-warnings
Fix test warnings
2 parents 9ddf8f4 + 2efc3c1 commit f887fa4

17 files changed

Lines changed: 161 additions & 235 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
_builds/
77
_projects/
88
_steps/
9-
npm-debug.log
9+
npm-debug.log*
1010
node_modules/
1111
bower_components/
1212
testBundle.js

src/collections/Menu/Menu.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, {Component, PropTypes} from 'react';
22
import classNames from 'classnames';
33
import META from 'src/utils/Meta';
4+
import getUnhandledProps from 'src/utils/getUnhandledProps';
45

56
export default class Menu extends Component {
67
static propTypes = {
@@ -38,8 +39,9 @@ export default class Menu extends Component {
3839
callbackParent: this.handleClickItem,
3940
});
4041
});
42+
const props = getUnhandledProps(this);
4143
return (
42-
<div {...this.props} className={classes}>
44+
<div {...props} className={classes}>
4345
{children}
4446
</div>
4547
);

src/collections/Table/Table.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default class Table extends Component {
1919
}
2020
},
2121
className: PropTypes.string,
22-
data: PropTypes.array.isRequired,
22+
data: PropTypes.array,
2323
};
2424

2525
static getSafeCellContents(content) {

test/specs/Conformance-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const getSDClassName = componentName => `sd-${_.kebabCase(componentName)}`;
1212
*/
1313
describe('Conformance', () => {
1414
/* eslint-disable no-console */
15-
console.info('Conformance-test renders all components with no props, warnings may occur.');
15+
console.info('Conformance-test renders each component with no props, required prop warnings may occur.');
1616
/* eslint-enable no-console */
1717
_.each(stardust, (SDComponent, name) => {
1818
const classes = faker.fake('{{hacker.noun}} {{hacker.noun}} {{hacker.noun}}');

test/specs/addons/Textarea-test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ describe('Textarea', () => {
55
it('has a default value', () => {
66
render(<Textarea defaultValue='Hello World' />)
77
.findTag('textarea')
8-
.getDOMNode()
98
.value.should.equal('Hello World');
109
});
1110
it('has a name assigned', () => {
12-
const renderedTextarea = render(<Textarea name='sample-post' />);
13-
expect(renderedTextarea.first().props.name).to.equal('sample-post');
11+
render(<Textarea name='sample-post' />)
12+
.first()
13+
.props.name.should.equal('sample-post');
1414
});
1515
it('has assigned amount of rows', () => {
16-
const renderedTextarea = render(<Textarea rows='6' />);
17-
expect(renderedTextarea.findTag('textarea').props.rows).to.equal('6');
16+
render(<Textarea rows='6' />)
17+
.findTag('textarea')
18+
.getAttribute('rows')
19+
.should.equal('6');
1820
});
1921
});

test/specs/collections/Form/Field-test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ describe('Field', () => {
77
it('has a label', () => {
88
render(<Field label='First Name' />)
99
.findTag('label')
10-
.props.children.should.equal('First Name');
10+
.textContent.should.equal('First Name');
1111
});
1212

1313
it('renders children', () => {
14-
render(<Field label='First Name'>yo child</Field>)
15-
.findText('yo child');
14+
render(<Field>yo child</Field>).assertText('yo child');
1615
});
1716

1817
it('can specify a width', () => {
1918
_.each(_.range(1, 17), n => {
20-
const classes = numberToWord(n) + ' wide';
21-
render(<Field width={n} />).findClass(classes);
19+
render(<Field width={n} />).findClass(`${numberToWord(n)} wide`);
2220
});
2321
});
2422
});

test/specs/collections/Form/Fields-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ describe('Fields', () => {
1616
it('renders children', () => {
1717
const child = faker.hacker.phrase();
1818
render(<Fields>{child}</Fields>)
19-
.findText(child);
19+
.assertText(child);
2020
});
2121
});
Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,9 @@
1-
import _ from 'lodash';
21
import React from 'react';
3-
import faker from 'faker';
42
import {Grid} from 'stardust';
53

64
describe('Grid', () => {
7-
it('is an sd-grid', () => {
8-
const gridClassName = render(<Grid />).findClass('sd-grid').props.className;
9-
gridClassName.should.contain('sd-grid');
10-
const nodeClass = render(<Grid />).findClass('sd-grid').getDOMNode().getAttribute('class');
11-
nodeClass.should.contain('sd-grid');
12-
});
13-
14-
it('inherits classes', () => {
15-
// generate crap classes like "system firewall protocol"
16-
const classes = _.times(_.random(3), faker.hacker.noun).join(' ');
17-
18-
const renderedGridClasses = render(<Grid className={classes} />)
19-
.findClass('sd-grid')
20-
.getDOMNode()
21-
.getAttribute('class');
22-
renderedGridClasses.should.contain(classes);
23-
});
24-
25-
it('inherits style', () => {
26-
const style = {display: 'block'};
27-
render(<Grid style={style} />).findClass('sd-grid').props.style.should.deep.equal(style);
28-
});
29-
305
it('renders its children', () => {
31-
render(<Grid><br /></Grid>).findClass('sd-grid').props.children.type.should.equal('br');
32-
});
33-
34-
it('text example', () => {
35-
render(
36-
<Grid>
37-
root
38-
<div>div1</div>
39-
<div>div2</div>
40-
after
41-
<div className='nested'>
42-
child div
43-
<div>nested child div</div>
44-
</div>
45-
</Grid>
46-
)
47-
.findText('root');
6+
render(<Grid>check it out</Grid>)
7+
.assertText('check it out');
488
});
499
});
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' />
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+
});
6672
});
6773
});

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ describe('Message', () => {
1010
const message = render(<Message header={header} />);
1111

1212
message.findClass('sd-message-header');
13-
message.findText(header);
13+
message.assertText(header);
1414
});
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)