Files
cloudron-box/src/test/translation-test.js
T

61 lines
2.0 KiB
JavaScript
Raw Normal View History

2020-11-19 23:38:59 +01:00
/* jslint node:true */
/* global it:false */
/* global describe:false */
'use strict';
2021-06-03 12:20:44 -07:00
const expect = require('expect.js'),
2020-11-19 23:38:59 +01:00
translation = require('../translation.js');
describe('translation', function () {
describe('translate', function () {
it('nonexisting token', function () {
2022-04-14 17:41:41 -05:00
const out = translation.translate('Foo {{ bar }}', {}, {});
2020-11-19 23:38:59 +01:00
expect(out).to.contain('{{ bar }}');
});
it('existing token', function () {
2022-04-14 17:41:41 -05:00
const out = translation.translate('Foo {{ bar }}', { bar: 'here' }, {});
2020-11-19 23:38:59 +01:00
expect(out).to.contain('here');
});
it('existing token as fallback', function () {
2022-04-14 17:41:41 -05:00
const out = translation.translate('Foo {{ bar }}', {}, { bar: 'here' });
2020-11-19 23:38:59 +01:00
expect(out).to.contain('here');
});
it('existing token deep', function () {
2022-04-14 17:41:41 -05:00
const out = translation.translate('Foo {{ bar.baz.foo }}', { bar: { baz: { foo: 'here' }}}, {});
2020-11-19 23:38:59 +01:00
expect(out).to.contain('here');
});
it('existing token deep as fallback', function () {
2022-04-14 17:41:41 -05:00
const out = translation.translate('Foo {{ bar.baz.foo }}', { bar: '' }, { bar: { baz: { foo: 'here' }}});
2020-11-19 23:38:59 +01:00
expect(out).to.contain('here');
});
it('with whitespace tokens', function () {
2022-04-14 17:41:41 -05:00
const obj = {
2020-11-19 23:38:59 +01:00
something: {
missing: {
there: '1'
}
},
here: '2',
there: '3',
foo: '4',
bar: '5'
};
2022-04-14 17:41:41 -05:00
const input = 'Hello {{ something.missing.there}} and some more {{here}} and {{ there }} with odd spacing {{foo }} lots of{{ bar }}';
2020-11-19 23:38:59 +01:00
2022-04-14 17:41:41 -05:00
const out = translation.translate(input, obj, {});
2020-11-19 23:38:59 +01:00
expect(out).to.contain('1');
expect(out).to.contain('2');
expect(out).to.contain('3');
expect(out).to.contain('4');
expect(out).to.contain('5');
});
});
});