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
+ } ) ;
0 commit comments