@@ -920,7 +920,7 @@ describe('NumberInput', () => {
920920 expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '0' ) ;
921921 } ) ;
922922
923- it ( 'should begin incrementing from min when input is empty' , async ( ) => {
923+ it ( 'should begin incrementing from 1 when input is empty and 0 is in between of min and max ' , async ( ) => {
924924 render (
925925 < NumberInput
926926 type = "text"
@@ -935,9 +935,27 @@ describe('NumberInput', () => {
935935 ) ;
936936 expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '' ) ;
937937 await userEvent . click ( screen . getByLabelText ( 'increment' ) ) ;
938- expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '-100 ' ) ;
938+ expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '1 ' ) ;
939939 } ) ;
940- it ( 'should begin decrementing from max when input is empty' , async ( ) => {
940+
941+ it ( 'should begin incrementing from min when input is empty and min is positive' , async ( ) => {
942+ render (
943+ < NumberInput
944+ type = "text"
945+ label = "test-label"
946+ id = "test"
947+ allowEmpty
948+ min = { 10 }
949+ max = { 100 }
950+ step = { 2 }
951+ translateWithId = { translateWithId }
952+ />
953+ ) ;
954+ expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '' ) ;
955+ await userEvent . click ( screen . getByLabelText ( 'increment' ) ) ;
956+ expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '10' ) ;
957+ } ) ;
958+ it ( 'should begin decrementing from max when input is empty and when min is negative' , async ( ) => {
941959 render (
942960 < NumberInput
943961 type = "text"
@@ -951,35 +969,85 @@ describe('NumberInput', () => {
951969 ) ;
952970 expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '' ) ;
953971 await userEvent . click ( screen . getByLabelText ( 'decrement' ) ) ;
954- expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '100' ) ;
972+ expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '-1' ) ;
973+ } ) ;
974+
975+ it ( 'should begin decrementing from min when input is empty and when min and max is greater than 0' , async ( ) => {
976+ render (
977+ < NumberInput
978+ type = "text"
979+ label = "test-label"
980+ id = "test"
981+ min = { 10 }
982+ max = { 100 }
983+ step = { 2 }
984+ translateWithId = { translateWithId }
985+ />
986+ ) ;
987+ expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '' ) ;
988+ await userEvent . click ( screen . getByLabelText ( 'decrement' ) ) ;
989+ expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '10' ) ;
990+ } ) ;
991+
992+ it ( 'should begin incrementing from 1 when no min is provided and input is empty' , async ( ) => {
993+ render (
994+ < NumberInput
995+ type = "text"
996+ label = "test-label"
997+ id = "test"
998+ step = { 2 }
999+ translateWithId = { translateWithId }
1000+ />
1001+ ) ;
1002+ expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '' ) ;
1003+ await userEvent . click ( screen . getByLabelText ( 'increment' ) ) ;
1004+ expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '1' ) ;
1005+ } ) ;
1006+ it ( 'should begin decrementing from -1 when no max is provided and input is empty' , async ( ) => {
1007+ render (
1008+ < NumberInput
1009+ type = "text"
1010+ label = "test-label"
1011+ id = "test"
1012+ step = { 2 }
1013+ translateWithId = { translateWithId }
1014+ />
1015+ ) ;
1016+ expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '' ) ;
1017+ await userEvent . click ( screen . getByLabelText ( 'decrement' ) ) ;
1018+ expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '-1' ) ;
9551019 } ) ;
956- it ( 'should begin incrementing from 0 when no min is provided and input is empty' , async ( ) => {
1020+
1021+ it ( 'should begin incrementing from stepStartValue when input is empty and stepStartValue is provided' , async ( ) => {
9571022 render (
9581023 < NumberInput
9591024 type = "text"
9601025 label = "test-label"
9611026 id = "test"
9621027 step = { 2 }
1028+ stepStartValue = { 10 }
9631029 translateWithId = { translateWithId }
9641030 />
9651031 ) ;
9661032 expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '' ) ;
9671033 await userEvent . click ( screen . getByLabelText ( 'increment' ) ) ;
968- expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '0 ' ) ;
1034+ expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '10 ' ) ;
9691035 } ) ;
970- it ( 'should begin decrementing from 0 when no max is provided and input is empty' , async ( ) => {
1036+
1037+ it ( 'should begin decrementing from stepStartValue when input is empty and stepStartValue is provided' , async ( ) => {
9711038 render (
9721039 < NumberInput
9731040 type = "text"
9741041 label = "test-label"
9751042 id = "test"
9761043 step = { 2 }
1044+ stepStartValue = { 10 }
9771045 translateWithId = { translateWithId }
9781046 />
9791047 ) ;
9801048 expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '' ) ;
9811049 await userEvent . click ( screen . getByLabelText ( 'decrement' ) ) ;
982- expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '0 ' ) ;
1050+ expect ( screen . getByLabelText ( 'test-label' ) ) . toHaveValue ( '10 ' ) ;
9831051 } ) ;
9841052 } ) ;
9851053 it ( 'should increase by the value of large step and format to the default locale' , async ( ) => {
@@ -1122,7 +1190,7 @@ describe('NumberInput', () => {
11221190 type = "text"
11231191 label = "NumberInput label"
11241192 id = "number-input"
1125- min = { - 100 }
1193+ min = { 10 }
11261194 max = { 100 }
11271195 value = { value }
11281196 onChange = { ( event , state ) => {
@@ -1147,17 +1215,17 @@ describe('NumberInput', () => {
11471215 expect ( input ) . toHaveValue ( '' ) ;
11481216
11491217 await userEvent . click ( screen . getByLabelText ( 'increment' ) ) ;
1150- expect ( input ) . toHaveValue ( '-100 ' ) ;
1218+ expect ( input ) . toHaveValue ( '10 ' ) ;
11511219 await userEvent . click ( screen . getByLabelText ( 'increment' ) ) ;
1152- expect ( input ) . toHaveValue ( '-99 ' ) ;
1220+ expect ( input ) . toHaveValue ( '11 ' ) ;
11531221
11541222 await userEvent . clear ( input ) ;
11551223 expect ( input ) . toHaveValue ( '' ) ;
11561224
11571225 await userEvent . click ( screen . getByLabelText ( 'decrement' ) ) ;
1158- expect ( input ) . toHaveValue ( '100 ' ) ;
1226+ expect ( input ) . toHaveValue ( '10 ' ) ;
11591227 await userEvent . click ( screen . getByLabelText ( 'decrement' ) ) ;
1160- expect ( input ) . toHaveValue ( '99 ' ) ;
1228+ expect ( input ) . toHaveValue ( '10 ' ) ;
11611229
11621230 await userEvent . click ( screen . getByText ( 'set to 50' ) ) ;
11631231 expect ( input ) . toHaveValue ( '50' ) ;
0 commit comments