Skip to content

Commit 84443fe

Browse files
committed
Merge branch '0.7.5' into develop
2 parents 94949ac + 4822413 commit 84443fe

File tree

5 files changed

+75
-7
lines changed

5 files changed

+75
-7
lines changed

__tests__/shared/components/Modal.jsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Modal, { BaseModal } from 'components/Modal';
2+
import React from 'react';
3+
import ReactDom from 'react-dom';
4+
import {
5+
findInDomByClass,
6+
renderDom,
7+
simulate,
8+
snapshot,
9+
} from 'utils/jest';
10+
11+
beforeAll(() => {
12+
/* Modal uses ReactJS portals to ensure proper rendering. react-test-renderer,
13+
* used by utils/jest under the hood, does not support it properly, thus this
14+
* simple mock for the createPortal(..) function. */
15+
ReactDom.createPortal = jest.fn(element => (
16+
<div className="MOCK_PORTAL">
17+
{element}
18+
</div>
19+
));
20+
});
21+
22+
test('Snapshot match', () => {
23+
snapshot(<Modal>CONTENT</Modal>);
24+
});
25+
26+
test('onCancel', () => {
27+
const onCancel = jest.fn();
28+
const dom = renderDom((
29+
<BaseModal
30+
onCancel={onCancel}
31+
theme={{ overlay: 'overlay' }}
32+
/>
33+
));
34+
const overlay = findInDomByClass(dom, 'overlay');
35+
simulate.click(overlay);
36+
expect(onCancel).toHaveBeenCalled();
37+
});
38+
39+
test('onWheel', () => {
40+
const dom = renderDom((
41+
<BaseModal
42+
theme={{ container: 'container' }}
43+
/>
44+
));
45+
const container = findInDomByClass(dom, 'container');
46+
const stopPropagation = jest.fn();
47+
simulate.wheel(container, { stopPropagation });
48+
expect(stopPropagation).toHaveBeenCalled();
49+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Snapshot match 1`] = `
4+
<div
5+
className="MOCK_PORTAL"
6+
>
7+
<div
8+
className="style__container___1SoeQ"
9+
onWheel={[Function]}
10+
>
11+
CONTENT
12+
</div>
13+
<button
14+
className="style__overlay___X12tn"
15+
onClick={[Function]}
16+
type="button"
17+
/>
18+
</div>
19+
`;

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,5 @@
121121
"mkDistDir:prod": "mkdir -p dist/prod/shared/utils && mkdir -p dist/prod/client",
122122
"test": "npm run lint && npm run jest"
123123
},
124-
"version": "0.7.7"
124+
"version": "0.7.8"
125125
}

src/shared/components/Modal/index.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import defaultStyle from './style.scss';
1919

2020
/* NOTE: Modal component is implemented as class, as it demands advanced
2121
* interaction with DOM upon mount and unmount. */
22-
class Modal extends React.Component {
22+
class BaseModal extends React.Component {
2323
constructor(props) {
2424
super(props);
2525
this.portal = document.createElement('div');
@@ -62,19 +62,19 @@ class Modal extends React.Component {
6262
}
6363
}
6464

65-
Modal.defaultProps = {
65+
BaseModal.defaultProps = {
6666
onCancel: _.noop,
6767
children: null,
6868
theme: {},
6969
};
7070

71-
Modal.propTypes = {
71+
BaseModal.propTypes = {
7272
onCancel: PT.func,
7373
children: PT.node,
7474
theme: PT.shape(),
7575
};
7676

7777
/* Non-themed version of the Modal. */
78-
export const BaseModal = Modal;
78+
export { BaseModal };
7979

80-
export default themr('Modal', defaultStyle)(Modal);
80+
export default themr('Modal', defaultStyle)(BaseModal);

0 commit comments

Comments
 (0)