Skip to content

Commit c83c426

Browse files
committed
Merge branch 'dev' into sierra
2 parents c017597 + a647722 commit c83c426

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { mount , configure } from 'enzyme';
2+
3+
import React from 'react';
4+
import { MemoryRouter , NavLink } from 'react-router-dom';
5+
6+
import StateContainer from '../containers/StateContainer';
7+
import Chart from '../components/Chart';
8+
import Tree from '../components/Tree';
9+
10+
import Adapter from 'enzyme-adapter-react-16';
11+
12+
configure({ adapter: new Adapter() });
13+
14+
describe('testing react router path',()=>{
15+
const wrapper = mount(<MemoryRouter><StateContainer/></MemoryRouter>);
16+
it('NavLink has two paths', () => {
17+
expect(wrapper.find(NavLink)).toHaveLength(2);
18+
});
19+
it('First NavLink should be root', () => {
20+
expect(wrapper.find(NavLink).at(0).props().to).toBe('/');
21+
});
22+
it('Second NavLink should be chart', () => {
23+
expect(wrapper.find(NavLink).at(1).props().to).toBe('/chart');
24+
});
25+
});
26+
27+
describe('render test', () => {
28+
const wrapper = mount(
29+
<MemoryRouter>
30+
<StateContainer snapshot={ {data :'root'} }/>
31+
</MemoryRouter>);
32+
it('Clicking first NavLink should render Tree only', () => {
33+
wrapper.find(NavLink).at(0).simulate('click', { button: 0 });
34+
expect(wrapper.find(Tree)).toHaveLength(1);
35+
expect(wrapper.find(Chart)).toHaveLength(0);
36+
});
37+
it('Clicking second NavLink should render Chart only', () => {
38+
wrapper.find(NavLink).at(1).simulate('click', { button: 0 });
39+
expect(wrapper.find(Tree)).toHaveLength(0);
40+
expect(wrapper.find(Chart)).toHaveLength(1);
41+
});
42+
});

src/app/__tests__/dropdown.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
import { configure, shallow } from 'enzyme';
3+
import Adapter from 'enzyme-adapter-react-16';
4+
import Dropdown from '../components/Dropdown';
5+
6+
configure({ adapter: new Adapter() });
7+
8+
describe('unit testing for Dropdown.jsx', () => {
9+
let wrapper;
10+
const props = {
11+
options: [
12+
{ value: 2000, label: '0.5x' },
13+
{ value: 1000, label: '1.0x' },
14+
{ value: 500, label: '2.0x' },
15+
],
16+
handleChangeSpeed: jest.fn(),
17+
selectedOption: { value: 1000, label: '1.0x' }
18+
};
19+
beforeEach(() => {
20+
wrapper = shallow(<Dropdown {...props} />);
21+
});
22+
23+
describe('Component', () => {
24+
test('array of objects that have value and label should be options props', () => {
25+
expect(wrapper.props().options).toEqual(props.options);
26+
});
27+
test('selectedOption should be value property', () => {
28+
expect(wrapper.props().value).toEqual(props.selectedOption);
29+
})
30+
})
31+
32+
describe('handlechangeSpeed', () => {
33+
test('should invoke handleChangeSpeed onChange', () => {
34+
wrapper.simulate('change', { value: 2000, label: '0.5x' });
35+
expect(props.handleChangeSpeed).toHaveBeenCalled();
36+
});
37+
});
38+
});

src/app/components/Chart.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { Component } from 'react';
2-
import '../styles/components/_d3Tree.scss';
32
import * as d3 from 'd3';
43

54
var root={};

src/app/styles/main.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@
2020

2121
// slider component
2222
@import './components/rc-slider', './components/sliderHandle';
23+
24+
// d3 chart component
25+
@import './components/d3Tree';

0 commit comments

Comments
 (0)