Skip to content

Commit b72de4c

Browse files
authored
Merge pull request #22 from CourageWolf/integration
Integrated features for pre-launch (webmetrics, testing, ui)
2 parents 957db15 + 267661d commit b72de4c

23 files changed

+705
-740
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 class name "metric" ', () => {
18+
expect(wrapper.find('.metric')).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/BarGraph.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { scaleBand, scaleLinear, scaleOrdinal } from '@visx/scale';
99
import { useTooltip, useTooltipInPortal, defaultStyles } from '@visx/tooltip';
1010
import { Text } from '@visx/text';
1111
import { schemeSet3 } from 'd3-scale-chromatic';
12-
import snapshots from './snapshots';
1312
import { onHover, onHoverExit } from '../actions/actions';
1413
import { useStoreContext } from '../store';
1514
import { save } from '../actions/actions';
@@ -126,7 +125,7 @@ const BarGraph = (props) => {
126125
return (
127126
<div>
128127
<button
129-
className='save-series-button'
128+
className="save-series-button"
130129
onClick={(e) => {
131130
dispatch(save(toStorage));
132131
}}
@@ -150,7 +149,7 @@ const BarGraph = (props) => {
150149
yScale={renderingScale}
151150
width={xMax}
152151
height={yMax}
153-
stroke='black'
152+
stroke="black"
154153
strokeOpacity={0.1}
155154
xOffset={snapshotIdScale.bandwidth() / 2}
156155
/>
@@ -166,9 +165,7 @@ const BarGraph = (props) => {
166165
{(barStacks) =>
167166
barStacks.map((barStack) =>
168167
barStack.bars.map((bar, idx) => {
169-
console.log('barstacks >>>', barStack);
170-
console.log('bars >>>', bar);
171-
// hides new components if components don't exist in previous snapshots
168+
// Hides new components if components don't exist in previous snapshots.
172169
if (Number.isNaN(bar.bar[1]) || bar.height < 0) {
173170
bar.height = 0;
174171
}
@@ -181,7 +178,7 @@ const BarGraph = (props) => {
181178
width={bar.width}
182179
fill={bar.color}
183180
/* TIP TOOL EVENT HANDLERS */
184-
// Hides tool tip once cursor moves off the current rect
181+
// Hides tool tip once cursor moves off the current rect.
185182
onMouseLeave={() => {
186183
dispatch(
187184
onHoverExit(data.componentData[bar.key].rtid),
@@ -190,7 +187,7 @@ const BarGraph = (props) => {
190187
}, 300))
191188
);
192189
}}
193-
// Cursor position in window updates position of the tool tip
190+
// Cursor position in window updates position of the tool tip.
194191
onMouseMove={(event) => {
195192
dispatch(onHover(data.componentData[bar.key].rtid));
196193
if (tooltipTimeout) clearTimeout(tooltipTimeout);
@@ -238,15 +235,15 @@ const BarGraph = (props) => {
238235
/>
239236
<Text
240237
x={-xMax / 2}
241-
y='15'
242-
transform='rotate(-90)'
238+
y="15"
239+
transform="rotate(-90)"
243240
fontSize={12}
244-
fill='#FFFFFF'
241+
fill="#FFFFFF"
245242
>
246243
Rendering Time (ms)
247244
</Text>
248245
<br />
249-
<Text x={xMax / 2 + 15} y={yMax + 70} fontSize={12} fill='#FFFFFF'>
246+
<Text x={xMax / 2 + 15} y={yMax + 70} fontSize={12} fill="#FFFFFF">
250247
Snapshot ID
251248
</Text>
252249
</svg>

src/app/components/BarGraphComparison.tsx

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-nocheck
2-
import React, { useEffect, useForceUpdate } from 'react';
2+
import React from 'react';
33
import { BarStack } from '@visx/shape';
44
import { SeriesPoint } from '@visx/shape/lib/types';
55
import { Group } from '@visx/group';
@@ -8,15 +8,11 @@ import { AxisBottom, AxisLeft } from '@visx/axis';
88
import { scaleBand, scaleLinear, scaleOrdinal } from '@visx/scale';
99
import { useTooltip, useTooltipInPortal, defaultStyles } from '@visx/tooltip';
1010
import { Text } from '@visx/text';
11-
1211
import { schemeSet3 } from 'd3-scale-chromatic';
1312
import { makeStyles } from '@material-ui/core/styles';
1413
import Select from '@material-ui/core/Select';
15-
import InputLabel from '@material-ui/core/InputLabel';
1614
import MenuItem from '@material-ui/core/MenuItem';
1715
import FormControl from '@material-ui/core/FormControl';
18-
import FormHelperText from '@material-ui/core/FormHelperText';
19-
import snapshots from './snapshots';
2016
import { onHover, onHoverExit } from '../actions/actions';
2117
import { useStoreContext } from '../store';
2218
import { deleteSeries } from '../actions/actions';
@@ -105,15 +101,17 @@ const BarGraphComparison = (props) => {
105101
const formatRenderTime = (time) => `${time} ms `;
106102
const getCurrentTab = (storedSeries) => storedSeries.currentTab;
107103
// create visualization SCALES with cleaned data
108-
//const xAxisPoints = [...titleFilter(comparison).map(getTabID), currentTab];
109-
//the domain array elements will place the bars along the x-axis
110-
const xAxisPoints = ['currentTab', 'comparison']; //[1.0.,2.0]
111-
//{ currentTab : 1 }, {currentTab : 2 }
104+
// the domain array/xAxisPoints elements will place the bars along the x-axis
105+
const xAxisPoints = ['currentTab', 'comparison'];
112106
const snapshotIdScale = scaleBand<string>({
113107
domain: xAxisPoints,
114108
padding: 0.2,
115109
});
116-
// calculateMax
110+
// This function will iterate through the snapshots of the series,
111+
// and grab the highest render times (sum of all component times).
112+
// We'll then use it in the renderingScale function and compare
113+
// with the render time of the current tab.
114+
// The max render time will determine the Y-axis's highest number.
117115
const calculateMaxTotalRender = (series) => {
118116
const currentSeriesBarStacks = !comparison[series]
119117
? []
@@ -128,11 +126,13 @@ const BarGraphComparison = (props) => {
128126
return currentMax;
129127
};
130128

129+
// the domain array on rendering scale will set the coordinates for Y-aix points.
131130
const renderingScale = scaleLinear<number>({
132131
domain: [0, Math.max(calculateMaxTotalRender(series), data.maxTotalRender)],
133132
nice: true,
134133
});
135-
134+
// the domain array will assign each key(component on test app) a different color
135+
// and use range to set the color scheme each bar
136136
const colorScale = scaleOrdinal<string>({
137137
domain: keys,
138138
range: schemeSet3,
@@ -144,7 +144,7 @@ const BarGraphComparison = (props) => {
144144
snapshotIdScale.rangeRound([0, xMax]);
145145
renderingScale.range([yMax, 0]);
146146

147-
// Dropdown to select series.
147+
// useStyles will change the styling on save series dropdown feature
148148
const useStyles = makeStyles((theme) => ({
149149
formControl: {
150150
margin: theme.spacing(1),
@@ -198,37 +198,37 @@ const BarGraphComparison = (props) => {
198198
e.target.classList.add('animate');
199199
e.target.innerHTML = 'Deleted!';
200200
setTimeout(function () {
201-
e.target.innerHTML = 'Clear Series';
201+
e.target.innerHTML = 'Clear All Series';
202202
e.target.classList.remove('animate');
203203
}, 1000);
204204
};
205205
const classname = document.getElementsByClassName('delete-button');
206206
for (let i = 0; i < classname.length; i++) {
207207
classname[i].addEventListener('click', animateButton, false);
208208
}
209-
//console.log('set x on current bar', setXpointsCurrentTab());
210209
return (
211210
<div>
212-
<div className='series-options-container'>
213-
<div className='snapshotId-header'>
211+
<div className="series-options-container">
212+
<div className="snapshotId-header">
214213
{' '}
215214
Snapshot ID: {currentIndex + 1}{' '}
216215
</div>
217216

218-
<div className='dropdown-and-delete-series-container'>
217+
<div className="dropdown-and-delete-series-container">
219218
<button
220-
className='delete-button'
219+
className="delete-button"
221220
onClick={(e) => {
222221
dispatch(deleteSeries());
223222
}}
224223
>
225224
Clear All Series
226225
</button>
227-
<FormControl variant='outlined' className={classes.formControl}>
226+
<h4 style={{ padding: '0 1rem' }}>Compare with: </h4>
227+
<FormControl variant="outlined" className={classes.formControl}>
228228
<Select
229229
style={{ color: 'white' }}
230-
labelId='simple-select-outlined-label'
231-
id='simple-select-outlined'
230+
labelId="simple-select-outlined-label"
231+
id="simple-select-outlined"
232232
className={classes.select}
233233
open={open}
234234
onClose={handleClose}
@@ -267,13 +267,13 @@ const BarGraphComparison = (props) => {
267267
yScale={renderingScale}
268268
width={xMax}
269269
height={yMax}
270-
stroke='black'
270+
stroke="black"
271271
strokeOpacity={0.1}
272272
xOffset={snapshotIdScale.bandwidth() / 2}
273273
/>
274274
<Group top={margin.top} left={margin.left}>
275275
<BarStack
276-
// OG Barstack
276+
// Current Tab bar stack.
277277
data={setXpointsCurrentTab()}
278278
keys={keys}
279279
x={getCurrentTab}
@@ -283,6 +283,11 @@ const BarGraphComparison = (props) => {
283283
>
284284
{(barStacks) =>
285285
barStacks.map((barStack, idx) => {
286+
// Uses map method to iterate through all components,
287+
// creating a rect component (from visx) for each iteration.
288+
// height/width/etc. are calculated by visx.
289+
// to set X and Y scale, it will used the passed in function and
290+
// will run it on the array thats outputted by data
286291
const bar = barStack.bars[currentIndex];
287292
if (Number.isNaN(bar.bar[1]) || bar.height < 0) {
288293
bar.height = 0;
@@ -323,7 +328,9 @@ const BarGraphComparison = (props) => {
323328
}
324329
</BarStack>
325330
<BarStack
326-
// Comparison Barstack
331+
// Comparison Barstack (populates based on series selected)
332+
//to set X and Y scale, it will used the passed in function and
333+
// will run it on the array thats outputted by data
327334
data={!comparison[series] ? [] : setXpointsComparison()}
328335
keys={keys}
329336
x={getCurrentTab}
@@ -333,6 +340,9 @@ const BarGraphComparison = (props) => {
333340
>
334341
{(barStacks) =>
335342
barStacks.map((barStack, idx) => {
343+
// Uses map method to iterate through all components,
344+
// creating a rect component (from visx) for each iteration.
345+
// height/width/etc. are calculated by visx.
336346
if (!barStack.bars[currentIndex]) {
337347
return <h1>No Comparison</h1>;
338348
}
@@ -405,14 +415,14 @@ const BarGraphComparison = (props) => {
405415
/>
406416
<Text
407417
x={-xMax / 2}
408-
y='15'
409-
transform='rotate(-90)'
418+
y="15"
419+
transform="rotate(-90)"
410420
fontSize={12}
411-
fill='#FFFFFF'
421+
fill="#FFFFFF"
412422
>
413423
Rendering Time (ms)
414424
</Text>
415-
<Text x={xMax / 2} y={yMax + 65} fontSize={12} fill='#FFFFFF'>
425+
<Text x={xMax / 2} y={yMax + 65} fontSize={12} fill="#FFFFFF">
416426
Series ID
417427
</Text>
418428
</svg>

0 commit comments

Comments
 (0)