Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jarda-svoboda committed Apr 6, 2022
1 parent 04c1f68 commit ee41138
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export const CONFIG: Config.T = {
},
{
key: 'common',
locale: 'cs',
loader: async () => (import('../data/translations/cs/common.json')),
locale: 'zh-Hans',
loader: async () => (import('../data/translations/zh-Hans/common.json')),
},
],
};
10 changes: 7 additions & 3 deletions tests/data/translations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ import type { Translations } from '../../../src/types';

import * as common from './en/common.json';
import * as route from './en/route.json';
import * as common_cs from './cs/common.json';
import * as common_ku from './ku/common.json';
import * as common_zhHans from './zh-Hans/common.json';

export default ({
en: toDotNotation({
common,
route1: route,
route2: route,
}),
cs: toDotNotation({
common: common_cs,
'zh-Hans': toDotNotation({
common: common_zhHans,
}),
ku: toDotNotation({
common: common_ku,
}),
}) as Translations.T;
File renamed without changes.
9 changes: 9 additions & 0 deletions tests/data/translations/zh-Hans/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"no_placeholder": "NO_PLACEHOLDER",
"placeholder": "VALUES: {{value}}, {{value;}}, {{ value }}, {{ value; }}",
"modifier_test": "VALUES: {{value; option1:VALUE1; option2:VALUE2; default:DEFAULT VALUE;}}, {{ value ; option1 : VALUE1 ; option2 : VALUE2 ; default : DEFAULT VALUE ;}}",
"custom_modifier": "{{date:date;}}",
"modifier_number": "{{value:number;}}",
"modifier_date": "{{value:date;}}",
"modifier_ago": "{{value:ago;}}"
}
7 changes: 6 additions & 1 deletion tests/specs/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('i18n instance', () => {
});
it('`locale` can be non-standard', async () => {
const nonStandardLocale = 'ku';
const { loading, locale, locales, setRoute, initialized } = new i18n({ loaders: [{ key: 'common', locale: `${nonStandardLocale}`.toUpperCase(), loader: () => import('../data/translations/en/common.json') }], parser });
const { loading, locale, locales, setRoute, initialized, translations } = new i18n({ loaders: [{ key: 'common', locale: `${nonStandardLocale}`.toUpperCase(), loader: () => import(`../data/translations/${nonStandardLocale}/common.json`) }], parser });
await setRoute('');
locale.set(nonStandardLocale);

Expand All @@ -136,6 +136,11 @@ describe('i18n instance', () => {

const $locales = locales.get();
expect($locales).toContainEqual(nonStandardLocale);

const $translations = translations.get();
expect($translations[nonStandardLocale]).toEqual(
expect.objectContaining(filterTranslationKeys(TRANSLATIONS[nonStandardLocale], ['common'])),
);
});
it('`getTranslationProps` method works', async () => {
const { initialized, getTranslationProps } = new i18n({ loaders, parser });
Expand Down

0 comments on commit ee41138

Please sign in to comment.