-
Notifications
You must be signed in to change notification settings - Fork 11
/
d.Upload.js
161 lines (150 loc) · 6.9 KB
/
d.Upload.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
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
/**
* Functions that need to be tested for Upload.js, as of now.
*
* 1. clearPreviousData - Somewhat Important ✓
* 2. sendPath - Important ✓
* 3. loadFile - Somewhat Important (TESTED THROUGH SENDPATH) ✓
* 4. loadProjectThatHasManifest (TESTED THROUGH SENDPATH) ✓
* 5. getParams - Important ✓
* 6. saveTargetLangeInAPI - Important ✓
* 7. checkIfUSFMProject ✓
* 8. saveManifest - Important (TESTED THROUGH SENDPATH) ✓
* 9. fixManifestVerThree - Somewhat Important (TESTED THROUGH SENDPATH)✓
* 10. manifestError ✘
* 11. isOldTestament - Somewhat Important (TESTED THROUGH SENDPATH) ✓
******************************************************************************/
const assert = require('chai').assert;
const expect = require('chai').expect;
const should = require('chai').should();
const Upload = require('../src/js/components/core/UploadMethods.js');
const CheckStore = require('../src/js/stores/CheckStore.js')
const path = require('path-extra');
const api = window.ModuleApi;
var fs = require('fs');
const testProjectPath = path.join(path.homedir(), 'translationCore', 'id_-co_text_reg');
const testUSFMProjectPath = path.join(window.__base, '/tests/static/3john');
const noTCManifestProject = path.join(window.__base, '/tests/static/id_-co_text_reg');
const undefinedProject = path.join(window.__base, '/tests/static/JesusSaves');
describe('Upload.sendFilePath(undefined project)', function () {
it('should fail', function (done) {
Upload.sendFilePath(undefinedProject, null, function () {
assert.isNotOk(api.getDataFromCommon('tcManifest'));
assert.isNotOk(api.getDataFromCommon('saveLocation'));
assert.isNotOk(api.getDataFromCommon('params'));
assert.isNotOk(api.getDataFromCommon('targetLanguage'));
api.inputJson(undefinedProject + '/tc-manifest.json', function (err, data) {
if (!err) {
assert.equal(true, false);
} else {
assert.isNotOk(data);
}
api.outputJson(noTCManifestProject + '/tc-manifest.json', null, function () {
done();
});
});
});
});
});
describe('Upload.sendFilePath(USFM project)', function () {
it('should load a USFM project', function (done) {
Upload.sendFilePath(testUSFMProjectPath, null, function () {
assert.isObject(api.getDataFromCommon('tcManifest'));
assert.isString(api.getDataFromCommon('saveLocation'));
assert.isObject(api.getDataFromCommon('params'));
assert.isObject(api.getDataFromCommon('targetLanguage'));
api.inputJson(testUSFMProjectPath + '/tc-manifest.json', function (err, data) {
if (err || !data) {
assert.equal(true, false);
} else {
assert.isObject(data);
assert(data.target_language);
}
done();
});
});
});
});
describe('Upload.sendFilePath(non-USFM project)', function () {
it('should load a regular project', function (done) {
Upload.sendFilePath(testProjectPath, null, function () {
assert.isObject(api.getDataFromCommon('tcManifest'));
assert.isString(api.getDataFromCommon('saveLocation'));
assert.isObject(api.getDataFromCommon('params'));
assert.isObject(api.getDataFromCommon('targetLanguage'));
api.inputJson(testProjectPath + '/tc-manifest.json', function (err, data) {
if (err || !data) {
assert.equal(true, false);
} else {
assert.isObject(data);
assert(data.target_language);
}
done();
});
});
});
});
describe('Upload.getParams(testProjectPath)', function () {
it('should generate and return correct parameters for a project', function (done) {
var params = Upload.getParams(testProjectPath);
expect(params.originalLanguagePath).to.be.string;
expect(params.bookAbbr).to.be.string;
expect(params.targetLanguagePath).to.be.string;
expect(params.gatewayLanguage).to.be.object;
expect(params.direction).to.be.string;
expect(params.originalLanguage).to.be.string;
done();
});
});
describe('Upload.getParams(testUSFMProjectPath)', function () {
it('should generate and return correct parameters for a project', function (done) {
var params = Upload.getParams(testUSFMProjectPath);
expect(params.originalLanguagePath).to.be.string;
expect(params.bookAbbr).to.be.string;
expect(params.targetLanguagePath).to.be.string;
expect(params.gatewayLanguage).to.be.object;
expect(params.direction).to.be.string;
expect(params.originalLanguage).to.be.string;
done();
});
});
describe('Upload.getParams(noTCManifestProject)', function () {
it('should still generate and return correct parameters for a project even with missing fields', function (done) {
var params = Upload.getParams(noTCManifestProject);
expect(params.originalLanguagePath).to.be.string;
expect(params.bookAbbr).to.be.string;
expect(params.targetLanguagePath).to.be.string;
expect(params.gatewayLanguage).to.be.object;
expect(params.direction).to.be.string;
expect(params.originalLanguage).to.be.string;
done();
});
});
describe('Upload.getParams(undefinedProject)', function () {
it('should fail', function (done) {
api.putDataInCommon('tcManifest', null);
var params = Upload.getParams(undefinedProject);
assert.isNotOk(params);
done();
});
});
describe('Upload.checkIfUSFMProject(USFM project)', function () {
it('should return the target language of test USFM project', function (done) {
var params = Upload.checkIfUSFMProject(testUSFMProjectPath, function (targetLanguage) {
if (targetLanguage) {
expect(targetLanguage.title).to.be.string;
expect(targetLanguage[1]).to.be.object;
assert.isString(api.getDataFromCommon('saveLocation'));
assert.isObject(api.getDataFromCommon('targetLanguage'));
done();
}
});
});
});
describe('Upload.checkIfUSFMProject(non-USFM project)', function () {
it('should return null because its not a USFM project', function (done) {
var params = Upload.checkIfUSFMProject(testProjectPath, function (targetLanguage) {
expect(targetLanguage).to.not.exist;
done();
});
});
});