Skip to content

Commit eb57db9

Browse files
C-STYRkev-ngoCourageWolfDennisLpzdemircaner
committed
Created enzyme test for new WebMetrics tab
Co-authored-by: kev-ngo <[email protected]> Co-authored-by: CourageWolf <[email protected]> Co-authored-by: DennisLpz <[email protected]> Co-authored-by: demircaner <[email protected]>
1 parent f186970 commit eb57db9

File tree

11 files changed

+45
-46
lines changed

11 files changed

+45
-46
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
"@babel/plugin-proposal-decorators": "^7.10.5",
7575
"@babel/preset-env": "^7.12.7",
7676
"@babel/preset-react": "^7.12.7",
77+
"@testing-library/jest-dom": "^4.2.4",
78+
"@types/chai": "^4.2.14",
7779
"@types/chrome": "^0.0.119",
7880
"@types/d3-scale-chromatic": "^2.0.0",
7981
"@types/jest": "^26.0.4",
@@ -85,7 +87,7 @@
8587
"core-js": "^3.6.5",
8688
"css-loader": "^3.6.0",
8789
"enzyme": "^3.11.0",
88-
"enzyme-adapter-react-16": "^1.15.2",
90+
"enzyme-adapter-react-16": "^1.15.6",
8991
"eslint": "^6.8.0",
9092
"eslint-config-airbnb": "^18.2.0",
9193
"eslint-plugin-import": "^2.22.0",
@@ -107,6 +109,7 @@
107109
"style-loader": "^0.23.1",
108110
"ts-jest": "^26.1.2",
109111
"ts-loader": "^7.0.5",
112+
"ts-node": "^9.1.1",
110113
"typedoc": "^0.17.8",
111114
"typedoc-webpack-plugin": "^1.1.4",
112115
"typescript": "^3.9.6",
@@ -140,6 +143,7 @@
140143
"acorn": "^7.3.1",
141144
"acorn-jsx": "^5.2.0",
142145
"apexcharts": "^3.23.1",
146+
"chai": "^4.2.0",
143147
"cookie": "^0.4.1",
144148
"d3": "^5.16.0",
145149
"d3-scale-chromatic": "^2.0.0",

src/app/__tests__/ActionContainer.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ useStoreContext.mockImplementation(() => [state, dispatch]);
8282

8383
let wrapper;
8484

85+
//actionView={true} must be passed in to <ActionContainer /> in beforeEach() to deal with new
86+
//conditional rendering in ActionContainer that shows/hides time-travel functionality
87+
8588
beforeEach(() => {
86-
wrapper = shallow(<ActionContainer />);
89+
wrapper = shallow(<ActionContainer actionView={true}/>);
8790
useStoreContext.mockClear();
8891
dispatch.mockClear();
8992
});

src/app/__tests__/MainContainer.test.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Adapter from 'enzyme-adapter-react-16';
88
import MainContainer from '../containers/MainContainer';
99
import { useStoreContext } from '../store';
1010

11-
import HeadContainer from '../containers/HeadContainer';
1211
import ActionContainer from '../containers/ActionContainer';
1312
import StateContainer from '../containers/StateContainer';
1413
import TravelContainer from '../containers/TravelContainer';
@@ -50,7 +49,6 @@ describe('MainContainer rendering', () => {
5049
expect(wrapper.text()).toEqual(
5150
'No React application found. Please visit reactime.io to more info.If you are using a React application, make sure tha you application is running in development mode.NOTE: The React Developer Tools extension is also required for Reactime to run, if you do not already have it installed on your browser.',
5251
);
53-
expect(wrapper.find(HeadContainer).length).toBe(0);
5452
expect(wrapper.find(ActionContainer).length).toBe(0);
5553
expect(wrapper.find(StateContainer).length).toBe(0);
5654
expect(wrapper.find(TravelContainer).length).toBe(0);
@@ -66,7 +64,6 @@ describe('MainContainer rendering', () => {
6664
};
6765

6866
wrapper = shallow(<MainContainer />);
69-
expect(wrapper.find(HeadContainer).length).toBe(1);
7067
expect(wrapper.find(ActionContainer).length).toBe(1);
7168
expect(wrapper.find(StateContainer).length).toBe(1);
7269
expect(wrapper.find(TravelContainer).length).toBe(1);

src/app/__tests__/WebMetrics.test.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* eslint:disable */
2+
import React from 'react';
3+
import { shallow, configure } from 'enzyme';
4+
import Adapter from 'enzyme-adapter-react-16';
5+
import WebMetrics from '../components/WebMetrics';
6+
import { expect } from 'chai';
7+
8+
9+
//the WebMetrics container should render 4 <div/> elements, each with id="card"
10+
//the WebMetrics container is itself <div class="web-metrics-container" />
11+
configure({ adapter: new (Adapter as any)() });
12+
13+
let wrapper = shallow(<WebMetrics />);
14+
15+
16+
describe('WebMetrics graph testing', ()=> {
17+
it ('should have 1 div with id "card" ', () => {
18+
expect(wrapper.find('#card')).to.have.lengthOf(1);
19+
})
20+
21+
it ('should have 1 div with id "chart" ', () => {
22+
expect(wrapper.find('#chart')).to.have.lengthOf(1);
23+
})
24+
25+
26+
})
27+

src/app/components/StateRoute.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ const StateRoute = (props: StateRouteProps) => {
139139
<div className="web-metrics-container">
140140
<WebMetrics color={LCPColor} series={(webMetrics.LCP / 2500) * 100} formatted={(val) => ((val / 100) * 2500).toFixed(2) + ' ms'} label="LCP"/>
141141
<WebMetrics color={FIDColor} series={(webMetrics.FID) * 25} formatted={(val) => ((val / 25)).toFixed(2) + ' ms'} label="FID"/>
142-
{/* <WebMetrics color={CLSColor} series={(webMetrics.CLS * 50) * 100} formatted={(val) => ((val / 100) / 50).toFixed(2)} label="CLS"/> */}
143-
<WebMetrics color={FCPColor} series={(webMetrics.FCP / 1000) * 100} formatted={(val) => ((val / 100) * 1000).toFixed(2) + ' ms'} label="FCP"/>
142+
<WebMetrics onMouseOver={() => handleMouseOver()} description={FCPDescription} color={FCPColor} series={(webMetrics.FCP / 1000) * 100} formatted={(val) => ((val / 100) * 1000).toFixed(2) + ' ms'} label="FCP"/>
144143
<WebMetrics color={TTFBColor} series={(webMetrics.TTFB / 10) * 100} formatted={(val) => ((val / 100) * 10).toFixed(2) + ' ms'} label="TTFB"/>
145144
</div>
146145
);

src/app/components/WebMetrics.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState, useEffect, Component } from 'react';
22
import Charts from 'react-apexcharts';
33
import useForceUpdate from './useForceUpdate';
44

5+
56
const radialGraph = (props) => {
67

78
const state = {
@@ -84,7 +85,7 @@ const radialGraph = (props) => {
8485
lineCap: 'flat'
8586
},
8687
labels: [props.label],
87-
},
88+
},
8889
};
8990

9091

src/app/containers/ActionContainer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ function ActionContainer(props) {
117117
setActionView(true);
118118
}, []);
119119

120-
// this is not logging; the prop is not being udpdated or the component is not being re-rendered.
120+
//the conditional logic below will cause ActionContainer.test.tsx to fail as it cannot find the Empty button
121+
//UNLESS actionView={true} is passed into <ActionContainer /> in the beforeEach() call in ActionContainer.test.tsx
121122
return (
122123
<div id='action-id' className='action-container'>
123124
<div id='arrow'>

src/app/containers/HeadContainer.tsx

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/app/containers/MainContainer.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useEffect, useState } from 'react';
2-
import HeadContainer from './HeadContainer';
32
import ActionContainer from './ActionContainer';
43
import StateContainer from './StateContainer';
54
import TravelContainer from './TravelContainer';
@@ -29,9 +28,6 @@ function MainContainer(): any {
2928
const toggleElem = document.querySelector('aside');
3029
toggleElem.classList.toggle('no-aside');
3130
};
32-
useEffect(() => {
33-
setActionView(true);
34-
}, []);
3531

3632
useEffect(() => {
3733
// only open port once
@@ -189,7 +185,6 @@ function MainContainer(): any {
189185

190186
return (
191187
<div className='main-container'>
192-
{/* <HeadContainer /> */}
193188
<div id='bodyContainer' className='body-container1'>
194189
<ActionContainer
195190
actionView={actionView}
@@ -198,7 +193,6 @@ function MainContainer(): any {
198193
/>
199194
{snapshots.length ? (
200195
<StateContainer
201-
toggleActionContainer={toggleActionContainer}
202196
webMetrics={webMetrics}
203197
viewIndex={viewIndex}
204198
snapshot={snapshotDisplay}

src/app/containers/StateContainer.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ interface StateContainerProps {
2424
}
2525
>;
2626
toggleActionContainer?: any;
27-
webMetrics: object;
27+
webMetrics?: object;
2828
AtomsRelationship?: any[];
2929
hierarchy: Record<string, unknown>;
30-
snapshots: [];
31-
viewIndex: number;
30+
snapshots?: [];
31+
viewIndex?: number;
3232
}
3333

3434
// eslint-disable-next-line react/prop-types
@@ -38,7 +38,6 @@ const StateContainer = (props: StateContainerProps): JSX.Element => {
3838
hierarchy,
3939
snapshots,
4040
viewIndex,
41-
toggleActionContainer,
4241
webMetrics,
4342
} = props;
4443

@@ -48,20 +47,6 @@ const StateContainer = (props: StateContainerProps): JSX.Element => {
4847
<div className='main-navbar-container'>
4948
<div className='main-navbar-text'>
5049
{' '}
51-
{/* <button
52-
id='side-bar-button'
53-
className='toggleAC'
54-
onClick={() => toggleActionContainer()}
55-
>
56-
Close
57-
</button> */}
58-
{/* <div className='toggleAC'>
59-
<aside className='no-aside'>
60-
<a className='toggle'>
61-
<i></i>
62-
</a>
63-
</aside>
64-
</div> */}
6550
</div>
6651
<div className='main-navbar'>
6752
<NavLink

0 commit comments

Comments
 (0)