-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
74 lines (66 loc) · 1.98 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import test from 'ava'
import {getI36n, initI36n} from "./src/index.js";
const translations = {
en: {
foo: 'I like i36n very much',
bar: 'I like {tool} even more!',
baz: [
'But there is more:',
'Do you know {cms}?',
'Btw, did I tell you that {foo}?'
]
},
fr: {
foo: "J'aime beaucoup i36n",
bar: "J'aime encore plus {tool}!"
},
baz: [
'Mais il y a plus:',
'Connaissez-vous {cms}?',
'Au faut, vous ai-je dit que {foo}?'
]
}
const load = ln => Promise.resolve(translations[ln])
test.before(() => {
initI36n('en', {
load
})
})
test('read a translated string', t => {
const { $label } = getI36n()
t.is($label.value('foo'), translations.en.foo)
})
test('read a translated string with param', t => {
const { $label } = getI36n()
t.is($label.value('bar', { tool: 'drosse'}), 'I like drosse even more!')
})
test('changing language should dynamically load translations', async t => {
const { $label, setLanguage } = getI36n()
t.is($label.value('foo'), translations.en.foo)
await setLanguage('fr')
t.is($label.value('foo'), translations.fr.foo)
})
test('read a list of translations + use existing translation keys inside another one', t => {
const { $labels } = getI36n()
t.deepEqual($labels.value('baz', { cms: 'hypercontent' }), [
'But there is more:',
'Do you know hypercontent?',
`Btw, did I tell you that ${translations.en.foo}?`
])
})
test('showKey flag allows to see keys instead of translated strings', t => {
const { $label, showKey } = getI36n()
showKey.value = true
t.is($label.value('foo'), `{foo}`)
showKey.value = false
})
test('showKey flag allows to see keys and placeholders instead of translated strings', t => {
const { $label, showKey } = getI36n()
showKey.value = true
t.is($label.value('bar'), `{bar, [tool]}`)
showKey.value = false
})
test('ignore unused placeholders', t => {
const { $label } = getI36n()
t.is($label.value('bar', { thing: 'drosse' }), translations.en.bar)
})