Skip to content

Commit 64e8d41

Browse files
committed
state container router testing
1 parent ab6ec22 commit 64e8d41

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { mount , shallow, 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/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)