-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
asset.test.mjs
130 lines (98 loc) · 4.07 KB
/
asset.test.mjs
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { Application } from '../../../src/framework/application.js';
import { Asset } from '../../../src/framework/asset/asset.js';
import { NullGraphicsDevice } from '../../../src/platform/graphics/null/null-graphics-device.js';
import { HTMLCanvasElement } from '@playcanvas/canvas-mock';
import { expect } from 'chai';
describe('Asset', function () {
let app;
beforeEach(function () {
const canvas = new HTMLCanvasElement(500, 500);
app = new Application(canvas, { graphicsDevice: new NullGraphicsDevice(canvas) });
});
afterEach(function () {
app.destroy();
});
const DEFAULT_LOCALE_FALLBACKS = {
'en': 'en-US',
'es': 'en-ES',
'zh': 'zh-CN',
'fr': 'fr-FR',
'de': 'de-DE',
'it': 'it-IT',
'ru': 'ru-RU',
'ja': 'ja-JP'
};
describe('#getLocalizedAssetId', function () {
it('should return null if no localizations exist', function () {
const asset = new Asset('asset', 'font');
asset.id = 1000;
expect(asset.getLocalizedAssetId('en')).to.equal(null);
});
it('should return fallback language if available', function () {
const asset = new Asset('asset', 'font');
let id = 1000;
for (const key in DEFAULT_LOCALE_FALLBACKS) {
asset.addLocalizedAssetId(DEFAULT_LOCALE_FALLBACKS[key], id);
id++;
}
id = 1000;
for (const key in DEFAULT_LOCALE_FALLBACKS) {
expect(asset.getLocalizedAssetId(key)).to.equal(id);
id++;
}
});
it('should return fallback language if available', function () {
const asset = new Asset('asset', 'font');
let id = 1000;
for (const key in DEFAULT_LOCALE_FALLBACKS) {
asset.addLocalizedAssetId(DEFAULT_LOCALE_FALLBACKS[key], id);
id++;
}
id = 1000;
for (const key in DEFAULT_LOCALE_FALLBACKS) {
expect(asset.getLocalizedAssetId(key)).to.equal(id);
id++;
}
});
it('should return fallback language if available', function () {
const asset = new Asset('asset', 'font');
let id = 1;
for (const key in DEFAULT_LOCALE_FALLBACKS) {
asset.addLocalizedAssetId(key + '-test', 1000 + id); // add other locale with same language which shouldn't be used
asset.addLocalizedAssetId(DEFAULT_LOCALE_FALLBACKS[key], 2000 + id);
id++;
}
id = 1;
for (const key in DEFAULT_LOCALE_FALLBACKS) {
expect(asset.getLocalizedAssetId(key)).to.equal(2000 + id);
id++;
}
});
it('zh-HK should return zh-HK if it exists', function () {
const asset = new Asset('asset', 'font');
asset.addLocalizedAssetId('zh-CN', 1);
asset.addLocalizedAssetId('zh-HK', 2);
asset.addLocalizedAssetId('zh-TW', 3);
expect(asset.getLocalizedAssetId('zh-HK')).to.equal(2);
});
it('zh-HK should fallback to zh-TW', function () {
const asset = new Asset('asset', 'font');
asset.addLocalizedAssetId('zh-CN', 1);
asset.addLocalizedAssetId('zh-TW', 2);
expect(asset.getLocalizedAssetId('zh-HK')).to.equal(2);
});
it('zh-TW should fallback to zh-HK', function () {
const asset = new Asset('asset', 'font');
asset.addLocalizedAssetId('zh-CN', 1);
asset.addLocalizedAssetId('zh-HK', 2);
expect(asset.getLocalizedAssetId('zh-TW')).to.equal(2);
});
it('zh-SG should fallback to zh-CN', function () {
const asset = new Asset('asset', 'font');
asset.addLocalizedAssetId('zh-HK', 1);
asset.addLocalizedAssetId('zh-CN', 2);
asset.addLocalizedAssetId('zh-TW', 2);
expect(asset.getLocalizedAssetId('zh-SG')).to.equal(2);
});
});
});