Skip to content

Commit

Permalink
fix(mixed): fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Fedyashov committed Aug 31, 2017
1 parent ddcd37d commit 4d5e272
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 36 deletions.
10 changes: 6 additions & 4 deletions src/elements/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ class Button extends Component {
static Or = ButtonOr

computeElementType = () => {
const { attached, label } = this.props
const { as, attached, label } = this.props

if (!_.isNil(attached) || !_.isNil(label)) return 'div'
return as
}

computeTabIndex = (ElementType) => {
Expand Down Expand Up @@ -251,8 +252,9 @@ class Button extends Component {
)

const rest = getUnhandledProps(Button, this.props)
const ElementType = getElementType(Button, this.props, this.computeElementType)
const tabIndex = this.computeTabIndex(ElementType)
const computedType = this.computeElementType()
const ElementType = getElementType(Button, this.props, computedType)
const tabIndex = this.computeTabIndex(computedType)

if (!_.isNil(label)) {
const buttonClasses = cx('ui', baseClasses, 'button', className)
Expand Down Expand Up @@ -280,7 +282,7 @@ class Button extends Component {
<ElementType
{...rest}
className={classes}
disabled={(disabled && ElementType === 'button') || undefined}
disabled={(disabled && computedType === 'button') || undefined}
innerRef={this.handleRef}
onClick={this.handleClick}
role='button'
Expand Down
4 changes: 1 addition & 3 deletions src/elements/Image/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ function Image(props) {
)
const rest = getUnhandledProps(Image, props)
const wrappedImage = !_.isNil(dimmer) || !_.isNil(label) || !_.isNil(wrapped) || !childrenUtils.isNil(children)
const ElementType = getElementType(Image, props, () => {
if (wrappedImage) return 'div'
})
const ElementType = getElementType(Image, props, wrappedImage && 'div')

if (!childrenUtils.isNil(children)) {
return <ElementType {...rest} className={classes}>{children}</ElementType>
Expand Down
2 changes: 1 addition & 1 deletion src/elements/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ class Input extends Component {
return [{
...htmlInputProps,
disabled,
type,
tabIndex,
type,
onChange: this.handleChange,
ref: this.handleInputRef,
}, rest]
Expand Down
7 changes: 4 additions & 3 deletions src/elements/List/ListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class ListItem extends Component {
render() {
const {
active,
as,
children,
className,
content,
Expand All @@ -106,15 +107,15 @@ class ListItem extends Component {
value,
} = this.props

const ElementType = getElementType(ListItem, this.props)
const classes = cx(
useKeyOnly(active, 'active'),
useKeyOnly(disabled, 'disabled'),
useKeyOnly(ElementType !== 'li', 'item'),
useKeyOnly(as !== 'li', 'item'),
className,
)
const rest = getUnhandledProps(ListItem, this.props)
const valueProp = ElementType === 'li' ? { value } : { 'data-value': value }
const ElementType = getElementType(ListItem, this.props)
const valueProp = as === 'li' ? { value } : { 'data-value': value }

if (!childrenUtils.isNil(children)) {
return (
Expand Down
8 changes: 4 additions & 4 deletions src/elements/List/ListList.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import {
* A list can contain a sub list.
*/
function ListList(props) {
const { children, className } = props
const { as, children, className } = props

const rest = getUnhandledProps(ListList, props)
const ElementType = getElementType(ListList, props)
const classes = cx(
useKeyOnly(ElementType !== 'ul' && ElementType !== 'ol', 'list'),
useKeyOnly(as !== 'ul' && as !== 'ol', 'list'),
className,
)
const rest = getUnhandledProps(ListList, props)
const ElementType = getElementType(ListList, props)

return <ElementType {...rest} className={classes}>{children}</ElementType>
}
Expand Down
29 changes: 8 additions & 21 deletions test/specs/elements/Input/Input-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash'
import React from 'react'

import Input from 'src/elements/Input/Input'
Expand Down Expand Up @@ -105,37 +106,23 @@ describe('Input', () => {
})

describe('input props', () => {
htmlInputProps.forEach((propName) => {
it(`passes \`${propName}\` to the <input>`, () => {
const propValue = propName === 'onChange' ? () => null : 'foo'
const wrapper = shallow(<Input {...{ [propName]: propValue }} />)

// account for overloading the onChange prop
const expectedValue = propName === 'onChange'
? wrapper.instance().handleChange
: propValue
const propValue = () => null

wrapper
_.without('onChange', htmlInputProps).forEach((propName) => {
it(`passes \`${propName}\` to the <input>`, () => {
shallow(<Input {...{ [propName]: propValue }} />)
.find('input')
.should.have.prop(propName, expectedValue)
.should.have.prop(propName, propValue)
})

it(`passes \`${propName}\` to the <input> when using children`, () => {
const propValue = propName === 'onChange' ? () => null : 'foo'
const wrapper = shallow(
shallow(
<Input {...{ [propName]: propValue }}>
<input />
</Input>,
)

// account for overloading the onChange prop
const expectedValue = propName === 'onChange'
? wrapper.instance().handleChange
: propValue

wrapper
.find('input')
.should.have.prop(propName, expectedValue)
.should.have.prop(propName, propValue)
})
})
})
Expand Down

0 comments on commit 4d5e272

Please sign in to comment.