forked from dimagi/Vellum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavaRosa.js
278 lines (266 loc) · 12.4 KB
/
javaRosa.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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/*jshint multistr: true */
require([
'chai',
'jquery',
'tests/utils',
'vellum/javaRosa'
], function (
chai,
$,
util,
jr
) {
var assert = chai.assert,
call = util.call;
describe("The javaRosa plugin with multiple languages", function () {
it("should not show itext errors when there is text in any language", function (done) {
util.init({
javaRosa: {langs: ['en', 'hin']},
core: {
form: TEST_XML_1,
onReady: function () {
$("textarea[name=itext-en-constraintMsg]").val("").change();
util.saveAndReload(function () {
// there should be no errors on load
// todo: this should inspect the model, not UI
var errors = $(".alert-block");
assert.equal(errors.length, 0, errors.text());
done();
});
}
}
});
});
it("should show warning on load for with unknown language", function (done) {
util.init({
javaRosa: {langs: ['en', 'hin']},
core: {
form: TEST_XML_3,
onReady: function () {
// todo: this should inspect the model, not UI
var errors = $(".alert-block"),
text = errors.text();
assert.equal(errors.length, 1, text);
assert(text.indexOf("You have languages in your form that are not specified") > -1, text);
assert(text.indexOf("page: es.") > -1, text);
done();
}
}
});
});
it("should preserve itext values on load + save", function (done) {
util.init({core: {onReady: function () {
util.addQuestion("Text", "question1");
$(".btn:contains(image)").click();
$(".btn:contains(audio)").click();
$(".btn:contains(video)").click();
$(".btn:contains(long)").click();
$(".btn:contains(short)").click();
$(".btn:contains(custom)").click();
$(".fd-modal-generic-container").find("input").val("custom");
$(".fd-modal-generic-container").find(".btn:contains(Add)").click();
$("[name='itext-en-label']").val('question1 en label').change();
$("[name='itext-hin-label']").val('question1 hin label').change();
$("[name='itext-en-constraintMsg']").val('question1 en validation').change();
$("[name='itext-hin-constraintMsg']").val('question1 hin validation').change();
$("[name='itext-en-hint']").val('question1 hint en').change();
$("[name='itext-hin-hint']").val('question1 hin hint').change();
$("[name='itext-en-label-long']").val("question1 en long").change();
$("[name='itext-hin-label-long']").val("question1 hin long").change();
$("[name='itext-en-label-short']").val("question1 en short").change();
$("[name='itext-hin-label-short']").val("question1 hin short").change();
$("[name='itext-en-label-custom']").val("question1 en custom").change();
$("[name='itext-hin-label-custom']").val("question1 hin custom").change();
util.assertXmlEqual(
call('createXML'),
util.xmlines(TEST_XML_2),
{normalize_xmlns: true}
);
done();
}}});
});
it("itext changes do not bleed back after copy", function (done) {
util.init({core: {onReady: function () {
var mug = util.addQuestion("Text", "question"),
dup = mug.form.duplicateMug(mug);
dup.p.labelItextID.setDefaultValue("q2");
util.saveAndReload(function () {
var mug = call("getMugByPath", "/data/question");
assert.equal(mug.p.labelItextID.defaultValue(), "question");
done();
});
}}});
});
it("itext changes do not bleed back from copy of copy", function (done) {
util.init({core: {onReady: function () {
var mug = util.addQuestion("Text", "question"),
dup = mug.form.duplicateMug(mug),
cpy = mug.form.duplicateMug(dup);
cpy.p.labelItextID.setDefaultValue("copy");
util.saveAndReload(function () {
var mug = call("getMugByPath", "/data/question"),
dup = call("getMugByPath", "/data/copy-1-of-question"),
cpy = call("getMugByPath", "/data/copy-2-of-question");
assert.equal(mug.p.labelItextID.defaultValue(), "question");
assert.equal(dup.p.labelItextID.defaultValue(), "question");
assert.equal(cpy.p.labelItextID.defaultValue(), "copy");
done();
});
}}});
});
});
var TEST_XML_1 = '' +
'<?xml version="1.0" encoding="UTF-8" ?>\
<h:html xmlns:h="http://www.w3.org/1999/xhtml"\
xmlns:orx="http://openrosa.org/jr/xforms"\
xmlns="http://www.w3.org/2002/xforms"\
xmlns:xsd="http://www.w3.org/2001/XMLSchema"\
xmlns:jr="http://openrosa.org/javarosa"\
xmlns:vellum="http://commcarehq.org/xforms/vellum">\
<h:head>\
<h:title>Untitled Form</h:title>\
<model>\
<instance>\
<data xmlns:jrm="http://dev.commcarehq.org/jr/xforms"\
xmlns="http://openrosa.org/formdesigner/8D6CF8A5-4396-45C3-9D05-64C3FD97A5D0"\
uiVersion="1"\
version="1"\
name="Untitled Form">\
<question1 />\
</data>\
</instance>\
<bind nodeset="/data/question1"\
type="xsd:string"\
constraint="1"\
jr:constraintMsg="jr:itext(\'question1-constraintMsg\')" />\
<itext>\
<translation lang="en" default="">\
<text id="question1-label">\
<value>question1</value>\
</text>\
</translation>\
<translation lang="hin">\
<text id="question1-constraintMsg">\
<value>xyz</value>\
</text>\
</translation>\
</itext>\
</model>\
</h:head>\
<h:body>\
<input ref="/data/question1">\
<label ref="jr:itext(\'question1-label\')" />\
</input>\
</h:body>\
</h:html>';
var TEST_XML_2 = '' +
'<h:html xmlns:h="http://www.w3.org/1999/xhtml"\
xmlns:orx="http://openrosa.org/jr/xforms"\
xmlns="http://www.w3.org/2002/xforms"\
xmlns:xsd="http://www.w3.org/2001/XMLSchema"\
xmlns:jr="http://openrosa.org/javarosa"\
xmlns:vellum="http://commcarehq.org/xforms/vellum">\
<h:head>\
<h:title>Untitled Form</h:title>\
<model>\
<instance>\
<data xmlns:jrm="http://dev.commcarehq.org/jr/xforms"\
xmlns="http://openrosa.org/formdesigner/8D6CF8A5-4396-45C3-9D05-64C3FD97A5D0"\
uiVersion="1" version="1" name="Untitled Form">\
<question1/>\
</data>\
</instance>\
<bind nodeset="/data/question1" type="xsd:string"\
jr:constraintMsg="jr:itext(\'question1-constraintMsg\')"/>\
<itext>\
<translation lang="en" default="">\
<text id="question1-label">\
<value>question1 en label</value>\
<value form="image">jr://file/commcare/image/data/question1.png</value>\
<value form="audio">jr://file/commcare/audio/data/question1.mp3</value>\
<value form="video">jr://file/commcare/video/data/question1.3gp</value>\
<value form="long">question1 en long</value>\
<value form="short">question1 en short</value>\
<value form="custom">question1 en custom</value>\
</text>\
<text id="question1-hint">\
<value>question1 hint en</value>\
</text>\
<text id="question1-constraintMsg">\
<value>question1 en validation</value>\
</text>\
</translation>\
<translation lang="hin">\
<text id="question1-label">\
<value>question1 hin label</value>\
<value form="image">jr://file/commcare/image/data/question1.png</value>\
<value form="audio">jr://file/commcare/audio/data/question1.mp3</value>\
<value form="video">jr://file/commcare/video/data/question1.3gp</value>\
<value form="long">question1 hin long</value>\
<value form="short">question1 hin short</value>\
<value form="custom">question1 hin custom</value>\
</text>\
<text id="question1-hint">\
<value>question1 hin hint</value>\
</text>\
<text id="question1-constraintMsg">\
<value>question1 hin validation</value>\
</text>\
</translation>\
</itext>\
</model>\
</h:head>\
<h:body>\
<input ref="/data/question1">\
<label ref="jr:itext(\'question1-label\')"/>\
<hint ref="jr:itext(\'question1-hint\')"/>\
</input>\
</h:body>\
</h:html>';
var TEST_XML_3 = '' +
'<?xml version="1.0" encoding="UTF-8" ?>\
<h:html xmlns:h="http://www.w3.org/1999/xhtml"\
xmlns:orx="http://openrosa.org/jr/xforms"\
xmlns="http://www.w3.org/2002/xforms"\
xmlns:xsd="http://www.w3.org/2001/XMLSchema"\
xmlns:jr="http://openrosa.org/javarosa"\
xmlns:vellum="http://commcarehq.org/xforms/vellum">\
<h:head>\
<h:title>Untitled Form</h:title>\
<model>\
<instance>\
<data xmlns:jrm="http://dev.commcarehq.org/jr/xforms"\
xmlns="http://openrosa.org/formdesigner/8D6CF8A5-4396-45C3-9D05-64C3FD97A5D0"\
uiVersion="1"\
version="1"\
name="Untitled Form">\
<question1 />\
</data>\
</instance>\
<bind nodeset="/data/question1" type="xsd:string" />\
<itext>\
<translation lang="en" default="">\
<text id="question1-label">\
<value>question1</value>\
</text>\
</translation>\
<translation lang="hin">\
<text id="question1-label">\
<value>xyz</value>\
</text>\
</translation>\
<translation lang="es">\
<text id="question1-label">\
<value>Spanish!</value>\
</text>\
</translation>\
</itext>\
</model>\
</h:head>\
<h:body>\
<input ref="/data/question1">\
<label ref="jr:itext(\'question1-label\')" />\
</input>\
</h:body>\
</h:html>';
});