From a6cf9d5fde7bf3878c62b562bbf8d2030d935c4a Mon Sep 17 00:00:00 2001 From: simonguo Date: Wed, 23 May 2018 17:08:41 +0800 Subject: [PATCH] Added tests --- test/ModalSpec.js | 56 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/test/ModalSpec.js b/test/ModalSpec.js index 385d3277b..151af89b5 100644 --- a/test/ModalSpec.js +++ b/test/ModalSpec.js @@ -1,12 +1,13 @@ import React from 'react'; import { findDOMNode } from 'react-dom'; import ReactTestUtils from 'react-dom/test-utils'; +import { getDOMNode, getInstance } from './TestWrapper'; import Modal from '../src/Modal'; describe('Modal', () => { it('Should render the modal content', () => { - const instance = ReactTestUtils.renderIntoDocument( + const instance = getInstance(

message

@@ -19,7 +20,7 @@ describe('Modal', () => { done(); }; - const instance = ReactTestUtils.renderIntoDocument(); + const instance = getInstance(); const dialog = instance.modal.getDialogElement(); ReactTestUtils.Simulate.click(dialog); @@ -27,9 +28,7 @@ describe('Modal', () => { it('Should not close the modal when the "static" dialog is clicked', () => { const onHideSpy = sinon.spy(); - const instance = ReactTestUtils.renderIntoDocument( - - ); + const instance = getInstance(); const dialog = instance.modal.getDialogElement(); ReactTestUtils.Simulate.click(dialog); @@ -37,7 +36,7 @@ describe('Modal', () => { }); it('Should be automatic height', () => { - const instance = ReactTestUtils.renderIntoDocument( + const instance = getInstance( @@ -49,7 +48,7 @@ describe('Modal', () => { const doneOp = () => { done(); }; - const instance = ReactTestUtils.renderIntoDocument( + const instance = getInstance( @@ -58,14 +57,53 @@ describe('Modal', () => { ReactTestUtils.Simulate.click(closeButton); }); + it('Should call onExited callback', done => { + const doneOp = () => { + done(); + }; + + class Demo extends React.Component { + constructor(props) { + super(props); + this.state = { + show: true + }; + this.handleClose = this.handleClose.bind(this); + } + handleClose() { + this.setState({ + show: false + }); + } + render() { + return ( + { + this.demo = ref; + }} + show={this.state.show} + onHide={this.handleClose} + onExited={doneOp} + > + + + ); + } + } + const instance = getInstance(); + const closeButton = findDOMNode(instance.demo.dialog).querySelector('.rs-modal-header-close'); + ReactTestUtils.Simulate.click(closeButton); + }); + it('Should have a custom className', () => { - const instance = ReactTestUtils.renderIntoDocument(); + const instance = getInstance(); assert.ok(findDOMNode(instance.dialog).className.match(/\bcustom\b/)); }); it('Should have a custom style', () => { const fontSize = '12px'; - const instance = ReactTestUtils.renderIntoDocument(); + const instance = getInstance(); assert.equal(findDOMNode(instance.dialog).style.fontSize, fontSize); }); });