@@ -419,6 +419,41 @@ test.describe('CurrencyInput', () => {
419419 await expect ( dinarsFormattedInput ) . toHaveAttribute ( 'placeholder' , 'How many Dinars?' ) ;
420420 } ) ;
421421
422+ test ( 'Prevent duplicated decimal points' , async ( { page } ) => {
423+ // Periods as decimals
424+ const poundUnformattedInput = page . locator ( '.currencyInput__unformatted[name=pound]' ) ;
425+ const poundFormattedInput = page . locator ( '.currencyInput__formatted[name="formatted-pound"]' ) ;
426+ await expect ( poundUnformattedInput ) . toHaveValue ( '1234.56' ) ;
427+ await expect ( poundFormattedInput ) . toHaveValue ( '£1,234.56' ) ;
428+
429+ await poundFormattedInput . focus ( ) ;
430+ await page . keyboard . type ( '....' ) ;
431+ await expect ( poundUnformattedInput ) . toHaveValue ( '1234.56' ) ;
432+ await expect ( poundFormattedInput ) . toHaveValue ( '£1,234.56' ) ;
433+
434+ // Commas as decimals
435+ const colonUnformattedInput = page . locator ( '.currencyInput__unformatted[name=colon]' ) ;
436+ const colonFormattedInput = page . locator ( '.currencyInput__formatted[name="formatted-colon"]' ) ;
437+ await expect ( colonUnformattedInput ) . toHaveValue ( '0' ) ;
438+ await expect ( colonFormattedInput ) . toHaveValue ( '' ) ;
439+
440+ await colonFormattedInput . focus ( ) ;
441+ await page . keyboard . type ( '123,,,,,' ) ;
442+ await expect ( colonUnformattedInput ) . toHaveValue ( '123' ) ;
443+ await expect ( colonFormattedInput ) . toHaveValue ( '₡123,' ) ;
444+
445+ // Pressing multiple commas when locale for decimals is a period
446+ const dinarsUnformattedInput = page . locator ( '.currencyInput__unformatted[name="dinars"]' ) ;
447+ const dinarsFormattedInput = page . locator ( '.currencyInput__formatted[name="formatted-dinars"]' ) ;
448+ await expect ( dinarsUnformattedInput ) . toHaveValue ( '0' ) ;
449+ await expect ( dinarsFormattedInput ) . toHaveValue ( '' ) ;
450+
451+ await dinarsFormattedInput . focus ( ) ;
452+ await page . keyboard . type ( '123,,,,,' ) ;
453+ await expect ( dinarsUnformattedInput ) . toHaveValue ( '123' ) ;
454+ await expect ( dinarsFormattedInput ) . toHaveValue ( 'RSD 123.' ) ;
455+ } ) ;
456+
422457 test . skip ( 'Updating chained inputs have the correct behavior' , async ( ) => {
423458 // TODO
424459 } ) ;
0 commit comments