Skip to content

Commit

Permalink
tests(mixed): update tests and fixes prop handling
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter committed Apr 2, 2017
1 parent 02364fc commit 845944b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/addons/Confirm/Confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ class Confirm extends Component {
}

handleCancelOverrides = predefinedProps => ({
onClick: e => {
_.invoke(predefinedProps, 'onClick', e, this.props)
onClick: (e, buttonProps) => {
_.invoke(predefinedProps, 'onClick', e, buttonProps)
this.handleCancel(e)
},
})

handleConfirmOverrides = predefinedProps => ({
onClick: e => {
_.invoke(predefinedProps, 'onClick', e, this.props)
onClick: (e, buttonProps) => {
_.invoke(predefinedProps, 'onClick', e, buttonProps)
_.invoke(this.props, 'onConfirm', e, this.props)
},
})
Expand Down
2 changes: 1 addition & 1 deletion src/elements/Label/Label.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default class Label extends Component {

handleIconOverrides = predefinedProps => ({
onClick: e => {
_.invoke(predefinedProps, 'onClick', e, this.props)
_.invoke(predefinedProps, 'onClick', e)
_.invoke(this.props, 'onRemove', e, this.props)
},
})
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class Modal extends Component {

handleIconOverrides = predefinedProps => ({
onClick: e => {
_.invoke(predefinedProps, 'onClick', e, this.props)
_.invoke(predefinedProps, 'onClick', e)
this.handleClose(e)
},
})
Expand Down
30 changes: 19 additions & 11 deletions test/specs/collections/Menu/Menu-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,35 @@ describe('Menu', () => {
})

describe('onItemClick', () => {
const items = [
{ key: 'home', name: 'home' },
{ key: 'users', name: 'users' },
]

it('can be omitted', () => {
const click = () => mount(<Menu items={items} />).find('MenuItem').first().simulate('click')
const click = () => mount(<Menu items={[{ key: 'home', name: 'home' }]} />)
.find('MenuItem')
.first()
.simulate('click')

expect(click).to.not.throw()
})

it('is called with (e, { name, index }) when clicked', () => {
const spy = sandbox.spy()
const event = { target: null }
const props = { name: 'home', index: 0 }
const itemSpy = sandbox.spy()
const menuSpy = sandbox.spy()

const items = [
{ key: 'home', name: 'home' },
{ key: 'users', name: 'users', onClick: itemSpy },
]
const matchProps = { index: 1, name: 'users' }

mount(<Menu items={items} onItemClick={spy} />).find('MenuItem').first()
mount(<Menu items={items} onItemClick={menuSpy} />)
.find('MenuItem')
.last()
.simulate('click', event)

spy.should.have.been.calledOnce()
spy.should.have.been.calledWithMatch(event, props)
itemSpy.should.have.been.calledOnce()
itemSpy.should.have.been.calledWithMatch(event, matchProps)
menuSpy.should.have.been.calledOnce()
menuSpy.should.have.been.calledWithMatch(event, matchProps)
})
})
})
17 changes: 17 additions & 0 deletions test/specs/elements/Label/Label-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ describe('Label', () => {
.find('Icon')
.should.have.prop('data-foo', true)
})

it('handles events on Label and Icon', () => {
const event = { target: null }
const iconSpy = sandbox.spy()
const labelSpy = sandbox.spy()

const iconProps = { 'data-foo': true, onClick: iconSpy }
const labelProps = { onRemove: labelSpy, removeIcon: iconProps }

mount(<Label {...labelProps} />)
.find('Icon')
.simulate('click', event)

iconSpy.should.have.been.calledOnce()
labelSpy.should.have.been.calledOnce()
labelSpy.should.have.been.calledWithMatch(event, labelProps)
})
})

describe('content', () => {
Expand Down

0 comments on commit 845944b

Please sign in to comment.