Skip to content

Commit

Permalink
renamed onRequestClose to requestClose
Browse files Browse the repository at this point in the history
  • Loading branch information
danrot committed Aug 29, 2017
1 parent e6753cb commit 97e10d9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export default class OverlayList extends React.PureComponent<Props> {
}

componentDidMount() {
window.addEventListener('blur', this.requestClose);
window.addEventListener('resize', this.requestClose);
window.addEventListener('blur', this.close);
window.addEventListener('resize', this.close);
}

componentWillUnmount() {
window.removeEventListener('blur', this.requestClose);
window.removeEventListener('resize', this.requestClose);
window.removeEventListener('blur', this.close);
window.removeEventListener('resize', this.close);
}

@action componentWillReceiveProps(newProps: Props) {
Expand All @@ -73,7 +73,7 @@ export default class OverlayList extends React.PureComponent<Props> {
});
}

requestClose = () => {
close = () => {
if (this.props.isOpen && this.props.onRequestClose) {
this.props.onRequestClose();
}
Expand Down Expand Up @@ -110,7 +110,7 @@ export default class OverlayList extends React.PureComponent<Props> {
}));
};

handleBackropClick = this.requestClose;
handleBackropClick = this.close;

render() {
let style = {opacity: '0'};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Props = {
confirmText: string,
onConfirm: () => void,
isOpen: boolean,
onRequestClose: () => void,
onClose: () => void,
};

const CLOSE_ICON = 'times';
Expand Down Expand Up @@ -57,7 +57,7 @@ export default class Overlay extends React.PureComponent<Props> {
}

close = () => {
this.props.onRequestClose();
this.props.onClose();
};

@action toggle() {
Expand Down Expand Up @@ -108,7 +108,7 @@ export default class Overlay extends React.PureComponent<Props> {
</footer>
</section>
</div>
<Backdrop local={true} onClick={this.props.onRequestClose} />
<Backdrop local={true} onClick={this.props.onClose} />
</div>
</Portal>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const onConfirm = () => {
<button onClick={() => setState({open: true})}>Open overlay</button>
<Overlay
title="Njan Njan Njan"
onRequestClose={() => setState({open: false})}
onClose={() => setState({open: false})}
actions={actions}
confirmText="Apply"
onConfirm={onConfirm}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ afterEach(() => document.body.innerHTML = '');

test('The component should render in body when open', () => {
const body = document.body;
const onRequestClose = () => {};
const onClose = () => {};
const view = mount(
<Overlay
title="My overlay title"
onRequestClose={onRequestClose}
onClose={onClose}
confirmText="Apply"
isOpen={true}>
<p>My overlay content</p>
Expand All @@ -30,11 +30,11 @@ test('The component should render in body with actions when open', () => {
{title: 'Action 2', onClick: () => {}},
];
const body = document.body;
const onRequestClose = () => {};
const onClose = () => {};
const view = mount(
<Overlay
title="My overlay title"
onRequestClose={onRequestClose}
onClose={onClose}
confirmText="Apply"
actions={actions}
isOpen={true}>
Expand All @@ -48,11 +48,11 @@ test('The component should render in body with actions when open', () => {

test('The component should not render in body when closed', () => {
const body = document.body;
const onRequestClose = () => {};
const onClose = () => {};
const view = mount(
<Overlay
title="My overlay title"
onRequestClose={onRequestClose}
onClose={onClose}
confirmText="Apply"
isOpen={false}>
<p>My overlay content</p>
Expand All @@ -63,11 +63,11 @@ test('The component should not render in body when closed', () => {
});

test('The component should request to be closed on click on backdrop', () => {
const requestCloseSpy = jest.fn();
const closeSpy = jest.fn();
const view = shallow(
<Overlay
title="My overlay title"
onRequestClose={requestCloseSpy}
onClose={closeSpy}
confirmText="Apply"
isOpen={true}>
<p>My overlay content</p>
Expand All @@ -76,52 +76,52 @@ test('The component should request to be closed on click on backdrop', () => {
const backdrop = view.find('Backdrop');
expect(backdrop.length).toBe(1);

expect(requestCloseSpy).not.toBeCalled();
expect(closeSpy).not.toBeCalled();
backdrop.props().onClick();
expect(requestCloseSpy).toBeCalled();
expect(closeSpy).toBeCalled();
});

test('The component should request to be closed when the close icon is clicked', () => {
const requestCloseSpy = jest.fn();
const closeSpy = jest.fn();
const view = shallow(
<Overlay
title="My overlay title"
onRequestClose={requestCloseSpy}
onClose={closeSpy}
confirmText="Apply"
isOpen={true}>
<p>My overlay content</p>
</Overlay>
);

expect(requestCloseSpy).not.toBeCalled();
expect(closeSpy).not.toBeCalled();
view.find('Icon').simulate('click');
expect(requestCloseSpy).toBeCalled();
expect(closeSpy).toBeCalled();
});

test('The component should request to be closed when the esc key is pressed', () => {
const requestCloseSpy = jest.fn();
const closeSpy = jest.fn();
mount(
<Overlay
title="My overlay title"
onRequestClose={requestCloseSpy}
onClose={closeSpy}
confirmText="Apply"
isOpen={true}>
<p>My overlay content</p>
</Overlay>
);

expect(requestCloseSpy).not.toBeCalled();
expect(closeSpy).not.toBeCalled();
Mousetrap.trigger('esc');
expect(requestCloseSpy).toBeCalled();
expect(closeSpy).toBeCalled();
});

test('The component should call the callback when the confirm button is clicked', () => {
const onRequestClose = () => {};
const onClose = () => {};
const onConfirm = jest.fn();
const view = shallow(
<Overlay
title="My title"
onRequestClose={onRequestClose}
onClose={onClose}
onConfirm={onConfirm}
confirmText="Alright mate!">
<p>My overlay content</p>
Expand Down

0 comments on commit 97e10d9

Please sign in to comment.