decide.nolog.cz/tests/integration/translations-test.js

79 lines
2.4 KiB
JavaScript
Raw Normal View History

2015-11-26 13:33:40 +01:00
import { moduleFor, test } from 'ember-qunit';
2016-08-17 23:56:14 +02:00
import Ember from 'ember';
2015-11-26 13:33:40 +01:00
import config from 'croodle/config/environment';
import LocaleHelper from 'ember-i18n/utils/locale';
2016-06-20 19:28:10 +02:00
import localesMeta from 'croodle/locales/meta';
2015-11-26 13:33:40 +01:00
2016-08-17 23:56:14 +02:00
const { getOwner } = Ember;
2015-11-26 13:33:40 +01:00
moduleFor('service:i18n', 'Integration | translations', {
integration: true
});
// Replace this with your real tests.
test('configuration is correct', function(assert) {
const i18n = this.subject();
const locales = i18n.get('locales');
const { defaultLocale } = config.i18n;
2015-11-26 13:33:40 +01:00
assert.ok(defaultLocale, 'default locale is set');
assert.ok(locales, 'there are locales');
assert.ok(locales.indexOf(defaultLocale) !== -1, 'default locale is part of locales');
});
test('all locales have same amount of translation strings as default locale', function(assert) {
const i18n = this.subject();
const locales = i18n.get('locales');
const { defaultLocale } = config.i18n;
2016-08-17 23:56:14 +02:00
const { translations: defaultTranslations } = new LocaleHelper(defaultLocale, getOwner(i18n));
2015-11-26 13:33:40 +01:00
assert.expect((locales.length - 1) * 2);
locales.map((locale) => {
if (locale === defaultLocale) {
return;
}
2016-08-17 23:56:14 +02:00
const { translations } = new LocaleHelper(locale, getOwner(i18n));
assert.ok(translations, `could retrive locale ${locale}`);
2015-11-26 13:33:40 +01:00
assert.equal(
Object.keys(translations).length,
Object.keys(defaultTranslations).length,
`correct amount of translations for locale ${locale}`
2015-11-26 13:33:40 +01:00
);
});
});
test('all locales have same translation strings as default locale', function(assert) {
const i18n = this.subject();
const locales = i18n.get('locales');
const { defaultLocale } = config.i18n;
2016-08-17 23:56:14 +02:00
const { translations: defaultTranslations } = new LocaleHelper(defaultLocale, getOwner(i18n));
2015-11-26 13:33:40 +01:00
assert.expect(
// count of non default locales * translation strings of default locale
(locales.length - 1) * Object.keys(defaultTranslations).length
2015-11-26 13:33:40 +01:00
);
Object.keys(defaultTranslations).map((translationString) => {
locales.map((locale) => {
if (locale === defaultLocale) {
return;
}
i18n.set('locale', locale);
assert.ok(
i18n.exists(translationString),
`translation for ${translationString} exists in locale ${locale}`
2015-11-26 13:33:40 +01:00
);
});
});
});
2016-06-20 19:28:10 +02:00
test('all locales have an entry in locales/meta', function(assert) {
const i18n = this.subject();
assert.deepEqual(
i18n.get('locales'),
Object.keys(localesMeta)
);
});