Skip to content

Commit c7fc9d4

Browse files
authored
test(Examples): assert no console errors (#645)
* test(Examples): assert no console errors * docs(Feed): remove unused examples * docs(Card): fix Feed.Content date usage * docs(Menu): fix Input icon shorthand * test(Examples): assert no console errors on mount * wip shorthand collection keys * fix(Header): remove unused import * fix(Image-test): update implementsShorthandProp name * fix(Table): restore tableData mapping logic * refactor(Table): fix doc block * refactor(factories): use arrow func over _.partial * refactor(factories): merge item/collection factories * fix(customPropTypes): allow array in itemShorthand * refactor(factories): cleanup cruft * fix(getUnhandledProps): always handle childKey * refactor(commonTests): implementsShorthandItemProp -> implementsShorthandProp * test(examples): assert no console messages * fix(docs|src): fix all example errors * fix(Introduction): fix icon name * fix(Menu): add MenuItem.create() and generateKey * fix(MessageList): add MessageItem.create() and generateKey * fix(Message): add Header.create() and List.create() * refactor(factories): one line if * fix(Menu): removed unused import * chore(karma): fix html-beautify module error * refactor(factories): do not hash prop keys * test(Menu): fix menu test * test(Message): fix message test * chore(webpack): remove unused html-beautify external
1 parent c7f5dc8 commit c7fc9d4

36 files changed

+222
-184
lines changed

docs/app/Components/ComponentDoc/ComponentExample.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as Babel from 'babel-standalone'
22
import _ from 'lodash'
33
import React, { Component, createElement, isValidElement, PropTypes } from 'react'
44
import { renderToStaticMarkup } from 'react-dom/server'
5-
import html from 'html-beautify'
5+
import { html } from 'js-beautify'
66
import copyToClipboard from 'copy-to-clipboard'
77

88
import { exampleContext, repoURL } from 'docs/app/utils'

docs/app/Examples/collections/Menu/Types/MenuExampleAttached.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const MenuExampleAttached = () => {
1010
<Dropdown as={Menu.Item} icon='wrench' simple>
1111
<Dropdown.Menu>
1212
<Dropdown.Item>
13-
<Icon name='dropdown icon' />
13+
<Icon name='dropdown' />
1414
<span className='text'>New</span>
1515

1616
<Dropdown.Menu>

docs/app/Examples/collections/Menu/Types/MenuExampleTabularOnTop.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class MenuExampleTabularOnTop extends Component {
1616
<Menu.Item name='photos' active={activeItem === 'photos'} onClick={this.handleItemClick} />
1717
<Menu.Menu position='right'>
1818
<Menu.Item>
19-
<Input transparent icon={{ name: 'search', link: 'true' }} placeholder='Search users...' />
19+
<Input transparent icon={{ name: 'search', link: true }} placeholder='Search users...' />
2020
</Menu.Item>
2121
</Menu.Menu>
2222
</Menu>
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import React from 'react'
22
import { Table } from 'semantic-ui-react'
33

4+
const tableData = [
5+
{ name: undefined, status: undefined, notes: undefined },
6+
{ name: 'Jimmy', status: 'Requires Action', notes: undefined },
7+
{ name: 'Jamie', status: undefined, notes: 'Hostile' },
8+
{ name: 'Jill', status: undefined, notes: undefined },
9+
]
10+
411
const headerRow = [
512
'Name',
613
'Status',
@@ -20,17 +27,13 @@ const renderBodyRow = ({ name, status, notes }) => ({
2027
],
2128
})
2229

23-
const tableData = [
24-
{ name: undefined, status: undefined, notes: undefined },
25-
{ name: 'Jimmy', status: 'Requires Action', notes: undefined },
26-
{ name: 'Jamie', status: undefined, notes: 'Hostile' },
27-
{ name: 'Jill', status: undefined, notes: undefined },
28-
]
29-
30-
const TableExampleWarningShorthand = () => {
31-
return (
32-
<Table celled headerRow={headerRow} renderBodyRow={renderBodyRow} tableData={tableData} />
33-
)
34-
}
30+
const TableExampleWarningShorthand = () => (
31+
<Table
32+
celled
33+
headerRow={headerRow}
34+
renderBodyRow={renderBodyRow}
35+
tableData={tableData}
36+
/>
37+
)
3538

3639
export default TableExampleWarningShorthand

docs/app/Examples/elements/Button/Variations/ButtonExampleToggle.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class ButtonExampleToggle extends Component {
88

99
render() {
1010
const { active } = this.state
11+
1112
return (
1213
<Button toggle active={active} onClick={this.handleClick}>
1314
Toggle

docs/app/Examples/elements/List/Content/ListExampleDescription.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import { List } from 'semantic-ui-react'
44
const ListExampleDescription = () => (
55
<List>
66
<List.Item>
7-
<List.Icon name='map marker' />
7+
<List.Icon name='marker' />
88
<List.Content>
99
<List.Header as='a'>Krowlewskie Jadlo</List.Header>
1010
<List.Description>An excellent polish restaurant, quick delivery and hearty, filling meals.</List.Description>
1111
</List.Content>
1212
</List.Item>
1313
<List.Item>
14-
<List.Icon name='map marker' />
14+
<List.Icon name='marker' />
1515
<List.Content>
1616
<List.Header as='a'>Xian Famous Foods</List.Header>
1717
<List.Description>
@@ -20,14 +20,14 @@ const ListExampleDescription = () => (
2020
</List.Content>
2121
</List.Item>
2222
<List.Item>
23-
<List.Icon name='map marker' />
23+
<List.Icon name='marker' />
2424
<List.Content>
2525
<List.Header as='a'>Sapporo Haru</List.Header>
2626
<List.Description>Greenpoint's best choice for quick and delicious sushi.</List.Description>
2727
</List.Content>
2828
</List.Item>
2929
<List.Item>
30-
<List.Icon name='map marker' />
30+
<List.Icon name='marker' />
3131
<List.Content>
3232
<List.Header as='a'>Enid's</List.Header>
3333
<List.Description>At night a bar, during the day a delicious brunch spot.</List.Description>

docs/app/Examples/views/Card/Content/CardExampleContentBlock.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const CardExampleContentBlock = () => (
3232

3333
<Feed.Event>
3434
<Feed.Label image='http://semantic-ui.com/images/avatar/small/elliot.jpg' />
35-
<Feed.Content date='4 days ago'>
35+
<Feed.Content>
36+
<Feed.Date content='4 days ago' />
3637
<Feed.Summary>
3738
You added <a>Elliot Baker</a> to your <a>musicians</a> group.
3839
</Feed.Summary>

docs/app/Examples/views/Feed/Content/FeedExampleDate.js

-47
This file was deleted.

docs/app/Examples/views/Feed/Content/FeedExampleDateShorthand.js

-24
This file was deleted.

docs/app/Examples/views/Item/Content/ItemExampleExtraContent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const ItemExampleExtraContent = () => (
1212
<Item.Header as='a'>Cute Dog</Item.Header>
1313
<Item.Description>{paragraph}</Item.Description>
1414
<Item.Extra>
15-
<Icon name='green check' /> 121 Votes
15+
<Icon color='green' name='check' /> 121 Votes
1616
</Item.Extra>
1717
</Item.Content>
1818
</Item>

docs/app/Views/Introduction.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ const Introduction = () => (
156156
Semantic-UI-React is the official React integration for <a href={semanticUIDocsURL}>Semantic UI</a> .
157157
</p>
158158
<List>
159-
<List.Item icon='check mark' content='jQuery Free' />
160-
<List.Item icon='check mark' content='Declarative API' />
161-
<List.Item icon='check mark' content='Augmentation' />
162-
<List.Item icon='check mark' content='Shorthand Props' />
163-
<List.Item icon='check mark' content='Sub Components' />
164-
<List.Item icon='check mark' content='Auto Controlled State' />
159+
<List.Item icon='mark' content='jQuery Free' />
160+
<List.Item icon='mark' content='Declarative API' />
161+
<List.Item icon='mark' content='Augmentation' />
162+
<List.Item icon='mark' content='Shorthand Props' />
163+
<List.Item icon='mark' content='Sub Components' />
164+
<List.Item icon='mark' content='Auto Controlled State' />
165165
</List>
166166
<p>
167167
Installation instructions are provided in the <Link to='/usage'>Usage</Link> section.

docs/app/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const parentComponents = _.flow(
1818
/**
1919
* Get the Webpack Context for all doc site examples.
2020
*/
21-
export const exampleContext = require.context('docs/app/Examples/', true, /\.js$/)
21+
export const exampleContext = require.context('docs/app/Examples/', true, /(\w+Example\w+|index)\.js$/)
2222

2323
export const repoURL = 'https://github.com/Semantic-Org/Semantic-UI-React'
2424
export const semanticUIDocsURL = 'http://semantic-ui.com/'

src/collections/Breadcrumb/BreadcrumbSection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ export default class BreadcrumbSection extends Component {
9393
}
9494
}
9595

96-
BreadcrumbSection.create = createShorthandFactory(BreadcrumbSection, content => ({ content, link: true }))
96+
BreadcrumbSection.create = createShorthandFactory(BreadcrumbSection, content => ({ content, link: true }), true)

src/collections/Menu/Menu.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import React, { PropTypes } from 'react'
44

55
import {
66
AutoControlledComponent as Component,
7-
createShorthand,
87
customPropTypes,
98
getElementType,
109
getUnhandledProps,
@@ -159,14 +158,11 @@ class Menu extends Component {
159158
const { items } = this.props
160159
const { activeIndex } = this.state
161160

162-
return _.map(items, (item, index) => {
163-
return createShorthand(MenuItem, val => ({ content: val, name: val }), item, {
164-
active: activeIndex === index,
165-
childKey: ({ content, name }) => [content, name].join('-'),
166-
index,
167-
onClick: this.handleItemClick,
168-
})
169-
})
161+
return _.map(items, (item, index) => MenuItem.create(item, {
162+
active: activeIndex === index,
163+
index,
164+
onClick: this.handleItemClick,
165+
}))
170166
}
171167

172168
render() {

src/collections/Menu/MenuItem.js

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import cx from 'classnames'
33
import React, { Component, PropTypes } from 'react'
44

55
import {
6+
createShorthandFactory,
67
customPropTypes,
78
getElementType,
89
getUnhandledProps,
@@ -133,3 +134,5 @@ export default class MenuItem extends Component {
133134
)
134135
}
135136
}
137+
138+
MenuItem.create = createShorthandFactory(MenuItem, val => ({ content: val, name: val }), true)

src/collections/Message/Message.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ function Message(props) {
8686
{Icon.create(icon)}
8787
{(header || content || list) && (
8888
<MessageContent>
89-
{createShorthand(MessageHeader, val => ({ children: val }), header)}
90-
{createShorthand(MessageList, val => ({ items: val }), list)}
89+
{MessageHeader.create(header)}
90+
{MessageList.create(list)}
9191
{createShorthand('p', val => ({ children: val }), content)}
9292
</MessageContent>
9393
)}
@@ -127,7 +127,7 @@ Message.propTypes = {
127127
customPropTypes.itemShorthand,
128128
]),
129129

130-
/** Array of string items for the MessageList. Mutually exclusive with children. */
130+
/** Array shorthand items for the MessageList. Mutually exclusive with children. */
131131
list: customPropTypes.collectionShorthand,
132132

133133
/**

src/collections/Message/MessageHeader.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ import cx from 'classnames'
22
import React, { PropTypes } from 'react'
33

44
import {
5+
createShorthandFactory,
56
customPropTypes,
67
getElementType,
78
getUnhandledProps,
89
META,
910
} from '../../lib'
1011

1112
function MessageHeader(props) {
12-
const { children, className } = props
13+
const { children, className, content } = props
1314
const classes = cx('header', className)
1415
const rest = getUnhandledProps(MessageHeader, props)
1516
const ElementType = getElementType(MessageHeader, props)
1617

17-
return <ElementType {...rest} className={classes}>{children}</ElementType>
18+
return <ElementType {...rest} className={classes}>{children || content}</ElementType>
1819
}
1920

2021
MessageHeader._meta = {
@@ -30,8 +31,13 @@ MessageHeader.propTypes = {
3031
/** Primary content. */
3132
children: PropTypes.node,
3233

34+
/** Shorthand for primary content. */
35+
content: customPropTypes.itemShorthand,
36+
3337
/** Additional classes. */
3438
className: PropTypes.string,
3539
}
3640

41+
MessageHeader.create = createShorthandFactory(MessageHeader, val => ({ content: val }))
42+
3743
export default MessageHeader

src/collections/Message/MessageItem.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ import cx from 'classnames'
22
import React, { PropTypes } from 'react'
33

44
import {
5+
createShorthandFactory,
56
customPropTypes,
67
getElementType,
78
getUnhandledProps,
89
META,
910
} from '../../lib'
1011

1112
function MessageItem(props) {
12-
const { children, className } = props
13+
const { children, className, content } = props
1314
const classes = cx('content', className)
1415
const rest = getUnhandledProps(MessageItem, props)
1516
const ElementType = getElementType(MessageItem, props)
1617

17-
return <ElementType {...rest} className={classes}>{children}</ElementType>
18+
return <ElementType {...rest} className={classes}>{content || children}</ElementType>
1819
}
1920

2021
MessageItem._meta = {
@@ -30,6 +31,9 @@ MessageItem.propTypes = {
3031
/** Primary content. */
3132
children: PropTypes.node,
3233

34+
/** Shorthand for primary content. */
35+
content: customPropTypes.itemShorthand,
36+
3337
/** Additional classes. */
3438
className: PropTypes.string,
3539
}
@@ -38,4 +42,6 @@ MessageItem.defaultProps = {
3842
as: 'li',
3943
}
4044

45+
MessageItem.create = createShorthandFactory(MessageItem, content => ({ content }), true)
46+
4147
export default MessageItem

0 commit comments

Comments
 (0)