trebol 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/README.md +12 -1
  2. package/dist/cli.js +17097 -12238
  3. package/dist/fonts/OFL.txt +93 -0
  4. package/dist/fonts/inter-cyrillic-ext.woff2 +0 -0
  5. package/dist/fonts/inter-cyrillic.woff2 +0 -0
  6. package/dist/fonts/inter-greek-ext.woff2 +0 -0
  7. package/dist/fonts/inter-greek.woff2 +0 -0
  8. package/dist/fonts/inter-latin-ext.woff2 +0 -0
  9. package/dist/fonts/inter-latin.woff2 +0 -0
  10. package/dist/fonts/inter-vietnamese.woff2 +0 -0
  11. package/dist/lib/core/boot.js +12 -8
  12. package/dist/lib/core/eval.js +2 -2
  13. package/dist/lib/core/func.d.ts +4 -0
  14. package/dist/lib/core/machine/checks.d.ts +1 -0
  15. package/dist/lib/core/machine/checks.js +250 -0
  16. package/dist/lib/core/machine/events.d.ts +1 -0
  17. package/dist/lib/core/machine/events.js +365 -0
  18. package/dist/lib/core/machine/running.d.ts +1 -0
  19. package/dist/lib/core/machine/running.js +180 -0
  20. package/dist/lib/core/machine/shared.d.ts +1 -0
  21. package/dist/lib/core/machine/shared.js +123 -0
  22. package/dist/lib/core/machine/snapshot.d.ts +1 -0
  23. package/dist/lib/core/machine/snapshot.js +244 -0
  24. package/dist/lib/core/machine/spec.d.ts +1 -0
  25. package/dist/lib/core/machine/spec.js +274 -0
  26. package/dist/lib/core/machine/words.d.ts +1 -0
  27. package/dist/lib/core/machine/words.js +98 -0
  28. package/dist/lib/core/machine.d.ts +1 -0
  29. package/dist/lib/core/machine.js +17 -0
  30. package/dist/lib/core/mezz.js +31 -0
  31. package/dist/lib/core/natives/control.js +2 -2
  32. package/dist/lib/core/natives/data.js +6 -1
  33. package/dist/lib/core/natives/series.js +59 -9
  34. package/dist/lib/core/natives/text.js +3 -1
  35. package/dist/lib/host/browser/calendar.d.ts +34 -0
  36. package/dist/lib/host/browser/calendar.js +268 -0
  37. package/dist/lib/host/browser/count.d.ts +15 -0
  38. package/dist/lib/host/browser/count.js +48 -0
  39. package/dist/lib/host/browser/dialogs.d.ts +39 -0
  40. package/dist/lib/host/browser/dialogs.js +443 -0
  41. package/dist/lib/host/browser/drag.d.ts +70 -0
  42. package/dist/lib/host/browser/drag.js +268 -0
  43. package/dist/lib/host/browser/drawings.d.ts +30 -0
  44. package/dist/lib/host/browser/drawings.js +176 -0
  45. package/dist/lib/host/browser/events.d.ts +16 -0
  46. package/dist/lib/host/browser/events.js +125 -0
  47. package/dist/lib/host/browser/faces.d.ts +35 -0
  48. package/dist/lib/host/browser/faces.js +131 -0
  49. package/dist/lib/host/browser/fields.d.ts +16 -0
  50. package/dist/lib/host/browser/fields.js +322 -0
  51. package/dist/lib/host/browser/keys.d.ts +29 -0
  52. package/dist/lib/host/browser/keys.js +151 -0
  53. package/dist/lib/host/browser/lookup.d.ts +25 -0
  54. package/dist/lib/host/browser/lookup.js +275 -0
  55. package/dist/lib/host/browser/menus.d.ts +20 -0
  56. package/dist/lib/host/browser/menus.js +149 -0
  57. package/dist/lib/host/browser/mount.d.ts +92 -0
  58. package/dist/lib/host/browser/mount.js +448 -0
  59. package/dist/lib/host/browser/orbits.d.ts +90 -0
  60. package/dist/lib/host/browser/orbits.js +379 -0
  61. package/dist/lib/host/browser/page.d.ts +13 -0
  62. package/dist/lib/host/browser/page.js +35 -0
  63. package/dist/lib/host/browser/richtext.d.ts +19 -0
  64. package/dist/lib/host/browser/richtext.js +379 -0
  65. package/dist/lib/host/browser/row-faces.d.ts +5 -0
  66. package/dist/lib/host/browser/row-faces.js +74 -0
  67. package/dist/lib/host/browser/screens.d.ts +37 -0
  68. package/dist/lib/host/browser/screens.js +140 -0
  69. package/dist/lib/host/browser/swipe.d.ts +31 -0
  70. package/dist/lib/host/browser/swipe.js +178 -0
  71. package/dist/lib/host/browser/sync.d.ts +24 -0
  72. package/dist/lib/host/browser/sync.js +450 -0
  73. package/dist/lib/host/browser/tables.d.ts +65 -0
  74. package/dist/lib/host/browser/tables.js +505 -0
  75. package/dist/lib/host/browser/times.d.ts +14 -0
  76. package/dist/lib/host/browser/times.js +114 -0
  77. package/dist/lib/host/browser/toolbars.d.ts +17 -0
  78. package/dist/lib/host/browser/toolbars.js +129 -0
  79. package/dist/lib/host/browser/trees.d.ts +20 -0
  80. package/dist/lib/host/browser/trees.js +235 -0
  81. package/dist/lib/host/browser/uploads.d.ts +29 -0
  82. package/dist/lib/host/browser/uploads.js +370 -0
  83. package/dist/lib/host/browser/widget.d.ts +13 -0
  84. package/dist/lib/host/browser/widget.js +105 -0
  85. package/dist/lib/host/browser.d.ts +25 -0
  86. package/dist/lib/host/browser.js +129 -3964
  87. package/dist/lib/host/devlog.d.ts +11 -0
  88. package/dist/lib/host/devlog.js +13 -0
  89. package/dist/lib/host/devtools/console.d.ts +9 -0
  90. package/dist/lib/host/devtools/console.js +104 -0
  91. package/dist/lib/host/devtools/faces.d.ts +25 -0
  92. package/dist/lib/host/devtools/faces.js +169 -0
  93. package/dist/lib/host/devtools/log.d.ts +3 -0
  94. package/dist/lib/host/devtools/log.js +32 -0
  95. package/dist/lib/host/devtools/machines.d.ts +34 -0
  96. package/dist/lib/host/devtools/machines.js +212 -0
  97. package/dist/lib/host/devtools/read.d.ts +13 -0
  98. package/dist/lib/host/devtools/read.js +52 -0
  99. package/dist/lib/host/devtools/state.d.ts +90 -0
  100. package/dist/lib/host/devtools/state.js +123 -0
  101. package/dist/lib/host/devtools.d.ts +19 -0
  102. package/dist/lib/host/devtools.js +238 -0
  103. package/dist/lib/host/fonts/OFL.txt +93 -0
  104. package/dist/lib/host/fonts/inter-cyrillic-ext.woff2 +0 -0
  105. package/dist/lib/host/fonts/inter-cyrillic.woff2 +0 -0
  106. package/dist/lib/host/fonts/inter-greek-ext.woff2 +0 -0
  107. package/dist/lib/host/fonts/inter-greek.woff2 +0 -0
  108. package/dist/lib/host/fonts/inter-latin-ext.woff2 +0 -0
  109. package/dist/lib/host/fonts/inter-latin.woff2 +0 -0
  110. package/dist/lib/host/fonts/inter-vietnamese.woff2 +0 -0
  111. package/dist/lib/host/fonts.d.ts +11 -0
  112. package/dist/lib/host/fonts.js +30 -0
  113. package/dist/lib/host/icons.js +4 -0
  114. package/dist/lib/host/index.d.ts +5 -1
  115. package/dist/lib/host/index.js +110 -5
  116. package/dist/lib/host/js.d.ts +5 -0
  117. package/dist/lib/host/js.js +130 -0
  118. package/dist/lib/host/locale.d.ts +18 -0
  119. package/dist/lib/host/locale.js +75 -5
  120. package/dist/lib/host/markdown.d.ts +6 -0
  121. package/dist/lib/host/markdown.js +18 -0
  122. package/dist/lib/host/modules.d.ts +4 -0
  123. package/dist/lib/host/modules.js +157 -20
  124. package/dist/lib/host/motion.d.ts +32 -0
  125. package/dist/lib/host/motion.js +190 -0
  126. package/dist/lib/host/net.js +14 -3
  127. package/dist/lib/host/orbit.d.ts +121 -0
  128. package/dist/lib/host/orbit.js +374 -0
  129. package/dist/lib/host/palette.d.ts +17 -0
  130. package/dist/lib/host/palette.js +131 -0
  131. package/dist/lib/host/rows.d.ts +14 -0
  132. package/dist/lib/host/rows.js +29 -0
  133. package/dist/lib/host/scheduler.d.ts +8 -0
  134. package/dist/lib/host/scheduler.js +64 -36
  135. package/dist/lib/host/share.d.ts +31 -0
  136. package/dist/lib/host/share.js +134 -0
  137. package/dist/lib/host/theme/classic.d.ts +1 -0
  138. package/dist/lib/host/theme/classic.js +120 -0
  139. package/dist/lib/host/theme/cupertino.d.ts +1 -0
  140. package/dist/lib/host/theme/cupertino.js +65 -0
  141. package/dist/lib/host/theme/data.d.ts +1 -0
  142. package/dist/lib/host/theme/data.js +109 -0
  143. package/dist/lib/host/theme/devtools.d.ts +1 -0
  144. package/dist/lib/host/theme/devtools.js +166 -0
  145. package/dist/lib/host/theme/dialogs.d.ts +1 -0
  146. package/dist/lib/host/theme/dialogs.js +63 -0
  147. package/dist/lib/host/theme/fluent.d.ts +1 -0
  148. package/dist/lib/host/theme/fluent.js +64 -0
  149. package/dist/lib/host/theme/forms.d.ts +1 -0
  150. package/dist/lib/host/theme/forms.js +239 -0
  151. package/dist/lib/host/theme/fusion.d.ts +1 -0
  152. package/dist/lib/host/theme/fusion.js +66 -0
  153. package/dist/lib/host/theme/layout.d.ts +1 -0
  154. package/dist/lib/host/theme/layout.js +166 -0
  155. package/dist/lib/host/theme/media.d.ts +1 -0
  156. package/dist/lib/host/theme/media.js +106 -0
  157. package/dist/lib/host/theme/navigation.d.ts +1 -0
  158. package/dist/lib/host/theme/navigation.js +36 -0
  159. package/dist/lib/host/theme/panes.d.ts +1 -0
  160. package/dist/lib/host/theme/panes.js +99 -0
  161. package/dist/lib/host/theme/popups.d.ts +1 -0
  162. package/dist/lib/host/theme/popups.js +149 -0
  163. package/dist/lib/host/theme/responsive.d.ts +1 -0
  164. package/dist/lib/host/theme/responsive.js +103 -0
  165. package/dist/lib/host/theme/toasts.d.ts +1 -0
  166. package/dist/lib/host/theme/toasts.js +62 -0
  167. package/dist/lib/host/theme.js +19 -1179
  168. package/dist/lib/ui/dialect/events.trb +276 -0
  169. package/dist/lib/ui/dialect/faces.trb +135 -0
  170. package/dist/lib/ui/dialect/layout.trb +283 -0
  171. package/dist/lib/ui/dialect/palette.trb +87 -0
  172. package/dist/lib/ui/dialect/problems.trb +174 -0
  173. package/dist/lib/ui/dialect/reactions.trb +198 -0
  174. package/dist/lib/ui/dialect/rows.trb +208 -0
  175. package/dist/lib/ui/dialect/screens.trb +293 -0
  176. package/dist/lib/ui/dialect/steps.trb +203 -0
  177. package/dist/lib/ui/dialect/validation.trb +137 -0
  178. package/dist/lib/ui/dialect/view.trb +110 -0
  179. package/dist/lib/ui/dialect/walking.trb +98 -0
  180. package/dist/lib/ui/dialect/words.trb +70 -0
  181. package/dist/lib/ui/i18n.trb +23 -0
  182. package/dist/lib/ui/test.trb +12 -0
  183. package/dist/lib/ui/testing/actions.trb +421 -0
  184. package/dist/lib/ui/testing/faces.trb +148 -0
  185. package/dist/lib/ui/testing/server.trb +73 -0
  186. package/dist/lib/ui/ui.trb +25 -1234
  187. package/dist/trebol.js +4882 -1088
  188. package/editors/vscode/README.md +15 -0
  189. package/editors/vscode/language-configuration.json +28 -0
  190. package/editors/vscode/package.json +42 -0
  191. package/editors/vscode/syntaxes/trebol.tmLanguage.json +237 -0
  192. package/package.json +7 -3
  193. package/src/core/boot.ts +10 -7
  194. package/src/core/eval.ts +2 -2
  195. package/src/core/func.ts +4 -0
  196. package/src/core/machine/checks.ts +251 -0
  197. package/src/core/machine/events.ts +366 -0
  198. package/src/core/machine/running.ts +181 -0
  199. package/src/core/machine/shared.ts +124 -0
  200. package/src/core/machine/snapshot.ts +245 -0
  201. package/src/core/machine/spec.ts +275 -0
  202. package/src/core/machine/words.ts +99 -0
  203. package/src/core/machine.ts +20 -0
  204. package/src/core/mezz.ts +31 -0
  205. package/src/core/natives/control.ts +2 -2
  206. package/src/core/natives/data.ts +6 -1
  207. package/src/core/natives/parse.ts +1 -1
  208. package/src/core/natives/series.ts +55 -11
  209. package/src/core/natives/text.ts +2 -1
  210. package/src/host/browser/calendar.ts +264 -0
  211. package/src/host/browser/count.ts +48 -0
  212. package/src/host/browser/dialogs.ts +439 -0
  213. package/src/host/browser/drag.ts +278 -0
  214. package/src/host/browser/drawings.ts +178 -0
  215. package/src/host/browser/events.ts +117 -0
  216. package/src/host/browser/faces.ts +143 -0
  217. package/src/host/browser/fields.ts +315 -0
  218. package/src/host/browser/keys.ts +145 -0
  219. package/src/host/browser/lookup.ts +262 -0
  220. package/src/host/browser/menus.ts +146 -0
  221. package/src/host/browser/mount.ts +420 -0
  222. package/src/host/browser/orbits.ts +418 -0
  223. package/src/host/browser/page.ts +43 -0
  224. package/src/host/browser/richtext.ts +346 -0
  225. package/src/host/browser/row-faces.ts +75 -0
  226. package/src/host/browser/screens.ts +142 -0
  227. package/src/host/browser/swipe.ts +168 -0
  228. package/src/host/browser/sync.ts +354 -0
  229. package/src/host/browser/tables.ts +461 -0
  230. package/src/host/browser/times.ts +115 -0
  231. package/src/host/browser/toolbars.ts +126 -0
  232. package/src/host/browser/trees.ts +205 -0
  233. package/src/host/browser/uploads.ts +367 -0
  234. package/src/host/browser/widget.ts +103 -0
  235. package/src/host/browser.ts +128 -3747
  236. package/src/host/devlog.ts +16 -0
  237. package/src/host/devtools/console.ts +102 -0
  238. package/src/host/devtools/faces.ts +160 -0
  239. package/src/host/devtools/log.ts +34 -0
  240. package/src/host/devtools/machines.ts +208 -0
  241. package/src/host/devtools/read.ts +58 -0
  242. package/src/host/devtools/state.ts +148 -0
  243. package/src/host/devtools.ts +238 -0
  244. package/src/host/fonts/OFL.txt +93 -0
  245. package/src/host/fonts/inter-cyrillic-ext.woff2 +0 -0
  246. package/src/host/fonts/inter-cyrillic.woff2 +0 -0
  247. package/src/host/fonts/inter-greek-ext.woff2 +0 -0
  248. package/src/host/fonts/inter-greek.woff2 +0 -0
  249. package/src/host/fonts/inter-latin-ext.woff2 +0 -0
  250. package/src/host/fonts/inter-latin.woff2 +0 -0
  251. package/src/host/fonts/inter-vietnamese.woff2 +0 -0
  252. package/src/host/fonts.ts +40 -0
  253. package/src/host/icons.ts +4 -0
  254. package/src/host/index.ts +110 -5
  255. package/src/host/js.ts +127 -0
  256. package/src/host/locale.ts +71 -5
  257. package/src/host/markdown.ts +18 -0
  258. package/src/host/modules.ts +150 -22
  259. package/src/host/motion.ts +204 -0
  260. package/src/host/net.ts +13 -3
  261. package/src/host/orbit.ts +432 -0
  262. package/src/host/palette.ts +139 -0
  263. package/src/host/rows.ts +30 -0
  264. package/src/host/scheduler.ts +67 -36
  265. package/src/host/share.ts +168 -0
  266. package/src/host/theme/classic.ts +121 -0
  267. package/src/host/theme/cupertino.ts +66 -0
  268. package/src/host/theme/data.ts +110 -0
  269. package/src/host/theme/devtools.ts +167 -0
  270. package/src/host/theme/dialogs.ts +64 -0
  271. package/src/host/theme/fluent.ts +65 -0
  272. package/src/host/theme/forms.ts +240 -0
  273. package/src/host/theme/fusion.ts +67 -0
  274. package/src/host/theme/layout.ts +167 -0
  275. package/src/host/theme/media.ts +107 -0
  276. package/src/host/theme/navigation.ts +37 -0
  277. package/src/host/theme/panes.ts +100 -0
  278. package/src/host/theme/popups.ts +150 -0
  279. package/src/host/theme/responsive.ts +104 -0
  280. package/src/host/theme/toasts.ts +63 -0
  281. package/src/host/theme.ts +19 -1179
  282. package/src/ui/dialect/events.trb +276 -0
  283. package/src/ui/dialect/faces.trb +135 -0
  284. package/src/ui/dialect/layout.trb +283 -0
  285. package/src/ui/dialect/palette.trb +87 -0
  286. package/src/ui/dialect/problems.trb +174 -0
  287. package/src/ui/dialect/reactions.trb +198 -0
  288. package/src/ui/dialect/rows.trb +208 -0
  289. package/src/ui/dialect/screens.trb +293 -0
  290. package/src/ui/dialect/steps.trb +203 -0
  291. package/src/ui/dialect/validation.trb +137 -0
  292. package/src/ui/dialect/view.trb +110 -0
  293. package/src/ui/dialect/walking.trb +98 -0
  294. package/src/ui/dialect/words.trb +70 -0
  295. package/src/ui/i18n.trb +23 -0
  296. package/src/ui/test.trb +12 -0
  297. package/src/ui/testing/actions.trb +421 -0
  298. package/src/ui/testing/faces.trb +148 -0
  299. package/src/ui/testing/server.trb +73 -0
  300. package/src/ui/ui.trb +25 -1234
@@ -0,0 +1,421 @@
1
+ ; A part of the words of screen tests: see test.trb, whose words it shares.
2
+
3
+ ; --- what the user does ---------------------------------------------------------
4
+
5
+ text-styles: [field password number money date date-range time area rich slider]
6
+
7
+ click: function [
8
+ "Clicks a button, link, tile, check, toggle, tab or a step done, the row of a table or list that shows a text, or a node of an orbit."
9
+ what [string! word!] "What it shows, or a field's name"
10
+ /local f p row id t back done
11
+ ] [
12
+ ; the Undo of the newest notice that has one
13
+ if all [string? what what = tr select i18n/ui 'undo] [
14
+ undos: copy []
15
+ foreach [id t back done] ui-toasts-on [if back [append undos id]]
16
+ unless empty? undos [
17
+ foreach [f p] test-shown [
18
+ if all [find [button link tile] f/style test-called? f what] [
19
+ do make error! rejoin ["click: a notice and a face on the screen are " mold what]
20
+ ]
21
+ ]
22
+ ui-toast-undo none last undos
23
+ return true
24
+ ]
25
+ ]
26
+ if string? what [
27
+ ; a neighbour of an orbit, or a node of its trail
28
+ foreach [f p] test-shown [
29
+ if f/style = 'orbit [
30
+ foreach [id t back] test-orbit-nodes f [
31
+ if t = what [
32
+ if any [f/disabled f/inert] [do make error! rejoin ["click: " mold what " cannot be used now"]]
33
+ ui-orbit f id back
34
+ return true
35
+ ]
36
+ ]
37
+ ]
38
+ ]
39
+ ; a row of a table or list
40
+ foreach [f p] test-shown [
41
+ if all [find [table list] f/style block? f/data] [
42
+ foreach row f/data [
43
+ if find test-cells f row what [
44
+ if any [f/disabled f/inert] [do make error! rejoin ["click: " mold what " cannot be used now"]]
45
+ ui-select f row
46
+ return true
47
+ ]
48
+ ]
49
+ ]
50
+ ]
51
+ ]
52
+ found: test-face 'click [button link tile check toggle tab step] what
53
+ test-activate first found second found
54
+ ]
55
+
56
+ ; Does what a click on a face does; parent is the face it is in.
57
+ test-activate: function [f parent] [
58
+ switch/default f/style [
59
+ check toggle [ui-input f not f/value ui-blur f]
60
+ tab [ui-input parent index? find parent/pane f]
61
+ ; only a step already done can be chosen by its title
62
+ step [
63
+ n: index? find parent/pane f
64
+ if n >= parent/value [do make error! rejoin ["click: " mold test-text f/text " cannot be used now"]]
65
+ ui-step-go parent n
66
+ ]
67
+ link [
68
+ case [
69
+ f/action [ui-click f]
70
+ any [word? f/value path? f/value] [go f/value]
71
+ ]
72
+ ]
73
+ ] [ui-click f]
74
+ true
75
+ ]
76
+
77
+ type: function [
78
+ "Types a text in a field, then leaves it; an empty text clears it. A slider moves to the number typed."
79
+ what [string! word!] "Its label or hint, or its name"
80
+ text [any-type!] "What to type; a number or date is typed as written, and a range as its two dates"
81
+ ] [
82
+ f: first test-face 'type text-styles what
83
+ text: case [string? :text [text] block? :text [mold/only :text] true [form :text]]
84
+ ui-input f either empty? text [none] [text]
85
+ ui-blur f
86
+ true
87
+ ]
88
+
89
+ choose: function [
90
+ "Chooses an option of a choice, radio or lookup by the text it shows."
91
+ what [string! word!] "Its label, or its name"
92
+ option [string!]
93
+ /local o
94
+ ] [
95
+ f: first test-face 'choose [choice radio lookup] what
96
+ if f/style = 'lookup [
97
+ ui-lookup-search f option
98
+ foreach o any [f/options []] [
99
+ if option = test-text o/text [
100
+ ui-lookup-pick f o
101
+ ui-blur f
102
+ return true
103
+ ]
104
+ ]
105
+ do make error! rejoin ["choose: " mold what " finds no " mold option]
106
+ ]
107
+ ; a group of options is a title then a block of them
108
+ options: collect [
109
+ opts: any [f/options []]
110
+ forall opts [
111
+ case [
112
+ block? first opts [keep first opts]
113
+ not block? pick opts 2 [keep/only first opts]
114
+ ]
115
+ ]
116
+ ]
117
+ foreach o options [
118
+ if option = either map? o [test-text o/text] [form o] [
119
+ ui-input f form either map? o [o/value] [o]
120
+ ui-blur f
121
+ return true
122
+ ]
123
+ ]
124
+ do make error! rejoin ["choose: " mold what " has no option " mold option]
125
+ ]
126
+
127
+ pick-menu: function [
128
+ "Chooses an item of the menu a button opens, of the context menu of a face, or of the row of a table or list that shows a text."
129
+ what [string! word!] "What the face or row shows, or a face's name"
130
+ item [string! block!] {The item's text; ["Move to" "Top"] for one in a submenu}
131
+ /local f p row i
132
+ ] [
133
+ on: none row: none
134
+ if string? what [
135
+ ; foreach keeps its words to itself
136
+ foreach [f p] test-shown [
137
+ if all [find [table list] f/style block? f/data f/menu] [
138
+ foreach r f/data [if find test-cells f r what [on: f row: r break]]
139
+ if row [break]
140
+ ]
141
+ ]
142
+ ]
143
+ either on [f: on] [
144
+ f: first test-face 'pick-menu collect [foreach [f p] test-shown [keep f/style]] what
145
+ unless block? f/menu [do make error! rejoin ["pick-menu: " mold what " has no menu"]]
146
+ ]
147
+ if any [f/disabled f/inert] [do make error! rejoin ["pick-menu: " mold what " cannot be used now"]]
148
+ items: f/menu
149
+ texts: either block? item [item] [reduce [item]]
150
+ forall texts [
151
+ found: none
152
+ foreach i items [if all [not i/divider (first texts) = test-text i/text] [found: i break]]
153
+ unless found [do make error! rejoin ["pick-menu: the menu of " mold what " has no " mold first texts]]
154
+ either tail? next texts [
155
+ if found/items [do make error! rejoin ["pick-menu: " mold first texts " opens a submenu"]]
156
+ ] [
157
+ unless found/items [do make error! rejoin ["pick-menu: " mold first texts " has no submenu"]]
158
+ items: found/items
159
+ ]
160
+ ]
161
+ ui-menu f found row
162
+ true
163
+ ]
164
+
165
+ ; [face row index ...] of the rows of the tables and lists on show that show a text.
166
+ test-rows: function [what /local f p] [
167
+ out: copy []
168
+ if string? what [
169
+ foreach [f p] test-shown [
170
+ if all [find [table list] f/style block? f/data] [
171
+ repeat i length? f/data [
172
+ if find test-cells f pick f/data i what [append out reduce [f pick f/data i i]]
173
+ ]
174
+ ]
175
+ ]
176
+ ]
177
+ out
178
+ ]
179
+
180
+ drag: function [
181
+ "Drags a face, or the row of a table or list that shows a text, onto another: in a list that can be reordered it takes that place, else it is dropped on it."
182
+ what [string! word!] "What the face or row shows, or a face's name"
183
+ onto [string! word!] "The place it goes: a face, or the row it goes before"
184
+ /local f p row i
185
+ ] [
186
+ shown: test-shown
187
+ styles: collect [foreach [f p] shown [keep f/style]]
188
+ ; what is dragged: its face, what it carries, where it is, and the face it moves in
189
+ either not empty? rows: test-rows what [
190
+ set [from payload index] rows
191
+ ; rows the user sorted by a header are not in the order of their data
192
+ sorted: all [from/sortable from/sorted not all [from/events select from/events 'on-sort]]
193
+ within: all [from/reorder not sorted from]
194
+ unless any [from/drag within] [do make error! rejoin ["drag: the rows of " mold what " cannot be dragged"]]
195
+ ] [
196
+ set [from p] test-face 'drag styles what
197
+ payload: from/value
198
+ within: all [p p/reorder not find [table list tree] p/style p]
199
+ index: all [within index? find/same within/pane from]
200
+ unless any [from/drag within] [do make error! rejoin ["drag: " mold what " cannot be dragged"]]
201
+ ]
202
+ ; moved to another place among its own
203
+ if within [
204
+ place: none
205
+ either find [table list] within/style [
206
+ foreach [f row i] test-rows onto [if same? f within [place: i break]]
207
+ ] [
208
+ foreach c within/pane [if all [not c/hidden test-called? c onto] [place: index? find/same within/pane c break]]
209
+ ]
210
+ if place [
211
+ ui-reorder within index place none
212
+ return true
213
+ ]
214
+ ]
215
+ ; dropped on a face, or before a row of one
216
+ zone: none
217
+ ; foreach keeps its words to itself
218
+ foreach [f row i] test-rows onto [if f/drop [zone: f at: i break]]
219
+ either zone [
220
+ if same? zone from [do make error! rejoin ["drag: " mold what " is already in " mold onto]]
221
+ ] [
222
+ zone: first test-face 'drag styles onto
223
+ unless zone/drop [do make error! rejoin ["drag: " mold onto " takes nothing dropped"]]
224
+ if test-inside? zone from shown [do make error! rejoin ["drag: " mold what " cannot go into itself"]]
225
+ at: 1 + length? either find [table list tree] zone/style [any [zone/data []]] [any [zone/pane []]]
226
+ ]
227
+ ui-drop zone :payload from at none
228
+ true
229
+ ]
230
+
231
+ ; Does an upload or photo whose accept is list take a file? As the browser's picker: "pdf" and ".pdf"
232
+ ; by its name, "image/png" and "image/*" by its type.
233
+ test-accepts?: function [list [block!] name [string!] type [string!]] [
234
+ if empty? list [return true]
235
+ name: lowercase copy name
236
+ type: lowercase copy type
237
+ foreach x list [
238
+ x: lowercase trim form x
239
+ if either find x #"/" [
240
+ either #"*" = last x [find/match type copy/part x (length? x) - 1] [type = x]
241
+ ] [
242
+ unless #"." = first x [x: join "." x]
243
+ all [(length? name) >= length? x x = skip tail name negate length? x]
244
+ ] [return true]
245
+ ]
246
+ false
247
+ ]
248
+
249
+ attach: function [
250
+ "Chooses files for an upload or photo, as the user picks them or drops them on it; the ones its accept refuses are refused, as the browser does."
251
+ what [string! word!] "Its label, or its name"
252
+ files [file! block!] "A file next to the test, or a block of them"
253
+ ] [
254
+ f: first test-face 'attach [upload photo] what
255
+ list: either block? f/accept [f/accept] [either f/style = 'photo [["image/*"]] [[]]]
256
+ taken: copy []
257
+ refused: copy []
258
+ foreach file either block? files [files] [reduce [files]] [
259
+ one: test-file file
260
+ either test-accepts? list one/1 one/3 [append taken one] [append refused one/1]
261
+ ]
262
+ ; one file unless it takes more
263
+ unless f/multiple [taken: copy/part taken 4]
264
+ ui-files f taken refused
265
+ true
266
+ ]
267
+
268
+ ; The face a face is in, among the faces on show.
269
+ test-parent: function [f shown /local g p] [
270
+ foreach [g p] shown [if same? g f [return p]]
271
+ none
272
+ ]
273
+
274
+ ; Is f inside the face outer (or outer itself)?
275
+ test-inside?: function [f outer shown] [
276
+ while [f] [
277
+ if same? f outer [return true]
278
+ f: test-parent f shown
279
+ ]
280
+ false
281
+ ]
282
+
283
+ ; "Ctrl+Shift+K" -> [ctrl shift alt key] as the browser compares them: Ctrl and Cmd are one, names as
284
+ ; the browser gives them, a letter in lower case
285
+ test-keys: function [spec [string!] /local k] [
286
+ parts: split lowercase copy spec #"+"
287
+ foreach k parts [trim k]
288
+ k: take/last parts
289
+ if empty? k [k: "+"]
290
+ k: any [select ["esc" "escape" "del" "delete" "up" "arrowup" "down" "arrowdown" "left" "arrowleft" "right" "arrowright" "space" " "] k k]
291
+ any-of: func [names] [not empty? intersect parts names]
292
+ reduce [any-of ["ctrl" "control" "cmd" "meta"] any-of ["shift"] any-of ["alt" "option"] k]
293
+ ]
294
+
295
+ ; The key of "Ctrl+S" as on-key gets it in event/key: a char (#"s", #"^M" for Enter) or a word ('left, 'F2).
296
+ test-key: function [spec [string!]] [
297
+ k: last split spec #"+"
298
+ if empty? k [k: "+"]
299
+ shift: find spec "shift+"
300
+ case [
301
+ c: select ["enter" #"^M" "escape" #"^[" "esc" #"^[" "tab" #"^-" "backspace" #"^H" "space" #" "] k [c]
302
+ 1 = length? k [either shift [uppercase first k] [lowercase first k]]
303
+ w: select [
304
+ "left" left "arrowleft" left "right" right "arrowright" right "up" up "arrowup" up "down" down "arrowdown" down
305
+ "home" home "end" end "pageup" page-up "pagedown" page-down "insert" insert "delete" delete "del" delete
306
+ ] k [w]
307
+ parse k [#"F" some digit] [to word! uppercase copy k]
308
+ true [do make error! rejoin ["press: " mold spec " is not a key"]]
309
+ ]
310
+ ]
311
+
312
+ digit: charset "0123456789"
313
+
314
+ press: function [
315
+ "Presses a key, as Enter or Ctrl+S: the button or link with it as its shortcut, or else the on-key of the face with the cursor, or of the view."
316
+ key [string!] {"Enter", "Escape", "Ctrl+S", "Shift+Tab", "a"}
317
+ /on "With the cursor in a face"
318
+ what [string! word!] "Its label, hint or text, or its name"
319
+ /local f p
320
+ ] [
321
+ shown: test-shown
322
+ want: test-keys key
323
+ ; a dialog on show keeps the rest of the page out of reach
324
+ dialog: none
325
+ foreach [f p] shown [if f/style = 'dialog [dialog: f]]
326
+ foreach [f p] shown [
327
+ if all [
328
+ f/shortcut
329
+ find [button link] f/style
330
+ want = test-keys f/shortcut
331
+ any [none? dialog test-inside? f dialog shown]
332
+ ] [
333
+ if any [f/disabled f/inert] [do make error! rejoin ["press: " mold key " cannot be used now"]]
334
+ return test-activate f p
335
+ ]
336
+ ]
337
+ at: none
338
+ if on [at: first test-face 'press collect [foreach [f p] shown [keep f/style]] what]
339
+ k: test-key key
340
+ fields: reduce [
341
+ quote key: either word? k [to lit-word! k] [k]
342
+ quote ctrl?: to logic! find key "ctrl+" quote shift?: to logic! find key "shift+" quote alt?: to logic! find key "alt+"
343
+ quote meta?: to logic! any [find key "cmd+" find key "meta+"]
344
+ ]
345
+ ; the face with the cursor or the nearest around it that has an on-key, or the view
346
+ f: any [at shown-view]
347
+ while [all [f not all [f/events select f/events 'on-key]]] [f: either at [test-parent f shown] [none]]
348
+ if f [ui-event f 'on-key fields]
349
+ ; a form in steps with Next on show: Enter in a one-line field of the step presses it
350
+ steps: at
351
+ while [all [steps steps/style <> 'steps]] [steps: test-parent steps shown]
352
+ next-face: all [steps pick get in last steps/pane 'pane 2]
353
+ case [
354
+ all [at k = #"^M" find [field password number money date] at/style next-face not next-face/hidden] [
355
+ ui-step steps 1
356
+ ]
357
+ ; Enter in a one-line field of a form clicks its submit, if it can be clicked
358
+ all [at k = #"^M" find [field password number money date] at/style at/form at/form/style = 'form] [
359
+ foreach [f p] test-shown [
360
+ if all [f/submit same? f/form at/form] [
361
+ unless any [f/disabled f/inert] [ui-click f]
362
+ break
363
+ ]
364
+ ]
365
+ ]
366
+ ; Escape closes the dialog on show
367
+ all [k = #"^[" dialog] [ui-close dialog]
368
+ ]
369
+ true
370
+ ]
371
+
372
+ dismiss: function [
373
+ "The notice that shows a text goes as if its time had passed: what waits for it (toast/then) runs now."
374
+ text [string!]
375
+ /local id t back done
376
+ ] [
377
+ foreach [id t back done] ui-toasts-on [
378
+ if find t text [
379
+ ui-toast-gone none id
380
+ return true
381
+ ]
382
+ ]
383
+ do make error! rejoin ["dismiss: no notice waiting to go shows " mold text]
384
+ ]
385
+
386
+ say: func [
387
+ "Says how the user answers the next question of confirm, which is yes when nothing is said; a test that leaves one unasked fails."
388
+ yes [logic!] "yes or no"
389
+ ] [
390
+ test-say yes
391
+ ]
392
+
393
+ see-mark: function [
394
+ "True if the tile on the screen called title has that mark (none: no mark); an error otherwise."
395
+ title [string! word!] "Its text, or its name"
396
+ mark [issue! none!]
397
+ /local f p
398
+ ] [
399
+ found: copy []
400
+ foreach [f p] test-shown [if all [f/style = 'tile test-called? f title] [append found f]]
401
+ if empty? found [do make error! rejoin ["see-mark: no tile on the screen is " mold title]]
402
+ if 1 < length? found [do make error! rejoin ["see-mark: " length? found " tiles on the screen are " mold title]]
403
+ has: found/1/mark
404
+ unless has = mark [
405
+ do make error! rejoin ["see-mark: " mold title " has " either has [mold has] ["no mark"] ", not " either mark [mold mark] ["none"]]
406
+ ]
407
+ true
408
+ ]
409
+
410
+ see: function [
411
+ "True if a text is on the screen, in a face, a field, a row or a notice; an error otherwise."
412
+ text [string!]
413
+ /not "True if it is not on the screen"
414
+ ] [
415
+ there: false
416
+ foreach t test-texts [if find t text [there: true break]]
417
+ if there = to logic! not [
418
+ do make error! rejoin ["see: " mold text either not [" is on the screen"] [" is not on the screen"]]
419
+ ]
420
+ true
421
+ ]
@@ -0,0 +1,148 @@
1
+ ; A part of the words of screen tests: see test.trb, whose words it shares.
2
+
3
+ ; --- the faces on show ----------------------------------------------------------
4
+
5
+ ; [face parent ...] of the faces the user sees, in their order on the page; first
6
+ ; the reactions run, as the browser runs them at the end of each round
7
+ test-shown: function [] [
8
+ out: copy []
9
+ if v: shown-view [
10
+ ; answers that cached asks for behind come before the user looks
11
+ forever [
12
+ foreach cycle ui-react v [print cycle]
13
+ tasks: copy []
14
+ foreach [key e] ui-cache-entries [if e/asking [append tasks e/task]]
15
+ if empty? tasks [break]
16
+ wait tasks
17
+ ]
18
+ test-walk v none out
19
+ ]
20
+ out
21
+ ]
22
+
23
+ test-walk: function [f parent out] [
24
+ ; on a wide screen, as the tests see it
25
+ if any [f/hidden f/narrow-only] [exit]
26
+ ; a browser deals a board's cards again when its data changes; here, when it is looked at
27
+ if f/style = 'board [ui-board f]
28
+ append out reduce [f parent]
29
+ unless block? f/pane [exit]
30
+ case [
31
+ f/style = 'tabs [
32
+ ; the label of every tab, the faces of the one chosen
33
+ repeat i length? f/pane [
34
+ t: pick f/pane i
35
+ append out reduce [t f]
36
+ if all [i = f/value block? t/pane] [foreach c t/pane [test-walk c t out]]
37
+ ]
38
+ ]
39
+ f/style = 'steps [
40
+ ; the title of every step that applies, the faces of the one on show, then Back and Next
41
+ repeat i length? f/pane [
42
+ t: pick f/pane i
43
+ case [
44
+ t/style <> 'step [test-walk t f out]
45
+ t/hidden []
46
+ true [
47
+ append out reduce [t f]
48
+ if all [i = f/value block? t/pane] [foreach c t/pane [test-walk c t out]]
49
+ ]
50
+ ]
51
+ ]
52
+ ]
53
+ true [foreach c f/pane [test-walk c f out]]
54
+ ]
55
+ ]
56
+
57
+ test-route: function [
58
+ "Called by the host when the page goes back or forward: the screens on show follow the link."
59
+ parts [block!]
60
+ /local f p
61
+ ] [
62
+ foreach [f p] test-shown [if f/style = 'screens [return ui-route f parts]]
63
+ ]
64
+
65
+ ; What a text of the interface shows: a string, a text per language or a word of the dictionary.
66
+ test-text: func [t] [either any [none? :t logic? :t] [none] [tr t]]
67
+
68
+ ; The cells of a row of a table or list, as shown.
69
+ test-cells: function [f row /local w label] [
70
+ collect [
71
+ foreach [w label] any [f/columns []] [
72
+ v: select row w
73
+ unless none? :v [keep either string? :v [v] [localize :v]]
74
+ ]
75
+ ]
76
+ ]
77
+
78
+ ; Every text on show: of faces, values, errors and rows, and the notices shown.
79
+ test-texts: function [/local f p t] [
80
+ out: copy []
81
+ foreach [f p] test-shown [
82
+ foreach t reduce [test-text f/text test-text f/hint f/error test-text f/mark-text] [if string? t [append out t]]
83
+ v: f/value
84
+ case [
85
+ string? :v [append out v]
86
+ find [number money date slider time] f/style [if v [append out localize v]]
87
+ all [f/style = 'date-range v] [append out rejoin [localize v/1 " – " localize v/2]]
88
+ ]
89
+ if all [f/style = 'lookup v] [
90
+ foreach one either block? v [v] [reduce [v]] [
91
+ append out either t: all [f/known select f/known one] [test-text t] [form one]
92
+ ]
93
+ ]
94
+ ; the names of the files an upload or photo has
95
+ if all [find [upload photo] f/style v] [
96
+ foreach one either block? v [v] [reduce [v]] [if object? one [append out one/name]]
97
+ ]
98
+ if all [find [choice radio] f/style v] [
99
+ foreach o any [f/options []] [
100
+ if all [map? o (form v) = form o/value] [append out test-text o/text]
101
+ ]
102
+ ]
103
+ if all [find [table list] f/style block? f/data] [
104
+ foreach row f/data [append out test-cells f row]
105
+ ]
106
+ ; the title of every node of an orbit, its focus too
107
+ if all [f/style = 'orbit block? f/data] [
108
+ parse any [select f/data 'nodes []] [any [skip set t skip (append out test-text t) opt block!]]
109
+ ]
110
+ ]
111
+ append out shown-toasts
112
+ append out shown-questions
113
+ out
114
+ ]
115
+
116
+ ; The nodes of an orbit as [id title back ...]: its neighbours, and its trail with back true.
117
+ test-orbit-nodes: function [f /local id t] [
118
+ out: copy []
119
+ unless block? f/data [return out]
120
+ focus: select f/data 'focus
121
+ trail: any [select f/data 'trail []]
122
+ parse any [select f/data 'nodes []] [any [
123
+ set id skip set t skip opt block! (
124
+ unless id = focus [append out reduce [id test-text t to logic! find trail id]]
125
+ )
126
+ ]]
127
+ out
128
+ ]
129
+
130
+ ; What a face is called: its label, hint or the text it shows.
131
+ test-called?: function [f what] [
132
+ either word? what [f/name = what] [
133
+ any [what = test-text f/text what = test-text f/hint]
134
+ ]
135
+ ]
136
+
137
+ ; The one face on show of some styles called what; an error naming the action if there is none or more than one.
138
+ test-face: function [action [word!] styles [block!] what /local f p] [
139
+ found: copy []
140
+ foreach [f p] test-shown [
141
+ if all [find styles f/style test-called? f what] [append found reduce [f p]]
142
+ ]
143
+ if empty? found [do make error! rejoin [action ": nothing on the screen is " mold what]]
144
+ if 2 < length? found [do make error! rejoin [action ": " (length? found) / 2 " faces on the screen are " mold what]]
145
+ f: first found
146
+ if any [f/disabled f/inert f/readonly] [do make error! rejoin [action ": " mold what " cannot be used now"]]
147
+ found
148
+ ]
@@ -0,0 +1,73 @@
1
+ ; A part of the words of screen tests: see test.trb, whose words it shares.
2
+
3
+ ; --- answers of the server ------------------------------------------------------
4
+
5
+ ; [method path handler ...] of every serve
6
+ test-routes: copy []
7
+
8
+ serve: function [
9
+ "Answers the requests of the app: a method, a path and a block that gives the answer, for each; a later serve comes first."
10
+ routes [block!] {GET "/api/clients/:id" [...]: the block sees body, query and the :words of the path}
11
+ /local m p b pos
12
+ ] [
13
+ new: copy []
14
+ parse routes [any [
15
+ set m ['GET | 'POST | 'PUT | 'PATCH | 'DELETE] set p string! set b block! (append new reduce [m p b])
16
+ | pos: skip (do make error! rejoin ["serve takes a method, a path and a block, not " mold/flat first pos])
17
+ ]]
18
+ ; a later serve, as one in a test, answers before those it follows
19
+ insert test-routes new
20
+ true
21
+ ]
22
+
23
+ reply: func [
24
+ "An answer of serve with its status: reply 422 #(errors: ...)."
25
+ status [integer!]
26
+ data [any-type!]
27
+ ] [
28
+ make object! [reply-status: status reply-data: :data]
29
+ ]
30
+
31
+ ; The words a path gives: "/api/clients/:id" and "/api/clients/42" -> [id: "42"]; none if they do not match.
32
+ test-match: function [pattern [string!] path [string!]] [
33
+ want: split pattern #"/"
34
+ got: split path #"/"
35
+ if (length? want) <> length? got [return none]
36
+ words: copy []
37
+ repeat i length? want [
38
+ w: pick want i g: pick got i
39
+ case [
40
+ #":" = first w [append words reduce [to set-word! next w dehex g]]
41
+ w <> g [return none]
42
+ ]
43
+ ]
44
+ words
45
+ ]
46
+
47
+ test-answer: function [
48
+ "Called by the host for each request of the app: its status and its body as JSON, or none when serve has no answer for it."
49
+ method [word!] url [string!] body [string! none!]
50
+ ] [
51
+ path: url
52
+ query: make map! []
53
+ if q: find url #"?" [
54
+ path: copy/part url q
55
+ foreach part split next q #"&" [
56
+ kv: split part #"="
57
+ poke query to word! dehex first kv either second kv [dehex second kv] [""]
58
+ ]
59
+ ]
60
+ foreach [m pattern b] test-routes [
61
+ if all [m = method words: test-match pattern path] [
62
+ data: all [body any [attempt [load-json body] body]]
63
+ append words compose/only [body: (data) query: (query)]
64
+ r: do bind copy/deep b make object! words
65
+ return either all [object? :r in r 'reply-status] [
66
+ reduce [r/reply-status to-json :r/reply-data]
67
+ ] [
68
+ reduce [200 to-json :r]
69
+ ]
70
+ ]
71
+ ]
72
+ none
73
+ ]