-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathTargetLanguageActions.test.js
More file actions
175 lines (163 loc) · 6.73 KB
/
TargetLanguageActions.test.js
File metadata and controls
175 lines (163 loc) · 6.73 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
import path from 'path';
import fs from 'fs-extra';
import ncp from 'ncp';
import AdmZip from 'adm-zip';
import * as manifestHelpers from '../js/helpers/manifestHelpers';
import * as helpers from '../js/helpers/TargetLanguageHelpers';
jest.unmock('fs-extra');
jest.unmock('adm-zip');
jest.unmock('../js/helpers/GitApi');
jest.mock('../js/selectors', () => ({
...require.requireActual('../js/selectors'),
getActiveLocaleLanguage: () => ({ code: 'en' }),
}));
const cleanOutput = () => {
fs.emptyDirSync(path.join(__dirname, 'output/tests'));
};
beforeEach(() => {
cleanOutput();
});
afterEach(() => {
cleanOutput();
});
describe('generateTargetBibleFromUSFMPath', () => {
it('generates a target bible', () => {
const usfmPath = path.join(__dirname, 'fixtures/usfm/valid/id_tit_text_reg.usfm');
const projectPath = path.join(__dirname, 'output/tests/tit_from_usfm');
const manifest = {
'project': { 'id': 'tit' },
'target_language': {
'id': 'en',
'name': 'English',
'direction': 'ltr',
},
};
helpers.generateTargetBibleFromUSFMPath(usfmPath, projectPath, manifest);
const bookPath = path.join(projectPath, manifest.project.id);
expect(fs.existsSync(bookPath)).toBeTruthy();
expect(fs.existsSync(path.join(bookPath, '1.json'))).toBeTruthy();
expect(fs.existsSync(path.join(bookPath, '2.json'))).toBeTruthy();
expect(fs.existsSync(path.join(bookPath, '3.json'))).toBeTruthy();
});
it('fails to generate from missing usfm', () => {
const usfmPath = path.join(__dirname, 'fixtures/usfm/valid/missing_file.usfm');
const projectPath = path.join(__dirname, 'output/tests/missing_output');
const manifest = {
'project': { 'id': 'tit' },
'target_language': {
'id': 'en',
'name': 'English',
'direction': 'ltr',
},
};
helpers.generateTargetBibleFromUSFMPath(usfmPath, projectPath, manifest);
const bookPath = path.join(projectPath, manifest.project.id);
expect(fs.existsSync(bookPath)).toBeFalsy();
});
});
describe('generateTargetBibleFromTstudioProjectPath', () => {
it('generates a Bible', () => {
const srcPath = path.join(__dirname, 'fixtures/project/full_project');
const projectPath = path.join(__dirname, 'output/tests/generate_from_project');
return new Promise((resolve, reject) => {
// copy source to output for manipulation
ncp(srcPath, projectPath, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
}).then(() => {
// perform test
const manifest = {
project: { id: 'gen' },
target_language: {
id: 'en',
name: 'English',
direction: 'ltr',
},
};
helpers.generateTargetBibleFromTstudioProjectPath(projectPath, manifest);
const bookPath = path.join(projectPath, manifest.project.id);
expect(fs.existsSync(path.join(bookPath, '1.json'))).toBeTruthy();
});
});
it('generates a Bible w/ single chunks', () => {
const srcPath = path.join(__dirname, 'fixtures/project/single_chunks');
const projectPath = path.join(__dirname, 'output/tests/single_chunks');
return new Promise((resolve, reject) => {
// copy source to output for manipulation
ncp(srcPath, projectPath, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
}).then(() => {
//perform test
const manifest = {
'project': { id: 'tit' },
'target_language': {
'direction': 'ltr',
'id': 'abu',
'name': 'Abure',
},
};
helpers.generateTargetBibleFromTstudioProjectPath(projectPath, manifest);
const bookPath = path.join(projectPath, manifest.project.id);
expect(fs.existsSync(path.join(bookPath, '1.json'))).toBeTruthy();
expect(fs.existsSync(path.join(bookPath, '2.json'))).toBeFalsy();
expect(fs.readJSONSync(path.join(bookPath, '3.json'))[8]).toBeDefined();
expect(fs.readJSONSync(path.join(bookPath, '3.json'))[3]).toBeDefined();
});
});
it('generates a Bible from tstudio project with 00 folder', () => {
const projectName = 'aaa_php_text_ulb';
const srcPath = path.join(__dirname, 'fixtures/project/tstudio_project/' + projectName + '.tstudio');
const unzipPath = path.join(__dirname, 'output/tests', projectName);
const projectPath = path.join(unzipPath, projectName);
const zip = new AdmZip(srcPath);
zip.extractAllTo(unzipPath, /*overwrite*/true); // extract .tstudio project
const manifest = manifestHelpers.getProjectManifest(projectPath);
helpers.generateTargetBibleFromTstudioProjectPath(projectPath, manifest);
const bookPath = path.join(projectPath, manifest.project.id);
expect(fs.existsSync(path.join(bookPath, '1.json'))).toBeTruthy();
expect(fs.existsSync(path.join(bookPath, '2.json'))).toBeTruthy();
const json3 = fs.readJSONSync(path.join(bookPath, '3.json'));
expect(fs.existsSync(path.join(bookPath, '4.json'))).toBeTruthy();
expect(fs.existsSync(path.join(bookPath, '5.json'))).toBeFalsy();
expect(json3['front']).not.toBeDefined();
expect(json3[8]).toBeDefined();
expect(json3[3]).toBeDefined();
expect(json3[22]).not.toBeDefined();
const headers = fs.readJSONSync(path.join(bookPath, 'headers.json'));
expect(headers.length).toEqual(1);
});
it('generates a Bible from tstudio project with front folder', () => {
const projectName = 'en_php_text_reg';
const srcPath = path.join(__dirname, 'fixtures/project/tstudio_project/' + projectName + '.tstudio');
const unzipPath = path.join(__dirname, 'output/tests', projectName);
const projectPath = path.join(unzipPath, projectName);
const zip = new AdmZip(srcPath);
zip.extractAllTo(unzipPath, /*overwrite*/true); // extract .tstudio project
const manifest = manifestHelpers.getProjectManifest(projectPath);
helpers.generateTargetBibleFromTstudioProjectPath(projectPath, manifest);
const bookPath = path.join(projectPath, manifest.project.id);
const json1 = fs.readJSONSync(path.join(bookPath, '1.json'));
expect(json1['front']).toBeDefined();
const json2 = fs.readJSONSync(path.join(bookPath, '2.json'));
expect(json2['front']).toBeDefined();
const json3 = fs.readJSONSync(path.join(bookPath, '3.json'));
expect(json3['front']).toBeDefined();
expect(json3[8]).toBeDefined();
expect(json3[3]).toBeDefined();
expect(json3[22]).not.toBeDefined();
const json4 = fs.readJSONSync(path.join(bookPath, '4.json'));
expect(json4['front']).toBeDefined();
expect(fs.existsSync(path.join(bookPath, '5.json'))).toBeFalsy();
const headers = fs.readJSONSync(path.join(bookPath, 'headers.json'));
expect(headers.length).toEqual(16);
});
});