Test de la traduction et pluralisation des unités

Implémentés dans 139ca46
pull/736/head
Maxime Quandalle 2019-10-17 08:49:06 +02:00
parent bcb251923c
commit 6440b3fad4
No known key found for this signature in database
GPG Key ID: 428641C03D29CA10
3 changed files with 24 additions and 3 deletions

View File

@ -58,7 +58,7 @@ export function formatValue({
if (typeof value !== 'number') {
return value
}
const serializedUnit = serialiseUnit(unit, value)
const serializedUnit = serialiseUnit(unit, value, language)
switch (serializedUnit) {
case '€':

View File

@ -1,5 +1,6 @@
import { expect } from 'chai'
import { formatCurrency, formatPercentage, formatValue } from './format'
import { parseUnit } from 'Engine/units'
describe('format engine values', () => {
it('format currencies', () => {
@ -25,3 +26,23 @@ describe('format engine values', () => {
expect(formatValue({ value: 1200, language: 'fr' })).to.equal('1 200')
})
})
describe('Units handling', () => {
it('translate unit', () => {
expect(formatValue({ value: 1, unit: 'jour', language: 'fr' })).to.equal(
'1 jour'
)
expect(formatValue({ value: 1, unit: 'jour', language: 'en' })).to.equal(
'1 day'
)
})
it('pluralize unit', () => {
expect(formatValue({ value: 2, unit: 'jour', language: 'fr' })).to.equal(
'2 jours'
)
expect(
formatValue({ value: 7, unit: parseUnit('jour/semaine'), language: 'fr' })
).to.equal('7 jours / semaine')
})
})

View File

@ -18,10 +18,10 @@ let printUnits = (units, count) =>
.join('-')
const plural = 2
export let serialiseUnit = (rawUnit, count = plural) => {
export let serialiseUnit = (rawUnit, count = plural, lng = undefined) => {
if (typeof rawUnit !== 'object') {
return typeof rawUnit === 'string'
? i18n.t(`units:${rawUnit}`, { count })
? i18n.t(`units:${rawUnit}`, { count, lng })
: rawUnit
}
let unit = simplify(rawUnit),