Merge branch 'dev' of http://git.verdnatura.es/salix into dev
This commit is contained in:
commit
56ab95ee73
|
@ -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 undefined;
|
||||
};
|
||||
}
|
||||
ngModule.filter('currency', currency);
|
||||
|
|
|
@ -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 = `<div id="test" >{{200 | currency: '€': 2}}</div>`;
|
||||
compile(html);
|
||||
|
||||
expect($element[0].innerHTML).toBe('200.00 €');
|
||||
});
|
||||
|
||||
it('sould return nothing when the value is not set', () => {
|
||||
let html = `<div id="test" >{{null | currency: '€': 2}}</div>`;
|
||||
compile(html);
|
||||
|
||||
expect($element[0].innerHTML).toBe('');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue