Skip to content

Commit 58afec7

Browse files
authored
Merge pull request #14 from oslabs-beta/45/timetraveling_tests
latest version history finished & no fail tests
2 parents e15a0c6 + a3a3a8d commit 58afec7

File tree

9 files changed

+55
-40
lines changed

9 files changed

+55
-40
lines changed

src/app/__tests__/ActionContainer.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ const state = {
6868
}],
6969
}],
7070
},
71+
currLocation: {
72+
index: 0,
73+
name: 1,
74+
branch: 0,
75+
},
7176
sliderIndex: 0,
7277
viewIndex: -1,
7378
},
@@ -86,7 +91,7 @@ let wrapper;
8691
//conditional rendering in ActionContainer that shows/hides time-travel functionality
8792

8893
beforeEach(() => {
89-
wrapper = shallow(<ActionContainer actionView={true}/>);
94+
wrapper = shallow(<ActionContainer actionView={true} />);
9095
useStoreContext.mockClear();
9196
dispatch.mockClear();
9297
});

src/app/actions/actions.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const save = (tabsObj) => ({
55
type: types.SAVE,
66
payload: tabsObj,
77
});
8-
export const deleteSeries = () =>({
8+
export const deleteSeries = () => ({
99
type: types.DELETE_SERIES,
1010
})
1111
export const toggleMode = (mode) => ({
@@ -95,3 +95,8 @@ export const onHoverExit = (rtid) => ({
9595
type: types.ON_HOVER_EXIT,
9696
payload: rtid,
9797
});
98+
99+
export const setCurrentLocation = (tabsObj) => ({
100+
type: types.SET_CURRENT_LOCATION,
101+
payload: tabsObj,
102+
})

src/app/components/History.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ function History(props: Record<string, unknown>) {
105105
.data(d3root.descendants())
106106
.enter()
107107
.append('g')
108-
// .selectAll("g")
109-
// .data(d3root.descendants())
110-
// .join("g")
108+
.style('cursor', 'pointer')
109+
.on('click', d => {
110+
dispatch(changeView(d.data.index));
111+
dispatch(changeSlider(d.data.index));
112+
})
111113
.attr('transform', d => `translate(${d.x},${d.y})`);
112114

113115

@@ -118,15 +120,6 @@ function History(props: Record<string, unknown>) {
118120
}
119121
return d.color ? d.color : '#555';
120122
})
121-
.style('display', 'block')
122-
.style('cursor', 'pointer')
123-
.on('click', d => {
124-
console.log('DEBUG >>> onclick d:', d);
125-
console.log('DEBUG >>> Clicked on currlocation:', currLocation);
126-
console.log('DEBUG >>> Clicked on d.data:', d.data.index);
127-
dispatch(changeView(d.data.index));
128-
dispatch(changeSlider(d.data.index));
129-
})
130123
.attr('r', 14);
131124

132125
node.append('text')
@@ -136,7 +129,6 @@ function History(props: Record<string, unknown>) {
136129
.clone(true)
137130
.lower()
138131
.attr('stroke', 'white');
139-
140132
return svg.node();
141133
};
142134

src/app/components/MainSlider.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import Slider from 'rc-slider';
33
import Tooltip from 'rc-tooltip';
44
import { changeSlider, pause } from '../actions/actions';
55
import { useStoreContext } from '../store';
6+
import { useEffect } from 'react';
67

78
const { Handle } = Slider;
89

@@ -37,18 +38,26 @@ interface MainSliderProps {
3738
function MainSlider(props: MainSliderProps) {
3839
const { snapshotsLength } = props;
3940
const [{ tabs, currentTab }, dispatch] = useStoreContext();
40-
const { currLocation, sliderIndex } = tabs[currentTab];
41+
const { currLocation } = tabs[currentTab];
42+
const [sliderIndex, setSliderIndex] = useState(0);
4143

4244
console.log('DEBUG >>> slider: ', currLocation);
4345

46+
useEffect(() => {
47+
setSliderIndex(currLocation.index);
48+
}, [currLocation])
49+
4450
return (
4551
<Slider
4652
min={0}
4753
max={snapshotsLength - 1}
48-
value={currLocation.index}
54+
value={sliderIndex}
4955
onChange={(index: any) => {
50-
const newIndex = index === -1 ? 0 : index;
51-
dispatch(changeSlider(newIndex));
56+
setSliderIndex(index);
57+
}}
58+
onAfterChange={() => {
59+
console.log("DEBUG >>> sliderIndex: ", sliderIndex);
60+
dispatch(changeSlider(sliderIndex));
5261
dispatch(pause());
5362
}}
5463
handle={handle}

src/app/constants/actionTypes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ export const SLIDER_ZERO = 'SLIDER_ZERO';
1616
export const ON_HOVER = 'ON_HOVER';
1717
export const ON_HOVER_EXIT = 'ON_HOVER_EXIT';
1818
export const SAVE = 'SAVE';
19-
export const DELETE_SERIES = 'DELETE_SERIES';
19+
export const DELETE_SERIES = 'DELETE_SERIES';
20+
export const SET_CURRENT_LOCATION = 'SET_CURRENT_LOCATION';

src/app/containers/MainContainer.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
setPort,
1010
setTab,
1111
deleteTab,
12+
setCurrentLocation,
1213
} from '../actions/actions';
1314
import { useStoreContext } from '../store';
1415
import MPID from '../user_id/user_id';
@@ -44,6 +45,7 @@ function MainContainer(): any {
4445
sourceTab: number;
4546
}) => {
4647
const { action, payload, sourceTab } = message;
48+
console.log("DEBUG >>> message: ", message);
4749
let maxTab;
4850
if (!sourceTab) {
4951
const tabsArray: any = Object.keys(payload);
@@ -71,6 +73,10 @@ function MainContainer(): any {
7173
console.log('this is the initial connect and settab', maxTab, payload);
7274
break;
7375
}
76+
case 'setCurrentLocation': {
77+
dispatch(setCurrentLocation(payload));
78+
break;
79+
}
7480
default:
7581
}
7682
return true;

src/app/reducers/mainReducer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ export default (state, action) => produce(state, draft => {
306306
}
307307
break;
308308
}
309+
case types.SET_CURRENT_LOCATION: {
310+
const { payload } = action;
311+
const { currLocation } = payload[currentTab];
312+
tabs[currentTab].currLocation = currLocation;
313+
break;
314+
}
309315
default:
310316
throw new Error(`nonexistent action: ${action.type}`);
311317
}

src/backend/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ window.addEventListener('message', ({ data: { action, payload } }: MsgData) => {
4242
case 'setPause':
4343
mode.paused = payload;
4444
break;
45-
// maybe this isn't work react cohort 45
45+
// maybe this isn't work react cohort 45
4646
case 'onHover':
4747
if (Array.isArray(payload)) {
4848
for (let i = 0; i < payload.length; i + 1) {
@@ -58,7 +58,7 @@ window.addEventListener('message', ({ data: { action, payload } }: MsgData) => {
5858
}
5959
}
6060
break;
61-
// maybe this isn't work react cohort 45
61+
// maybe this isn't work react cohort 45
6262
case 'onHoverExit':
6363
if (Array.isArray(payload)) {
6464
for (let i = 0; i < payload.length; i++) {

src/extension/background.js

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ const tabsObj = {};
1010
// Will store Chrome web vital metrics and their corresponding values.
1111
const metrics = {};
1212

13-
let isRecordAfterJump = false;
14-
1513
// This function will create the first instance of the test app's tabs object
1614
// which will hold test app's snapshots, link fiber tree info, chrome tab info, etc.
1715
function createTabObj(title) {
@@ -99,12 +97,7 @@ function countCurrName(rootNode, name) {
9997
function changeCurrLocation(tabObj, rootNode, index, name) {
10098
// index comes from the app's main reducer to locate the correct current location on tabObj
10199
// check if current node has the index wanted
102-
console.log('DEBUG >>> rootNode.index: ', rootNode.index);
103-
console.log('DEBUG >>> index: ', index);
104100
if (rootNode.index === index) {
105-
console.log('DEBUG >>> jump index: ', index);
106-
console.log('DEBUG >>> jump name: ', name);
107-
console.log('DEBUG >>> jump hierachy: ', rootNode);
108101
tabObj.currLocation = rootNode;
109102
// Count number of nodes in the tree with name = next name.
110103
const currNameCount = countCurrName(tabObj.hierarchy, name + 1);
@@ -257,7 +250,12 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
257250
case 'jumpToSnap': {
258251
console.log('DEBUG >>> in jumpToSnap action!')
259252
changeCurrLocation(tabsObj[tabId], tabsObj[tabId].hierarchy, index, name);
260-
isRecordAfterJump = true;
253+
if (portsArr.length > 0) {
254+
portsArr.forEach(bg => bg.postMessage({
255+
action: 'setCurrentLocation',
256+
payload: tabsObj,
257+
}));
258+
}
261259
break;
262260
}
263261
// This injects a script into the app that you're testing Reactime on,
@@ -343,6 +341,8 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
343341
break;
344342
}
345343

344+
console.log("DEBUG >>> reached previousSnap");
345+
346346
// DUPLICATE SNAPSHOT CHECK
347347
const previousSnap = tabsObj[tabId].currLocation.stateSnapshot.children[0].componentData
348348
.actualDuration;
@@ -353,9 +353,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
353353
if (reloaded[tabId]) {
354354
// don't add anything to snapshot storage if tab is reloaded for the initial snapshot
355355
reloaded[tabId] = false;
356-
} else if (isRecordAfterJump) {
357-
console.log('DEBUG >>> test currLocation: ', tabsObj[tabId].currLocation);
358-
isRecordAfterJump = false;
359356
} else {
360357
tabsObj[tabId].snapshots.push(request.payload);
361358
//! INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN!!!!
@@ -366,12 +363,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
366363
new Node(request.payload, tabsObj[tabId]),
367364
);
368365
}
369-
// else {
370-
// sendToHierarchy(
371-
// tabsObj[tabId],
372-
// new NewNode(request.payload, tabsObj[tabId])
373-
// );
374-
// }
375366
}
376367
// sends new tabs obj to devtools
377368
if (portsArr.length > 0) {

0 commit comments

Comments
 (0)