Skip to content

Commit d1e498f

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 0812d00 + 93fd449 commit d1e498f

19 files changed

+9747
-6834
lines changed

.github/workflows/ReactNativeSlider-CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
key: ${{ hashFiles('./package/package.json') }}
7070

7171
- name: Run unit tests
72-
run: cd package && npx jest src
72+
run: cd package && npx jest --coverage --verbose
7373

7474

7575
verify-example-sources:

example-web/package-lock.json

Lines changed: 5041 additions & 3491 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example-web/src/Examples.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,19 @@ export const examples: Props[] = [
232232
);
233233
},
234234
},
235+
// Check the fix for the issue #743
236+
{
237+
title: 'With step numbers',
238+
render() {
239+
return (
240+
<SliderExample
241+
minimumValue={1}
242+
maximumValue={5}
243+
step={1}
244+
renderStepNumber={true}
245+
style={[styles.slider, { height: 70 }]}
246+
/>
247+
);
248+
},
249+
},
235250
];

example/ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ PODS:
13561356
- ReactCommon/turbomodule/bridging
13571357
- ReactCommon/turbomodule/core
13581358
- Yoga
1359-
- react-native-slider (5.1.1):
1359+
- react-native-slider (5.1.2):
13601360
- DoubleConversion
13611361
- glog
13621362
- hermes-engine
@@ -1371,7 +1371,7 @@ PODS:
13711371
- React-hermes
13721372
- React-ImageManager
13731373
- React-jsi
1374-
- react-native-slider/common (= 5.1.1)
1374+
- react-native-slider/common (= 5.1.2)
13751375
- React-NativeModulesApple
13761376
- React-RCTFabric
13771377
- React-renderercss
@@ -1381,7 +1381,7 @@ PODS:
13811381
- ReactCommon/turbomodule/bridging
13821382
- ReactCommon/turbomodule/core
13831383
- Yoga
1384-
- react-native-slider/common (5.1.1):
1384+
- react-native-slider/common (5.1.2):
13851385
- DoubleConversion
13861386
- glog
13871387
- hermes-engine
@@ -1997,7 +1997,7 @@ SPEC CHECKSUMS:
19971997
React-Mapbuffer: c3f4b608e4a59dd2f6a416ef4d47a14400194468
19981998
React-microtasksnativemodule: 054f34e9b82f02bd40f09cebd4083828b5b2beb6
19991999
react-native-pager-view: f238ed7fb53458bd03366944a33686f067c83e9a
2000-
react-native-slider: 5d7e61470399d2bfb0c9682a8d8ea10214e7eda1
2000+
react-native-slider: 4f5bd3b637b60c7ba1e05dc120b85d48be8fccee
20012001
React-NativeModulesApple: 2c4377e139522c3d73f5df582e4f051a838ff25e
20022002
React-oscompat: ef5df1c734f19b8003e149317d041b8ce1f7d29c
20032003
React-perflogger: 9a151e0b4c933c9205fd648c246506a83f31395d

example/package-lock.json

Lines changed: 1151 additions & 1091 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,4 +361,7 @@ MigrationBackup/
361361
.ionide/
362362

363363
# Fody - auto-generated XML schema
364-
FodyWeavers.xsd
364+
FodyWeavers.xsd
365+
366+
# Jest coverage reports
367+
coverage/

package/__test__/Slider.test.tsx

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import React from 'react';
2+
import {fireEvent, render} from '@testing-library/react-native';
3+
import Slider from '../src/Slider';
4+
5+
describe('Slider', () => {
6+
it('Calls the given onValueChange when native event is emitted', () => {
7+
const onValueChange = jest.fn();
8+
const {getByTestId} = render(
9+
<Slider testID="slider" onValueChange={onValueChange} />,
10+
);
11+
const slider = getByTestId('slider');
12+
fireEvent(slider, 'change', {nativeEvent: {value: 2}});
13+
expect(onValueChange).toHaveBeenCalledWith(2);
14+
});
15+
16+
it('Handles provided events when sliding starts is emitted', () => {
17+
const onSlidingStart = jest.fn();
18+
const {getByTestId} = render(
19+
<Slider testID="slider" onSlidingStart={onSlidingStart} />,
20+
);
21+
const slider = getByTestId('slider');
22+
23+
fireEvent(slider, 'onRNCSliderSlidingStart', {nativeEvent: {value: 2}});
24+
expect(onSlidingStart).toHaveBeenCalledWith(2);
25+
});
26+
27+
it('Handles provided events when sliding end is emitted', () => {
28+
const onSlidingComplete = jest.fn();
29+
const {getByTestId} = render(
30+
<Slider testID="slider" onSlidingComplete={onSlidingComplete} />,
31+
);
32+
const slider = getByTestId('slider');
33+
34+
fireEvent(slider, 'onRNCSliderSlidingComplete', {nativeEvent: {value: 2}});
35+
expect(onSlidingComplete).toHaveBeenCalledWith(2);
36+
});
37+
38+
it('Calls the accessibility handler when accessibility action is triggered', () => {
39+
const mockedAccessibilityHandler = jest.fn();
40+
const {getByTestId} = render(
41+
<Slider
42+
testID="slider"
43+
onAccessibilityAction={mockedAccessibilityHandler}
44+
/>,
45+
);
46+
const slider = getByTestId('slider');
47+
48+
fireEvent(slider, 'onRNCSliderAccessibilityAction', {
49+
actionName: 'mocked-action',
50+
});
51+
expect(mockedAccessibilityHandler).toHaveBeenCalledWith({
52+
actionName: 'mocked-action',
53+
});
54+
});
55+
56+
it('Emitts a warning in the dev console if lower and upper limits are switched', () => {
57+
const mockedWarn = jest.fn();
58+
console.warn = mockedWarn;
59+
render(<Slider testID="slider" lowerLimit={10} upperLimit={2} />);
60+
expect(mockedWarn).toHaveBeenCalled();
61+
});
62+
63+
it('Provides the onLayout with the measured width', () => {
64+
const {getByTestId} = render(<Slider testID="slider" />);
65+
const slider = getByTestId('slider');
66+
fireEvent(slider, 'onLayout', {nativeEvent: {layout: {width: 200}}});
67+
expect(slider).toHaveStyle({width: 200});
68+
});
69+
70+
it('Prevents the gesture control from being released externally', () => {
71+
const mockedRelease = jest.fn();
72+
jest.mock('../src/index', () => ({
73+
...jest.requireActual('../src/index'),
74+
onResponderRelease: mockedRelease,
75+
}));
76+
const {getByTestId} = render(<Slider testID="slider" />);
77+
fireEvent(getByTestId('slider'), 'onResponderTerminationRequest');
78+
expect(mockedRelease).not.toHaveBeenCalled();
79+
});
80+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import {render} from '@testing-library/react-native';
3+
import {StepNumber} from '../../src/components/StepNumber';
4+
5+
describe('StepNumber', () => {
6+
it('Displays number of step according to given index', () => {
7+
const {getByText} = render(
8+
<StepNumber i={0} index={0} style={undefined} />,
9+
);
10+
expect(getByText('0')).toBeDefined();
11+
});
12+
});
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import {render} from '@testing-library/react-native';
3+
import {MarkerProps, SliderTrackMark} from '../../src/components/TrackMark';
4+
import {View} from 'react-native';
5+
6+
const MockedStepMarker = ({}: MarkerProps) => (
7+
<View testID="mockedStepMarker" />
8+
);
9+
10+
const MockedThumbImage = 1;
11+
12+
describe('TrackMark', () => {
13+
it('Renders the StepMarker if custom component is given', () => {
14+
const {getByTestId} = render(
15+
<SliderTrackMark
16+
StepMarker={MockedStepMarker}
17+
isTrue={false}
18+
index={0}
19+
currentValue={0}
20+
min={0}
21+
max={0}
22+
/>,
23+
);
24+
expect(getByTestId('mockedStepMarker')).toBeDefined();
25+
});
26+
27+
it('Renders the StepMarker with thumbImage if provided', () => {
28+
const {getByTestId} = render(
29+
<SliderTrackMark
30+
thumbImage={MockedThumbImage}
31+
StepMarker={MockedStepMarker}
32+
isTrue={true}
33+
index={0}
34+
currentValue={0}
35+
min={0}
36+
max={0}
37+
/>,
38+
);
39+
expect(getByTestId('sliderTrackMark-thumbImage')).toBeDefined();
40+
});
41+
});

0 commit comments

Comments
 (0)