@@ -403,6 +403,52 @@ describe('SpinButton', () => {
403403 setupDefaultSpinButton ( ) ;
404404 expect ( inputElement . getAttribute ( 'inputmode' ) ) . toBe ( 'numeric' ) ;
405405 } ) ;
406+
407+ it ( 'should filter non-numeric characters from input' , ( ) => {
408+ setupSpinButton ( { value : 5 } ) ;
409+ const input = inputElement as HTMLInputElement ;
410+ input . value = '1a2b3' ;
411+ input . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
412+ fixture . detectChanges ( ) ;
413+ expect ( input . value ) . toBe ( '123' ) ;
414+ } ) ;
415+
416+ it ( 'should update value model on change event with valid number' , ( ) => {
417+ setupSpinButton ( { value : 5 } ) ;
418+ const input = inputElement as HTMLInputElement ;
419+ input . value = '42' ;
420+ input . dispatchEvent ( new Event ( 'change' , { bubbles : true } ) ) ;
421+ fixture . detectChanges ( ) ;
422+ expect ( spinButtonInstance . value ( ) ) . toBe ( 42 ) ;
423+ } ) ;
424+
425+ it ( 'should revert input to current value on invalid input' , ( ) => {
426+ setupSpinButton ( { value : 5 } ) ;
427+ const input = inputElement as HTMLInputElement ;
428+ input . value = 'invalid' ;
429+ input . dispatchEvent ( new Event ( 'change' , { bubbles : true } ) ) ;
430+ fixture . detectChanges ( ) ;
431+ expect ( input . value ) . toBe ( '5' ) ;
432+ expect ( spinButtonInstance . value ( ) ) . toBe ( 5 ) ;
433+ } ) ;
434+
435+ it ( 'should sync input value when model changes externally' , async ( ) => {
436+ setupSpinButton ( { value : 5 } ) ;
437+ const input = inputElement as HTMLInputElement ;
438+ spinButtonInstance . value . set ( 10 ) ;
439+ fixture . detectChanges ( ) ;
440+ await fixture . whenStable ( ) ;
441+ expect ( input . value ) . toBe ( '10' ) ;
442+ } ) ;
443+
444+ it ( 'should allow negative numbers' , ( ) => {
445+ setupSpinButton ( { value : 0 , min : - 10 } ) ;
446+ const input = inputElement as HTMLInputElement ;
447+ input . value = '-5' ;
448+ input . dispatchEvent ( new Event ( 'change' , { bubbles : true } ) ) ;
449+ fixture . detectChanges ( ) ;
450+ expect ( spinButtonInstance . value ( ) ) . toBe ( - 5 ) ;
451+ } ) ;
406452 } ) ;
407453
408454 describe ( 'span-based spinbutton' , ( ) => {
0 commit comments