-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8623216
commit c977bfe
Showing
1 changed file
with
101 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) | ||
}) |