Skip to content

Commit

Permalink
Merge 05eecdb into 2013c1b
Browse files Browse the repository at this point in the history
  • Loading branch information
simonguo committed May 23, 2018
2 parents 2013c1b + 05eecdb commit 8127886
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
3 changes: 2 additions & 1 deletion karma.conf.js
Expand Up @@ -29,7 +29,8 @@ module.exports = config => {
frameworks: ['mocha', 'sinon-chai'],
colors: true,
reporters: ['mocha', 'coverage'],

// https://github.com/karma-runner/karma/blob/master/docs/config/01-configuration-file.md#browsernoactivitytimeout
browserNoActivityTimeout: 100000,
logLevel: config.LOG_INFO,
preprocessors: {
'test/*.js': ['webpack']
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -50,14 +50,14 @@
"react-flow-types": "^0.2.0-beta.6",
"recompose": "^0.26.0",
"rsuite-cascader": "^3.0.1",
"rsuite-checkpicker": "^3.0.1",
"rsuite-checkpicker": "^3.0.2",
"rsuite-checktreepicker": "^3.0.4",
"rsuite-datepicker": "^3.0.2",
"rsuite-daterangepicker": "^3.0.1",
"rsuite-intl": "^1.0.4",
"rsuite-notification": "^3.0.2",
"rsuite-schema": "0.0.12",
"rsuite-selectpicker": "^3.0.1",
"rsuite-selectpicker": "^3.0.2",
"rsuite-table": "^3.0.0",
"rsuite-treepicker": "^3.0.2",
"rsuite-utils": "^1.0.1"
Expand Down
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 8127886

Please sign in to comment.