Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #191 from storybooks/test/treeNode
Browse files Browse the repository at this point in the history
test(treeNode): test animations and decorators methods
  • Loading branch information
maximilianoforlenza authored Apr 27, 2019
2 parents e0aef08 + 3325103 commit 1b8d50f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
42 changes: 42 additions & 0 deletions __tests__/TreeNode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,46 @@ describe('<TreeNode/>', () => {
expect(clickFn.mock.calls[0][1]).toBe(false);
});
});
describe('Drawer when toggled is false', () => {
test('should be children size equal to zero', () => {
const wrapper = shallow(renderComponent({node: {...data, toggled: false}}));
expect(wrapper.find('Drawer').children().length).toBe(0);
})
});
describe('animations method', () => {
describe('animations and node toggled are false', () => {
test('should return a toggle object with an animation with rotateZ 0 and duration zero', () => {
const wrapper = shallow(renderComponent({animations: false, node: {...data, toggled: false}}));
const instance = wrapper.instance();
const animations = instance.animations();
expect(animations).toEqual({
toggle: {
animation: {rotateZ: 0},
duration: 0
}
});
})
});
describe('animations are false and node toggled is true', () => {
test('should return a toggle object with an animation with rotateZ 90 and duration zero', () => {
const wrapper = shallow(renderComponent({animations: false}));
const instance = wrapper.instance();
const animations = instance.animations();
expect(animations).toEqual({
toggle: {
animation: {rotateZ: 90},
duration: 0
}
});
})
});
});
describe('decorators method', () => {
test('should return defaultDecorators if node decorators not exists', () => {
const wrapper = shallow(renderComponent({animations: false}));
const instance = wrapper.instance();
const decorators = instance.decorators();
expect(decorators).toEqual(defaultDecorators);
});
})
});
26 changes: 6 additions & 20 deletions src/components/TreeNode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,6 @@ class TreeNode extends PureComponent {
return Object.assign({}, decorators, nodeDecorators);
}

renderDrawer(decorators, animations) {
const {toggled} = this.props.node;
if (!animations) {
if (!toggled) {
return null;
}
return this.renderChildren(decorators, animations);
}

const {...restAnimationInfo} = animations.drawer;
return (
<Drawer restAnimationInfo={{...restAnimationInfo}}>
{toggled ? this.renderChildren(decorators, animations) : null}
</Drawer>
);
}

renderChildren(decorators) {
const {animations, decorators: propDecorators, node, style, onToggle} = this.props;

Expand Down Expand Up @@ -92,24 +75,27 @@ class TreeNode extends PureComponent {
const {node, style} = this.props;
const decorators = this.decorators();
const animations = this.animations();
const {...restAnimationInfo} = animations.drawer;
return (
<Li style={style.base}>
<NodeHeader {...{decorators, animations, node, style}} onClick={() => this.onClick()}/>
{this.renderDrawer(decorators, animations)}
<Drawer restAnimationInfo={{...restAnimationInfo}}>
{node.toggled ? this.renderChildren(decorators, animations) : null}
</Drawer>
</Li>
);
}
}

TreeNode.propTypes = {
onToggle: PropTypes.func,
style: PropTypes.object.isRequired,
node: PropTypes.object.isRequired,
decorators: PropTypes.object.isRequired,
animations: PropTypes.oneOfType([
PropTypes.object,
PropTypes.bool
]).isRequired,
onToggle: PropTypes.func
]).isRequired
};

export default TreeNode;

0 comments on commit 1b8d50f

Please sign in to comment.