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 );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|