@@ -8,6 +8,7 @@ import { Component, ElementRef, viewChild } from '@angular/core';
8
8
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
9
9
import { FormsModule } from '@angular/forms' ;
10
10
11
+ import { dispatchKeyboardEvent } from 'ng-zorro-antd/core/testing' ;
11
12
import { NzSizeLDSType , NzStatus } from 'ng-zorro-antd/core/types' ;
12
13
import { provideNzIconsTesting } from 'ng-zorro-antd/icon/testing' ;
13
14
@@ -373,6 +374,19 @@ describe('Input number', () => {
373
374
expect ( hostElement . querySelector ( '.ant-input-number-handler-wrap' ) ) . toBeNull ( ) ;
374
375
} ) ;
375
376
377
+ it ( 'should not format input value if incomplete' , ( ) => {
378
+ fixture . detectChanges ( ) ;
379
+
380
+ input ( '1.0' ) ;
381
+ expect ( component . displayValue ) . toBe ( '1.0' ) ;
382
+
383
+ input ( '1.00' ) ; // 2 consecutive zeros
384
+ expect ( component . displayValue ) . toBe ( '1.00' ) ;
385
+
386
+ input ( '1.10' ) ; // zero is not preceded by a `.`
387
+ expect ( component . displayValue ) . toBe ( '1.10' ) ;
388
+ } ) ;
389
+
376
390
function upStepByHandler ( eventInit ?: MouseEventInit ) : void {
377
391
const handler = hostElement . querySelector ( '.ant-input-number-handler-up' ) ! ;
378
392
handler . dispatchEvent ( new MouseEvent ( 'mousedown' , eventInit ) ) ;
@@ -385,13 +399,13 @@ describe('Input number', () => {
385
399
}
386
400
387
401
function upStepByKeyboard ( ) : void {
388
- hostElement . dispatchEvent ( new KeyboardEvent ( 'keydown' , { keyCode : UP_ARROW } ) ) ;
402
+ dispatchKeyboardEvent ( hostElement , 'keydown' , UP_ARROW ) ;
389
403
}
390
404
function downStepByKeyboard ( ) : void {
391
- hostElement . dispatchEvent ( new KeyboardEvent ( 'keydown' , { keyCode : DOWN_ARROW } ) ) ;
405
+ dispatchKeyboardEvent ( hostElement , 'keydown' , DOWN_ARROW ) ;
392
406
}
393
407
function enter ( ) : void {
394
- hostElement . dispatchEvent ( new KeyboardEvent ( 'keydown' , { keyCode : ENTER } ) ) ;
408
+ dispatchKeyboardEvent ( hostElement , 'keydown' , ENTER ) ;
395
409
}
396
410
397
411
function getInputElement ( ) : HTMLInputElement {
@@ -496,6 +510,10 @@ class InputNumberTestComponent {
496
510
value : number | null = null ;
497
511
controlDisabled = false ;
498
512
inputNumber = viewChild . required ( NzInputNumberComponent ) ;
513
+
514
+ get displayValue ( ) : string {
515
+ return this . inputNumber ( ) [ 'displayValue' ] ( ) ;
516
+ }
499
517
}
500
518
501
519
@Component ( {
0 commit comments