Skip to content

Commit

Permalink
test(Confirm): test updated confirm
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Aug 11, 2016
1 parent 8623216 commit c977bfe
Showing 1 changed file with 101 additions and 25 deletions.
126 changes: 101 additions & 25 deletions test/specs/addons/Confirm-test.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,113 @@
import React from 'react'

import { Confirm } from 'stardust'
import { Confirm, Modal } from 'stardust'
import * as common from '../commonTests'
import sandbox from 'test/utils/Sandbox-util'

describe('Confirm', () => {
common.isConformant(Confirm)

it('default prop abortLabel should be "Cancel"', () => {
Confirm.defaultProps.abortLabel
.should.equal('Cancel')
it('renders a small Modal', () => {
const wrapper = shallow(<Confirm />)
wrapper
.type()
.should.equal(Modal)
wrapper
.should.have.prop('size', 'small')
})
it('default prop confirmLabel should be "Yes"', () => {
Confirm.defaultProps.confirmLabel
.should.equal('Yes')

describe('cancelButton', () => {
it('is "Cancel" by default', () => {
Confirm.defaultProps.cancelButton
.should.equal('Cancel')
})
it('sets the cancel button text', () => {
shallow(<Confirm cancelButton='foo' />)
.find('Button')
.first()
.shallow()
.should.have.text('foo')
})
})

describe('confirmButton', () => {
it('is "OK" by default', () => {
Confirm.defaultProps.confirmButton
.should.equal('OK')
})
it('sets the confirm button text', () => {
shallow(<Confirm confirmButton='foo' />)
.find('Button.primary')
.shallow()
.should.have.text('foo')
})
})
it('should return true on confirm', () => {
const confirm = mount(<Confirm />)
confirm
.instance()
.show()
.then(isConfirmed => isConfirmed.should.equal(true))
confirm
.findWhere(c => c.text() === 'Yes')
.simulate('click')

describe('header', () => {
it('is not present by default', () => {
shallow(<Confirm />)
.should.not.have.descendants('ModalHeader')
})
it('sets the header text', () => {
const wrapper = shallow(<Confirm header='foo' />)
wrapper
.should.have.descendants('ModalHeader')
wrapper
.find('ModalHeader')
.shallow()
.should.have.text('foo')
})
})
it('should return false on abort', () => {
const confirm = mount(<Confirm />)
confirm
.instance()
.show()
.then(isConfirmed => isConfirmed.should.equal(false))
confirm
.findWhere(c => c.text() === 'Cancel')
.simulate('click')

describe('content', () => {
it('is "Are you sure?" by default', () => {
const wrapper = shallow(<Confirm />)
wrapper
.should.have.descendants('ModalContent')
wrapper
.find('ModalContent')
.shallow()
.should.have.text('Are you sure?')
})
it('sets the content text', () => {
const wrapper = shallow(<Confirm content='foo' />)
wrapper
.should.have.descendants('ModalContent')
wrapper
.find('ModalContent')
.shallow()
.should.have.text('foo')
})
})

describe('onCancel', () => {
it('is called on Cancel button click', () => {
const spy = sandbox.spy()
shallow(<Confirm onCancel={spy} />)
.find('Button')
.first()
.simulate('click')

spy.should.have.been.calledOnce()
})

it('is passed to the Modal onHide prop', () => {
const func = () => null

shallow(<Confirm onCancel={func} />)
.find('Modal')
.prop('onHide', func)
})
})

describe('onConfirm', () => {
it('is called on OK button click', () => {
const spy = sandbox.spy()
shallow(<Confirm onConfirm={spy} />)
.find('Button.primary')
.simulate('click')

spy.should.have.been.calledOnce()
})
})
})

0 comments on commit c977bfe

Please sign in to comment.