Skip to content

Commit

Permalink
test(Dropdown): fix shorthand tests
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Feb 21, 2017
1 parent c35fe46 commit 7e4c956
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 63 deletions.
28 changes: 8 additions & 20 deletions src/modules/Dropdown/DropdownItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,33 +142,21 @@ export default class DropdownItem extends Component {
description,
props => ({ className: 'description' })
)

if (descriptionElement) {
const textElement = createShorthand(
'span',
val => ({ children: val }),
content || text,
props => ({ className: 'text' })
)
return (
<ElementType {...rest} {...ariaOptions} className={classes} onClick={this.handleClick}>
{imageElement}
{iconElement}
{flagElement}
{labelElement}
{descriptionElement}
{textElement}
</ElementType>
)
}
const textElement = createShorthand(
'span',
val => ({ children: val }),
content || text,
props => ({ className: 'text' })
)

return (
<ElementType {...rest} {...ariaOptions} className={classes} onClick={this.handleClick}>
{imageElement}
{iconElement}
{flagElement}
{labelElement}
{content || text}
{descriptionElement}
{textElement}
</ElementType>
)
}
Expand Down
2 changes: 1 addition & 1 deletion test/specs/elements/Image/Image-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SUI } from 'src/lib'
import Dimmer from 'src/modules/Dimmer/Dimmer'
import * as common from 'test/specs/commonTests'

describe('Image Component', () => {
describe('Image', () => {
common.isConformant(Image)
common.hasSubComponents(Image, [ImageGroup])
common.hasUIClassName(Image)
Expand Down
24 changes: 12 additions & 12 deletions test/specs/modules/Dropdown/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const dropdownMenuIsOpen = () => {

const nativeEvent = { nativeEvent: { stopImmediatePropagation: _.noop } }

describe('Dropdown Component', () => {
describe('Dropdown', () => {
beforeEach(() => {
attachTo = undefined
wrapper = undefined
Expand Down Expand Up @@ -769,12 +769,12 @@ describe('Dropdown Component', () => {
const nextItem = _.sample(_.without(options, initialItem))

wrapperMount(<Dropdown options={options} selection value={initialItem.value} />)
.find('.text')
.find('div.text')
.should.contain.text(initialItem.text)

wrapper
.setProps({ value: nextItem.value })
.find('.text')
.find('div.text')
.should.contain.text(nextItem.text)
})
})
Expand All @@ -784,7 +784,7 @@ describe('Dropdown Component', () => {
const text = faker.hacker.phrase()

wrapperRender(<Dropdown options={options} selection text={text} />)
.find('.text')
.find('div.text')
.should.contain.text(text)
})
it('prevents updates on item click if defined', () => {
Expand All @@ -797,7 +797,7 @@ describe('Dropdown Component', () => {
.simulate('click')

wrapper
.find('.text')
.find('div.text')
.should.contain.text(text)
})
it('is updated on item click if not already defined', () => {
Expand All @@ -814,7 +814,7 @@ describe('Dropdown Component', () => {

// text updated
wrapper
.find('.text')
.find('div.text')
.should.contain.text(item.text())
})
it('displays if value is 0', () => {
Expand All @@ -832,10 +832,10 @@ describe('Dropdown Component', () => {

// text updated
wrapper
.find('.text')
.find('div.text')
.should.contain.text(item.text())
})
it('does not display if value is \'\'', () => {
it("does not display if value is ''", () => {
const text = faker.hacker.noun()

wrapperMount(<Dropdown options={[{ value: '', text }]} selection />)
Expand All @@ -844,7 +844,7 @@ describe('Dropdown Component', () => {
.simulate('click')

wrapper
.find('.text')
.find('div.text')
.should.contain.text('')
})
it('does not display if value is null', () => {
Expand All @@ -856,7 +856,7 @@ describe('Dropdown Component', () => {
.simulate('click')

wrapper
.find('.text')
.find('div.text')
.should.contain.text('')
})
it('does not display if value is undefined', () => {
Expand All @@ -868,7 +868,7 @@ describe('Dropdown Component', () => {
.simulate('click')

wrapper
.find('.text')
.find('div.text')
.should.contain.text('')
})
})
Expand All @@ -887,7 +887,7 @@ describe('Dropdown Component', () => {
const trigger = <div className='trigger'>{text}</div>

wrapperRender(<Dropdown options={options} trigger={trigger} text={text} />)
.should.not.have.descendants('.text')
.should.not.have.descendants('div.text')
})
})

Expand Down
36 changes: 7 additions & 29 deletions test/specs/modules/Dropdown/DropdownItem-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,21 @@ describe('DropdownItem', () => {
common.implementsShorthandProp(DropdownItem, {
propKey: 'flag',
ShorthandComponent: Flag,
mapValueToProps: val => ({ name: val }),
mapValueToProps: name => ({ name }),
})

common.implementsShorthandProp(DropdownItem, {
propKey: 'description',
ShorthandComponent: 'span',
mapValueToProps: val => ({
children: val,
}),
shorthandDefaultProps: props => ({
className: 'description',
}),
mapValueToProps: children => ({ children }),
shorthandDefaultProps: props => ({ className: 'description' }),
})

common.implementsShorthandProp(DropdownItem, {
propKey: 'text',
ShorthandComponent: 'span',
mapValueToProps: val => ({
children: val,
}),
shorthandDefaultProps: props => ({
className: 'description',
}),
mapValueToProps: children => ({ children }),
shorthandDefaultProps: props => ({ className: 'text' }),
})

describe('aria', () => {
Expand Down Expand Up @@ -87,28 +79,14 @@ describe('DropdownItem', () => {
describe('description', () => {
it('adds className="description" to element shorthand', () => {
shallow(<DropdownItem description={<strong />} />)
.should.not.have.descendants('strong.description')
.should.have.descendants('strong.description')
})
})

describe('text', () => {
it('renders with wrapping span when description', () => {
const wrapper = shallow(<DropdownItem text='hey' description='description' />)

wrapper.should.have.descendants('span.text')
wrapper.text().should.include('hey')
})

it('renders without wrapping span when no description', () => {
const wrapper = shallow(<DropdownItem text='hey' />)

wrapper.should.not.have.descendants('span.text')
wrapper.text().should.equal('hey')
})

it('adds className="text" to element shorthand', () => {
shallow(<DropdownItem text={<strong />} />)
.should.not.have.descendants('strong.text')
.should.have.descendants('strong.text')
})
})

Expand Down
2 changes: 1 addition & 1 deletion test/specs/modules/Search/Search-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const openSearchResults = () => {

const nativeEvent = { nativeEvent: { stopImmediatePropagation: _.noop } }

describe('Search Component', () => {
describe('Search', () => {
beforeEach(() => {
attachTo = undefined
wrapper = undefined
Expand Down

0 comments on commit 7e4c956

Please sign in to comment.