Merge "Allow optional default value in noValue filter"

This commit is contained in:
Jenkins 2016-02-24 15:14:41 +00:00 committed by Gerrit Code Review
commit b7fd639b34
2 changed files with 13 additions and 3 deletions

View File

@ -127,13 +127,14 @@
* @ngdoc filter
* @name noValue
* @description
* Replaces null / undefined / empty string with translated '-'.
* Replaces null / undefined / empty string with translated '-' or the optional
* default value provided.
*/
function noValueFilter() {
return function (input) {
return function (input, def) {
if (input === null || angular.isUndefined(input) ||
(angular.isString(input) && '' === input.trim())) {
return gettext('-');
return def || gettext('-');
} else {
return input;
}

View File

@ -151,6 +151,15 @@
expect(noValueFilter('')).toBe('-');
expect(noValueFilter(' ')).toBe('-');
});
it('replaces undefined, null, blank with provided value', function () {
expect(noValueFilter(null, 'default')).toBe('default');
expect(noValueFilter(undefined, 'default')).toBe('default');
expect(noValueFilter('', 'default')).toBe('default');
expect(noValueFilter(' ', 'default')).toBe('default');
expect(noValueFilter('value', 'default')).toBe('value');
expect(noValueFilter(false, 'default')).toBe(false);
});
});
describe('noName', function () {