2021-02-15 17:44:58 +01:00
|
|
|
/* eslint-disable node/global-require */
|
2020-11-05 14:01:23 +01:00
|
|
|
import { get } from 'svelte/store';
|
2019-11-26 17:05:17 +01:00
|
|
|
|
2019-11-26 03:09:05 +01:00
|
|
|
import {
|
2019-11-27 04:58:53 +01:00
|
|
|
init,
|
2019-11-26 17:05:17 +01:00
|
|
|
getOptions,
|
|
|
|
defaultOptions,
|
|
|
|
defaultFormats,
|
2020-11-05 14:01:23 +01:00
|
|
|
} from '../../src/runtime/configs';
|
|
|
|
import { $locale } from '../../src/runtime/stores/locale';
|
2019-11-26 17:05:17 +01:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-08-24 04:59:40 +02:00
|
|
|
init(defaultOptions as any);
|
2020-11-05 14:01:23 +01:00
|
|
|
});
|
2019-11-26 03:09:05 +01:00
|
|
|
|
2019-11-27 04:58:53 +01:00
|
|
|
test('inits the fallback locale', () => {
|
2020-11-05 14:01:23 +01:00
|
|
|
expect(getOptions().fallbackLocale).toBeNull();
|
2019-11-27 04:58:53 +01:00
|
|
|
init({
|
2019-11-26 17:05:17 +01:00
|
|
|
fallbackLocale: 'en',
|
2020-11-05 14:01:23 +01:00
|
|
|
});
|
|
|
|
expect(getOptions().fallbackLocale).toBe('en');
|
|
|
|
});
|
2019-11-26 17:05:17 +01:00
|
|
|
|
2019-11-27 04:58:53 +01:00
|
|
|
test('inits the initial locale by string', () => {
|
|
|
|
init({
|
2019-11-26 17:05:17 +01:00
|
|
|
fallbackLocale: 'pt',
|
|
|
|
initialLocale: 'en',
|
2020-11-05 14:01:23 +01:00
|
|
|
});
|
|
|
|
expect(getOptions().initialLocale).toBe('en');
|
|
|
|
expect(get($locale)).toBe('en');
|
|
|
|
});
|
2019-11-26 17:05:17 +01:00
|
|
|
|
|
|
|
test('adds custom formats for time, date and number values', () => {
|
2020-11-05 14:01:23 +01:00
|
|
|
const customFormats = require('../fixtures/formats.json');
|
2019-11-26 17:05:17 +01:00
|
|
|
|
2019-11-27 04:58:53 +01:00
|
|
|
init({
|
2019-11-26 03:09:05 +01:00
|
|
|
fallbackLocale: 'en',
|
2019-11-26 17:05:17 +01:00
|
|
|
formats: customFormats,
|
2020-11-05 14:01:23 +01:00
|
|
|
});
|
|
|
|
expect(getOptions().formats).toMatchObject(defaultFormats);
|
|
|
|
expect(getOptions().formats).toMatchObject(customFormats);
|
|
|
|
});
|
2019-11-26 17:05:17 +01:00
|
|
|
|
|
|
|
test('sets the minimum delay to set the loading store value', () => {
|
2020-11-05 14:01:23 +01:00
|
|
|
init({ fallbackLocale: 'en', loadingDelay: 300 });
|
|
|
|
expect(getOptions().loadingDelay).toBe(300);
|
|
|
|
});
|