Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ReactNativeSlider-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
key: ${{ hashFiles('./package/package.json') }}

- name: Run unit tests
run: cd package && npx jest src
run: cd package && npx jest --coverage --verbose


verify-example-sources:
Expand Down
5 changes: 4 additions & 1 deletion package/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,7 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

# Jest coverage reports
coverage/
12 changes: 12 additions & 0 deletions package/__test__/components/StepNumber.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import {render} from '@testing-library/react-native';
import {StepNumber} from '../../src/components/StepNumber';

describe('StepNumber', () => {
it('Displays number of step according to given index', () => {
const {getByText} = render(
<StepNumber i={0} index={0} style={undefined} />,
);
expect(getByText('0')).toBeDefined();
});
});
93 changes: 93 additions & 0 deletions package/__test__/components/StepsIndicator.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import React from 'react';
import {render} from '@testing-library/react-native';
import {StepsIndicator} from '../../src/components/StepsIndicator';
import {constants} from '../../src/utils/constants';
import {Platform} from 'react-native';
import {styles} from '../../src/utils/styles';

const defaultOptions = [0, 1, 2, 3, 4, 5];
const longerOptions = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

describe('StepsIndicator', () => {
it('Renders every step provided in options', () => {
const {getByText} = render(
<StepsIndicator
options={defaultOptions}
sliderWidth={20}
currentValue={0}
renderStepNumber
/>,
);
for (const step of defaultOptions) {
expect(getByText(step.toString())).toBeDefined();
}
});

it('Applies the big font size to the lower number of steps', () => {
const {getByTestId} = render(
<StepsIndicator
options={defaultOptions}
sliderWidth={20}
currentValue={0}
renderStepNumber
/>,
);
expect(getByTestId('0th-step')).toHaveStyle({
fontSize: constants.STEP_NUMBER_TEXT_FONT_BIG,
});
});

it('Applies the small font size to the number of steps higher than 9', () => {
const {getByTestId} = render(
<StepsIndicator
options={longerOptions}
sliderWidth={20}
currentValue={0}
renderStepNumber
/>,
);
expect(getByTestId('0th-step')).toHaveStyle({
fontSize: constants.STEP_NUMBER_TEXT_FONT_SMALL,
});
});

it('Applies platform-dependent styles for web', () => {
Platform.OS = 'web';
const {getByTestId} = render(
<StepsIndicator
options={longerOptions}
sliderWidth={20}
currentValue={0}
renderStepNumber
/>,
);
expect(getByTestId('StepsIndicator-Container')).toHaveStyle(
styles.stepsIndicator,
);
});

it('Reverts given options when isLTR is set', () => {
const {getByTestId} = render(
<StepsIndicator
options={defaultOptions}
sliderWidth={20}
currentValue={0}
renderStepNumber
isLTR
/>,
);
expect(getByTestId('0th-step')).toHaveTextContent('5');
expect(getByTestId('2th-step')).toHaveTextContent('3');
});

it('Does not display any step numbers if prop is not set', () => {
const {queryByTestId} = render(
<StepsIndicator
options={defaultOptions}
sliderWidth={20}
currentValue={0}
/>,
);
expect(queryByTestId('0th-step')).toBeFalsy();
});
});
Loading