Skip to content

Commit 355def4

Browse files
authored
Merge pull request #136 from open-source-labs/d3-testing
D3 testing completed + additional code base cleanup
2 parents a12e83a + e2debb6 commit 355def4

File tree

6 files changed

+89
-48
lines changed

6 files changed

+89
-48
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
},
1313
"keywords": [
1414
"react",
15-
"time",
16-
"time travel",
15+
"useState",
16+
"state",
17+
"debug",
18+
"react dev tool",
1719
"reactime"
1820
],
1921
"repository": {

package/__tests__/linkFiber.test.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,6 @@ class App extends Component {
2020
}
2121
}
2222

23-
// Need to create a functioanl component instance to test
24-
// Would need to be revised but here's the gist
25-
// const funcComponent = () => {
26-
// const [ number, setNumber ] = useState(0);
27-
// const newNumber = setNumber(1);
28-
29-
// return (
30-
// <div>{newNumber}</div>
31-
// )
32-
// }
33-
3423
describe('unit test for linkFiber', () => {
3524
beforeEach(() => {
3625
snapShot = { tree: null };

package/__tests__/timeJump.test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ class FiberNode {
2020
}
2121
}
2222

23-
// MVP FEATURE: Additional Testing
24-
// Testing for useState and useContext
25-
26-
2723
describe('unit testing for timeJump.js', () => {
2824
let timeJump;
2925
let snapShot;

src/app/__tests__/Chart.test.jsx

Lines changed: 85 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,88 @@
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+
});
2262

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);
2668
});
2769
});
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+
});

src/app/components/Chart.jsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
/* eslint-disable no-use-before-define */
1111
/* eslint-disable react/no-string-refs */
1212
import React, { Component } from 'react';
13-
// import PropTypes from 'prop-types';
1413
import * as d3 from 'd3';
15-
// import d3Tip from 'd3-tip';
1614

1715
let root = {};
1816
class Chart extends Component {
@@ -192,8 +190,4 @@ class Chart extends Component {
192190
}
193191
}
194192

195-
// Chart.propTypes = {
196-
// snapshot: PropTypes.arrayOf(PropTypes.object).isRequired,
197-
// };
198-
199193
export default Chart;

src/app/containers/ActionContainer.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable react/no-array-index-key */
22
import React from 'react';
3-
// import SwitchStateDropdown from '../components/SwitchState';
43
import Action from '../components/Action';
54

65
import { emptySnapshots } from '../actions/actions';

0 commit comments

Comments
 (0)