2019-11-26 17:05:17 +01:00
|
|
|
import { get } from 'svelte/store'
|
|
|
|
|
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,
|
2019-11-26 03:09:05 +01:00
|
|
|
} from '../../src/client/configs'
|
2019-11-26 17:05:17 +01:00
|
|
|
import { $locale } from '../../src/client/stores/locale'
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-11-27 04:58:53 +01:00
|
|
|
init(defaultOptions)
|
2019-11-26 17:05:17 +01:00
|
|
|
})
|
2019-11-26 03:09:05 +01:00
|
|
|
|
2019-11-27 04:58:53 +01:00
|
|
|
test('inits the fallback locale', () => {
|
2019-11-26 17:05:17 +01:00
|
|
|
expect(getOptions().fallbackLocale).toBe(null)
|
2019-11-27 04:58:53 +01:00
|
|
|
init({
|
2019-11-26 17:05:17 +01:00
|
|
|
fallbackLocale: 'en',
|
|
|
|
})
|
|
|
|
expect(getOptions().fallbackLocale).toBe('en')
|
|
|
|
})
|
|
|
|
|
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',
|
|
|
|
})
|
|
|
|
expect(getOptions().initialLocale).toBe('en')
|
|
|
|
expect(get($locale)).toBe('en')
|
|
|
|
})
|
|
|
|
|
2019-11-27 04:58:53 +01:00
|
|
|
test('inits the initial locale by client heuristics', () => {
|
2019-11-26 17:05:17 +01:00
|
|
|
delete window.location
|
|
|
|
window.location = {
|
|
|
|
search: '?lang=en-US&foo',
|
|
|
|
pathname: '/',
|
|
|
|
hostname: 'example.com',
|
|
|
|
hash: '',
|
|
|
|
} as any
|
|
|
|
|
2019-11-27 04:58:53 +01:00
|
|
|
init({
|
2019-11-26 17:05:17 +01:00
|
|
|
fallbackLocale: 'pt',
|
|
|
|
initialLocale: {
|
|
|
|
search: 'lang',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
expect(getOptions().initialLocale).toBe('en-US')
|
|
|
|
expect(get($locale)).toBe('en-US')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('adds custom formats for time, date and number values', () => {
|
|
|
|
const customFormats = require('../fixtures/formats.json')
|
|
|
|
|
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,
|
2019-11-26 03:09:05 +01:00
|
|
|
})
|
2019-11-26 17:05:17 +01:00
|
|
|
expect(getOptions().formats).toMatchObject(defaultFormats)
|
|
|
|
expect(getOptions().formats).toMatchObject(customFormats)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('sets the minimum delay to set the loading store value', () => {
|
2019-11-27 04:58:53 +01:00
|
|
|
init({ fallbackLocale: 'en', loadingDelay: 300 })
|
2019-11-26 17:05:17 +01:00
|
|
|
expect(getOptions().loadingDelay).toBe(300)
|
2019-11-26 03:09:05 +01:00
|
|
|
})
|