diff --git a/test/specs/addons/Confirm-test.js b/test/specs/addons/Confirm-test.js index cd047b00a2..02a0af6017 100644 --- a/test/specs/addons/Confirm-test.js +++ b/test/specs/addons/Confirm-test.js @@ -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() + 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() + .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() + .find('Button.primary') + .shallow() + .should.have.text('foo') + }) }) - it('should return true on confirm', () => { - const confirm = mount() - 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() + .should.not.have.descendants('ModalHeader') + }) + it('sets the header text', () => { + const wrapper = shallow() + wrapper + .should.have.descendants('ModalHeader') + wrapper + .find('ModalHeader') + .shallow() + .should.have.text('foo') + }) }) - it('should return false on abort', () => { - const confirm = mount() - 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() + wrapper + .should.have.descendants('ModalContent') + wrapper + .find('ModalContent') + .shallow() + .should.have.text('Are you sure?') + }) + it('sets the content text', () => { + const wrapper = shallow() + 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() + .find('Button') + .first() + .simulate('click') + + spy.should.have.been.calledOnce() + }) + + it('is passed to the Modal onHide prop', () => { + const func = () => null + + shallow() + .find('Modal') + .prop('onHide', func) + }) + }) + + describe('onConfirm', () => { + it('is called on OK button click', () => { + const spy = sandbox.spy() + shallow() + .find('Button.primary') + .simulate('click') + + spy.should.have.been.calledOnce() + }) }) })