-
Notifications
You must be signed in to change notification settings - Fork 13
/
actions.html
287 lines (271 loc) · 8.22 KB
/
actions.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Actions tests</title>
<link rel="stylesheet" href="https://get.mavo.io/mavo.css" />
<link rel="stylesheet" href="style.css" />
<style>
div[mv-multiple] {
border: 1px solid rgba(0,0,0,.2);
background: rgba(0,0,0,.1);
padding: .5em;
margin: .5em;
}
button {
font: inherit;
}
</style>
<script src="https://get.mavo.io/mavo.js"></script>
<script src="mavotest.js"></script>
</head>
<body>
<h1>Actions tests</h1>
<section>
<h1>Expression Rewrite</h1>
<p>These tests check if MavoScript is rewritten to JS correctly</p>
<table class="reftest" data-test="expressionRewrite" data-columns="3">
<tr>
<td>if(age > 40, set(name, Chris))</td>
<td>$fn.iff($fn.gt(age, 40), $fn.setif($fn.gt(age, 40), name, Chris))</td>
</tr>
<tr>
<td>if(age > 40, set(name, Gandalf), set(name, Sauron))</td>
<td>$fn.iff($fn.gt(age, 40), $fn.setif($fn.gt(age, 40), name, Gandalf), $fn.setif($fn.not($fn.gt(age, 40)), name, Sauron))</td>
</tr>
</table>
</section>
<section>
<h1>Delete / clear</h1>
<table class="reftest" data-click="td:first-child > button[mv-action] wait 1s after mv-load">
<tr title="Delete one item" mv-app mv-source="data/creatures.json" class="mv-autoedit">
<td><button mv-action="delete(person where name = 'Lea Verou')">Delete Lea</button></td>
<td>
<div class="mv-bar mv-ui"></div>
<div property="person" mv-multiple>
<strong property="name">John Doe</strong>
<span property="age">0</span>
</div>
</td>
<td>
David Karger 50
</td>
</tr>
<tr title="Delete multiple items" mv-app mv-source="data/creatures.json" class="mv-autoedit">
<td><button mv-action="delete(cat where age > 2)">Delete cats older than 2</button></td>
<td>
<div class="mv-bar mv-ui"></div>
<div property="cat" mv-multiple>
<strong property="name">John Doe</strong>
<span property="age">0</span>
</div>
</td>
<td>
Çiki 1
</td>
</tr>
<tr title="Empty collection" mv-app mv-source="data/creatures.json" class="mv-autoedit">
<td><button mv-action="delete(cat)">Delete all cats</button></td>
<td>
<div class="mv-bar mv-ui"></div>
<div property="cat" mv-multiple>
<strong property="name">John Doe</strong>
<span property="age">0</span>
</div>
</td>
<td>
</td>
</tr>
<tr title="Clear collection without deleting items" mv-app mv-source="data/creatures.json" class="mv-autoedit">
<td><button mv-action="clear(cat.name, cat.age)">Clear cat data</button></td>
<td>
<div class="mv-bar mv-ui"></div>
<div property="cat" mv-multiple>
<strong property="name">John Doe</strong>
<span property="age">1</span>
</div>
</td>
<td>
</td>
</tr>
</table>
</section>
<section>
<h1>Add</h1>
<p>Click the buttons in the first column</p>
<table class="reftest" data-click="td:first-child > button[mv-action] wait 1s after mv-load">
<tr title="Add one item" mv-app mv-source="data/creatures.json" class="mv-autoedit">
<td><button mv-action="add(group(name: 'Tarfah Alrashed', age: 30), person)">Add Tarfah</button></td>
<td>
<div class="mv-bar mv-ui"></div>
<div property="person" mv-multiple>
<strong property="name">John Doe</strong>
<span property="age">0</span>
</div>
</td>
<td>
Lea Verou 32
David Karger 50
Tarfah Alrashed 30
</td>
</tr>
<tr title="Duplicate item" mv-app mv-source="data/creatures.json" class="mv-autoedit" data-click=".duplicate wait 1s after mv-load">
<td></td>
<td>
<div class="mv-bar mv-ui"></div>
<div property="person" mv-multiple>
<strong property="name">John Doe</strong>
<span property="age">0</span>
<button class="duplicate test-content-ignore" mv-action="add(person, person)">Duplicate [name]</button>
</div>
</td>
<td>
Lea Verou 32
Lea Verou 32
David Karger 50
David Karger 50
</td>
</tr>
</table>
</section>
<section>
<h1>Set</h1>
<p>Click the buttons in the first column</p>
<table class="reftest" data-click="td:first-child > button[mv-action] wait 3s after mv-load">
<tr title="Set one property across multiple items" mv-app mv-source="data/creatures.json" class="mv-autoedit">
<td><button mv-action="set(name, 'Chris Lilley')">Set all names to Chris Lilley</button></td>
<td>
<div class="mv-bar mv-ui"></div>
<div property="person" mv-multiple>
<strong property="name">John Doe</strong>
<span property="age">0</span>
</div>
</td>
<td>
Chris Lilley 32
Chris Lilley 50
</td>
</tr>
<tr title="Set property to other property" mv-app mv-source="data/creatures.json" class="mv-autoedit">
<td><button mv-action="set(name, age)">Set all names to their ages</button></td>
<td>
<div class="mv-bar mv-ui"></div>
<div property="person" mv-multiple>
<strong property="name">John Doe</strong>
<span property="age">0</span>
</div>
</td>
<td>
32 32
50 50
</td>
</tr>
<tr title="Increment property" mv-app mv-source="data/creatures.json" class="mv-autoedit">
<td><button mv-action="set(age, age + 1)">Increment all ages</button></td>
<td>
<div class="mv-bar mv-ui"></div>
<div property="person" mv-multiple>
<strong property="name">John Doe</strong>
<span property="age">0</span>
</div>
</td>
<td>
Lea Verou 33
David Karger 51
</td>
</tr>
<tr title="Set property with filter" mv-app mv-source="data/creatures.json" class="mv-autoedit">
<td><button mv-action="set(name where age > 40, 'Chris Lilley')">Set names to Chris Lilley for people above 40</button></td>
<td>
<div class="mv-bar mv-ui"></div>
<div property="person" mv-multiple>
<strong property="name">John Doe</strong>
<span property="age">0</span>
</div>
</td>
<td>
Lea Verou 32
Chris Lilley 50
</td>
</tr>
<tr title="Set property with if" mv-app mv-source="data/creatures.json" class="mv-autoedit">
<td><button mv-action="if (age > 40, set(name, 'Chris Lilley'))">Set names to Chris Lilley for people above 40</button></td>
<td>
<div class="mv-bar mv-ui"></div>
<div property="person" mv-multiple>
<strong property="name">John Doe</strong>
<span property="age">0</span>
</div>
</td>
<td>
Lea Verou 32
Chris Lilley 50
</td>
</tr>
<tr title="Set on collection" mv-app mv-source="data/creatures.json" class="mv-autoedit">
<td><button mv-action="set(person, list(group(name: 'First', age: 1), group(name: 'Second', age: 2)))">Set collection</button></td>
<td>
<div class="mv-bar mv-ui"></div>
<div property="person" mv-multiple>
<strong property="name">John Doe</strong>
<span property="age">0</span>
</div>
</td>
<td>
First 1
Second 2
</td>
</tr>
</table>
</section>
<section>
<h1>Move</h1>
<p>Click the buttons in the first column</p>
<table class="reftest" data-click="td:first-child > button[mv-action] wait 1s after mv-load">
<tr title="Move item" mv-app mv-source="data/creatures.json" class="mv-autoedit">
<td><button mv-action="move(first(person), cat)">Move first person to cats</button></td>
<td>
<div class="mv-bar mv-ui"></div>
<div property="person" mv-multiple>
<strong property="name">John Doe</strong>
<span property="age">0</span>
<button mv-action="move(person, cat)" class="test-content-ignore">Move to cats</button>
</div>
<div property="cat" mv-multiple>
<strong property="name">John Doe</strong>
<span property="age">0</span>
<button mv-action="move(cat, 0)" class="test-content-ignore">Move to top</button>
</div>
</td>
<td>
David Karger 50
Vector 12
Adam Catlace 4
Çiki 1
Lea Verou 32
</td>
</tr>
</table>
</section>
<section>
<h1>Using action names as unquoted strings in mv-action</h1>
<table class="reftest">
<tr>
<td mv-app>
<span property="prop1"></span>
<button data-click="wait 1s" mv-action="set(prop1, add)" class="test-content-ignore">Set prop1 to add</button>
</td>
<td>
add
</td>
</tr>
</table>
</section>
<script>
function expressionRewrite(test, result, expected) {
var r = result.textContent = Mavo.Script.rewrite(test.textContent);
return Test.equals(r, expected.textContent);
}
</script>
</body>
</html>