Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simonguo committed May 23, 2018
1 parent 8d3cf3a commit a6cf9d5
Showing 1 changed file with 47 additions and 9 deletions.
56 changes: 47 additions & 9 deletions 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(
<Modal show>
<p>message</p>
</Modal>
Expand All @@ -19,25 +20,23 @@ describe('Modal', () => {
done();
};

const instance = ReactTestUtils.renderIntoDocument(<Modal show onHide={doneOp} />);
const instance = getInstance(<Modal show onHide={doneOp} />);
const dialog = instance.modal.getDialogElement();

ReactTestUtils.Simulate.click(dialog);
});

it('Should not close the modal when the "static" dialog is clicked', () => {
const onHideSpy = sinon.spy();
const instance = ReactTestUtils.renderIntoDocument(
<Modal show onHide={onHideSpy} backdrop="static" />
);
const instance = getInstance(<Modal show onHide={onHideSpy} backdrop="static" />);
const dialog = instance.modal.getDialogElement();
ReactTestUtils.Simulate.click(dialog);

assert.ok(!onHideSpy.calledOnce);
});

it('Should be automatic height', () => {
const instance = ReactTestUtils.renderIntoDocument(
const instance = getInstance(
<Modal className="custom" overflow show>
<Modal.Body style={{ height: 2000 }} />
</Modal>
Expand All @@ -49,7 +48,7 @@ describe('Modal', () => {
const doneOp = () => {
done();
};
const instance = ReactTestUtils.renderIntoDocument(
const instance = getInstance(
<Modal className="custom" show onHide={doneOp}>
<Modal.Header />
</Modal>
Expand All @@ -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 (
<Modal
className="custom"
ref={ref => {
this.demo = ref;
}}
show={this.state.show}
onHide={this.handleClose}
onExited={doneOp}
>
<Modal.Header />
</Modal>
);
}
}
const instance = getInstance(<Demo />);
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(<Modal className="custom" show />);
const instance = getInstance(<Modal className="custom" show />);
assert.ok(findDOMNode(instance.dialog).className.match(/\bcustom\b/));
});

it('Should have a custom style', () => {
const fontSize = '12px';
const instance = ReactTestUtils.renderIntoDocument(<Modal style={{ fontSize }} show />);
const instance = getInstance(<Modal style={{ fontSize }} show />);
assert.equal(findDOMNode(instance.dialog).style.fontSize, fontSize);
});
});

0 comments on commit a6cf9d5

Please sign in to comment.