Skip to content

Commit e839e90

Browse files
authored
Merge pull request #51 from nmwenz90/diffroute
DiffRoute
2 parents aba3b6b + 40fd8fa commit e839e90

File tree

2 files changed

+85
-17
lines changed

2 files changed

+85
-17
lines changed

src/app/__tests__/DiffRoute.test.jsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React from 'react';
2+
import { configure, shallow } from 'enzyme';
3+
import Adapter from 'enzyme-adapter-react-16';
4+
import {
5+
MemoryRouter as Router, Route, NavLink, Switch,
6+
} from 'react-router-dom';
7+
8+
import DiffRoute from '../components/DiffRoute.jsx';
9+
10+
const props = {
11+
snapshot: [{}],
12+
};
13+
14+
15+
configure({ adapter: new Adapter() });
16+
let wrapper;
17+
18+
describe('DiffRoute props', () => {
19+
it('should have a property called snapshot', () => {
20+
expect(props).toHaveProperty('snapshot');
21+
});
22+
it('props snapshot value should be an array', () => {
23+
expect(Array.isArray(props.snapshot)).toBe(true);
24+
});
25+
});
26+
27+
describe('DiffRoute component', () => {
28+
beforeEach(() => {
29+
wrapper = shallow(<DiffRoute />);
30+
});
31+
it('should contain a router component', () => {
32+
expect(wrapper.find(Router).type()).toEqual(Router);
33+
});
34+
it('div tag in Router should have a classname "navbar', () => {
35+
expect(wrapper.find('.navbar').type()).toBe('div');
36+
});
37+
it('router should have a switch component', () => {
38+
expect(wrapper.find(Switch).type()).toEqual(Switch);
39+
});
40+
});
41+
42+
// remaining tests:
43+
// check if router component has a div with a navlik component
44+
// check if navlinks go to appropriate routes, and text shows Tree and Raw
45+
// check if routes in switch have appropriate props

src/app/__tests__/SwitchApp.test.jsx

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,56 @@ describe('Unit testing for SwitchApp.jsx', () => {
1616

1717
const state = {
1818
currentTab: 100,
19-
tabs: { 100: { snapshots: [1, 2, 3, 4], viewIndex: 1, sliderIndex: 1 } },
19+
tabs: { 100: { snapshots: [1, 2, 3, 4], viewIndex: 1, sliderIndex: 1, title: 'component'} },
2020
};
21-
const tabsArray = [];
22-
const currTab = {
21+
const dropdownCurrTabLabel = {
2322
value: 100,
24-
label: {},
23+
label: 'component',
2524
};
26-
25+
// nate and edwin: mockImplementation creates a mock function call
2726
const dispatch = jest.fn();
28-
useStoreContext.mockImplementation(() => [dispatch, state]);
27+
28+
// nate and edwin: mockImplementation creates a mock state
29+
useStoreContext.mockImplementation(() => [state, dispatch]);
2930

3031
beforeEach(() => {
3132
wrapper = shallow(<SwitchApp />);
33+
dispatch.mockClear();
34+
});
35+
36+
describe('SwitchApp Component', () => {
37+
beforeEach(() => {
38+
wrapper.find('.tab-select-container').simulate('change', {});
39+
});
40+
// console.log('dispatch mock calls', dispatch.mock.calls);
41+
it('SwitchApp component returns <Select /> from react-select library', () => {
42+
expect(wrapper.find('.tab-select-container').type()).toEqual(Select);
43+
expect(wrapper.find('.tab-select-container').props().className).toBe('tab-select-container');
44+
expect(wrapper.find('.tab-select-container').props().value).toEqual(dropdownCurrTabLabel);
45+
});
46+
it('OnChange should run dispatch function', () => {
47+
expect(dispatch.mock.calls.length).toBe(1);
48+
})
49+
it('options prop should be an array', () => {
50+
expect(Array.isArray(wrapper.find('.tab-select-container').props().options)).toBeTruthy();
51+
expect(wrapper.find('.tab-select-container').props().options[0]).toHaveProperty('value');
52+
expect(wrapper.find('.tab-select-container').props().options[0]).toHaveProperty('label');
53+
});
3254
});
3355

34-
describe('currentTab', () => {
56+
describe('dropdownCurrTabLabel', () => {
3557
it('should have properties value and label', () => {
36-
expect(currTab).toHaveProperty('value');
37-
expect(currTab).toHaveProperty('label');
58+
expect(dropdownCurrTabLabel).toHaveProperty('value');
59+
expect(dropdownCurrTabLabel).toHaveProperty('label');
3860
});
3961
});
4062

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-
})
63+
describe('state', () => {
64+
it('currentTab value should be a number', () => {
65+
expect(typeof state.currentTab).toEqual('number');
66+
});
67+
it('tabs value should be an object', () => {
68+
expect(typeof state.tabs).toEqual('object');
69+
});
70+
});
71+
});

0 commit comments

Comments
 (0)