Skip to content

Commit

Permalink
test(Examples): assert no console errors (#645)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
levithomason authored Dec 16, 2016
1 parent c7f5dc8 commit c7fc9d4
Show file tree
Hide file tree
Showing 36 changed files with 222 additions and 184 deletions.
2 changes: 1 addition & 1 deletion docs/app/Components/ComponentDoc/ComponentExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Babel from 'babel-standalone'
import _ from 'lodash'
import React, { Component, createElement, isValidElement, PropTypes } from 'react'
import { renderToStaticMarkup } from 'react-dom/server'
import html from 'html-beautify'
import { html } from 'js-beautify'
import copyToClipboard from 'copy-to-clipboard'

import { exampleContext, repoURL } from 'docs/app/utils'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const MenuExampleAttached = () => {
<Dropdown as={Menu.Item} icon='wrench' simple>
<Dropdown.Menu>
<Dropdown.Item>
<Icon name='dropdown icon' />
<Icon name='dropdown' />
<span className='text'>New</span>

<Dropdown.Menu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class MenuExampleTabularOnTop extends Component {
<Menu.Item name='photos' active={activeItem === 'photos'} onClick={this.handleItemClick} />
<Menu.Menu position='right'>
<Menu.Item>
<Input transparent icon={{ name: 'search', link: 'true' }} placeholder='Search users...' />
<Input transparent icon={{ name: 'search', link: true }} placeholder='Search users...' />
</Menu.Item>
</Menu.Menu>
</Menu>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import React from 'react'
import { Table } from 'semantic-ui-react'

const tableData = [
{ name: undefined, status: undefined, notes: undefined },
{ name: 'Jimmy', status: 'Requires Action', notes: undefined },
{ name: 'Jamie', status: undefined, notes: 'Hostile' },
{ name: 'Jill', status: undefined, notes: undefined },
]

const headerRow = [
'Name',
'Status',
Expand All @@ -20,17 +27,13 @@ const renderBodyRow = ({ name, status, notes }) => ({
],
})

const tableData = [
{ name: undefined, status: undefined, notes: undefined },
{ name: 'Jimmy', status: 'Requires Action', notes: undefined },
{ name: 'Jamie', status: undefined, notes: 'Hostile' },
{ name: 'Jill', status: undefined, notes: undefined },
]

const TableExampleWarningShorthand = () => {
return (
<Table celled headerRow={headerRow} renderBodyRow={renderBodyRow} tableData={tableData} />
)
}
const TableExampleWarningShorthand = () => (
<Table
celled
headerRow={headerRow}
renderBodyRow={renderBodyRow}
tableData={tableData}
/>
)

export default TableExampleWarningShorthand
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ButtonExampleToggle extends Component {

render() {
const { active } = this.state

return (
<Button toggle active={active} onClick={this.handleClick}>
Toggle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { List } from 'semantic-ui-react'
const ListExampleDescription = () => (
<List>
<List.Item>
<List.Icon name='map marker' />
<List.Icon name='marker' />
<List.Content>
<List.Header as='a'>Krowlewskie Jadlo</List.Header>
<List.Description>An excellent polish restaurant, quick delivery and hearty, filling meals.</List.Description>
</List.Content>
</List.Item>
<List.Item>
<List.Icon name='map marker' />
<List.Icon name='marker' />
<List.Content>
<List.Header as='a'>Xian Famous Foods</List.Header>
<List.Description>
Expand All @@ -20,14 +20,14 @@ const ListExampleDescription = () => (
</List.Content>
</List.Item>
<List.Item>
<List.Icon name='map marker' />
<List.Icon name='marker' />
<List.Content>
<List.Header as='a'>Sapporo Haru</List.Header>
<List.Description>Greenpoint's best choice for quick and delicious sushi.</List.Description>
</List.Content>
</List.Item>
<List.Item>
<List.Icon name='map marker' />
<List.Icon name='marker' />
<List.Content>
<List.Header as='a'>Enid's</List.Header>
<List.Description>At night a bar, during the day a delicious brunch spot.</List.Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const CardExampleContentBlock = () => (

<Feed.Event>
<Feed.Label image='http://semantic-ui.com/images/avatar/small/elliot.jpg' />
<Feed.Content date='4 days ago'>
<Feed.Content>
<Feed.Date content='4 days ago' />
<Feed.Summary>
You added <a>Elliot Baker</a> to your <a>musicians</a> group.
</Feed.Summary>
Expand Down
47 changes: 0 additions & 47 deletions docs/app/Examples/views/Feed/Content/FeedExampleDate.js

This file was deleted.

24 changes: 0 additions & 24 deletions docs/app/Examples/views/Feed/Content/FeedExampleDateShorthand.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const ItemExampleExtraContent = () => (
<Item.Header as='a'>Cute Dog</Item.Header>
<Item.Description>{paragraph}</Item.Description>
<Item.Extra>
<Icon name='green check' /> 121 Votes
<Icon color='green' name='check' /> 121 Votes
</Item.Extra>
</Item.Content>
</Item>
Expand Down
12 changes: 6 additions & 6 deletions docs/app/Views/Introduction.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ const Introduction = () => (
Semantic-UI-React is the official React integration for <a href={semanticUIDocsURL}>Semantic UI</a> .
</p>
<List>
<List.Item icon='check mark' content='jQuery Free' />
<List.Item icon='check mark' content='Declarative API' />
<List.Item icon='check mark' content='Augmentation' />
<List.Item icon='check mark' content='Shorthand Props' />
<List.Item icon='check mark' content='Sub Components' />
<List.Item icon='check mark' content='Auto Controlled State' />
<List.Item icon='mark' content='jQuery Free' />
<List.Item icon='mark' content='Declarative API' />
<List.Item icon='mark' content='Augmentation' />
<List.Item icon='mark' content='Shorthand Props' />
<List.Item icon='mark' content='Sub Components' />
<List.Item icon='mark' content='Auto Controlled State' />
</List>
<p>
Installation instructions are provided in the <Link to='/usage'>Usage</Link> section.
Expand Down
2 changes: 1 addition & 1 deletion docs/app/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const parentComponents = _.flow(
/**
* Get the Webpack Context for all doc site examples.
*/
export const exampleContext = require.context('docs/app/Examples/', true, /\.js$/)
export const exampleContext = require.context('docs/app/Examples/', true, /(\w+Example\w+|index)\.js$/)

export const repoURL = 'https://github.com/Semantic-Org/Semantic-UI-React'
export const semanticUIDocsURL = 'http://semantic-ui.com/'
Expand Down
2 changes: 1 addition & 1 deletion src/collections/Breadcrumb/BreadcrumbSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ export default class BreadcrumbSection extends Component {
}
}

BreadcrumbSection.create = createShorthandFactory(BreadcrumbSection, content => ({ content, link: true }))
BreadcrumbSection.create = createShorthandFactory(BreadcrumbSection, content => ({ content, link: true }), true)
14 changes: 5 additions & 9 deletions src/collections/Menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React, { PropTypes } from 'react'

import {
AutoControlledComponent as Component,
createShorthand,
customPropTypes,
getElementType,
getUnhandledProps,
Expand Down Expand Up @@ -159,14 +158,11 @@ class Menu extends Component {
const { items } = this.props
const { activeIndex } = this.state

return _.map(items, (item, index) => {
return createShorthand(MenuItem, val => ({ content: val, name: val }), item, {
active: activeIndex === index,
childKey: ({ content, name }) => [content, name].join('-'),
index,
onClick: this.handleItemClick,
})
})
return _.map(items, (item, index) => MenuItem.create(item, {
active: activeIndex === index,
index,
onClick: this.handleItemClick,
}))
}

render() {
Expand Down
3 changes: 3 additions & 0 deletions src/collections/Menu/MenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import cx from 'classnames'
import React, { Component, PropTypes } from 'react'

import {
createShorthandFactory,
customPropTypes,
getElementType,
getUnhandledProps,
Expand Down Expand Up @@ -133,3 +134,5 @@ export default class MenuItem extends Component {
)
}
}

MenuItem.create = createShorthandFactory(MenuItem, val => ({ content: val, name: val }), true)
6 changes: 3 additions & 3 deletions src/collections/Message/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ function Message(props) {
{Icon.create(icon)}
{(header || content || list) && (
<MessageContent>
{createShorthand(MessageHeader, val => ({ children: val }), header)}
{createShorthand(MessageList, val => ({ items: val }), list)}
{MessageHeader.create(header)}
{MessageList.create(list)}
{createShorthand('p', val => ({ children: val }), content)}
</MessageContent>
)}
Expand Down Expand Up @@ -127,7 +127,7 @@ Message.propTypes = {
customPropTypes.itemShorthand,
]),

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

/**
Expand Down
10 changes: 8 additions & 2 deletions src/collections/Message/MessageHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ import cx from 'classnames'
import React, { PropTypes } from 'react'

import {
createShorthandFactory,
customPropTypes,
getElementType,
getUnhandledProps,
META,
} from '../../lib'

function MessageHeader(props) {
const { children, className } = props
const { children, className, content } = props
const classes = cx('header', className)
const rest = getUnhandledProps(MessageHeader, props)
const ElementType = getElementType(MessageHeader, props)

return <ElementType {...rest} className={classes}>{children}</ElementType>
return <ElementType {...rest} className={classes}>{children || content}</ElementType>
}

MessageHeader._meta = {
Expand All @@ -30,8 +31,13 @@ MessageHeader.propTypes = {
/** Primary content. */
children: PropTypes.node,

/** Shorthand for primary content. */
content: customPropTypes.itemShorthand,

/** Additional classes. */
className: PropTypes.string,
}

MessageHeader.create = createShorthandFactory(MessageHeader, val => ({ content: val }))

export default MessageHeader
10 changes: 8 additions & 2 deletions src/collections/Message/MessageItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ import cx from 'classnames'
import React, { PropTypes } from 'react'

import {
createShorthandFactory,
customPropTypes,
getElementType,
getUnhandledProps,
META,
} from '../../lib'

function MessageItem(props) {
const { children, className } = props
const { children, className, content } = props
const classes = cx('content', className)
const rest = getUnhandledProps(MessageItem, props)
const ElementType = getElementType(MessageItem, props)

return <ElementType {...rest} className={classes}>{children}</ElementType>
return <ElementType {...rest} className={classes}>{content || children}</ElementType>
}

MessageItem._meta = {
Expand All @@ -30,6 +31,9 @@ MessageItem.propTypes = {
/** Primary content. */
children: PropTypes.node,

/** Shorthand for primary content. */
content: customPropTypes.itemShorthand,

/** Additional classes. */
className: PropTypes.string,
}
Expand All @@ -38,4 +42,6 @@ MessageItem.defaultProps = {
as: 'li',
}

MessageItem.create = createShorthandFactory(MessageItem, content => ({ content }), true)

export default MessageItem
Loading

0 comments on commit c7fc9d4

Please sign in to comment.