Skip to content

Commit c466861

Browse files
stelselimMxKevinBeqo
authored andcommitted
fix: add missing tests and update the slider color
1 parent b1264f3 commit c466861

6 files changed

Lines changed: 50 additions & 11 deletions

File tree

packages/pluggableWidgets/range-slider-native/src/RangeSlider.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function RangeSlider(props: Props): ReactElement {
2727

2828
const onValueChange = useCallback(
2929
(values: number[]): void => {
30-
if (values[0] === null || values[0] === undefined || values[1] === null || values[1] === undefined) {
30+
if (values[0] == null || values[1] == null) {
3131
return;
3232
}
3333
props.lowerValueAttribute.setValue(new Big(values[0]));
@@ -39,10 +39,8 @@ export function RangeSlider(props: Props): ReactElement {
3939
const onSlidingComplete = useCallback(
4040
(values: number[]): void => {
4141
if (
42-
values[0] === null ||
43-
values[0] === undefined ||
44-
values[1] === null ||
45-
values[1] === undefined ||
42+
values[0] == null ||
43+
values[1] == null ||
4644
(lastLowerValue.current === values[0] && lastUpperValue.current === values[1])
4745
) {
4846
return;

packages/pluggableWidgets/range-slider-native/src/__tests__/RangeSlider.spec.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,47 @@ describe("RangeSlider", () => {
181181
expect(onChangeAction.execute).not.toHaveBeenCalled();
182182
});
183183

184+
it("renders with the width of the parent view", () => {
185+
const component = render(
186+
<RangeSlider
187+
{...defaultProps}
188+
style={[
189+
{
190+
container: { width: 100 },
191+
track: {},
192+
trackDisabled: {},
193+
minimumTrack: {},
194+
minimumTrackDisabled: {},
195+
maximumTrack: {},
196+
maximumTrackDisabled: {},
197+
thumb: {},
198+
thumbActive: {},
199+
thumbDisabled: {},
200+
validationMessage: {}
201+
}
202+
]}
203+
/>
204+
);
205+
const container = component.getByTestId("range-slider-test");
206+
expect(container.props.style).toEqual(expect.objectContaining({ width: 100 }));
207+
});
208+
209+
it("changes the lower value when swiping", () => {
210+
const onChangeAction = actionValue();
211+
const component = render(<RangeSlider {...defaultProps} onChange={onChangeAction} />);
212+
const slider = component.getByTestId("mocked-slider");
213+
214+
fireEvent(slider, "onValueChange", [120, 210]);
215+
216+
expect(onChangeAction.execute).not.toHaveBeenCalled();
217+
218+
fireEvent(slider, "onSlidingComplete", [120, 210]);
219+
220+
expect(defaultProps.lowerValueAttribute.setValue).toHaveBeenCalledWith(new Big(120));
221+
expect(defaultProps.upperValueAttribute.setValue).toHaveBeenCalledWith(new Big(210));
222+
expect(onChangeAction.execute).toHaveBeenCalledTimes(1);
223+
});
224+
184225
it("applies custom styles", () => {
185226
const component = render(
186227
<RangeSlider

packages/pluggableWidgets/range-slider-native/src/__tests__/__snapshots__/RangeSlider.spec.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ exports[`RangeSlider applies custom styles: with custom styles 1`] = `
1919
maximumValue={280}
2020
minimumTrackStyle={
2121
{
22-
"backgroundColor": "rgb(0,122,255)",
22+
"backgroundColor": "rgb(30, 76, 231)",
2323
}
2424
}
2525
minimumValue={0}
@@ -76,7 +76,7 @@ exports[`RangeSlider renders 1`] = `
7676
maximumValue={280}
7777
minimumTrackStyle={
7878
{
79-
"backgroundColor": "rgb(0,122,255)",
79+
"backgroundColor": "rgb(30, 76, 231)",
8080
}
8181
}
8282
minimumValue={0}

packages/pluggableWidgets/range-slider-native/src/ui/Styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface RangeSliderStyle extends Style {
1515
validationMessage: TextStyle;
1616
}
1717

18-
const blue = "rgb(0,122,255)";
18+
const blue = "rgb(30, 76, 231)";
1919

2020
const trackBase: ViewStyle = {
2121
height: 4,

packages/pluggableWidgets/slider-native/src/__tests__/__snapshots__/Slider.spec.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ exports[`Slider applies custom styles: with custom styles 1`] = `
1919
maximumValue={280}
2020
minimumTrackStyle={
2121
{
22-
"backgroundColor": "rgb(0,122,255)",
22+
"backgroundColor": "rgb(30, 76, 231)",
2323
}
2424
}
2525
minimumValue={0}
@@ -71,7 +71,7 @@ exports[`Slider renders 1`] = `
7171
maximumValue={280}
7272
minimumTrackStyle={
7373
{
74-
"backgroundColor": "rgb(0,122,255)",
74+
"backgroundColor": "rgb(30, 76, 231)",
7575
}
7676
}
7777
minimumValue={0}

packages/pluggableWidgets/slider-native/src/ui/Styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface SliderStyle extends Style {
1414
validationMessage: TextStyle;
1515
}
1616

17-
const blue = "rgb(0,122,255)";
17+
const blue = "rgb(30, 76, 231)";
1818

1919
const trackBase: ViewStyle = {
2020
height: 4,

0 commit comments

Comments
 (0)