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

Test/tree node #211

Merged
merged 3 commits into from
May 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/Container.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {shallow} from 'enzyme';
import {decorators} from '../src';
import Container from '../src/components/Decorators/Container';
import animations from '../src/themes/animations';
import data from '../example/data';
import style from '../src/themes/default';
import data from './mocks/data';

const onClick = jest.fn();

Expand Down
2 changes: 1 addition & 1 deletion __tests__/NodeHeader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import NodeHeader from '../src/components/NodeHeader';
import defaultTheme from '../src/themes/default';
import defaultDecorators from '../src/components/Decorators';
import defaultAnimations from '../src/themes/animations';
import data from '../example/data';
import data from './mocks/data';

const onClick = jest.fn();

Expand Down
24 changes: 19 additions & 5 deletions __tests__/TreeNode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import TreeNode from '../src/components/TreeNode';
import defaultTheme from '../src/themes/default';
import defaultAnimations from '../src/themes/animations';
import defaultDecorators from '../src/components/Decorators';
import data from '../example/data';
import data from './mocks/data';

const onToggle = jest.fn();

Expand All @@ -29,15 +29,29 @@ const renderComponent = (props = {}) => {

describe('<TreeNode/>', () => {
describe('when NodeHeader is clicked', () => {
it('should call onToggle with the selected node and toggled in false', () => {
it('should call onToggle', () => {
const wrapper = renderComponent();
wrapper.simulateClickOnHeader();
expect(onToggle).toHaveBeenCalled();
expect(onToggle).toBeCalledWith(data, false);
});
describe('and node.toggle is true', () => {
it('should return the selected node and toggled in false', () => {
const wrapper = renderComponent();
wrapper.simulateClickOnHeader();
expect(onToggle).toBeCalledWith(data, false);
});
});
describe('and node.toggle is false', () => {
it('should return the selected node and toggled in true', () => {
const node = {...data, toggled: false};
const wrapper = renderComponent({node});
wrapper.simulateClickOnHeader();
expect(onToggle).toBeCalledWith(node, true);
});
});
});

describe('> <Drawer/>', () => {
describe('<Drawer/>', () => {
describe('when toggle is false', () => {
it('should have children.size to be 0', () => {
const wrapper = renderComponent({
Expand Down Expand Up @@ -100,7 +114,7 @@ describe('<TreeNode/>', () => {
});
});

describe('> decorators', () => {
describe('decorators', () => {
describe('when node decorators not exists', () => {
describe('and decorators is called', () => {
it('should return defaultDecorators', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/Treebeard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {shallow} from 'enzyme';
import {castArray} from 'lodash';

import Treebeard from '../src/components';
import data from '../example/data';
import data from './mocks/data';

const renderComponent = (props = {}) => shallow(
<Treebeard data={castArray(data)} {...props}/>
Expand Down
45 changes: 45 additions & 0 deletions __tests__/mocks/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export default {
name: 'react-treebeard',
id: 1,
toggled: true,
children: [
{
name: 'example',
children: [
{ name: 'app.js' },
{ name: 'data.js' },
{ name: 'index.html' },
{ name: 'styles.js' },
{ name: 'webpack.config.js' }
]
},
{
name: 'node_modules',
loading: true,
children: []
},
{
name: 'src',
children: [
{
name: 'components',
children: [
{ name: 'decorators.js' },
{ name: 'treebeard.js' }
]
},
{ name: 'index.js' }
]
},
{
name: 'themes',
children: [
{ name: 'animations.js' },
{ name: 'default.js' }
]
},
{ name: 'gulpfile.js' },
{ name: 'index.js' },
{ name: 'package.json' }
]
};