2018-07-26 06:40:19 +02:00
|
|
|
import i18n from '../src/svelte-i18n'
|
|
|
|
import { Store } from 'svelte/store.umd'
|
|
|
|
import { capitalize, titlelize, upper, lower, getNestedProp } from '../src/utils'
|
|
|
|
|
|
|
|
const store = new Store()
|
|
|
|
const locales = {
|
|
|
|
'pt-br': {
|
|
|
|
test: 'teste',
|
|
|
|
phrase: 'Adoro banana',
|
2018-07-27 04:24:17 +02:00
|
|
|
phrases: ['Frase 1', 'Frase 2'],
|
|
|
|
obj: {
|
|
|
|
a: 'a'
|
|
|
|
}
|
2018-07-26 06:40:19 +02:00
|
|
|
},
|
|
|
|
po: {
|
|
|
|
test: 'prøve',
|
|
|
|
phrase: 'Jeg elsker banan',
|
|
|
|
phrases: ['sætning 1', 'sætning 2']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-27 04:24:17 +02:00
|
|
|
i18n(store, [
|
|
|
|
locales,
|
|
|
|
{
|
|
|
|
'pt-br': {
|
|
|
|
obj: {
|
|
|
|
b: 'b'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
])
|
2018-07-26 03:40:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dummy test
|
|
|
|
*/
|
2018-07-26 06:40:19 +02:00
|
|
|
describe('utils', () => {
|
|
|
|
it('works', () => {
|
|
|
|
expect(getNestedProp(store['pt-br'], 'phrases[3]')).toBe(undefined)
|
|
|
|
})
|
|
|
|
})
|
2018-07-26 03:40:38 +02:00
|
|
|
describe('Dummy test', () => {
|
|
|
|
it('works if true is truthy', () => {
|
2018-07-26 06:40:19 +02:00
|
|
|
expect(store.get().locale).toBeFalsy()
|
|
|
|
expect(store.get()._).toBeFalsy()
|
2018-07-26 03:40:38 +02:00
|
|
|
|
2018-07-26 06:40:19 +02:00
|
|
|
store.fire('locale', 'en')
|
|
|
|
expect(store.get().locale).toBe('en')
|
|
|
|
store.locale('pt-br')
|
|
|
|
expect(store.get().locale).toBe('pt-br')
|
|
|
|
expect(store.get()._).toBeInstanceOf(Function)
|
|
|
|
expect(store.get()._('non-existent')).toBe('non-existent')
|
|
|
|
expect(store.get()._('test')).toBe(locales['pt-br'].test)
|
2018-07-27 04:24:17 +02:00
|
|
|
expect(store.get()._('obj.b')).toBe('b')
|
2018-07-26 06:40:19 +02:00
|
|
|
store.fire('locale', 'po')
|
|
|
|
expect(store.get()._('test')).not.toBe(locales['pt-br'].test)
|
|
|
|
expect(store.get()._('test')).toBe(locales.po.test)
|
|
|
|
expect(store.get()._('phrases[1]')).toBe(locales.po.phrases[1])
|
|
|
|
expect(store.get()._('phrases[2]')).toBe('phrases[2]')
|
|
|
|
expect(store.get()._.capitalize('phrase')).toBe(capitalize(locales.po.phrase))
|
|
|
|
expect(store.get()._.titlelize('phrase')).toBe(titlelize(locales.po.phrase))
|
|
|
|
expect(store.get()._.upper('phrase')).toBe(upper(locales.po.phrase))
|
|
|
|
expect(store.get()._.lower('phrase')).toBe(lower(locales.po.phrase))
|
2018-07-26 03:40:38 +02:00
|
|
|
})
|
|
|
|
})
|