@knowark/componarkjs 1.13.4 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/base/component/component.js +17 -1
- package/lib/base/component/component.test.js +475 -389
- package/lib/base/utils/define.js +28 -6
- package/lib/base/utils/define.test.js +129 -42
- package/lib/base/utils/format.test.js +16 -16
- package/lib/base/utils/helpers.js +11 -4
- package/lib/base/utils/helpers.test.js +134 -115
- package/lib/base/utils/slots.test.js +38 -38
- package/lib/base/utils/uuid.test.js +13 -13
- package/lib/components/audio/components/audio.js +19 -1
- package/lib/components/audio/components/audio.test.js +120 -90
- package/lib/components/camera/components/camera.js +5 -0
- package/lib/components/camera/components/camera.test.js +96 -91
- package/lib/components/capture/components/capture.js +30 -2
- package/lib/components/capture/components/capture.test.js +165 -97
- package/lib/components/droparea/components/droparea-preview.js +58 -8
- package/lib/components/droparea/components/droparea-preview.test.js +262 -80
- package/lib/components/droparea/components/droparea.js +41 -4
- package/lib/components/droparea/components/droparea.test.js +309 -299
- package/lib/components/emit/components/emit.js +23 -3
- package/lib/components/emit/components/emit.test.js +192 -134
- package/lib/components/list/components/item.test.js +69 -68
- package/lib/components/list/components/list.js +33 -3
- package/lib/components/list/components/list.test.js +358 -227
- package/lib/components/paginator/components/paginator.test.js +146 -143
- package/lib/components/spinner/components/spinner.test.js +36 -41
- package/lib/components/splitview/components/splitview.detail.test.js +75 -73
- package/lib/components/splitview/components/splitview.js +36 -8
- package/lib/components/splitview/components/splitview.master.js +27 -2
- package/lib/components/splitview/components/splitview.master.test.js +52 -52
- package/lib/components/splitview/components/splitview.test.js +135 -31
- package/lib/components/translate/components/translate.js +28 -8
- package/lib/components/translate/components/translate.test.js +492 -133
- package/package.json +3 -27
- package/scripts/node-test-setup.js +94 -0
|
@@ -1,88 +1,436 @@
|
|
|
1
|
+
import { it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
1
3
|
import { Translate } from './translate.js'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
let container = null
|
|
6
|
+
|
|
7
|
+
const setup = () => {
|
|
8
|
+
document.body.innerHTML = '';
|
|
9
|
+
container = document.createElement('div')
|
|
10
|
+
document.body.appendChild(container)
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
it('can be instantiated', () => {
|
|
14
|
+
setup();
|
|
15
|
+
container.innerHTML = /* html */`
|
|
16
|
+
<ark-translate>
|
|
17
|
+
</ark-translate>
|
|
18
|
+
`
|
|
19
|
+
|
|
20
|
+
const translate = container.querySelector('ark-translate')
|
|
21
|
+
|
|
22
|
+
assert.ok(translate)
|
|
23
|
+
assert.strictEqual(translate, translate.init())
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('translates the marked text inside the given root', async () => {
|
|
27
|
+
setup();
|
|
28
|
+
const root = document.createElement('div')
|
|
29
|
+
root.innerHTML = /* html */`
|
|
30
|
+
<span data-i18n="hello">Hello</span>
|
|
31
|
+
<p>
|
|
32
|
+
<span data-i18n="happy">Happy</span>!!!
|
|
33
|
+
<span data-i18n="world">World</span>!!!
|
|
34
|
+
</p>
|
|
35
|
+
`
|
|
36
|
+
container.appendChild(root)
|
|
37
|
+
const translateContainer = document.createElement('div')
|
|
38
|
+
translateContainer.innerHTML = /* html */`
|
|
39
|
+
<ark-translate>
|
|
40
|
+
<template>{
|
|
41
|
+
"en": {
|
|
42
|
+
"default": {
|
|
43
|
+
"hello": "Hello",
|
|
44
|
+
"world": "World"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"es": {
|
|
48
|
+
"default": {
|
|
49
|
+
"hello": "Hola",
|
|
50
|
+
"world": "Mundo"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}</template>
|
|
54
|
+
</ark-translate>
|
|
55
|
+
`
|
|
56
|
+
container.appendChild(translateContainer)
|
|
57
|
+
const translate = /** @type Translate **/ (
|
|
58
|
+
translateContainer.querySelector('ark-translate'))
|
|
59
|
+
|
|
60
|
+
await translate.transliterate()
|
|
61
|
+
|
|
62
|
+
const expectedRoot = document.createElement('div')
|
|
63
|
+
expectedRoot.innerHTML = /* html */`
|
|
64
|
+
<span data-i18n="hello">Hola</span>
|
|
65
|
+
<p>
|
|
66
|
+
<span data-i18n="happy">Happy</span>!!!
|
|
67
|
+
<span data-i18n="world">Mundo</span>!!!
|
|
68
|
+
</p>
|
|
69
|
+
`
|
|
70
|
+
assert.deepStrictEqual(root, expectedRoot)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('might use different translation languages and namespaces', async () => {
|
|
74
|
+
setup();
|
|
75
|
+
const root = document.createElement('div')
|
|
76
|
+
root.innerHTML = /* html */`
|
|
77
|
+
<span data-i18n="introModule:hello">hello</span>
|
|
78
|
+
<p>
|
|
79
|
+
<span data-i18n="introModule:happy">happy</span>!!!
|
|
80
|
+
<span data-i18n="introModule:world">world</span>!!!
|
|
81
|
+
</p>
|
|
82
|
+
`
|
|
83
|
+
container.appendChild(root)
|
|
84
|
+
const translateContainer = document.createElement('div')
|
|
85
|
+
translateContainer.innerHTML = /* html */`
|
|
86
|
+
<ark-translate>
|
|
87
|
+
<template>{
|
|
88
|
+
"es": {
|
|
89
|
+
"default": {
|
|
90
|
+
"hello": "Hola",
|
|
91
|
+
"world": "Mundo"
|
|
92
|
+
},
|
|
93
|
+
"introModule": {
|
|
94
|
+
"hello": "Quiubo",
|
|
95
|
+
"world": "Gente"
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"en": {
|
|
99
|
+
"default": {
|
|
100
|
+
"hello": "Hello",
|
|
101
|
+
"world": "World"
|
|
102
|
+
},
|
|
103
|
+
"introModule": {
|
|
104
|
+
"hello": "Hey",
|
|
105
|
+
"world": "Folks"
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}</template>
|
|
109
|
+
</ark-translate>
|
|
110
|
+
`
|
|
111
|
+
container.appendChild(translateContainer)
|
|
112
|
+
const translate = /** @type Translate **/ (
|
|
113
|
+
translateContainer.querySelector('ark-translate'))
|
|
114
|
+
|
|
115
|
+
let options = { language: 'en' }
|
|
116
|
+
await translate.transliterate(options)
|
|
117
|
+
|
|
118
|
+
const expectedRoot = document.createElement('div')
|
|
119
|
+
expectedRoot.innerHTML = /* html */`
|
|
120
|
+
<span data-i18n="introModule:hello">Hey</span>
|
|
121
|
+
<p>
|
|
122
|
+
<span data-i18n="introModule:happy">happy</span>!!!
|
|
123
|
+
<span data-i18n="introModule:world">Folks</span>!!!
|
|
124
|
+
</p>
|
|
125
|
+
`
|
|
126
|
+
assert.deepStrictEqual(root, expectedRoot)
|
|
127
|
+
|
|
128
|
+
// Unknown Namespace:
|
|
129
|
+
root.innerHTML = /* html */`
|
|
130
|
+
<span data-i18n="unknown:hello">Hello</span>
|
|
131
|
+
<p>
|
|
132
|
+
<span data-i18n="unknown:happy">Happy</span>!!!
|
|
133
|
+
<span data-i18n="unknown:world">World</span>!!!
|
|
134
|
+
</p>
|
|
135
|
+
`
|
|
136
|
+
|
|
137
|
+
options = { language: 'es' }
|
|
138
|
+
await translate.transliterate(options)
|
|
139
|
+
|
|
140
|
+
expectedRoot.innerHTML = /* html */`
|
|
141
|
+
<span data-i18n="unknown:hello">Hello</span>
|
|
142
|
+
<p>
|
|
143
|
+
<span data-i18n="unknown:happy">Happy</span>!!!
|
|
144
|
+
<span data-i18n="unknown:world">World</span>!!!
|
|
145
|
+
</p>
|
|
146
|
+
`
|
|
147
|
+
assert.deepStrictEqual(root, expectedRoot)
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('translates the page content on language changes', async () => {
|
|
151
|
+
setup();
|
|
152
|
+
const translateContainer = document.createElement('div')
|
|
153
|
+
translateContainer.innerHTML = /* html */`
|
|
154
|
+
<ark-translate languages="es,en">
|
|
155
|
+
<template>{
|
|
156
|
+
"es": {
|
|
157
|
+
"default": {
|
|
158
|
+
"hello": "Hola",
|
|
159
|
+
"world": "Mundo"
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
"en": {
|
|
163
|
+
"default": {
|
|
164
|
+
"hello": "Hello",
|
|
165
|
+
"world": "World"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}</template>
|
|
169
|
+
</ark-translate>
|
|
170
|
+
`
|
|
171
|
+
container.appendChild(translateContainer)
|
|
172
|
+
const translate = /** @type Translate **/ (
|
|
173
|
+
translateContainer.querySelector('ark-translate'))
|
|
174
|
+
const mockEvent = { target: { value: 'en' }, stopPropagation: () => {} }
|
|
175
|
+
let givenOptions = null
|
|
176
|
+
translate.transliterate = async (options) => {
|
|
177
|
+
givenOptions = options
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
await translate.onLanguageChanged(mockEvent)
|
|
181
|
+
|
|
182
|
+
assert.deepStrictEqual(givenOptions, { language: 'en' })
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
it('fetches its translation files from the server', async () => {
|
|
186
|
+
setup();
|
|
187
|
+
const root = document.createElement('div')
|
|
188
|
+
root.innerHTML = /* html */`
|
|
189
|
+
<span data-i18n="hello">hello</span>
|
|
190
|
+
<p>
|
|
191
|
+
<span data-i18n="happy">happy</span>!!!
|
|
192
|
+
<span data-i18n="world">world</span>!!!
|
|
193
|
+
</p>
|
|
194
|
+
`
|
|
195
|
+
container.appendChild(root)
|
|
196
|
+
const translateContainer = document.createElement('div')
|
|
197
|
+
translateContainer.innerHTML = `
|
|
198
|
+
<ark-translate languages="es,en"></ark-translate>
|
|
199
|
+
`
|
|
200
|
+
container.appendChild(translateContainer)
|
|
201
|
+
const translate = /** @type Translate **/ (
|
|
202
|
+
translateContainer.querySelector('ark-translate'))
|
|
203
|
+
|
|
204
|
+
const mockFetch = async (url) => ({
|
|
205
|
+
json: async () => ({
|
|
206
|
+
hello: 'Hola',
|
|
207
|
+
world: 'Mundo',
|
|
208
|
+
happy: 'Feliz'
|
|
209
|
+
})
|
|
210
|
+
})
|
|
211
|
+
translate.init({
|
|
212
|
+
global: { fetch: mockFetch, document }
|
|
8
213
|
})
|
|
9
214
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
215
|
+
await translate.transliterate({ language: 'es' })
|
|
216
|
+
|
|
217
|
+
const expectedRoot = document.createElement('div')
|
|
218
|
+
expectedRoot.innerHTML = /* html */`
|
|
219
|
+
<span data-i18n="hello">Hola</span>
|
|
220
|
+
<p>
|
|
221
|
+
<span data-i18n="happy">Feliz</span>!!!
|
|
222
|
+
<span data-i18n="world">Mundo</span>!!!
|
|
223
|
+
</p>
|
|
224
|
+
`
|
|
225
|
+
assert.deepStrictEqual(root, expectedRoot)
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
it('renders unknown language codes without crashing', () => {
|
|
229
|
+
setup()
|
|
230
|
+
const translateContainer = document.createElement('div')
|
|
231
|
+
translateContainer.innerHTML = `
|
|
232
|
+
<ark-translate languages="es,de"></ark-translate>
|
|
233
|
+
`
|
|
234
|
+
container.appendChild(translateContainer)
|
|
235
|
+
const translate = /** @type Translate **/ (
|
|
236
|
+
translateContainer.querySelector('ark-translate'))
|
|
237
|
+
|
|
238
|
+
const option = translate.querySelector('option[value="de"]')
|
|
239
|
+
assert.ok(option)
|
|
240
|
+
assert.deepStrictEqual(option.textContent, 'de')
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
it('emits error when inline dictionary JSON is invalid', () => {
|
|
244
|
+
setup()
|
|
245
|
+
const translateContainer = document.createElement('div')
|
|
246
|
+
translateContainer.innerHTML = /* html */`
|
|
247
|
+
<ark-translate>
|
|
248
|
+
<template>{ invalid json }</template>
|
|
249
|
+
</ark-translate>
|
|
250
|
+
`
|
|
251
|
+
container.appendChild(translateContainer)
|
|
252
|
+
const translate = /** @type Translate **/ (
|
|
253
|
+
translateContainer.querySelector('ark-translate'))
|
|
254
|
+
let errorEvent = null
|
|
255
|
+
|
|
256
|
+
translate.addEventListener('error', (event) => {
|
|
257
|
+
errorEvent = event
|
|
13
258
|
})
|
|
259
|
+
translate.init()
|
|
14
260
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
<ark-translate>
|
|
18
|
-
</ark-translate>
|
|
19
|
-
`
|
|
261
|
+
assert.ok(errorEvent)
|
|
262
|
+
})
|
|
20
263
|
|
|
21
|
-
|
|
264
|
+
it('emits error when dictionary fetch fails', async () => {
|
|
265
|
+
setup()
|
|
266
|
+
const root = document.createElement('div')
|
|
267
|
+
root.innerHTML = /* html */`
|
|
268
|
+
<span data-i18n="hello">hello</span>
|
|
269
|
+
`
|
|
270
|
+
container.appendChild(root)
|
|
271
|
+
const translateContainer = document.createElement('div')
|
|
272
|
+
translateContainer.innerHTML = `
|
|
273
|
+
<ark-translate></ark-translate>
|
|
274
|
+
`
|
|
275
|
+
container.appendChild(translateContainer)
|
|
276
|
+
const translate = /** @type Translate **/ (
|
|
277
|
+
translateContainer.querySelector('ark-translate'))
|
|
278
|
+
let errorEvent = null
|
|
279
|
+
translate.addEventListener('error', (event) => {
|
|
280
|
+
errorEvent = event
|
|
281
|
+
})
|
|
22
282
|
|
|
23
|
-
|
|
24
|
-
|
|
283
|
+
translate.init({
|
|
284
|
+
global: {
|
|
285
|
+
document,
|
|
286
|
+
fetch: async () => {
|
|
287
|
+
throw new Error('Network failed')
|
|
288
|
+
}
|
|
289
|
+
}
|
|
25
290
|
})
|
|
26
291
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
292
|
+
await translate.transliterate({ language: 'es' })
|
|
293
|
+
|
|
294
|
+
assert.ok(errorEvent)
|
|
295
|
+
assert.deepStrictEqual(errorEvent.detail.message, 'Network failed')
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
it('translates with dynamic options', async () => {
|
|
299
|
+
setup()
|
|
300
|
+
const root = document.createElement('div')
|
|
301
|
+
root.innerHTML = /* html */`
|
|
302
|
+
<span data-i18n="hello">hello</span>
|
|
303
|
+
<p>
|
|
304
|
+
<span data-i18n="happy">happy</span>!!!
|
|
305
|
+
<span data-i18n="world">world</span>!!!
|
|
306
|
+
</p>
|
|
307
|
+
`
|
|
308
|
+
container.appendChild(root)
|
|
309
|
+
const translateContainer = document.createElement('div')
|
|
310
|
+
translateContainer.innerHTML = /* html */`
|
|
311
|
+
<ark-translate languages="es,en">
|
|
312
|
+
<template>{
|
|
313
|
+
"es": {
|
|
314
|
+
"default": {
|
|
315
|
+
"hello": "Hola",
|
|
316
|
+
"world": "Mundo"
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
"en": {
|
|
320
|
+
"default": {
|
|
321
|
+
"hello": "Hello",
|
|
322
|
+
"world": "World"
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}</template>
|
|
326
|
+
</ark-translate>
|
|
327
|
+
`
|
|
328
|
+
container.appendChild(translateContainer)
|
|
329
|
+
const translate = /** @type Translate **/ (
|
|
330
|
+
translateContainer.querySelector('ark-translate'))
|
|
331
|
+
|
|
332
|
+
await translate.transliterate({ language: 'es' })
|
|
333
|
+
|
|
334
|
+
const expectedRoot = document.createElement('div')
|
|
335
|
+
expectedRoot.innerHTML = /* html */`
|
|
336
|
+
<span data-i18n="hello">Hola</span>
|
|
337
|
+
<p>
|
|
338
|
+
<span data-i18n="happy">Happy</span>!!!
|
|
339
|
+
<span data-i18n="world">Mundo</span>!!!
|
|
340
|
+
</p>
|
|
341
|
+
`
|
|
342
|
+
assert.deepStrictEqual(root, expectedRoot)
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
it('renders the translate component correctly', async () => {
|
|
346
|
+
setup();
|
|
347
|
+
const template = `
|
|
39
348
|
<ark-translate>
|
|
40
349
|
<template>{
|
|
350
|
+
"es": {
|
|
351
|
+
"default": {
|
|
352
|
+
"hello": "Hola",
|
|
353
|
+
"world": "Mundo"
|
|
354
|
+
}
|
|
355
|
+
},
|
|
41
356
|
"en": {
|
|
42
357
|
"default": {
|
|
43
358
|
"hello": "Hello",
|
|
44
359
|
"world": "World"
|
|
45
360
|
}
|
|
46
|
-
}
|
|
361
|
+
}
|
|
362
|
+
}</template>
|
|
363
|
+
</ark-translate>
|
|
364
|
+
`;
|
|
365
|
+
container.innerHTML = template
|
|
366
|
+
const translateContainer = container.querySelector('ark-translate')
|
|
367
|
+
const translate = /** @type Translate **/ (translateContainer)
|
|
368
|
+
|
|
369
|
+
assert.strictEqual(translate, translate.init())
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
it('renders the translate component with a single language', async () => {
|
|
373
|
+
setup();
|
|
374
|
+
const root = document.createElement('div')
|
|
375
|
+
root.innerHTML = /* html */`
|
|
376
|
+
<span data-i18n="hello">Hello</span>
|
|
377
|
+
<p>
|
|
378
|
+
<span data-i18n="happy">Happy</span>!!!
|
|
379
|
+
<span data-i18n="world">World</span>!!!
|
|
380
|
+
</p>
|
|
381
|
+
`
|
|
382
|
+
container.appendChild(root)
|
|
383
|
+
|
|
384
|
+
const translateContainer = document.createElement('div')
|
|
385
|
+
translateContainer.innerHTML = /* html */`
|
|
386
|
+
<ark-translate languages="es,en">
|
|
387
|
+
<template>{
|
|
47
388
|
"es": {
|
|
48
389
|
"default": {
|
|
49
390
|
"hello": "Hola",
|
|
50
391
|
"world": "Mundo"
|
|
51
392
|
}
|
|
393
|
+
},
|
|
394
|
+
"en": {
|
|
395
|
+
"default": {
|
|
396
|
+
"hello": "Hello",
|
|
397
|
+
"world": "World"
|
|
398
|
+
}
|
|
52
399
|
}
|
|
53
400
|
}</template>
|
|
54
401
|
</ark-translate>
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
translateContainer.querySelector('ark-translate'))
|
|
402
|
+
`
|
|
403
|
+
container.appendChild(translateContainer)
|
|
404
|
+
const translate = /** @type Translate **/ (translateContainer.querySelector('ark-translate'))
|
|
59
405
|
|
|
60
|
-
|
|
406
|
+
await translate.transliterate({ language: 'es' })
|
|
61
407
|
|
|
62
|
-
|
|
63
|
-
|
|
408
|
+
const expectedRoot = document.createElement('div')
|
|
409
|
+
expectedRoot.innerHTML = /* html */`
|
|
64
410
|
<span data-i18n="hello">Hola</span>
|
|
65
411
|
<p>
|
|
66
412
|
<span data-i18n="happy">Happy</span>!!!
|
|
67
413
|
<span data-i18n="world">Mundo</span>!!!
|
|
68
414
|
</p>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
415
|
+
`
|
|
416
|
+
assert.deepStrictEqual(root, expectedRoot)
|
|
417
|
+
})
|
|
72
418
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
419
|
+
it('renders the translate component with a nested namespace', async () => {
|
|
420
|
+
setup();
|
|
421
|
+
const root = document.createElement('div')
|
|
422
|
+
root.innerHTML = /* html */`
|
|
423
|
+
<span data-i18n="introModule:hello">Hello</span>
|
|
77
424
|
<p>
|
|
78
|
-
<span data-i18n="introModule:happy">
|
|
79
|
-
<span data-i18n="introModule:world">
|
|
425
|
+
<span data-i18n="introModule:happy">Happy</span>!!!
|
|
426
|
+
<span data-i18n="introModule:world">World</span>!!!
|
|
80
427
|
</p>
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
428
|
+
`
|
|
429
|
+
container.appendChild(root)
|
|
430
|
+
|
|
431
|
+
const translateContainer = document.createElement('div')
|
|
432
|
+
translateContainer.innerHTML = /* html */`
|
|
433
|
+
<ark-translate languages="es,en">
|
|
86
434
|
<template>{
|
|
87
435
|
"es": {
|
|
88
436
|
"default": {
|
|
@@ -106,50 +454,51 @@ describe('Translate', () => {
|
|
|
106
454
|
}
|
|
107
455
|
}</template>
|
|
108
456
|
</ark-translate>
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
translateContainer.querySelector('ark-translate'))
|
|
457
|
+
`
|
|
458
|
+
container.appendChild(translateContainer)
|
|
459
|
+
const translate = /** @type Translate **/ (translateContainer.querySelector('ark-translate'))
|
|
113
460
|
|
|
114
|
-
|
|
115
|
-
await translate.transliterate(options)
|
|
461
|
+
await translate.transliterate({ language: 'es' })
|
|
116
462
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
<span data-i18n="introModule:hello">
|
|
463
|
+
const expectedRoot = document.createElement('div')
|
|
464
|
+
expectedRoot.innerHTML = /* html */`
|
|
465
|
+
<span data-i18n="introModule:hello">Quiubo</span>
|
|
120
466
|
<p>
|
|
121
|
-
<span data-i18n="introModule:happy">
|
|
122
|
-
<span data-i18n="introModule:world">
|
|
467
|
+
<span data-i18n="introModule:happy">Happy</span>!!!
|
|
468
|
+
<span data-i18n="introModule:world">Gente</span>!!!
|
|
123
469
|
</p>
|
|
124
|
-
|
|
125
|
-
|
|
470
|
+
`
|
|
471
|
+
assert.deepStrictEqual(root, expectedRoot)
|
|
472
|
+
})
|
|
126
473
|
|
|
127
|
-
|
|
474
|
+
it('renders the translate component with an invalid dictionary JSON', () => {
|
|
475
|
+
setup();
|
|
476
|
+
|
|
477
|
+
const template = `<ark-translate>
|
|
478
|
+
<template>{ "invalid": {} }</template>
|
|
479
|
+
</ark-translate>`
|
|
480
|
+
container.innerHTML = template
|
|
481
|
+
const translateContainer = container.querySelector('ark-translate')
|
|
482
|
+
const translate = /** @type Translate **/ (translateContainer)
|
|
128
483
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
<p>
|
|
132
|
-
<span data-i18n="unknown:happy">Happy</span>!!!
|
|
133
|
-
<span data-i18n="unknown:world">World</span>!!!
|
|
134
|
-
</p>
|
|
135
|
-
`
|
|
136
|
-
|
|
137
|
-
options = { language: 'es' }
|
|
138
|
-
await translate.transliterate(options)
|
|
484
|
+
assert.strictEqual(translate, translate.init())
|
|
485
|
+
})
|
|
139
486
|
|
|
140
|
-
|
|
141
|
-
|
|
487
|
+
it('translates with dynamic options using global fetch', async () => {
|
|
488
|
+
setup();
|
|
489
|
+
|
|
490
|
+
const root = document.createElement('div')
|
|
491
|
+
root.innerHTML = /* html */`
|
|
492
|
+
<span data-i18n="hello">Hello</span>
|
|
142
493
|
<p>
|
|
143
|
-
<span data-i18n="
|
|
144
|
-
<span data-i18n="
|
|
494
|
+
<span data-i18n="happy">Happy</span>!!!
|
|
495
|
+
<span data-i18n="world">World</span>!!!
|
|
145
496
|
</p>
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const translateContainer = document.createElement('div')
|
|
152
|
-
translateContainer.innerHTML = /* html */`
|
|
497
|
+
`
|
|
498
|
+
container.appendChild(root)
|
|
499
|
+
|
|
500
|
+
const translateContainer = document.createElement('div')
|
|
501
|
+
translateContainer.innerHTML = /* html */`
|
|
153
502
|
<ark-translate languages="es,en">
|
|
154
503
|
<template>{
|
|
155
504
|
"es": {
|
|
@@ -166,60 +515,70 @@ describe('Translate', () => {
|
|
|
166
515
|
}
|
|
167
516
|
}</template>
|
|
168
517
|
</ark-translate>
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
translateContainer.querySelector('ark-translate'))
|
|
173
|
-
const mockEvent = { target: { value: 'en' }, stopPropagation: () => {} }
|
|
174
|
-
let givenOptions = null
|
|
175
|
-
translate.transliterate = async (options) => {
|
|
176
|
-
givenOptions = options
|
|
177
|
-
}
|
|
518
|
+
`
|
|
519
|
+
container.appendChild(translateContainer)
|
|
520
|
+
const translate = /** @type Translate **/ (translateContainer.querySelector('ark-translate'))
|
|
178
521
|
|
|
179
|
-
|
|
522
|
+
await translate.transliterate({ language: 'es' })
|
|
180
523
|
|
|
181
|
-
|
|
182
|
-
|
|
524
|
+
const expectedRoot = document.createElement('div')
|
|
525
|
+
expectedRoot.innerHTML = /* html */`
|
|
526
|
+
<span data-i18n="hello">Hola</span>
|
|
527
|
+
<p>
|
|
528
|
+
<span data-i18n="happy">Happy</span>!!!
|
|
529
|
+
<span data-i18n="world">Mundo</span>!!!
|
|
530
|
+
</p>
|
|
531
|
+
`
|
|
532
|
+
assert.deepStrictEqual(root, expectedRoot)
|
|
533
|
+
})
|
|
183
534
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
535
|
+
it('renders the translate component with empty dictionaries', async () => {
|
|
536
|
+
setup();
|
|
537
|
+
|
|
538
|
+
const template = `<ark-translate>
|
|
539
|
+
<template>{ "es": {} }</template>
|
|
540
|
+
</ark-translate>`
|
|
541
|
+
container.innerHTML = template
|
|
542
|
+
const translateContainer = container.querySelector('ark-translate')
|
|
543
|
+
const translate = /** @type Translate **/ (translateContainer)
|
|
544
|
+
|
|
545
|
+
assert.strictEqual(translate, translate.init())
|
|
546
|
+
})
|
|
547
|
+
|
|
548
|
+
it('renders the translate component with an empty dictionary', async () => {
|
|
549
|
+
setup();
|
|
550
|
+
|
|
551
|
+
const root = document.createElement('div')
|
|
552
|
+
root.innerHTML = /* html */`
|
|
553
|
+
<span data-i18n="hello">Hello</span>
|
|
188
554
|
<p>
|
|
189
|
-
<span data-i18n="happy">
|
|
190
|
-
<span data-i18n="world">
|
|
555
|
+
<span data-i18n="happy">Happy</span>!!!
|
|
556
|
+
<span data-i18n="world">World</span>!!!
|
|
191
557
|
</p>
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
happy: 'Feliz'
|
|
207
|
-
})
|
|
208
|
-
})
|
|
209
|
-
translate.init({
|
|
210
|
-
global: { fetch: mockFetch, document }
|
|
211
|
-
})
|
|
558
|
+
`
|
|
559
|
+
container.appendChild(root)
|
|
560
|
+
|
|
561
|
+
const translateContainer = document.createElement('div')
|
|
562
|
+
translateContainer.innerHTML = /* html */`
|
|
563
|
+
<ark-translate languages="es,en">
|
|
564
|
+
<template>{
|
|
565
|
+
"es": {},
|
|
566
|
+
"en": {}
|
|
567
|
+
}</template>
|
|
568
|
+
</ark-translate>
|
|
569
|
+
`
|
|
570
|
+
container.appendChild(translateContainer)
|
|
571
|
+
const translate = /** @type Translate **/ (translateContainer.querySelector('ark-translate'))
|
|
212
572
|
|
|
213
|
-
|
|
573
|
+
await translate.transliterate({ language: 'es' })
|
|
214
574
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
<span data-i18n="hello">
|
|
575
|
+
const expectedRoot = document.createElement('div')
|
|
576
|
+
expectedRoot.innerHTML = /* html */`
|
|
577
|
+
<span data-i18n="hello">Hello</span>
|
|
218
578
|
<p>
|
|
219
|
-
<span data-i18n="happy">
|
|
220
|
-
<span data-i18n="world">
|
|
579
|
+
<span data-i18n="happy">Happy</span>!!!
|
|
580
|
+
<span data-i18n="world">World</span>!!!
|
|
221
581
|
</p>
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
})
|
|
582
|
+
`
|
|
583
|
+
assert.deepStrictEqual(root, expectedRoot)
|
|
584
|
+
})
|