|
| 1 | +import React from 'react'; |
| 2 | +import { shallow } from 'enzyme'; |
| 3 | +import Typography from '@material-ui/core/Typography'; |
| 4 | +import Slider from '@material-ui/core/Slider'; |
| 5 | +import Input from '@material-ui/core/Input'; |
| 6 | +import { FontSizeSlider } from './FontSizeSlider'; |
| 7 | +import { DEFAULT_FONT_SIZE, FONT_SIZE_MIN_VALUE } from '../../config/constants'; |
| 8 | + |
| 9 | +const createFontSizeSliderProps = ({ fontSize } = {}) => ({ |
| 10 | + dispatchSetFontSize: jest.fn(), |
| 11 | + fontSize, |
| 12 | +}); |
| 13 | + |
| 14 | +describe('<FontSizeSlider />', () => { |
| 15 | + let wrapper; |
| 16 | + |
| 17 | + describe('default render', () => { |
| 18 | + beforeAll(() => { |
| 19 | + const props = createFontSizeSliderProps(); |
| 20 | + // eslint-disable-next-line react/jsx-props-no-spreading |
| 21 | + wrapper = shallow(<FontSizeSlider {...props} />); |
| 22 | + }); |
| 23 | + |
| 24 | + it('renders correctly', () => { |
| 25 | + expect(wrapper).toMatchSnapshot(); |
| 26 | + }); |
| 27 | + |
| 28 | + it('renders one <Slider /> and one <Input /> component with default font size', () => { |
| 29 | + const text = wrapper.find(Typography); |
| 30 | + expect(text).toHaveLength(1); |
| 31 | + expect(text.contains('Font Size')).toBeTruthy(); |
| 32 | + |
| 33 | + const slider = wrapper.find(Slider); |
| 34 | + expect(slider.prop('value')).toBe(DEFAULT_FONT_SIZE); |
| 35 | + |
| 36 | + const input = wrapper.find(Input); |
| 37 | + expect(input.prop('value')).toBe(DEFAULT_FONT_SIZE); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + describe('correct font size render', () => { |
| 42 | + beforeAll(() => { |
| 43 | + const props = createFontSizeSliderProps({ |
| 44 | + fontSize: FONT_SIZE_MIN_VALUE, |
| 45 | + }); |
| 46 | + // eslint-disable-next-line react/jsx-props-no-spreading |
| 47 | + wrapper = shallow(<FontSizeSlider {...props} />); |
| 48 | + }); |
| 49 | + |
| 50 | + it('renders correctly', () => { |
| 51 | + expect(wrapper).toMatchSnapshot(); |
| 52 | + }); |
| 53 | + |
| 54 | + it('renders one <Slider /> and one <Input /> component with given font size', () => { |
| 55 | + const text = wrapper.find(Typography); |
| 56 | + expect(text).toHaveLength(1); |
| 57 | + expect(text.contains('Font Size')).toBeTruthy(); |
| 58 | + |
| 59 | + const slider = wrapper.find(Slider); |
| 60 | + expect(slider.prop('value')).toBe(FONT_SIZE_MIN_VALUE); |
| 61 | + |
| 62 | + const input = wrapper.find(Input); |
| 63 | + expect(input.prop('value')).toBe(FONT_SIZE_MIN_VALUE); |
| 64 | + }); |
| 65 | + }); |
| 66 | +}); |
0 commit comments