@@ -34,7 +34,7 @@ test.describe('CurrencyInput', () => {
3434 await expect ( yenUnformattedInput ) . toHaveAttribute ( 'type' , 'hidden' ) ;
3535 await expect ( yenUnformattedInput ) . toHaveValue ( '5678.9' ) ;
3636 await expect ( yenFormattedInput ) . not . toBeDisabled ( ) ;
37- await expect ( yenFormattedInput ) . toHaveValue ( '¥5,678.9 ' ) ;
37+ await expect ( yenFormattedInput ) . toHaveValue ( '¥5,678.90 ' ) ;
3838 await expect ( yenFormattedInput ) . toHaveAttribute ( 'type' , 'text' ) ;
3939 await expect ( yenFormattedInput ) . toHaveAttribute ( 'placeholder' , '¥0.00' ) ;
4040 await expect ( yenFormattedInput ) . toHaveClass ( / c u r r e n c y I n p u t _ _ f o r m a t t e d - - p o s i t i v e / ) ;
@@ -87,13 +87,15 @@ test.describe('CurrencyInput', () => {
8787 bitcoin : '0.87654321' ,
8888 'formatted-bitcoin' : '฿0.87654321' ,
8989 yen : '5678.9' ,
90- 'formatted-yen' : '¥5,678.9 ' ,
90+ 'formatted-yen' : '¥5,678.90 ' ,
9191 euro : '-42069.69' ,
9292 'formatted-euro' : '€ -42.069,69' ,
9393 won : '0' ,
9494 'formatted-won' : '' ,
9595 pesos : '999' ,
96- 'formatted-pesos' : '$ 999' ,
96+ 'formatted-pesos' : '$ 999,00' ,
97+ rupees : '678' ,
98+ 'formatted-rupees' : '₹678.000' ,
9799 } ,
98100 null ,
99101 2
@@ -293,7 +295,7 @@ test.describe('CurrencyInput', () => {
293295 // Tabbing in Webkit is broken: https://github.com/Canutin/svelte-currency-input/issues/40
294296 if ( testInfo . project . name !== 'webkit' ) {
295297 const formattedInputs = page . locator ( '.currencyInput__formatted' ) ;
296- expect ( await formattedInputs . count ( ) ) . toBe ( 9 ) ;
298+ expect ( await formattedInputs . count ( ) ) . toBe ( 10 ) ;
297299
298300 await formattedInputs . first ( ) . focus ( ) ;
299301 await expect ( formattedInputs . nth ( 0 ) ) . toBeFocused ( ) ;
@@ -352,6 +354,24 @@ test.describe('CurrencyInput', () => {
352354 await expect ( pesosFormattedInput ) . toHaveAttribute ( 'autocomplete' , 'off' ) ;
353355 } ) ;
354356
357+ test ( 'A value with zero cents and more than 1 fraction digits gets formatted on blur' , async ( { page } ) => {
358+ const rupeesFormattedInput = page . locator ( '.currencyInput__formatted[name="formatted-rupees"]' ) ;
359+ const rupeesUnformattedInput = page . locator ( '.currencyInput__unformatted[name="rupees"]' ) ;
360+ await expect ( rupeesFormattedInput ) . toHaveValue ( '₹678.000' ) ;
361+ await expect ( rupeesUnformattedInput ) . toHaveValue ( '678' ) ;
362+
363+ await rupeesFormattedInput . focus ( ) ;
364+ await selectAll ( page ) ;
365+ await page . keyboard . press ( 'Backspace' ) ;
366+ await page . keyboard . type ( '123' ) ;
367+ await expect ( rupeesFormattedInput ) . toHaveValue ( '₹123' ) ;
368+ await expect ( rupeesFormattedInput ) . not . toHaveValue ( '₹123.000' ) ;
369+
370+ await page . locator ( 'body' ) . click ( ) ; // Click outside the input to trigger formatting
371+ await expect ( rupeesFormattedInput ) . toHaveValue ( '₹123.000' ) ;
372+ await expect ( rupeesUnformattedInput ) . toHaveValue ( '123' ) ;
373+ } ) ;
374+
355375 test . skip ( 'Updating chained inputs have the correct behavior' , async ( ) => {
356376 // TODO
357377 } ) ;
0 commit comments