Skip to content

Commit 11be34f

Browse files
authored
Merge pull request #38 from oslabs-beta/staging
Staging
2 parents e544ca8 + d8d5104 commit 11be34f

File tree

9 files changed

+174
-14
lines changed

9 files changed

+174
-14
lines changed

src/app/__tests__/Diff.test.jsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React from 'react';
2+
import { configure, shallow } from 'enzyme';
3+
import Adapter from 'enzyme-adapter-react-16';
4+
import Diff from '../components/Diff.jsx';
5+
6+
import { useStoreContext } from '../store';
7+
8+
configure({ adapter: new Adapter() });
9+
10+
jest.mock('../store');
11+
12+
describe('Unit testing for Diff.jsx', () => {
13+
let wrapper;
14+
const props = {
15+
show: false,
16+
snapshot: [{
17+
children: [{
18+
state: { total: 12, next: 5, operation: null },
19+
}],
20+
21+
}],
22+
}
23+
24+
const state = {
25+
currentTab: 100,
26+
tabs: { 100: { snapshots: [1, 2, 3, 4], viewIndex: 1, sliderIndex: 1 } },
27+
};
28+
29+
30+
useStoreContext.mockImplementation(() => [state]);
31+
32+
const delta = { children: {} }; // expect delta to be an obj
33+
const html = 'html'; // expect html to be a string
34+
const previous = { state: 'string', children: {} }; // expect previous to be an obj
35+
36+
beforeEach(() => {
37+
wrapper = shallow(<Diff {...props} />);
38+
});
39+
40+
describe('delta', () => {
41+
it('delta variable should be an object, with a property children', () => {
42+
expect(typeof delta).toBe('object');
43+
expect(delta).toHaveProperty('children');
44+
});
45+
});
46+
47+
describe('html', () => {
48+
it('html variable should be a string', () => {
49+
expect(typeof html).toBe('string');
50+
});
51+
});
52+
53+
describe('previous', () => {
54+
it('previous variable should be a object', () => {
55+
expect(previous).toHaveProperty('state');
56+
expect(previous).toHaveProperty('children');
57+
expect(typeof previous).toBe('object');
58+
});
59+
});
60+
61+
describe('Diff Component', () => {
62+
it('Check if Diff component is a div', () => {
63+
expect(wrapper.type()).toEqual('div');
64+
});
65+
it('Check if Diff component inner text value is a string', () => {
66+
expect(typeof wrapper.text()).toEqual('string');
67+
});
68+
xit('Check if Diff component div has a className noState ', () => {
69+
console.log(wrapper.props());
70+
expect(wrapper.props().className).toEqual('noState');
71+
});
72+
});
73+
74+
});

src/app/__tests__/SwitchApp.test.jsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from 'react';
2+
import Select from 'react-select';
3+
import { configure, shallow } from 'enzyme';
4+
import Adapter from 'enzyme-adapter-react-16';
5+
import SwitchApp from '../components/SwitchApp.jsx';
6+
7+
import { useStoreContext } from '../store';
8+
9+
configure({ adapter: new Adapter() });
10+
11+
jest.mock('../store');
12+
13+
14+
describe('Unit testing for SwitchApp.jsx', () => {
15+
let wrapper;
16+
17+
const state = {
18+
currentTab: 100,
19+
tabs: { 100: { snapshots: [1, 2, 3, 4], viewIndex: 1, sliderIndex: 1 } },
20+
};
21+
const tabsArray = [];
22+
const currTab = {
23+
value: 100,
24+
label: {},
25+
};
26+
27+
const dispatch = jest.fn();
28+
useStoreContext.mockImplementation(() => [dispatch, state]);
29+
30+
beforeEach(() => {
31+
wrapper = shallow(<SwitchApp />);
32+
});
33+
34+
describe('currentTab', () => {
35+
it('should have properties value and label', () => {
36+
expect(currTab).toHaveProperty('value');
37+
expect(currTab).toHaveProperty('label');
38+
});
39+
});
40+
41+
// check if currTab has properties value, label
42+
// currentTab should be a number
43+
// tab should be an object
44+
// check if onChange if the function runs
45+
// className should be tab-select-container
46+
// options should be an array
47+
// value prop should be equal to a number
48+
})

src/app/components/Action.jsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ const Action = props => {
2323
} else {
2424
seconds = '00';
2525
}
26-
miliseconds = JSON.stringify(miliseconds);
26+
miliseconds = Number.parseFloat(miliseconds).toFixed(2)
2727
const arrayMiliseconds = miliseconds.split('.');
2828
if (arrayMiliseconds[0].length < 2) {
2929
arrayMiliseconds[0] = '0'.concat(arrayMiliseconds[0]);
3030
}
31-
if (arrayMiliseconds[1].length > 3) {
32-
arrayMiliseconds[1] = arrayMiliseconds[1].slice(0, 2);
33-
}
3431
if (index == 0) {
3532
return `${seconds}:${arrayMiliseconds[0]}.${arrayMiliseconds[1]}`;
3633
}

src/app/components/Diff.jsx

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,58 @@ import { useStoreContext } from '../store';
77

88
function Diff({ snapshot, show }) {
99
const [mainState] = useStoreContext();
10+
// console.log('this is the mainState variable -->', mainState);
1011
const { currentTab, tabs } = mainState; // Nate:: k/v pairs of mainstate store object being created
12+
// console.log('this is the currentTab variable -->', currentTab);
13+
// console.log('this is the tabs variable -->', tabs);
1114
const { snapshots, viewIndex, sliderIndex } = tabs[currentTab];
1215
let previous;
1316

1417
// previous follows viewIndex or sliderIndex
15-
if (viewIndex !== -1) {
18+
if (viewIndex !== -1) { // if tab isnt selected, view index is set to -1
1619
previous = snapshots[viewIndex - 1];
20+
// console.log('previous with viewIndex - 1: ', previous)
1721
} else {
1822
previous = snapshots[sliderIndex - 1];
23+
// console.log('previous with sliderIndex - 1: ', previous)
1924
}
20-
// Nate:: diff function returns a comparaison of two objects, one has an updated change
21-
const delta = diff(previous, snapshot);
25+
26+
// gabi :: cleanning preview from stateless data
27+
const statelessCleanning = obj => {
28+
const newObj = { ...obj };
29+
if (newObj.name === 'nameless') {
30+
delete newObj.name;
31+
}
32+
if (newObj.componentData) {
33+
delete newObj.componentData;
34+
}
35+
if (newObj.state === 'stateless') {
36+
delete newObj.state;
37+
}
38+
if (newObj.stateSnaphot) {
39+
newObj.stateSnaphot = statelessCleanning(obj.stateSnaphot);
40+
}
41+
if (newObj.children) {
42+
newObj.children = [];
43+
if (obj.children.length > 0) {
44+
obj.children.forEach(element => {
45+
if (element.state !== 'stateless' || element.children.length > 0) {
46+
const clean = statelessCleanning(element);
47+
newObj.children.push(clean);
48+
}
49+
});
50+
}
51+
}
52+
return newObj;
53+
};
54+
// gabi :: just display stateful data
55+
const previousDisplay = statelessCleanning(previous);
56+
// Nate:: diff function returns a comparison of two objects, one has an updated change
57+
// gabi :: just display stateful data
58+
const delta = diff(previousDisplay, snapshot);
2259
// returns html in string
23-
const html = formatters.html.format(delta, previous);
60+
// gabi :: just display stateful data
61+
const html = formatters.html.format(delta, previousDisplay);
2462
if (show) formatters.html.showUnchanged();
2563
else formatters.html.hideUnchanged();
2664

src/app/components/StateRoute.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ const StateRoute = ({ snapshot, hierarchy, snapshots, viewIndex }) => {
3939
<Router>
4040
<div className="navbar">
4141
<NavLink className="router-link" activeClassName="is-active" exact to="/">
42-
State
42+
Tree
4343
</NavLink>
4444
<NavLink className="router-link" activeClassName="is-active" to="/chart">
4545
History
4646
</NavLink>
4747
<NavLink className="router-link" activeClassName="is-active" to="/performance">
48-
Rendering
48+
Performance
4949
</NavLink>
5050
</div>
5151
<Switch>

src/app/components/SwitchApp.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import { setTab } from '../actions/actions';
66

77
const SwitchAppDropdown = () => {
88
const [{ currentTab, tabs }, dispatch] = useStoreContext();
9-
9+
console.log('tabs object -->', tabs);
10+
1011
const tabsArray = [];
11-
1212
Object.keys(tabs).forEach(tab => {
1313
tabsArray.unshift({ value: tab, label: tabs[tab].title });
1414
});
15+
console.log('tabs object -->', tabsArray);
1516

1617
const currTab = {
1718
value: currentTab,

src/app/styles/components/_actionComponent.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515

1616
.action-component-text{
17-
margin-bottom: 10px;
17+
margin-bottom: 8px;
1818
}
1919

2020
.action-component.selected {

src/app/styles/components/_buttons.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
.time-button {
2222
outline: none;
2323
height: 20px;
24+
margin-bottom: 8px;
2425
width: 70px;
2526
border: none;
2627
border-radius: 3px;
@@ -31,6 +32,7 @@
3132

3233
.jump-button {
3334
@extend %button-shared;
35+
margin-bottom: 8px;
3436
width: 50px;
3537
opacity: 0;
3638
transform: rotateX(90deg);

src/app/styles/components/d3graph.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ div.tooltip {
9696
.perfContainer {
9797
display: block;
9898
margin: 0 -14px;
99-
background-color: hsl(152,80%,80%);
99+
background-color: hsl(221,16%,20%);
100100
/* border: 2px solid red; */
101101
}
102102

0 commit comments

Comments
 (0)