From 03e433221056fbaa61fb92e379a18804f5882bc4 Mon Sep 17 00:00:00 2001 From: Gerard Date: Mon, 19 Nov 2018 13:37:55 +0100 Subject: [PATCH] #830 test currency filter --- client/core/src/filters/currency.js | 10 +++---- .../core/src/filters/specs/currency.spec.js | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 client/core/src/filters/specs/currency.spec.js diff --git a/client/core/src/filters/currency.js b/client/core/src/filters/currency.js index f96963882..d90fe963d 100644 --- a/client/core/src/filters/currency.js +++ b/client/core/src/filters/currency.js @@ -1,17 +1,17 @@ import ngModule from '../module'; /** - * Override angular currency formats a number adding symbol after value. + * Override angular currency formatting a number, adding symbol after value. * * @return {String} The formated number */ export default function currency() { return function(input, symbol, fractionSize) { - if (input === undefined || input === null || input === '') - return undefined; - if (typeof input == 'number' && fractionSize) + if (typeof input == 'number' && fractionSize) { input = input.toFixed(fractionSize); - return `${input} ${symbol}`; + return `${input} ${symbol}`; + } + return undefined; }; } ngModule.filter('currency', currency); diff --git a/client/core/src/filters/specs/currency.spec.js b/client/core/src/filters/specs/currency.spec.js new file mode 100644 index 000000000..38e4e19db --- /dev/null +++ b/client/core/src/filters/specs/currency.spec.js @@ -0,0 +1,27 @@ +fdescribe('Currency filter', () => { + let compile; + let $element; + + beforeEach(ngModule('client')); + + compile = html => { + inject(($compile, $rootScope) => { + $element = $compile(html)($rootScope); + $rootScope.$digest(); + }); + }; + + it('should return the value formatted with two decimals when the value is a number and you set it a 2 as param', () => { + let html = `
{{200 | currency: '€': 2}}
`; + compile(html); + + expect($element[0].innerHTML).toBe('200.00 €'); + }); + + it('sould return nothing when the value is not set', () => { + let html = `
{{null | currency: '€': 2}}
`; + compile(html); + + expect($element[0].innerHTML).toBe(''); + }); +});