|
| 1 | +import React from 'react'; |
| 2 | +import {render} from '@testing-library/react-native'; |
| 3 | +import {StepsIndicator} from '../../src/components/StepsIndicator'; |
| 4 | +import {constants} from '../../src/utils/constants'; |
| 5 | +import {Platform} from 'react-native'; |
| 6 | +import {styles} from '../../src/utils/styles'; |
| 7 | + |
| 8 | +const defaultOptions = [0, 1, 2, 3, 4, 5]; |
| 9 | +const longerOptions = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
| 10 | + |
| 11 | +describe('StepsIndicator', () => { |
| 12 | + it('Renders every step provided in options', () => { |
| 13 | + const {getByText} = render( |
| 14 | + <StepsIndicator |
| 15 | + options={defaultOptions} |
| 16 | + sliderWidth={20} |
| 17 | + currentValue={0} |
| 18 | + renderStepNumber |
| 19 | + />, |
| 20 | + ); |
| 21 | + for (const step of defaultOptions) { |
| 22 | + expect(getByText(step.toString())).toBeDefined(); |
| 23 | + } |
| 24 | + }); |
| 25 | + |
| 26 | + it('Applies the big font size to the lower number of steps', () => { |
| 27 | + const {getByTestId} = render( |
| 28 | + <StepsIndicator |
| 29 | + options={defaultOptions} |
| 30 | + sliderWidth={20} |
| 31 | + currentValue={0} |
| 32 | + renderStepNumber |
| 33 | + />, |
| 34 | + ); |
| 35 | + expect(getByTestId('0th-step')).toHaveStyle({ |
| 36 | + fontSize: constants.STEP_NUMBER_TEXT_FONT_BIG, |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + it('Applies the small font size to the number of steps higher than 9', () => { |
| 41 | + const {getByTestId} = render( |
| 42 | + <StepsIndicator |
| 43 | + options={longerOptions} |
| 44 | + sliderWidth={20} |
| 45 | + currentValue={0} |
| 46 | + renderStepNumber |
| 47 | + />, |
| 48 | + ); |
| 49 | + expect(getByTestId('0th-step')).toHaveStyle({ |
| 50 | + fontSize: constants.STEP_NUMBER_TEXT_FONT_SMALL, |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + it('Applies platform-dependent styles for web', () => { |
| 55 | + Platform.OS = 'web'; |
| 56 | + const {getByTestId} = render( |
| 57 | + <StepsIndicator |
| 58 | + options={longerOptions} |
| 59 | + sliderWidth={20} |
| 60 | + currentValue={0} |
| 61 | + renderStepNumber |
| 62 | + />, |
| 63 | + ); |
| 64 | + expect(getByTestId('StepsIndicator-Container')).toHaveStyle( |
| 65 | + styles.stepsIndicator, |
| 66 | + ); |
| 67 | + }); |
| 68 | + |
| 69 | + it('Reverts given options when isLTR is set', () => { |
| 70 | + const {getByTestId} = render( |
| 71 | + <StepsIndicator |
| 72 | + options={defaultOptions} |
| 73 | + sliderWidth={20} |
| 74 | + currentValue={0} |
| 75 | + renderStepNumber |
| 76 | + isLTR |
| 77 | + />, |
| 78 | + ); |
| 79 | + expect(getByTestId('0th-step')).toHaveTextContent('5'); |
| 80 | + expect(getByTestId('2th-step')).toHaveTextContent('3'); |
| 81 | + }); |
| 82 | + |
| 83 | + it('Does not display any step numbers if prop is not set', () => { |
| 84 | + const {queryByTestId} = render( |
| 85 | + <StepsIndicator |
| 86 | + options={defaultOptions} |
| 87 | + sliderWidth={20} |
| 88 | + currentValue={0} |
| 89 | + />, |
| 90 | + ); |
| 91 | + expect(queryByTestId('0th-step')).toBeFalsy(); |
| 92 | + }); |
| 93 | +}); |
0 commit comments