Skip to content

Commit

Permalink
[test] Add visual regression test for SpeedDIal (mui#13140)
Browse files Browse the repository at this point in the history
* [SpeedDialAction] Fix tooltip not being open on already open speeddial

* [test] Add visual regression test for SpeedDial
  • Loading branch information
eps1lon authored Oct 8, 2018
1 parent 8c0d257 commit 340b85e
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ export const styles = theme => ({
});

class SpeedDialAction extends React.Component {
state = {
tooltipOpen: false,
};
constructor(props) {
super();
this.state = {
tooltipOpen: props.tooltipOpen,
};
}

static getDerivedStateFromProps = (props, state) => {
if (!props.open && state.tooltipOpen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ describe('<SpeedDialAction />', () => {
wrapper.unmount();
});

it('initializes its state from props', () => {
const wrapper = shallow(<SpeedDialAction {...defaultProps} open tooltipOpen />);
assert.strictEqual(wrapper.state().tooltipOpen, true);
});

it('should render a Tooltip', () => {
const wrapper = shallow(<SpeedDialAction {...defaultProps} />);
assert.strictEqual(wrapper.type(), Tooltip);
Expand Down
92 changes: 92 additions & 0 deletions test/regressions/tests/SpeedDial/Directions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import classNames from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import Avatar from '@material-ui/core/Avatar';
import { withStyles } from '@material-ui/core/styles';
import { capitalize } from '@material-ui/core/utils/helpers';
import SpeedDial from '@material-ui/lab/SpeedDial';
import SpeedDialIcon from '@material-ui/lab/SpeedDialIcon';
import SpeedDialAction from '@material-ui/lab/SpeedDialAction';

const styles = {
root: {
position: 'relative',
height: 360,
width: 400,
},
speedDial: {
position: 'absolute',
'&$directionUp': {
bottom: 0,
right: 0,
},
'&$directionRight': {
bottom: 0,
left: 0,
},
'&$directionDown': {
top: 0,
left: 0,
},
'&$directionLeft': {
top: 0,
right: 0,
},
},
directionUp: {},
directionRight: {},
directionDown: {},
directionLeft: {},
};

function SimpleSpeedDial(props) {
const tooltipPlacement = {
up: 'left',
right: 'top',
down: 'right',
left: 'bottom',
};
const secondaryPlacement = ['-start', '', '-end'];

return (
<SpeedDial icon={<SpeedDialIcon />} open {...props}>
{['A', 'B', 'C'].map((name, i) => {
return (
<SpeedDialAction
key={name}
icon={<Avatar>{name}</Avatar>}
tooltipOpen
tooltipPlacement={`${tooltipPlacement[props.direction]}${secondaryPlacement[i]}`}
tooltipTitle={'Tooltip'}
/>
);
})}
</SpeedDial>
);
}

function Directions({ classes }) {
const speedDialClassName = direction =>
classNames(classes.speedDial, classes[`direction${capitalize(direction)}`]);

return (
<div className={classes.root}>
{['up', 'right', 'down', 'left'].map(direction => {
return (
<SimpleSpeedDial
key={direction}
ariaLabel={direction}
className={speedDialClassName(direction)}
direction={direction}
/>
);
})}
</div>
);
}

Directions.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(Directions);

0 comments on commit 340b85e

Please sign in to comment.