Skip to content

Commit 26e2b95

Browse files
authored
Merge pull request #37 from nmwenz90/diffview
Diffview
2 parents 12edde8 + ad08026 commit 26e2b95

File tree

4 files changed

+142
-7
lines changed

4 files changed

+142
-7
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/Diff.jsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,35 @@ 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
}
2025
// Nate:: diff function returns a comparaison of two objects, one has an updated change
21-
const delta = diff(previous, snapshot);
26+
const delta = diff(previous, snapshot); // initilly an array with one object, on state change becomes an object
27+
// console.log('delta: ', delta);
2228
// returns html in string
2329
const html = formatters.html.format(delta, previous);
24-
if (show) formatters.html.showUnchanged();
25-
else formatters.html.hideUnchanged();
26-
30+
// console.log('html -->', html)
31+
if (show){
32+
// console.log('showing unchanged values', formatters.html.showUnchanged() );
33+
formatters.html.showUnchanged();
34+
} else {
35+
// console.log('hiding unchanged values', formatters.html.hideUnchanged() );
36+
formatters.html.hideUnchanged();
37+
};
38+
2739
if (previous === undefined || delta === undefined) {
2840
return <div className='noState'> No state change detected. Trigger an event to change state </div>;
2941
}

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,

0 commit comments

Comments
 (0)