Skip to content

Commit

Permalink
write a regresion test
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Apr 10, 2019
1 parent 8a41851 commit bcde044
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
6 changes: 4 additions & 2 deletions packages/material-ui-lab/src/SpeedDial/SpeedDial.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,9 @@ describe('<SpeedDial />', () => {
resetDialToOpen(dialDirection);

getDialButton().simulate('keydown', { keyCode: keycodes[firstKey] });
assert.isTrue(
assert.strictEqual(
isActionFocused(firstFocusedAction),
true,
`focused action initial ${firstKey} should be ${firstFocusedAction}`,
);

Expand All @@ -363,8 +364,9 @@ describe('<SpeedDial />', () => {
getActionButton(previousFocusedAction).simulate('keydown', {
keyCode: keycodes[arrowKey],
});
assert.isTrue(
assert.strictEqual(
isActionFocused(expectedFocusedAction),
true,
`focused action after ${combinationUntilNot.join(
',',
)} should be ${expectedFocusedAction}`,
Expand Down
61 changes: 31 additions & 30 deletions packages/material-ui/src/Modal/Modal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,40 +376,41 @@ describe('<Modal />', () => {
assert.strictEqual(modalNode.getAttribute('aria-hidden'), 'true');
});

/* Test case for https://github.com/mui-org/material-ui/issues/15180 */
// Test case for https://github.com/mui-org/material-ui/issues/15180
it('should remove the transition children in the DOM when closed whilst transition status is entering', () => {
const onEntering = spy();
const onEntered = spy();
const childrenId = '__Modal_test_js__children__id__';
const childrenIdSelector = `#${childrenId}`;
const TestCase = props => (
<Modal open={props.open} keepMounted={false}>
<Fade
in={props.open}
exit={false} // Disable exit transition, so it immediately unmounts when open=false
onEntering={onEntering}
onEntered={onEntered}
>
<span id={childrenId}>Hello</span>
</Fade>
</Modal>
);
TestCase.propTypes = { open: PropTypes.bool };
const children = <p>Hello World</p>;

const wrapper = mount(<TestCase open={false} />);
assert.isFalse(wrapper.exists(childrenIdSelector));
assert.strictEqual(onEntering.callCount, 0);
class OpenClose extends React.Component {
state = {
open: false,
};

wrapper.setProps({ open: true });
wrapper.update();
assert.isTrue(wrapper.exists(childrenIdSelector));
assert.strictEqual(onEntering.callCount, 1);
assert.strictEqual(onEntered.callCount, 0);
handleClick = () => {
this.setState({ open: true }, () => {
this.setState({ open: false });
});
};

wrapper.setProps({ open: false });
wrapper.update();
assert.isFalse(wrapper.exists(childrenIdSelector));
assert.strictEqual(onEntered.callCount, 0); // Ensure transition state was never "entered"
render() {
return (
<div>
<button type="button" onClick={this.handleClick}>
Toggle Tooltip
</button>
<Modal open={this.state.open}>
<Fade in={this.state.open}>
<span>{children}</span>
</Fade>
</Modal>
</div>
);
}
}

const wrapper = mount(<OpenClose />);
assert.strictEqual(wrapper.contains(children), false);
wrapper.find('button').simulate('click');
assert.strictEqual(wrapper.contains(children), false);
});
});

Expand Down

0 comments on commit bcde044

Please sign in to comment.