diff --git a/__tests__/TreeNode.test.js b/__tests__/TreeNode.test.js
index b2116b4..2492d72 100644
--- a/__tests__/TreeNode.test.js
+++ b/__tests__/TreeNode.test.js
@@ -39,4 +39,46 @@ describe('', () => {
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);
+ });
+ })
});
diff --git a/src/components/TreeNode/index.js b/src/components/TreeNode/index.js
index eb6922d..7fb752a 100644
--- a/src/components/TreeNode/index.js
+++ b/src/components/TreeNode/index.js
@@ -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 (
-
- {toggled ? this.renderChildren(decorators, animations) : null}
-
- );
- }
-
renderChildren(decorators) {
const {animations, decorators: propDecorators, node, style, onToggle} = this.props;
@@ -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 (
this.onClick()}/>
- {this.renderDrawer(decorators, animations)}
+
+ {node.toggled ? this.renderChildren(decorators, animations) : null}
+
);
}
}
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;