2015-11-26 13:33:40 +01:00
|
|
|
import { moduleFor, test } from 'ember-qunit';
|
|
|
|
import config from 'croodle/config/environment';
|
|
|
|
import LocaleHelper from 'ember-i18n/utils/locale';
|
|
|
|
|
|
|
|
moduleFor('service:i18n', 'Integration | translations', {
|
|
|
|
integration: true
|
|
|
|
});
|
|
|
|
|
|
|
|
// Replace this with your real tests.
|
|
|
|
test('configuration is correct', function(assert) {
|
2016-01-28 12:34:56 +01:00
|
|
|
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) {
|
2016-01-28 12:34:56 +01:00
|
|
|
const i18n = this.subject();
|
|
|
|
const locales = i18n.get('locales');
|
|
|
|
const { defaultLocale } = config.i18n;
|
|
|
|
const { translations: defaultTranslations } = new LocaleHelper(defaultLocale, i18n.get('container'));
|
2015-11-26 13:33:40 +01:00
|
|
|
|
|
|
|
assert.expect((locales.length - 1) * 2);
|
|
|
|
|
|
|
|
locales.map((locale) => {
|
|
|
|
if (locale === defaultLocale) {
|
|
|
|
return;
|
|
|
|
}
|
2016-01-28 12:34:56 +01:00
|
|
|
const { translations } = new LocaleHelper(locale, i18n.get('container'));
|
|
|
|
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,
|
2016-01-28 12:34:56 +01:00
|
|
|
`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) {
|
2016-01-28 12:34:56 +01:00
|
|
|
const i18n = this.subject();
|
|
|
|
const locales = i18n.get('locales');
|
|
|
|
const { defaultLocale } = config.i18n;
|
|
|
|
const { translations: defaultTranslations } = new LocaleHelper(defaultLocale, i18n.get('container'));
|
2015-11-26 13:33:40 +01:00
|
|
|
|
|
|
|
assert.expect(
|
|
|
|
// count of non default locales * translation strings of default locale
|
2016-01-28 12:34:56 +01:00
|
|
|
(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),
|
2016-01-28 12:34:56 +01:00
|
|
|
`translation for ${translationString} exists in locale ${locale}`
|
2015-11-26 13:33:40 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|