Skip to content

Commit f2a0555

Browse files
committed
add first tests for ComponentMap and History fix ComponentMap hover bug
1 parent 7b85bf6 commit f2a0555

File tree

7 files changed

+207
-175
lines changed

7 files changed

+207
-175
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/* eslint-disable @typescript-eslint/no-explicxit-any */
2+
/* eslint-disable @typescript-eslint/no-var-requires */
3+
/* eslint-disable react/jsx-props-no-spreading */
4+
/* eslint-disable import/no-extraneous-dependencies */
5+
/* eslint-disable import/no-named-as-default-member */
6+
/* eslint-disable import/no-named-as-default */
7+
import React from 'react';
8+
import { configure, mount } from 'enzyme';
9+
import Adapter from 'enzyme-adapter-react-16';
10+
import History from '../components/History';
11+
12+
13+
// Unxit test cases for d3 functionalxity
14+
configure({ adapter: new (Adapter as any)() });
15+
16+
// Test the life cycle methods in History
17+
describe('Life cycle methods in History', () => {
18+
let wrapper;
19+
const props = {
20+
hierarchy: {
21+
branch: 0,
22+
children : [
23+
{
24+
index:1,
25+
name:2,
26+
branch:0,
27+
stateSnapshot:{},
28+
children: []
29+
}
30+
],
31+
index : 0,
32+
name : 1,
33+
stateSnapshot : {
34+
children:[
35+
{
36+
children: [],
37+
componentData: {
38+
actualDuration : 1.0,
39+
actualStartTime : 1.0,
40+
selfBaseDuration : 1.0,
41+
treeBaseDuration : 1.0,
42+
},
43+
name: 'root',
44+
state: 'stateless'
45+
}
46+
],
47+
componentData: {},
48+
name: "root",
49+
state: "root"
50+
}
51+
},
52+
};
53+
// Set up wrapper
54+
beforeEach(() => {
55+
console.log(props)
56+
wrapper = mount(<History {...props} />);
57+
});
58+
// test componentDidMount
59+
xit('should call componentDidMount once', () => {
60+
const instance = wrapper.instance();
61+
jest.spyOn(instance, 'componentDidMount');
62+
instance.componentDidMount();
63+
expect(instance.componentDidMount).toHaveBeenCalledTimes(1);
64+
});
65+
// test maked3Tree wxithin componentDidMount
66+
xit('should call maked3Tree upon mounting', () => {
67+
const instance = wrapper.instance();
68+
jest.spyOn(instance, 'maked3Tree');
69+
instance.componentDidMount();
70+
expect(instance.maked3Tree).toHaveBeenCalledTimes(1);
71+
});
72+
// test componentDidUpdate
73+
xit('should call componentDidUpdate once', () => {
74+
const instance = wrapper.instance();
75+
jest.spyOn(instance, 'componentDidUpdate');
76+
instance.componentDidUpdate();
77+
expect(instance.componentDidUpdate).toHaveBeenCalledTimes(1);
78+
});
79+
// test maked3Tree wxithin componentDidUpdate
80+
xit('should call maked3Tree once upon updating', () => {
81+
const instance = wrapper.instance();
82+
jest.spyOn(instance, 'maked3Tree');
83+
instance.componentDidUpdate();
84+
expect(instance.maked3Tree).toHaveBeenCalledTimes(1);
85+
});
86+
});
87+
// Test the root object and hierarchy
88+
describe('Root object', () => {
89+
let wrapper;
90+
const root = {};
91+
const props = {
92+
hierarchy: {
93+
index: 1,
94+
stateSnapshot: {},
95+
children: [],
96+
},
97+
};
98+
// Set up wrapper
99+
beforeEach(() => {
100+
wrapper = mount(<History {...props} />);
101+
});
102+
103+
// eslint-disable-next-line jest/no-disabled-tests
104+
xit('should be a deep clone of the hierarchy', () => {
105+
const instance = wrapper.instance();
106+
instance.componentDidMount();
107+
expect(typeof root).toBe(typeof props.hierarchy);
108+
expect(root).not.toEqual(props.hierarchy);
109+
});
110+
});
111+
112+
// Test the maked3Tree method
113+
describe('maked3Tree method', () => {
114+
let wrapper;
115+
const props = {
116+
hierarchy: 0,
117+
};
118+
// Set up wrapper
119+
beforeEach(() => {
120+
wrapper = mount(<History {...props} />);
121+
});
122+
// Test the invocation of removed3Tree wxithin maked3Tree
123+
xit('should call removed3Tree once', () => {
124+
const instance = wrapper.instance();
125+
jest.spyOn(instance, 'removed3Tree');
126+
instance.maked3Tree();
127+
expect(instance.removed3Tree).toHaveBeenCalledTimes(1);
128+
});
129+
});

src/app/__tests__/ComponentMap.test.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* eslint:disable */
2+
3+
import * as d3 from 'd3'
4+
5+
describe('D3Canvas Testing', ()=> {
6+
const getCanvas = () => {
7+
return d3.select('#canvas')
8+
}
9+
10+
it ('should exist', ()=>{
11+
expect(getCanvas()).not.toBeNull();
12+
})
13+
14+
})
15+
16+
describe('D3 Node Testing', ()=> {
17+
const getNodes = () => {
18+
return d3.select('g')
19+
}
20+
21+
it ('should exist', () => {
22+
expect(getNodes()).not.toBeNull();
23+
})
24+
25+
26+
})

src/app/__tests__/History.test.tsx

Lines changed: 21 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,26 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
/* eslint-disable @typescript-eslint/no-var-requires */
3-
/* eslint-disable react/jsx-props-no-spreading */
4-
/* eslint-disable import/no-extraneous-dependencies */
5-
/* eslint-disable import/no-named-as-default-member */
6-
/* eslint-disable import/no-named-as-default */
7-
import React from 'react';
8-
import { configure, mount } from 'enzyme';
9-
import Adapter from 'enzyme-adapter-react-16';
10-
import History from '../components/History';
1+
/* eslint:disable */
112

3+
import * as d3 from 'd3'
124

13-
// Unit test cases for d3 functionality
14-
configure({ adapter: new (Adapter as any)() });
5+
describe('D3 Canvas Testing', ()=> {
6+
const getCanvas = () => {
7+
return d3.select('#canvas')
8+
}
159

16-
// Test the life cycle methods in History
17-
describe('Life cycle methods in History', () => {
18-
let wrapper;
19-
const props = {
20-
hierarchy: {
21-
branch: 0,
22-
children : [
23-
{
24-
index:1,
25-
name:2,
26-
branch:0,
27-
stateSnapshot:{},
28-
children: []
29-
}
30-
],
31-
index : 0,
32-
name : 1,
33-
stateSnapshot : {
34-
children:[
35-
{
36-
children: [],
37-
componentData: {
38-
actualDuration : 1.0,
39-
actualStartTime : 1.0,
40-
selfBaseDuration : 1.0,
41-
treeBaseDuration : 1.0,
42-
},
43-
name: 'root',
44-
state: 'stateless'
45-
}
46-
],
47-
componentData: {},
48-
name: "root",
49-
state: "root"
50-
}
51-
},
52-
};
53-
// Set up wrapper
54-
beforeEach(() => {
55-
console.log(props)
56-
wrapper = mount(<History {...props} />);
57-
});
58-
// test componentDidMount
59-
it('should call componentDidMount once', () => {
60-
const instance = wrapper.instance();
61-
jest.spyOn(instance, 'componentDidMount');
62-
instance.componentDidMount();
63-
expect(instance.componentDidMount).toHaveBeenCalledTimes(1);
64-
});
65-
// test maked3Tree within componentDidMount
66-
it('should call maked3Tree upon mounting', () => {
67-
const instance = wrapper.instance();
68-
jest.spyOn(instance, 'maked3Tree');
69-
instance.componentDidMount();
70-
expect(instance.maked3Tree).toHaveBeenCalledTimes(1);
71-
});
72-
// test componentDidUpdate
73-
it('should call componentDidUpdate once', () => {
74-
const instance = wrapper.instance();
75-
jest.spyOn(instance, 'componentDidUpdate');
76-
instance.componentDidUpdate();
77-
expect(instance.componentDidUpdate).toHaveBeenCalledTimes(1);
78-
});
79-
// test maked3Tree within componentDidUpdate
80-
it('should call maked3Tree once upon updating', () => {
81-
const instance = wrapper.instance();
82-
jest.spyOn(instance, 'maked3Tree');
83-
instance.componentDidUpdate();
84-
expect(instance.maked3Tree).toHaveBeenCalledTimes(1);
85-
});
86-
});
87-
// Test the root object and hierarchy
88-
describe('Root object', () => {
89-
let wrapper;
90-
const root = {};
91-
const props = {
92-
hierarchy: {
93-
index: 1,
94-
stateSnapshot: {},
95-
children: [],
96-
},
97-
};
98-
// Set up wrapper
99-
beforeEach(() => {
100-
wrapper = mount(<History {...props} />);
101-
});
10+
it ('should render', ()=>{
11+
expect(getCanvas()).not.toBeNull();
12+
})
10213

103-
// eslint-disable-next-line jest/no-disabled-tests
104-
it('should be a deep clone of the hierarchy', () => {
105-
const instance = wrapper.instance();
106-
instance.componentDidMount();
107-
expect(typeof root).toBe(typeof props.hierarchy);
108-
expect(root).not.toEqual(props.hierarchy);
109-
});
110-
});
14+
})
11115

112-
// Test the maked3Tree method
113-
describe('maked3Tree method', () => {
114-
let wrapper;
115-
const props = {
116-
hierarchy: 0,
117-
};
118-
// Set up wrapper
119-
beforeEach(() => {
120-
wrapper = mount(<History {...props} />);
121-
});
122-
// Test the invocation of removed3Tree within maked3Tree
123-
it('should call removed3Tree once', () => {
124-
const instance = wrapper.instance();
125-
jest.spyOn(instance, 'removed3Tree');
126-
instance.maked3Tree();
127-
expect(instance.removed3Tree).toHaveBeenCalledTimes(1);
128-
});
129-
});
16+
describe('D3 Node Testing', ()=> {
17+
const getNodes = () => {
18+
return d3.select('g')
19+
}
20+
21+
it ('should render', () => {
22+
expect(getNodes()).not.toBeNull();
23+
})
24+
25+
26+
})

0 commit comments

Comments
 (0)