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 13, 2016
1 parent a3d9f01 commit 5846198
Showing 1 changed file with 103 additions and 26 deletions.
129 changes: 103 additions & 26 deletions test/specs/addons/Confirm-test.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,114 @@
import React from 'react'

import Confirm from 'src/addons/Confirm/Confirm'
import * as common from '../commonTests'
import { Confirm } from 'src/addons'
import { Modal } from 'src/modules'
import { sandbox } from 'test/utils'
import * as common from 'test/specs/commonTests'

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 5846198

Please sign in to comment.