1
- // import TestRunner from 'jest-runner';
2
-
3
- // Unit Test Cases for Charts
4
- // description: lifecycle methods
5
- // Component should call make3dTree upon mounting
6
- // object 'root' should be a deep clone of the snapshot
7
- // i.e.: this.props.snapshot !== root
8
-
9
- // description: maked3Tree
10
- // Should call function 'removed3tree' only once
11
- // Should call appropriate function upon triggering a certain event on the tooltip div
12
- // i.e.:
13
- // 'mouseover' event -> 'tipMouseover' function
14
- // 'mouseout' event -> 'tipMouseout' function
15
- // Should call appropriate function upon triggering a certain event on a node
16
- // (nested under the 'update' function)
17
- // i.e.:
18
- // 'mouseover' event -> 'mouseover' function
19
- // 'mouseout' event -> 'mouseout' function
20
- // 'click' event -> 'click' function
21
- // Should call function 'update' at least once
1
+ import React from 'react' ;
2
+ import { configure , mount } from 'enzyme' ;
3
+ import Adapter from 'enzyme-adapter-react-16' ;
4
+ // eslint-disable-next-line import/no-named-as-default-member
5
+ import Chart from '../components/Chart' ;
6
+ // Unit test cases for d3 functionality
7
+ configure ( { adapter : new Adapter ( ) } ) ;
8
+ // Test the life cycle methods in Chart
9
+ describe ( 'Life cycle methods in Chart' , ( ) => {
10
+ let wrapper ;
11
+ const props = {
12
+ hierarchy : 0 ,
13
+ } ;
14
+ // Set up wrapper
15
+ beforeEach ( ( ) => {
16
+ wrapper = mount ( < Chart { ...props } /> ) ;
17
+ } ) ;
18
+ // test componentDidMount
19
+ it ( 'should call componentDidMount once' , ( ) => {
20
+ const instance = wrapper . instance ( ) ;
21
+ jest . spyOn ( instance , 'componentDidMount' ) ;
22
+ instance . componentDidMount ( ) ;
23
+ expect ( instance . componentDidMount ) . toHaveBeenCalledTimes ( 1 ) ;
24
+ } ) ;
25
+ // test maked3Tree within componentDidMount
26
+ it ( 'should call maked3Tree upon mounting' , ( ) => {
27
+ const instance = wrapper . instance ( ) ;
28
+ jest . spyOn ( instance , 'maked3Tree' ) ;
29
+ instance . componentDidMount ( ) ;
30
+ expect ( instance . maked3Tree ) . toHaveBeenCalledTimes ( 1 ) ;
31
+ } ) ;
32
+ // test componentDidUpdate
33
+ it ( 'should call componentDidUpdate once' , ( ) => {
34
+ const instance = wrapper . instance ( ) ;
35
+ jest . spyOn ( instance , 'componentDidUpdate' ) ;
36
+ instance . componentDidUpdate ( ) ;
37
+ expect ( instance . componentDidUpdate ) . toHaveBeenCalledTimes ( 1 ) ;
38
+ } ) ;
39
+ // test maked3Tree within componentDidUpdate
40
+ it ( 'should call maked3Tree once upon updating' , ( ) => {
41
+ const instance = wrapper . instance ( ) ;
42
+ jest . spyOn ( instance , 'maked3Tree' ) ;
43
+ instance . componentDidUpdate ( ) ;
44
+ expect ( instance . maked3Tree ) . toHaveBeenCalledTimes ( 1 ) ;
45
+ } ) ;
46
+ } ) ;
47
+ // Test the root object and hierarchy
48
+ describe ( 'Root object' , ( ) => {
49
+ let wrapper ;
50
+ const root = { } ;
51
+ const props = {
52
+ hierarchy : {
53
+ index : 1 ,
54
+ stateSnapshot : { } ,
55
+ children : [ ] ,
56
+ } ,
57
+ } ;
58
+ // Set up wrapper
59
+ beforeEach ( ( ) => {
60
+ wrapper = mount ( < Chart { ...props } /> ) ;
61
+ } ) ;
22
62
23
- describe ( 'placeholder' , ( ) => {
24
- it . skip ( 'placeholder for tests' , ( ) => {
25
- expect ( 1 + 1 ) . toEqual ( 2 ) ;
63
+ it ( 'should be a deep clone of the hierarchy' , ( ) => {
64
+ const instance = wrapper . instance ( ) ;
65
+ instance . componentDidMount ( ) ;
66
+ expect ( typeof root ) . toBe ( typeof props . hierarchy ) ;
67
+ expect ( root ) . not . toEqual ( props . hierarchy ) ;
26
68
} ) ;
27
69
} ) ;
70
+
71
+ // Test the maked3Tree method
72
+ describe ( 'maked3Tree method' , ( ) => {
73
+ let wrapper ;
74
+ const props = {
75
+ hierarchy : 0 ,
76
+ } ;
77
+ // Set up wrapper
78
+ beforeEach ( ( ) => {
79
+ wrapper = mount ( < Chart { ...props } /> ) ;
80
+ } ) ;
81
+ // Test the invocation of removed3Tree within maked3Tree
82
+ it ( 'should call removed3Tree once' , ( ) => {
83
+ const instance = wrapper . instance ( ) ;
84
+ jest . spyOn ( instance , 'removed3Tree' ) ;
85
+ instance . maked3Tree ( ) ;
86
+ expect ( instance . removed3Tree ) . toHaveBeenCalledTimes ( 1 ) ;
87
+ } ) ;
88
+ } ) ;
0 commit comments