Skip to content

Commit

Permalink
Merge pull request #151 from hshoff/harry-legend-fix
Browse files Browse the repository at this point in the history
[legend] fix legend style prop, add tests. fixes #150
  • Loading branch information
hshoff authored Sep 18, 2017
2 parents d69c3eb + c398ce4 commit b3e02f9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
9 changes: 6 additions & 3 deletions packages/vx-legend/src/legends/Legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ Legend.propTypes = {
labelTransform: PropTypes.func,
};

const defaultStyle = {
display: 'flex',
};

export default function Legend({
className,
style,
style = defaultStyle,
shapeStyle,
scale,
shape,
Expand All @@ -56,9 +60,8 @@ export default function Legend({
return (
<div
className={cx('vx-legend', className)}
style={style}
style={{
display: 'flex',
...style,
flexDirection: direction,
}}
>
Expand Down
42 changes: 40 additions & 2 deletions packages/vx-legend/test/Legend.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,45 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Legend } from '../src';
import { scaleLinear } from '../../vx-scale';

const defaultProps = {
scale: scaleLinear({
rangeRound: [10, 0],
domain: [0, 10],
}),
};

describe('<Legend />', () => {
test('it should be defined', () => {
expect(Legend).toBeDefined();
})
})
});

test('it should default style to display: flex, flex-direction: column ', () => {
const wrapper = shallow(<Legend {...defaultProps} />);
expect(wrapper.prop('style')).toEqual({
display: 'flex',
flexDirection: 'column',
});
});

test('it should extend style prop', () => {
const wrapper = shallow(
<Legend {...defaultProps} style={{ display: 'block' }} />,
);
expect(wrapper.prop('style')).toEqual({
display: 'block',
flexDirection: 'column',
});
});

test('it should pass through direction prop to style prop', () => {
const wrapper = shallow(
<Legend {...defaultProps} direction="row" />,
);
expect(wrapper.prop('style')).toEqual({
display: 'flex',
flexDirection: 'row',
});
});
});

0 comments on commit b3e02f9

Please sign in to comment.