|
| 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