Skip to content

Commit 1b3e20d

Browse files
committed
Created test on app folder supporting Typescripst
2 parents fd5a13d + 9919e47 commit 1b3e20d

13 files changed

+67
-5
lines changed

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/app/__tests__/ButtonsContainer.test.js renamed to src/app/__tests__/ButtonsContainer.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ describe('testing the bottom buttons', () => {
105105
expect(wrapper.find('.persist-button').text()).toBe('Unpersist');
106106
});
107107
});
108-
});
108+
});
File renamed without changes.
File renamed without changes.

src/app/__tests__/MainSlider.test.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* eslint-disable react/jsx-props-no-spreading */
2+
import { shallow, configure } from 'enzyme';
3+
import React from 'react';
4+
import Adapter from 'enzyme-adapter-react-16';
5+
import Slider from 'rc-slider';
6+
import Tooltip from 'rc-tooltip';
7+
import MainSlider from '../components/MainSlider';
8+
9+
import { useStoreContext } from '../store';
10+
11+
configure({ adapter: new Adapter() });
12+
13+
jest.mock('../store');
14+
// the handle function in MainSlider returns out a Tooltip Component
15+
const handle = Tooltip;
16+
17+
describe('Unit testing for MainSlider.jsx', () => {
18+
let wrapper;
19+
const props = {
20+
snapshotsLength: 1,
21+
};
22+
23+
const state = {
24+
tabs: {
25+
100: {
26+
sliderIndex: 1,
27+
},
28+
},
29+
currentTab: 100,
30+
};
31+
32+
const dispatch = jest.fn();
33+
useStoreContext.mockImplementation(() => [state, dispatch]);
34+
35+
beforeEach(() => {
36+
wrapper = shallow(<MainSlider {...props} />);
37+
dispatch.mockClear();
38+
});
39+
it('Component should return <Slider /> component from rc-slider library', () => {
40+
expect(wrapper.type()).toEqual(Slider);
41+
});
42+
it('Component should have min, max, value, and handle props', () => {
43+
expect(wrapper.props()).toHaveProperty('min');
44+
expect(wrapper.props()).toHaveProperty('max');
45+
expect(wrapper.props()).toHaveProperty('value');
46+
expect(wrapper.props()).toHaveProperty('handle');
47+
});
48+
it('Prop type tests on component', () => {
49+
expect(typeof wrapper.prop('min')).toEqual('number');
50+
expect(typeof wrapper.prop('max')).toEqual('number');
51+
expect(typeof wrapper.prop('value')).toEqual('number');
52+
expect(typeof wrapper.prop('handle')).toEqual('function');
53+
});
54+
55+
describe('Testing for handle functional component', () => {
56+
// this doesnt work, not sure how to implement yet
57+
// the handle function should return a Tooltip component
58+
// eslint-disable-next-line jest/no-test-prefixes
59+
// eslint-disable-next-line jest/no-disabled-tests
60+
it.skip('handle prop should return <Tooltip /> component from rc-tooltip library', () => {
61+
expect(wrapper.prop('handle')()).toEqual(handle);
62+
});
63+
});
64+
});

0 commit comments

Comments
 (0)