From de3d42d1880d1d36929bf64b6bdf5d72ef475df9 Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Thu, 10 Oct 2019 14:25:36 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Ajout=20de=20tests=20unitaires=20su?= =?UTF-8?q?r=20le=20formatage=20des=20valeurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/engine/format.js | 3 ++- source/engine/format.test.js | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 source/engine/format.test.js diff --git a/source/engine/format.js b/source/engine/format.js index 75f0086c5..76d836622 100644 --- a/source/engine/format.js +++ b/source/engine/format.js @@ -75,7 +75,8 @@ export function formatValue({ numberFormatter({ style: 'decimal', minimumFractionDigits, - maximumFractionDigits + maximumFractionDigits, + language })(value) + (typeof serializedUnit === 'string' ? `\u00A0${serializedUnit}` : '') ) diff --git a/source/engine/format.test.js b/source/engine/format.test.js new file mode 100644 index 000000000..577dfeab9 --- /dev/null +++ b/source/engine/format.test.js @@ -0,0 +1,27 @@ +import { expect } from 'chai' +import { formatCurrency, formatPercentage, formatValue } from './format' + +describe('format engine values', () => { + it('format currencies', () => { + expect(formatCurrency(12, 'fr')).to.equal('12 €') + expect(formatCurrency(1200, 'fr')).to.equal('1 200 €') + expect(formatCurrency(12, 'en')).to.equal('€ 12') + expect(formatCurrency(12.1)).to.equal('€ 12.10') + expect(formatCurrency(12.123)).to.equal('€ 12.12') + }) + + it('format percentages', () => { + expect(formatPercentage(0.1)).to.equal('10%') + expect(formatPercentage(1)).to.equal('100%') + expect(formatPercentage(0.102)).to.equal('10.2%') + }) + + it('format values', () => { + expect(formatValue({ unit: '€', value: 12 })).to.equal('€12') + expect(formatValue({ unit: '€', value: 12.1 })).to.equal('€12.10') + expect(formatValue({ unit: '€', value: 12, language: 'fr' })).to.equal( + '12 €' + ) + expect(formatValue({ value: 1200, language: 'fr' })).to.equal('1 200') + }) +})