2019-12-16 16:48:02 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2019-12-18 11:29:20 +00:00
|
|
|
import { formatPrice, getCurrency } from '../price';
|
2019-12-16 16:48:02 +00:00
|
|
|
|
|
|
|
describe( 'formatPrice', () => {
|
|
|
|
test.each`
|
2020-09-07 17:31:10 +00:00
|
|
|
value | prefix | suffix | expected
|
|
|
|
${ 1000 } | ${ '€' } | ${ '' } | ${ '€10' }
|
|
|
|
${ 1000 } | ${ '' } | ${ '€' } | ${ '10€' }
|
|
|
|
${ 1000 } | ${ '' } | ${ '$' } | ${ '10$' }
|
|
|
|
${ '1000' } | ${ '€' } | ${ '' } | ${ '€10' }
|
|
|
|
${ 0 } | ${ '€' } | ${ '' } | ${ '€0' }
|
|
|
|
${ '' } | ${ '€' } | ${ '' } | ${ '' }
|
|
|
|
${ null } | ${ '€' } | ${ '' } | ${ '' }
|
|
|
|
${ undefined } | ${ '€' } | ${ '' } | ${ '' }
|
2019-12-16 16:48:02 +00:00
|
|
|
`(
|
2019-12-18 11:29:20 +00:00
|
|
|
'correctly formats price given "$value", "$prefix" prefix, and "$suffix" suffix',
|
|
|
|
( { value, prefix, suffix, expected } ) => {
|
2019-12-16 16:48:02 +00:00
|
|
|
const formattedPrice = formatPrice(
|
|
|
|
value,
|
2019-12-18 11:29:20 +00:00
|
|
|
getCurrency( { prefix, suffix } )
|
2019-12-16 16:48:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
expect( formattedPrice ).toEqual( expected );
|
|
|
|
}
|
|
|
|
);
|
2021-10-04 03:54:28 +00:00
|
|
|
|
|
|
|
test.each`
|
|
|
|
value | expected
|
|
|
|
${ 1000 } | ${ '$10' }
|
|
|
|
${ 0 } | ${ '$0' }
|
|
|
|
${ '' } | ${ '' }
|
|
|
|
${ null } | ${ '' }
|
|
|
|
${ undefined } | ${ '' }
|
|
|
|
`(
|
|
|
|
'correctly formats price given "$value" only',
|
|
|
|
( { value, expected } ) => {
|
|
|
|
const formattedPrice = formatPrice( value );
|
|
|
|
|
|
|
|
expect( formattedPrice ).toEqual( expected );
|
|
|
|
}
|
|
|
|
);
|
2019-12-16 16:48:02 +00:00
|
|
|
} );
|