-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmapping_test.html
229 lines (212 loc) · 7.64 KB
/
mapping_test.html
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
<html>
<head>
<script src="static-bleve-mapping/js/mapping/type-mapping.js"></script>
</head>
<body>
<div>
failures:
<pre id="failures">NONE</pre>
</div>
<hr/>
<div>
tests:
<pre id="tests">(running...)</pre>
</div>
<script>
var tests = [];
var failures = [];
function test(name, result) {
tests.push(name + "... " + (result ? "ok" : result));
document.getElementById("tests").innerHTML = tests.join("\n");
if (!result) {
failures.push(name + ": " + result);
document.getElementById("failures").innerHTML = failures.join("\n");
}
}
function echo(x) {
console.log(x);
return x;
}
test("bleveConvertFromTypeMapping({})",
JSON.stringify(bleveConvertFromTypeMapping({})) == "[]");
test("bleveConvertToTypeMapping(bleveConvertFromTypeMapping({}))",
JSON.stringify(bleveConvertToTypeMapping(bleveConvertFromTypeMapping({}))) == "{}");
test("bleveConvertToTypeMapping(bleveConvertFromTypeMapping(beer))",
echo(JSON.stringify(bleveConvertToTypeMapping(bleveConvertFromTypeMapping({
'beer': {}
})))) == '{"beer":{"properties":{},"display_order":"0"}}');
test("empty beer and brewery))",
echo(JSON.stringify(bleveConvertToTypeMapping(bleveConvertFromTypeMapping({
'beer': {}, 'brewery': {}
})))) == '{"beer":{"properties":{},"display_order":"0"},"brewery":{"properties":{},"display_order":"1"}}');
test("empty attrs)",
echo(JSON.stringify(bleveConvertToTypeMapping(bleveConvertFromTypeMapping({
"beer":{"fields":[],"properties":{},"display_order":"0"},
"brewery":{"fields":[],"properties":{},"display_order":"1"}
})))) == '{"beer":{"display_order":"0","properties":{}},"brewery":{"display_order":"1","properties":{}}}');
test("reverse display_order)",
echo(JSON.stringify(bleveConvertToTypeMapping(bleveConvertFromTypeMapping({
"beer":{"fields":[],"properties":{},"display_order":"1"},
"brewery":{"fields":[],"properties":{},"display_order":"0"}
})))) == '{"brewery":{"display_order":"0","properties":{}},"beer":{"display_order":"1","properties":{}}}');
test("display_order goes down to 0)",
echo(JSON.stringify(bleveConvertToTypeMapping(bleveConvertFromTypeMapping({
"brewery":{
"fields":[],
"properties":{
},
"display_order":"10"
}
})))) == '{"brewery":{"display_order":"0","properties":{}}}');
test("one brewery field",
echo(JSON.stringify(bleveConvertToTypeMapping(bleveConvertFromTypeMapping({
"brewery":{
"fields":[{"name":"description"}],
"properties":{
},
"display_order":"10"
}
})))) == '{"brewery":{"fields":[{"name":"description","display_order":"0"}],"display_order":"0","properties":{}}}');
test("one brewery propertied field",
echo(JSON.stringify(bleveConvertToTypeMapping(bleveConvertFromTypeMapping({
"brewery":{
"fields":[{"name":"description"}],
"properties":{
"address": {
"fields":[{"name":"addr"}]
}
},
"display_order":"10"
}
})))) == '{"brewery":{"fields":[{"name":"description","display_order":"0"}],"display_order":"0","properties":{"address":{"enabled":true,"dynamic":false,"properties":{},"fields":[{"name":"addr","display_order":"1"}]}}}}');
test("bleveConverted brewery propertied field",
echo(JSON.stringify(bleveConvertFromTypeMapping({
"brewery":{
"fields":[{"name":"description"}],
"properties":{
"address": {
"fields":[{"name":"addr"}]
}
},
"display_order":"10"
}
}))) == '[{"fields":[{"name":"description","_kind":"field"},{"name":"addr","property":"address","_kind":"field"}],"display_order":"10","_kind":"mappingType","name":"brewery","mappings":[]}]');
test("1 brewery propertied field with two searchable names",
echo(JSON.stringify(bleveConvertToTypeMapping(bleveConvertFromTypeMapping({
"brewery":{
"fields":[{"name":"description"}],
"properties":{
"address": {
"fields":[{"name":"addr"},{"name":"addrx"}]
}
},
"display_order":"10"
}
})))) == '{"brewery":{"fields":[{"name":"description","display_order":"0"}],"display_order":"0","properties":{"address":{"enabled":true,"dynamic":false,"properties":{},"fields":[{"name":"addr","display_order":"1"},{"name":"addrx","display_order":"2"}]}}}}');
test("2 brewery propertied fields with two searchable names",
echo(JSON.stringify(bleveConvertToTypeMapping(bleveConvertFromTypeMapping(bleveConvertToTypeMapping(bleveConvertFromTypeMapping({
"brewery":{
"fields":[{"name":"description"}],
"properties":{
"address": {
"fields":[{"name":"addr"},{"name":"addrx"}]
},
"owner": {
"fields":[{"name":"owner"},{"name":"ownerx"}]
}
},
"display_order":"10"
}
})))))) == '{"brewery":{"fields":[{"name":"description","display_order":"0"}],"display_order":"0","properties":{"address":{"enabled":true,"dynamic":false,"properties":{},"fields":[{"name":"addr","display_order":"1"},{"name":"addrx","display_order":"2"}]},"owner":{"enabled":true,"dynamic":false,"properties":{},"fields":[{"name":"owner","display_order":"3"},{"name":"ownerx","display_order":"4"}]}}}}');
test("beer and brewery propertied fields with two searchable names",
echo(JSON.stringify(bleveConvertToTypeMapping(bleveConvertFromTypeMapping(bleveConvertToTypeMapping(bleveConvertFromTypeMapping({
"brewery":{
"fields":[{"name":"description"}],
"properties":{
"address": {
"fields":[{"name":"addr"},{"name":"addrx"}]
},
"owner": {
"fields":[{"name":"owner"},{"name":"ownerx"}]
}
},
"display_order":"10"
},
"beer":{
"fields":[{"name":"description"}],
"properties":{
"ingredients": {
"fields":[{"name":"name"},{"name":"nombre"}]
},
"label": {
"fields":[{"name":"contents"},{"name":"text"}]
}
},
"display_order":"5"
}
})))))) == JSON.stringify({
"beer":{
"fields":[{"name":"description","display_order":"0"}],
"display_order":"0",
"properties":{
"ingredients":{
"enabled":true,"dynamic":false,
"properties":{},
"fields":[{"name":"name","display_order":"1"},{"name":"nombre","display_order":"2"}]
},
"label":{
"enabled":true,"dynamic":false,
"properties":{},
"fields":[{"name":"contents","display_order":"3"},{"name":"text","display_order":"4"}]
}
}
},
"brewery":{
"fields":[{"name":"description","display_order":"0"}],
"display_order":"1",
"properties":{
"address":{
"enabled":true,"dynamic":false,
"properties":{},
"fields":[{"name":"addr","display_order":"1"},{"name":"addrx","display_order":"2"}]
},
"owner":{
"enabled":true,"dynamic":false,
"properties":{},
"fields":[{"name":"owner","display_order":"3"},{"name":"ownerx","display_order":"4"}]
}}}}));
test("1 brewery with 2 level nested properties",
echo(JSON.stringify(bleveConvertToTypeMapping(bleveConvertFromTypeMapping({
"brewery":{
"fields":[{"name":"description"}],
"properties":{
"address": {
"properties":{
"state":{
"fields":[{"name":"state"},{"name":"st"}]
}
}
}
}
}
})))) == JSON.stringify({
"brewery":{
"fields":[{"name":"description","display_order":"0"}],
"properties":{
"address":{
"display_order":"0",
"properties":{
"state":{
"enabled":true,"dynamic":false,
"properties":{},
"fields":[{"name":"state","display_order":"0"},{"name":"st","display_order":"1"}]
}
}
}
},
"display_order":"0"
}
}));
</script>
</body>
</html>