diff --git a/jest.config.js b/jest.config.js index facd1c8a7..874d9ac0b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -70,7 +70,8 @@ module.exports = { `front`, `modules`, `front/node_modules`, - `node_modules` + `node_modules`, + `print` ], // An array of file extensions your modules use @@ -153,6 +154,7 @@ module.exports = { // The glob patterns Jest uses to detect test files testMatch: [ '**/front/**/*.spec.js', + '**/print/**/*.spec.js', // 'loopback/**/*.spec.js', // 'modules/*/back/**/*.spec.js' // "**/__tests__/**/*.[jt]s?(x)", diff --git a/print/core/config.js b/print/core/config.js index 864e1658a..5194762b4 100644 --- a/print/core/config.js +++ b/print/core/config.js @@ -4,8 +4,8 @@ let env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development'; let configPath = `/etc/salix`; let config = require('../config/print.json'); let configFiles = [ - `${appPath}/config/print.local.json`, - `${appPath}/config/print.${env}.json`, + `../config/print.local.json`, + `../config/print.${env}.json`, `${configPath}/print.json`, `${configPath}/print.local.json`, `${configPath}/print.${env}.json` diff --git a/print/core/filters/currency.js b/print/core/filters/currency.js index ec6808906..098c2fe20 100644 --- a/print/core/filters/currency.js +++ b/print/core/filters/currency.js @@ -2,9 +2,13 @@ const Vue = require('vue'); const config = require('../config'); const defaultLocale = config.i18n.locale; -Vue.filter('currency', function(value, currency = 'EUR', locale = defaultLocale) { +const currency = function(value, currency = 'EUR', locale = defaultLocale) { if (!locale) locale = defaultLocale; return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(parseFloat(value)); -}); +}; + +Vue.filter('currency', currency); + +module.exports = currency; diff --git a/print/core/filters/date.js b/print/core/filters/date.js index 5d1bc0de5..70267c76e 100644 --- a/print/core/filters/date.js +++ b/print/core/filters/date.js @@ -1,7 +1,11 @@ const Vue = require('vue'); const strftime = require('strftime'); -Vue.filter('date', function(value, specifiers = '%d-%m-%Y') { +const date = function(value, specifiers = '%d-%m-%Y') { if (!(value instanceof Date)) value = new Date(value); return strftime(specifiers, value); -}); +}; + +Vue.filter('date', date); + +module.exports = date; diff --git a/print/core/filters/number.js b/print/core/filters/number.js index c785706fe..a0c5e61f7 100644 --- a/print/core/filters/number.js +++ b/print/core/filters/number.js @@ -2,9 +2,13 @@ const Vue = require('vue'); const config = require('../config'); const defaultLocale = config.i18n.locale; -Vue.filter('number', function(value, locale = defaultLocale) { +const number = function(value, locale = defaultLocale) { if (!locale) locale = defaultLocale; return new Intl.NumberFormat(locale, { style: 'decimal' }).format(parseFloat(value)); -}); +}; + +Vue.filter('number', number); + +module.exports = number; diff --git a/print/core/filters/percentage.js b/print/core/filters/percentage.js index 078d2fd89..c535fe944 100644 --- a/print/core/filters/percentage.js +++ b/print/core/filters/percentage.js @@ -2,11 +2,15 @@ const Vue = require('vue'); const config = require('../config'); const defaultLocale = config.i18n.locale; -Vue.filter('percentage', function(value, minFraction = 2, maxFraction = 2, locale = defaultLocale) { +const percentage = function(value, minFraction = 2, maxFraction = 2, locale = defaultLocale) { if (!locale) locale = defaultLocale; return new Intl.NumberFormat(locale, { style: 'percent', minimumFractionDigits: minFraction, maximumFractionDigits: maxFraction }).format(parseFloat(value)); -}); +}; + +Vue.filter('percentage', percentage); + +module.exports = percentage; diff --git a/print/core/filters/specs/currency.spec.js b/print/core/filters/specs/currency.spec.js new file mode 100644 index 000000000..5a345ddbe --- /dev/null +++ b/print/core/filters/specs/currency.spec.js @@ -0,0 +1,16 @@ +// Extended locale intl polyfill +const IntlPolyfill = require('intl'); +Intl.NumberFormat = IntlPolyfill.NumberFormat; +Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat; + +import currency from '../currency.js'; + +describe('currency filter', () => { + it('should filter the currency in spanish as default', () => { + expect(currency(999, 'EUR')).toEqual('999,00 €'); + }); + + it('should filter the currency in english', () => { + expect(currency(999, 'EUR', 'en')).toEqual('€999.00'); + }); +}); diff --git a/print/core/filters/specs/date.spec.js b/print/core/filters/specs/date.spec.js new file mode 100644 index 000000000..aa38af515 --- /dev/null +++ b/print/core/filters/specs/date.spec.js @@ -0,0 +1,27 @@ +import date from '../date.js'; + +describe('date filter', () => { + const superDuperDate = new Date('February 18, 1984 @ 11:30:00 am'); + + it('should filter the date as %d-%m-%Y by default', () => { + expect(date(superDuperDate)).toEqual('18-02-1984'); + }); + + it('should filter the date as %m-%d-%Y', () => { + const dateFormat = '%m-%d-%Y'; + + expect(date(superDuperDate, dateFormat)).toEqual('02-18-1984'); + }); + + it('should filter the date as %y-%d-%m', () => { + const dateFormat = '%y-%d-%m'; + + expect(date(superDuperDate, dateFormat)).toEqual('84-18-02'); + }); + + it('should filter the date as %Y-%d-%m', () => { + const dateFormat = '%Y-%d-%m'; + + expect(date(superDuperDate, dateFormat)).toEqual('1984-18-02'); + }); +}); diff --git a/print/core/filters/specs/number.spec.js b/print/core/filters/specs/number.spec.js new file mode 100644 index 000000000..752200694 --- /dev/null +++ b/print/core/filters/specs/number.spec.js @@ -0,0 +1,9 @@ +import number from '../number.js'; + +describe('number filter', () => { + const superDuperNumber = 18021984; + + it('should filter the number with commas by default', () => { + expect(number(superDuperNumber)).toEqual('18,021,984'); + }); +}); diff --git a/print/core/filters/specs/percentage.spec.js b/print/core/filters/specs/percentage.spec.js new file mode 100644 index 000000000..0a9111cbc --- /dev/null +++ b/print/core/filters/specs/percentage.spec.js @@ -0,0 +1,11 @@ +import percentage from '../percentage.js'; + +describe('percentage filter', () => { + it('should filter the percentage also round it correctly', () => { + expect(percentage(99.9999999999999999 / 100)).toEqual('100.00%'); + }); + + it('should filter the percentage and round it correctly', () => { + expect(percentage(1.25444444444444444 / 100)).toEqual('1.25%'); + }); +}); diff --git a/print/core/filters/specs/uppercase.spec.js b/print/core/filters/specs/uppercase.spec.js new file mode 100644 index 000000000..77c493359 --- /dev/null +++ b/print/core/filters/specs/uppercase.spec.js @@ -0,0 +1,10 @@ +import uppercase from '../uppercase.js'; + +describe('uppercase filter', () => { + it('should filter the string to uppercase', () => { + let lowerCase = 'text'; + let upperCase = 'TEXT'; + + expect(uppercase(lowerCase)).toEqual(upperCase); + }); +}); diff --git a/print/core/filters/uppercase.js b/print/core/filters/uppercase.js index a4a826070..806b996f2 100644 --- a/print/core/filters/uppercase.js +++ b/print/core/filters/uppercase.js @@ -1,5 +1,9 @@ const Vue = require('vue'); -Vue.filter('uppercase', function(value) { +const uppercase = function(value) { return value.toUpperCase(); -}); +}; + +Vue.filter('uppercase', uppercase); + +module.exports = uppercase;