@@ -87,6 +87,54 @@ describe('useSliderState', () => {
87
87
expect ( result . current . getThumbMinValue ( 2 ) ) . toBe ( 90 ) ;
88
88
} ) ;
89
89
90
+ it ( 'should round values to nearest step with two thumbs' , ( ) => {
91
+ let result = renderHook ( ( ) => useSliderState ( {
92
+ minValue : 1 ,
93
+ maxValue : 15 ,
94
+ step : 2.5 ,
95
+ defaultValue : [ 1 , 13 ] ,
96
+ numberFormatter
97
+ } ) ) . result ;
98
+
99
+ expect ( result . current . values ) . toEqual ( [ 1 , 13.5 ] ) ;
100
+ expect ( result . current . getThumbMinValue ( 1 ) ) . toBe ( 1 ) ;
101
+
102
+ act ( ( ) => result . current . setThumbValue ( 0 , 3 ) ) ;
103
+ expect ( result . current . values ) . toEqual ( [ 3.5 , 13.5 ] ) ;
104
+ expect ( result . current . getThumbMinValue ( 1 ) ) . toBe ( 3.5 ) ;
105
+ expect ( result . current . getThumbMaxValue ( 0 ) ) . toBe ( 13.5 ) ;
106
+
107
+ act ( ( ) => result . current . setThumbValue ( 1 , 5 ) ) ;
108
+ expect ( result . current . values ) . toEqual ( [ 3.5 , 6 ] ) ;
109
+ expect ( result . current . getThumbMaxValue ( 0 ) ) . toBe ( 6 ) ;
110
+ } ) ;
111
+
112
+ it ( 'should round values to nearest step with three thumbs' , ( ) => {
113
+ let result = renderHook ( ( ) => useSliderState ( {
114
+ minValue : 1 ,
115
+ maxValue : 15 ,
116
+ step : 2.5 ,
117
+ defaultValue : [ 1 , 6 , 13 ] ,
118
+ numberFormatter
119
+ } ) ) . result ;
120
+
121
+ expect ( result . current . values ) . toEqual ( [ 1 , 6 , 13.5 ] ) ;
122
+ expect ( result . current . getThumbMinValue ( 1 ) ) . toBe ( 1 ) ;
123
+ expect ( result . current . getThumbMinValue ( 2 ) ) . toBe ( 6 ) ;
124
+
125
+ act ( ( ) => result . current . setThumbValue ( 0 , 3 ) ) ;
126
+ expect ( result . current . values ) . toEqual ( [ 3.5 , 6 , 13.5 ] ) ;
127
+ expect ( result . current . getThumbMinValue ( 2 ) ) . toBe ( 6 ) ;
128
+ expect ( result . current . getThumbMinValue ( 1 ) ) . toBe ( 3.5 ) ;
129
+ expect ( result . current . getThumbMaxValue ( 0 ) ) . toBe ( 6 ) ;
130
+ expect ( result . current . getThumbMaxValue ( 1 ) ) . toBe ( 13.5 ) ;
131
+
132
+ act ( ( ) => result . current . setThumbValue ( 2 , 5 ) ) ;
133
+ expect ( result . current . values ) . toEqual ( [ 3.5 , 6 , 6 ] ) ;
134
+ expect ( result . current . getThumbMaxValue ( 0 ) ) . toBe ( 6 ) ;
135
+ expect ( result . current . getThumbMaxValue ( 1 ) ) . toBe ( 6 ) ;
136
+ } ) ;
137
+
90
138
it ( 'should call onChange and onChangeEnd appropriately' , ( ) => {
91
139
let onChangeEndSpy = jest . fn ( ) ;
92
140
let onChangeSpy = jest . fn ( ) ;
0 commit comments