-
Notifications
You must be signed in to change notification settings - Fork 13
/
dataroute.html.ignore
173 lines (161 loc) · 4.25 KB
/
dataroute.html.ignore
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Data Routing Tests</title>
<link rel="stylesheet" href="https://get.mavo.io/mavo.css" />
<link rel="stylesheet" href="style.css" />
<style>
td {
font: bold 100%/1.5 Consolas, Monaco, monospace;
}
</style>
<script src="https://get.mavo.io/mavo.js"></script>
<script src="mavotest.js"></script>
<script>
function testRoutes(routes, script) {
var out = script.parentNode;
var appTd = out.previousElementSibling;
var app;
$.ready()
.then(() => Mavo.inited)
.then(() => Mavo.defer(1000))
.then(() => {
app = Mavo.get(appTd);
return app.dataLoaded;
}).then(() => {
var obj = app.root.liveData.data;
var test = [];
var ref = [];
for (var route in routes) {
var data = eval(route);
test.push(`${route} route: ${Test.format($.value(data, Mavo.route))}`);
ref.push(`${route} route: ${routes[route]}`);
}
out.innerHTML = test.join("<br> ");
out.nextElementSibling.innerHTML = ref.join("<br> ");
});
}
</script>
</head>
<body>
<h1>Data routing Tests</h1>
<p>These tests test whether routing works correctly on objects</p>
<section>
<h1>Mavo.Data.computeRoutes()</h1>
<table class="reftest">
<tr>
<td>
<script>
let obj = {foo: [{ yolo: 3}, {yolo: 4}], bar: {baz: 5}};
print(obj);
</script>
</td>
<td>
<script>
Mavo.Data.computeRoutes(obj);
println("obj route: ", obj[Mavo.route]);
println("foo route:", obj.foo[Mavo.route]);
println("obj.foo[0] route:", obj.foo[0][Mavo.route]);
println("obj.foo[0].yolo route:", obj.foo[0].yolo[Mavo.route]);
println("obj.bar route:", obj.bar[Mavo.route]);
</script>
</td>
<td style="white-space: pre-line">obj route: foo yolo bar baz
foo route: yolo
obj.foo[0] route: yolo
obj.foo[0].yolo route: undefined
obj.bar route: baz
</td>
</tr>
<tr>
<td mv-app mv-source='data:application/json,{"foo": [{ "yolo": 3}, {"yolo": 4}], "bar": {"baz": 5}}' mv-expressions-ignore="mv-source">
<div property="foo" mv-multiple>
<span property="yolo">1</span>
</div>
</td>
<td>
<script>
testRoutes({
"obj": "foo yolo bar baz",
"obj.foo": "yolo",
"obj.foo[0]": "yolo",
"obj.foo[0].yolo": "undefined",
"obj.bar": "baz"
}, document.currentScript);
</script>
</td>
<td>
</td>
</tr>
<tr>
<td mv-app="creatures" mv-source='data/creatures.json'>
<div property="person" mv-multiple mv-accepts="cat">
<strong property="name">John Doe</strong>
<span property="age">0</span>
[person]
<ul>
<li property="hobby" mv-multiple>Fishing</li>
</ul>
</div>
<div property="cat" mv-multiple mv-accepts="person">
<strong property="name">John Doe</strong>
<span property="age">0</span>
<ul>
<li property="hobby" mv-multiple mv-related="hobby">Fishing</li>
</ul>
</div>
</td>
<td>
<script>
testRoutes({
"obj": "person name age hobby cat",
"obj.person": "name age hobby",
"obj.cat": "name age hobby",
"obj.person[0]": "name age hobby",
"obj.cat[0]": "name age hobby",
"obj.cat[0].hobby": "(empty set)",
"obj.cat[0].hobby[0]": "undefined"
}, document.currentScript);
</script>
</td>
<td>
</td>
</tr>
<tr title="Implicit collection of primitives">
<td mv-app="implicitCollection">
<div property="numbers" style="--prepend: '[numbers]'; --append: '[$index]';">11</div>
<div property="numbers" style="--prepend: '[numbers]'; --append: '[$index]';">12</div>
<div property="numbers" style="--prepend: '[numbers]'; --append: '[$index]';">13</div>
</td>
<td>
<script>
testRoutes({
"obj": "numbers",
"obj.numbers": "(empty set)",
"obj.numbers[0]": "undefined"
}, document.currentScript);
</script>
</td>
<td>
</td>
</tr>
<tr title="Rendering an object on a primitive">
<td mv-app mv-source='data:application/json,{"prop": [{"prop1": 1}, {"prop1": 2}]}' mv-expressions-ignore="mv-source">
<meta property="prop" />
</td>
<td>
<script>
testRoutes({
"obj": "prop prop1",
"obj.prop": "prop1"
}, document.currentScript);
</script>
</td>
<td>
</td>
</tr>
</table>
</section>
</body>
</html>