-
Notifications
You must be signed in to change notification settings - Fork 0
/
mforms_parse_test.js
337 lines (300 loc) · 6.94 KB
/
mforms_parse_test.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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/* Test mparser.js function using local nodejs.
intended to make it easier to unit tests javascript
intended to run in browser.
*/
if (typeof require != "undefined") {
var mforms = require("./mforms_parse.js");
} else {
// emulate module variable for browser
var mforms = {
"mformsParseMeta": mformsParseMeta
};
}
var testStrForm1 = `
- widget:
id: projectNum
widget_type: text
label:
text: Project #
place: left
align: right
width: 38
size: 20
data_context: cert/con_project_number
required: true
max_len: 25
class: input_field
data_type: text
- widget:
id: facilityName
widget_type: text
label : Facility Name #
label_align: left
size: 30
data_context: con_project_number
required: true
max_len: 50
class: input_field
data_type: text
- form:
- row:
col:
widgets:
- projectNum
- FacilityName
`;
var testStrOptArr = `
- option:
- {"label" : "Admin", "value" : "admin"}
- {"label" : "Regional", "value": "region"}
- {"label" : "Full", "value" : "Full"}
- {"label" : "unknown", "value": "none", "default" : true}
`;
var testStrPeople1 = `
- jack:
projectNum : 1983
- lingua:
hasPlane: false
pets:
sam:
living: true
girtude:
living: false
kids:
- hacker:
living: true
- nancy:
living: false
`;
var testStrPeople2 = `
- jimmy
- jack:
phone : 206-828-2387
sex: male
projectNum : 1983
- lingua:
phone: 205-686-38383
yearBorn: 1983
hourly: 198.24
taxCred: -1983.21
hasCar: true
hasPlane: false
cars: ["ford", "toyota Tacoma", "subaru"]
label:
text: I am text
align: right
pets:
sam:
living: true
girtude:
living: false
kids:
- jack:
living: true
- nancy:
living: false
`;
var testStrPerson3 = `
person:
id: lingua
phone: 205-686-38383
yearBorn: 1983
hourly: 198.24
taxCred: -1983.21
hasCar: true
hasPlane: false
cars: ["ford", "toyota Tacoma", "subaru"]
label:
text: I am text
align: right
pets:
sam:
living: true
girtude:
living: false
kids:
- jack:
living: true
- nancy:
living: false
`;
var testStrPerson4 = `
id: lingua
phone: 205-686-38383
yearBorn: 1983
hourly: 198.24
taxCred: -1983.21
hasCar: true
hasPlane: false
cars: ["ford", "toyota Tacoma", "subaru"]
label:
text: I am text
align: right
pets:
sam:
living: true
girtude:
living: false
kids:
- jack:
living: true
- nancy:
living: false
`;
var testMerge1 = `
---
- &CENTER { x: 1, y: 2 }
- &LEFT { x: 0, y: 2 }
- &BIG { r: 10 }
- &SMALL { r: 1 }
# All the following maps are equal:
# Explicit keys
- widget:
x: 1
y: 2
r: 10
label: center/big
# Merge one map
- widget:
<< : *CENTER
r: 10
label: center/big
# Merge multiple maps
- widget:
<< : [ *CENTER, *BIG ]
label: center/big
# Override
- widget:
<< : [ *BIG, *LEFT, *SMALL ]
x: 1
label: center/big
`;
var testMerge2 = `
- validators:
auth_patern: {0.9}8.\s\w\n
phone: ^([0-9]( |-)?)?(\(?[0-9]{3}\)?|[0-9]{3})( |-)?([0-9]{3}( |-)?[0-9]{4}|[a-zA-Z0-9]{7})$
zip: ^[0-9]{5}(?:-[0-9]{4})?$
- &GENDER widget:
data_type: text
type: radio
label : Gender
class: hor_radio
ignore-case-match: true
default: M
option:
- {"label" : "Male", "value" : "M"}
- {"label" : "Female", "value": "F"}
- &ANCHOR widget:
id: basic_phone
data_type: text
type: text
label: phone
data_context: empty
class: input_field
ignore_case_match: true
valid_patt: <validators.phone
- widget:
<< : *ANCHOR
id: basic_phone_1
label: Patient Phone
data_context: claim.patient.phoneNum
- widget:
<< : *GENDER
id: gender_1
data_context: claim.patient.gender
`;
var testInclude = `
- validators:
auth_patern: {0.9}8.\s\w\n
phone: ^([0-9]( |-)?)?(\(?[0-9]{3}\)?|[0-9]{3})( |-)?([0-9]{3}( |-)?[0-9]{4}|[a-zA-Z0-9]{7})$
zip: ^[0-9]{5}(?:-[0-9]{4})?$
- &GENDER !include gender_test.yaml
- &ANCHOR widget:
id: basic_phone
data_type: text
type: text
label: phone
data_context: empty
class: input_field
ignore_case_match: true
valid_patt: <validators.phone
- widget:
<< : *ANCHOR
id: basic_phone_1
label: Patient Phone
data_context: claim.patient.phoneNum
- widget:
<< : *GENDER
id: gender_1
data_context: claim.patient.gender
`;
var testStrNestedObj = `
- widget:
id: procedures
type: table
total_col:
- arrProcFee
columns:
- arrProcDate:
total: false
label: Procedure Date
- arrProcArea:
total: false
label: Area
title: Procedure Area
`;
var testStrObjectCommentOnEOL = `
- widget:
id: procedures # Code must be unique
type: table # Type is used to lookup rendering agent
total_col: # Total Column is used
- arrProcFee # One of columns to total
columns: # List of column objects
- arrProcDate: # one of my columns
total: false # whether I should add total on this column
label: Procedure Date
- arrProcArea:
total: false
label: 'Area '' #54' # hash in single quotes with escaped single quote
title: "Procedure Area \\" &" # ampersand in double quotes with escaped double quote
`;
// Should produce and array of tab inside the widget.
var testProperArrayDetections = `
- widget:
id: provMainTabBar
class: tabbar
type: tabbar
content_div: mainTabSubBar
tabs:
- tab:
label: Summary
class: tabGood
form: forms/provider-summary
active: true
- tab:
label: Provider
icon: none
form: forms/provider-provider
- tab:
label: License
icon: none
child: provLicenseTab
`;
function mParserTest(label, dataStr) {
var tres = mforms.mformsParseMeta(dataStr, {});
console.log("L77: mParserTest:", label, " Out=", JSON.stringify(tres, null, 2));
return tres;
}
if (typeof require != "undefined") {
mParserTest("test 1 form", testStrForm1);
mParserTest("test 2 people", testStrPeople1);
mParserTest("test 3 people", testStrPeople2);
// Tests to see if an outermost object of
// type person gets created with the proper
// containment eg {" person" : {}}
mParserTest("test single person dict object", testStrPerson3);
mParserTest("test single dict at outer level", testStrPerson4);
mParserTest("test merge 1", testMerge1);
mParserTest("test merge 2", testMerge2);
mParserTest("test include", testInclude);
}