-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathconvertConfigSAB.test.ts
More file actions
231 lines (199 loc) · 8.43 KB
/
convertConfigSAB.test.ts
File metadata and controls
231 lines (199 loc) · 8.43 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import { readFileSync } from 'fs';
import path from 'path';
import type { ScriptureConfig } from '$config';
import jsdom from 'jsdom';
import { expect, test } from 'vitest';
import {
parseAnalytics,
parseAudioSources,
parseBackgroundImages,
parseBookCollections,
parseColorThemes,
parseFeatures,
parseFirebase,
parseFonts,
parseIllustrations,
parseInterfaceLanguages,
parseKeys,
parseLayouts,
parseMenuItems,
parseMenuLocalizations,
parsePlans,
parseTraits,
parseVideos,
parseWatermarkImages
} from '../../convertConfig';
const dataDir = './data/';
const dom = new jsdom.JSDOM(readFileSync(path.join(dataDir, 'appdef.xml')).toString(), {
contentType: 'text/xml'
});
const { document } = dom.window;
const appDefinition = document.getElementsByTagName('app-definition')[0];
const programType = appDefinition.attributes.getNamedItem('type')!.value;
test('convertConfig: parse fonts', () => {
const result = parseFonts(document, 1);
for (const f of result) {
expect(f.family).not.toSatisfy((r) => r === '' || r === undefined);
//CHECK WITH CHRIS FOR EMPTY FONT NAMES
//expect(f.name).not.toSatisfy((r) => r === "" || r === undefined);
expect(f.file).not.toSatisfy((r) => r === '' || r === undefined);
expect(f.fontStyle).not.toSatisfy((r) => r === '' || r === undefined);
expect(f.fontWeight).not.toSatisfy((r) => r === '' || r === undefined);
}
});
test('convertConfig: parse color themes', () => {
const result = parseColorThemes(document, 1);
expect(result.defaultTheme).not.toSatisfy((r) => r === '' || r === undefined);
for (const theme of result.themes) {
expect(theme.name).not.toSatisfy((r) => r === '' || r === undefined);
const colorsets = theme.colorSets;
for (const cs of colorsets) {
const allKeys = Object.keys(cs.colors);
for (const key of allKeys) {
expect(cs.colors[key].match(/^#[a-f0-9]{6}$/i)).not.toBe(null);
}
}
}
});
test('convertConfig: parse interface languages', () => {
const result = parseInterfaceLanguages(document, {} as ScriptureConfig, 1);
for (const lang in result.writingSystems) {
expect(result.writingSystems[lang].fontFamily).not.toEqual('');
expect(result.writingSystems[lang].textDirection).toSatisfy(
(r) => r === 'LTR' || r === 'RTL'
);
//expect(Object.keys(result.writingSystems[lang].displayNames).length).toEqual(Object.keys(result.writingSystems).length);
}
});
test('convertConfig: parse firebase', () => {
const result = parseFirebase(document, 1);
expect(Object.keys(result.features)).not.toHaveLength(0);
});
if (programType === 'DAB') {
test('Dummy test for SAB testing for DAB file', () => {
expect(0).toEqual(0);
});
} else if (programType === 'SAB') {
test('convertConfig: parse traits', () => {
const result = parseTraits(document, 'dummy', 1);
expect(Object.keys(result)).toHaveLength(7);
});
test('convertConfig: parse book collections', () => {
const result = parseBookCollections(document, 1);
expect(result).not.toHaveLength(0);
for (const bookCol in result) {
const bc = result[bookCol];
expect(Object.keys(bc)).toHaveLength(13);
expect(bc.id).not.toBe('');
expect(bc.collectionName).not.toBe('');
expect(bc.collectionAbbreviation).not.toBe('');
expect(bc.collectionImage).not.toBe('');
expect(bc.languageCode).not.toBe('');
expect(bc.languageName).not.toBe('');
expect(Object.keys(bc.features).length).toBeGreaterThanOrEqual(39);
expect(bc.books).not.toHaveLength(0);
for (const bk in bc.books) {
const bkk = bc.books[bk];
expect(bkk.chapters).not.toBe(0 || undefined);
expect(bkk.chaptersN).not.toSatisfy((r) => r === '' || r === undefined);
expect(bkk.id).not.toSatisfy((r) => r === '' || r === undefined);
expect(bkk.name).not.toSatisfy((r) => r === '' || r === undefined);
expect(bkk.section).not.toSatisfy((r) => r === '' || r === undefined);
expect(bkk.testament).not.toSatisfy((r) => r === '' || r === undefined);
expect(bkk.abbreviation).not.toSatisfy((r) => r === '' || r === undefined);
expect(bkk.file).not.toSatisfy((r) => r === '' || r === undefined);
for (const audio in bkk.audio) {
expect(bkk.audio[audio].num).not.toSatisfy((r) => r === '' || r === undefined);
expect(bkk.audio[audio].filename).not.toSatisfy(
(r) => r === '' || r === undefined
);
expect(bkk.audio[audio].len).not.toSatisfy((r) => r === '' || r === undefined);
expect(bkk.audio[audio].size).not.toSatisfy((r) => r === '' || r === undefined);
expect(bkk.audio[audio].src).not.toSatisfy((r) => r === '' || r === undefined);
expect(bkk.audio[audio].timingFile).not.toSatisfy(
(r) => r === '' || r === undefined
);
}
}
expect(Object.keys(bc.style)).toHaveLength(6);
let ind = 0;
for (const style in bc.styles) {
const st = bc.styles[ind];
expect(st.name).not.toSatisfy((r) => r === '' || r === undefined);
expect(Object.keys(st.properties)).not.toHaveLength(0);
ind += 1;
}
}
});
test('convertConfig: parse keys', () => {
const result = parseKeys(document, 1);
//expect(result).not.toHaveLength(0);
for (const k of result) {
expect(k).not.toSatisfy((r) => r === '' || r === undefined);
}
});
test('convertConfig: parse analytics', () => {
const result = parseAnalytics(document, 1);
for (const p in result.providers) {
expect(p).not.toSatisfy((r) => r === '' || r === undefined);
//for (const provider in p) {
// expect(provider).not.toSatisfy((r) => r === "" || r === undefined);
//}
}
});
test('convertConfig: parse audio sources', () => {
const result = parseAudioSources(document, 1);
expect(result).not.toBe(undefined);
// no audio yet
});
test('convertConfig: parse videos', () => {
const result = parseVideos(document, 1);
expect(result).not.toBe(undefined);
// not video yet
});
test('convertConfig: parse illustrations', () => {
const result = parseIllustrations(document, 1);
expect(result).not.toBe(undefined);
// no illustrations yet
});
test('convertConfig: parse layouts', () => {
const result = parseLayouts(document, 1, 1);
expect(result.layouts).not.toHaveLength(0);
for (const layout of result.layouts) {
expect(layout.mode).not.toSatisfy((r) => r === '' || r === undefined);
expect(layout.layoutCollections).not.toHaveLength(0);
for (const lc of layout.layoutCollections) {
expect(lc).not.toSatisfy((r) => r === '' || r === undefined);
}
for (const lc of Object.keys(layout.features)) {
expect(layout.features[lc]).not.toSatisfy((r) => r === '' || r === undefined);
}
}
});
test('convertConfig: parse features', () => {
const result = parseFeatures(document, 1);
expect(Object.keys(result)).toHaveLength(140);
});
test('convertConfig: parse background images', () => {
const result = parseBackgroundImages(document, 1);
expect(result).not.toBe(undefined);
// none yet
});
test('convertConfig: parse watermark images', () => {
const result = parseWatermarkImages(document, 1);
expect(result).not.toBe(undefined);
// none yet
});
test('convertConfig: parse menu items', () => {
const result = parseMenuItems(document, '', 1);
expect(result).not.toBe(undefined);
// none yet
});
test('convertConfig: parse plans', () => {
const result = parsePlans(document, 1);
expect(result).not.toBe(undefined);
// none yet
});
} else {
throw new Error(`Unsupported program type parsed: ${programType}`);
}