@ember-joinery/test-support 0.0.0-stage → 1.1.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 (321) hide show
  1. package/CHANGELOG.md +574 -0
  2. package/LICENSE.md +9 -0
  3. package/NOTICE +532 -0
  4. package/README.md +356 -2
  5. package/addon-main.cjs +4 -0
  6. package/dist/-private/checkable.d.ts +21 -0
  7. package/dist/-private/checkable.d.ts.map +1 -0
  8. package/dist/-private/checkable.js +80 -0
  9. package/dist/-private/control.d.ts +18 -0
  10. package/dist/-private/control.d.ts.map +1 -0
  11. package/dist/-private/control.js +55 -0
  12. package/dist/-private/menu.d.ts +145 -0
  13. package/dist/-private/menu.d.ts.map +1 -0
  14. package/dist/-private/menu.js +322 -0
  15. package/dist/-private/overlay.d.ts +9 -0
  16. package/dist/-private/overlay.d.ts.map +1 -0
  17. package/dist/-private/overlay.js +39 -0
  18. package/dist/-private/showing.d.ts +7 -0
  19. package/dist/-private/showing.d.ts.map +1 -0
  20. package/dist/-private/showing.js +10 -0
  21. package/dist/-private/size.d.ts +10 -0
  22. package/dist/-private/size.d.ts.map +1 -0
  23. package/dist/-private/size.js +24 -0
  24. package/dist/-private/tree.d.ts +34 -0
  25. package/dist/-private/tree.d.ts.map +1 -0
  26. package/dist/-private/tree.js +80 -0
  27. package/dist/accordion.d.ts +62 -0
  28. package/dist/accordion.d.ts.map +1 -0
  29. package/dist/accordion.js +112 -0
  30. package/dist/alert-dialog.d.ts +24 -0
  31. package/dist/alert-dialog.d.ts.map +1 -0
  32. package/dist/alert-dialog.js +37 -0
  33. package/dist/alert.d.ts +27 -0
  34. package/dist/alert.d.ts.map +1 -0
  35. package/dist/alert.js +43 -0
  36. package/dist/app-shell.d.ts +43 -0
  37. package/dist/app-shell.d.ts.map +1 -0
  38. package/dist/app-shell.js +78 -0
  39. package/dist/aspect-ratio.d.ts +21 -0
  40. package/dist/aspect-ratio.d.ts.map +1 -0
  41. package/dist/aspect-ratio.js +30 -0
  42. package/dist/attachment.d.ts +86 -0
  43. package/dist/attachment.d.ts.map +1 -0
  44. package/dist/attachment.js +156 -0
  45. package/dist/avatar.d.ts +65 -0
  46. package/dist/avatar.d.ts.map +1 -0
  47. package/dist/avatar.js +106 -0
  48. package/dist/badge.d.ts +29 -0
  49. package/dist/badge.d.ts.map +1 -0
  50. package/dist/badge.js +49 -0
  51. package/dist/breadcrumb.d.ts +36 -0
  52. package/dist/breadcrumb.d.ts.map +1 -0
  53. package/dist/breadcrumb.js +80 -0
  54. package/dist/bubble.d.ts +56 -0
  55. package/dist/bubble.d.ts.map +1 -0
  56. package/dist/bubble.js +94 -0
  57. package/dist/button-group.d.ts +34 -0
  58. package/dist/button-group.d.ts.map +1 -0
  59. package/dist/button-group.js +62 -0
  60. package/dist/button.d.ts +37 -0
  61. package/dist/button.d.ts.map +1 -0
  62. package/dist/button.js +77 -0
  63. package/dist/calendar.d.ts +115 -0
  64. package/dist/calendar.d.ts.map +1 -0
  65. package/dist/calendar.js +276 -0
  66. package/dist/card.d.ts +31 -0
  67. package/dist/card.d.ts.map +1 -0
  68. package/dist/card.js +49 -0
  69. package/dist/checkbox.d.ts +46 -0
  70. package/dist/checkbox.d.ts.map +1 -0
  71. package/dist/checkbox.js +84 -0
  72. package/dist/child.d.ts +29 -0
  73. package/dist/child.d.ts.map +1 -0
  74. package/dist/child.js +27 -0
  75. package/dist/collapsible.d.ts +44 -0
  76. package/dist/collapsible.d.ts.map +1 -0
  77. package/dist/collapsible.js +83 -0
  78. package/dist/color-scheme.d.ts +44 -0
  79. package/dist/color-scheme.d.ts.map +1 -0
  80. package/dist/color-scheme.js +123 -0
  81. package/dist/combobox.d.ts +114 -0
  82. package/dist/combobox.d.ts.map +1 -0
  83. package/dist/combobox.js +293 -0
  84. package/dist/command.d.ts +92 -0
  85. package/dist/command.d.ts.map +1 -0
  86. package/dist/command.js +183 -0
  87. package/dist/context-menu.d.ts +37 -0
  88. package/dist/context-menu.d.ts.map +1 -0
  89. package/dist/context-menu.js +59 -0
  90. package/dist/date-picker.d.ts +48 -0
  91. package/dist/date-picker.d.ts.map +1 -0
  92. package/dist/date-picker.js +136 -0
  93. package/dist/dialog.d.ts +64 -0
  94. package/dist/dialog.d.ts.map +1 -0
  95. package/dist/dialog.js +142 -0
  96. package/dist/drawer.d.ts +63 -0
  97. package/dist/drawer.d.ts.map +1 -0
  98. package/dist/drawer.js +136 -0
  99. package/dist/dropdown-menu.d.ts +35 -0
  100. package/dist/dropdown-menu.d.ts.map +1 -0
  101. package/dist/dropdown-menu.js +49 -0
  102. package/dist/empty.d.ts +29 -0
  103. package/dist/empty.d.ts.map +1 -0
  104. package/dist/empty.js +47 -0
  105. package/dist/field.d.ts +86 -0
  106. package/dist/field.d.ts.map +1 -0
  107. package/dist/field.js +150 -0
  108. package/dist/file-drop.d.ts +74 -0
  109. package/dist/file-drop.d.ts.map +1 -0
  110. package/dist/file-drop.js +137 -0
  111. package/dist/focus.d.ts +54 -0
  112. package/dist/focus.d.ts.map +1 -0
  113. package/dist/focus.js +174 -0
  114. package/dist/harness.d.ts +90 -0
  115. package/dist/harness.d.ts.map +1 -0
  116. package/dist/harness.js +189 -0
  117. package/dist/heading.d.ts +16 -0
  118. package/dist/heading.d.ts.map +1 -0
  119. package/dist/heading.js +19 -0
  120. package/dist/hero.d.ts +21 -0
  121. package/dist/hero.d.ts.map +1 -0
  122. package/dist/hero.js +28 -0
  123. package/dist/hover-card.d.ts +46 -0
  124. package/dist/hover-card.d.ts.map +1 -0
  125. package/dist/hover-card.js +85 -0
  126. package/dist/icon.d.ts +10 -0
  127. package/dist/icon.d.ts.map +1 -0
  128. package/dist/icon.js +13 -0
  129. package/dist/index.d.ts +98 -0
  130. package/dist/index.d.ts.map +1 -0
  131. package/dist/index.js +99 -0
  132. package/dist/input-group.d.ts +55 -0
  133. package/dist/input-group.d.ts.map +1 -0
  134. package/dist/input-group.js +103 -0
  135. package/dist/input-otp.d.ts +103 -0
  136. package/dist/input-otp.d.ts.map +1 -0
  137. package/dist/input-otp.js +293 -0
  138. package/dist/input.d.ts +53 -0
  139. package/dist/input.d.ts.map +1 -0
  140. package/dist/input.js +90 -0
  141. package/dist/inspector.d.ts +47 -0
  142. package/dist/inspector.d.ts.map +1 -0
  143. package/dist/inspector.js +97 -0
  144. package/dist/item.d.ts +63 -0
  145. package/dist/item.d.ts.map +1 -0
  146. package/dist/item.js +104 -0
  147. package/dist/kbd.d.ts +28 -0
  148. package/dist/kbd.d.ts.map +1 -0
  149. package/dist/kbd.js +36 -0
  150. package/dist/keys.d.ts +20 -0
  151. package/dist/keys.d.ts.map +1 -0
  152. package/dist/keys.js +32 -0
  153. package/dist/label.d.ts +24 -0
  154. package/dist/label.d.ts.map +1 -0
  155. package/dist/label.js +39 -0
  156. package/dist/layers.d.ts +42 -0
  157. package/dist/layers.d.ts.map +1 -0
  158. package/dist/layers.js +70 -0
  159. package/dist/link.d.ts +44 -0
  160. package/dist/link.d.ts.map +1 -0
  161. package/dist/link.js +60 -0
  162. package/dist/marker.d.ts +42 -0
  163. package/dist/marker.d.ts.map +1 -0
  164. package/dist/marker.js +73 -0
  165. package/dist/menubar.d.ts +76 -0
  166. package/dist/menubar.d.ts.map +1 -0
  167. package/dist/menubar.js +139 -0
  168. package/dist/message-scroller.d.ts +101 -0
  169. package/dist/message-scroller.d.ts.map +1 -0
  170. package/dist/message-scroller.js +215 -0
  171. package/dist/message.d.ts +48 -0
  172. package/dist/message.d.ts.map +1 -0
  173. package/dist/message.js +72 -0
  174. package/dist/native-form.d.ts +44 -0
  175. package/dist/native-form.d.ts.map +1 -0
  176. package/dist/native-form.js +111 -0
  177. package/dist/native-select.d.ts +56 -0
  178. package/dist/native-select.d.ts.map +1 -0
  179. package/dist/native-select.js +100 -0
  180. package/dist/navigation-bar.d.ts +30 -0
  181. package/dist/navigation-bar.d.ts.map +1 -0
  182. package/dist/navigation-bar.js +52 -0
  183. package/dist/navigation-menu.d.ts +97 -0
  184. package/dist/navigation-menu.d.ts.map +1 -0
  185. package/dist/navigation-menu.js +207 -0
  186. package/dist/navigation-stack.d.ts +36 -0
  187. package/dist/navigation-stack.d.ts.map +1 -0
  188. package/dist/navigation-stack.js +67 -0
  189. package/dist/observers.d.ts +21 -0
  190. package/dist/observers.d.ts.map +1 -0
  191. package/dist/observers.js +34 -0
  192. package/dist/page.d.ts +38 -0
  193. package/dist/page.d.ts.map +1 -0
  194. package/dist/page.js +68 -0
  195. package/dist/pagination.d.ts +39 -0
  196. package/dist/pagination.d.ts.map +1 -0
  197. package/dist/pagination.js +71 -0
  198. package/dist/pointer.d.ts +38 -0
  199. package/dist/pointer.d.ts.map +1 -0
  200. package/dist/pointer.js +82 -0
  201. package/dist/popover.d.ts +50 -0
  202. package/dist/popover.d.ts.map +1 -0
  203. package/dist/popover.js +90 -0
  204. package/dist/progress.d.ts +38 -0
  205. package/dist/progress.d.ts.map +1 -0
  206. package/dist/progress.js +81 -0
  207. package/dist/pull-to-refresh.d.ts +40 -0
  208. package/dist/pull-to-refresh.d.ts.map +1 -0
  209. package/dist/pull-to-refresh.js +65 -0
  210. package/dist/questionnaire.d.ts +117 -0
  211. package/dist/questionnaire.d.ts.map +1 -0
  212. package/dist/questionnaire.js +240 -0
  213. package/dist/radio-group.d.ts +53 -0
  214. package/dist/radio-group.d.ts.map +1 -0
  215. package/dist/radio-group.js +95 -0
  216. package/dist/rating.d.ts +67 -0
  217. package/dist/rating.d.ts.map +1 -0
  218. package/dist/rating.js +160 -0
  219. package/dist/resizable.d.ts +76 -0
  220. package/dist/resizable.d.ts.map +1 -0
  221. package/dist/resizable.js +138 -0
  222. package/dist/routing.d.ts +36 -0
  223. package/dist/routing.d.ts.map +1 -0
  224. package/dist/routing.js +50 -0
  225. package/dist/roving-focus.d.ts +38 -0
  226. package/dist/roving-focus.d.ts.map +1 -0
  227. package/dist/roving-focus.js +60 -0
  228. package/dist/scroll-area.d.ts +58 -0
  229. package/dist/scroll-area.d.ts.map +1 -0
  230. package/dist/scroll-area.js +153 -0
  231. package/dist/scroller.d.ts +41 -0
  232. package/dist/scroller.d.ts.map +1 -0
  233. package/dist/scroller.js +65 -0
  234. package/dist/select.d.ts +98 -0
  235. package/dist/select.d.ts.map +1 -0
  236. package/dist/select.js +203 -0
  237. package/dist/selectors.d.ts +44 -0
  238. package/dist/selectors.d.ts.map +1 -0
  239. package/dist/selectors.js +63 -0
  240. package/dist/send-pointer.d.ts +17 -0
  241. package/dist/send-pointer.d.ts.map +1 -0
  242. package/dist/send-pointer.js +35 -0
  243. package/dist/separator.d.ts +26 -0
  244. package/dist/separator.d.ts.map +1 -0
  245. package/dist/separator.js +40 -0
  246. package/dist/shadowed.d.ts +55 -0
  247. package/dist/shadowed.d.ts.map +1 -0
  248. package/dist/shadowed.js +97 -0
  249. package/dist/sheet.d.ts +14 -0
  250. package/dist/sheet.d.ts.map +1 -0
  251. package/dist/sheet.js +15 -0
  252. package/dist/sidebar.d.ts +159 -0
  253. package/dist/sidebar.d.ts.map +1 -0
  254. package/dist/sidebar.js +299 -0
  255. package/dist/skeleton.d.ts +18 -0
  256. package/dist/skeleton.d.ts.map +1 -0
  257. package/dist/skeleton.js +25 -0
  258. package/dist/slider.d.ts +66 -0
  259. package/dist/slider.d.ts.map +1 -0
  260. package/dist/slider.js +155 -0
  261. package/dist/spinner.d.ts +10 -0
  262. package/dist/spinner.d.ts.map +1 -0
  263. package/dist/spinner.js +13 -0
  264. package/dist/split-view.d.ts +77 -0
  265. package/dist/split-view.d.ts.map +1 -0
  266. package/dist/split-view.js +145 -0
  267. package/dist/status-bar.d.ts +25 -0
  268. package/dist/status-bar.d.ts.map +1 -0
  269. package/dist/status-bar.js +42 -0
  270. package/dist/sticky-footer.d.ts +33 -0
  271. package/dist/sticky-footer.d.ts.map +1 -0
  272. package/dist/sticky-footer.js +65 -0
  273. package/dist/switch.d.ts +44 -0
  274. package/dist/switch.d.ts.map +1 -0
  275. package/dist/switch.js +77 -0
  276. package/dist/tab-bar.d.ts +38 -0
  277. package/dist/tab-bar.d.ts.map +1 -0
  278. package/dist/tab-bar.js +78 -0
  279. package/dist/table.d.ts +41 -0
  280. package/dist/table.d.ts.map +1 -0
  281. package/dist/table.js +100 -0
  282. package/dist/tabs.d.ts +66 -0
  283. package/dist/tabs.d.ts.map +1 -0
  284. package/dist/tabs.js +149 -0
  285. package/dist/test-hooks.d.ts +9 -0
  286. package/dist/test-hooks.d.ts.map +1 -0
  287. package/dist/test-hooks.js +1 -0
  288. package/dist/textarea.d.ts +47 -0
  289. package/dist/textarea.d.ts.map +1 -0
  290. package/dist/textarea.js +78 -0
  291. package/dist/title-bar.d.ts +43 -0
  292. package/dist/title-bar.d.ts.map +1 -0
  293. package/dist/title-bar.js +74 -0
  294. package/dist/toaster.d.ts +172 -0
  295. package/dist/toaster.d.ts.map +1 -0
  296. package/dist/toaster.js +307 -0
  297. package/dist/toggle-group.d.ts +51 -0
  298. package/dist/toggle-group.d.ts.map +1 -0
  299. package/dist/toggle-group.js +97 -0
  300. package/dist/toggle.d.ts +21 -0
  301. package/dist/toggle.d.ts.map +1 -0
  302. package/dist/toggle.js +26 -0
  303. package/dist/toolbar.d.ts +40 -0
  304. package/dist/toolbar.d.ts.map +1 -0
  305. package/dist/toolbar.js +67 -0
  306. package/dist/tooltip.d.ts +48 -0
  307. package/dist/tooltip.d.ts.map +1 -0
  308. package/dist/tooltip.js +91 -0
  309. package/dist/trace.d.ts +118 -0
  310. package/dist/trace.d.ts.map +1 -0
  311. package/dist/trace.js +196 -0
  312. package/dist/translator.d.ts +34 -0
  313. package/dist/translator.d.ts.map +1 -0
  314. package/dist/translator.js +75 -0
  315. package/dist/window-frame.d.ts +40 -0
  316. package/dist/window-frame.d.ts.map +1 -0
  317. package/dist/window-frame.js +66 -0
  318. package/dist/zoetrope.d.ts +51 -0
  319. package/dist/zoetrope.d.ts.map +1 -0
  320. package/dist/zoetrope.js +94 -0
  321. package/package.json +68 -3
package/dist/field.js ADDED
@@ -0,0 +1,150 @@
1
+ import { Harness } from "./harness.js";
2
+ import { textOf } from "./-private/checkable.js";
3
+ /** The nearest field-family root an element is in: a field, field set or field group. */
4
+ function fieldOf(element) {
5
+ return element.closest('[data-test-jn="field"]');
6
+ }
7
+ /**
8
+ * Drives a `<Field>` from `@ember-joinery/ember`: reads its label, description and error, and
9
+ * its state, and finds the control inside it with `find()`.
10
+ *
11
+ * const email = new FieldHarness('email') // <Field @name="email">
12
+ * assert.strictEqual(email.label, 'Email')
13
+ * assert.strictEqual(email.error, 'Enter a valid email address.')
14
+ * assert.true(email.isInvalid)
15
+ * await email.find(InputHarness).fillIn('ada@example.com')
16
+ */
17
+ export class FieldHarness extends Harness {
18
+ static component = 'field';
19
+ /** All the text it shows, whitespace collapsed. */
20
+ get text() {
21
+ return textOf(this.element);
22
+ }
23
+ /**
24
+ * Its label: the `<FieldLabel>` or `<FieldTitle>` in it (both are `data-slot="field-label"`),
25
+ * not one in a field inside it; else a plain `<Label>` or `<label>` in it; else the
26
+ * `<FieldLabel>` around it, as in a choice card. `null` when it has none.
27
+ */
28
+ get labelElement() {
29
+ const root = this.element;
30
+ const own = (selector) => [...root.querySelectorAll(selector)].find(element => fieldOf(element) === root);
31
+ return (own('[data-slot="field-label"]') ??
32
+ own('label') ??
33
+ root.parentElement?.closest('[data-slot="field-label"]') ??
34
+ null);
35
+ }
36
+ /** Its label's text, or `''` without one. */
37
+ get label() {
38
+ const label = this.labelElement;
39
+ return label ? textOf(label) : '';
40
+ }
41
+ /** The control its `<FieldLabel>` labels, as the browser works it out, or `null`. */
42
+ get control() {
43
+ const label = this.labelElement;
44
+ return label instanceof HTMLLabelElement ? label.control : null;
45
+ }
46
+ /** Each `<FieldDescription>`'s text, in order. */
47
+ get descriptions() {
48
+ return this.parts('description').map(textOf);
49
+ }
50
+ /** Its descriptions' text, joined with a space, or `''` without one. */
51
+ get description() {
52
+ return this.descriptions.join(' ');
53
+ }
54
+ /** Its `<FieldError>`, while one shows, or `null`. */
55
+ get errorElement() {
56
+ return this.queryPart('error');
57
+ }
58
+ /** The error it shows, or `''` without one: a list of errors' text, joined with a space. */
59
+ get error() {
60
+ const error = this.errorElement;
61
+ return error ? textOf(error) : '';
62
+ }
63
+ /** Each error it shows: one, or each item of the list `@errors` renders for several. */
64
+ get errors() {
65
+ const error = this.errorElement;
66
+ if (!error)
67
+ return [];
68
+ const items = [...error.querySelectorAll('li')];
69
+ return items.length ? items.map(textOf) : [textOf(error)];
70
+ }
71
+ /** Whether it is in its error state (`data-invalid="true"`). */
72
+ get isInvalid() {
73
+ return this.element.getAttribute('data-invalid') === 'true';
74
+ }
75
+ /** Whether it shows as disabled (`data-disabled="true"`). */
76
+ get isDisabled() {
77
+ return this.element.getAttribute('data-disabled') === 'true';
78
+ }
79
+ /** `vertical`, `horizontal` or `responsive` (`data-orientation`). */
80
+ get orientation() {
81
+ return this.element.getAttribute('data-orientation');
82
+ }
83
+ /** Its `<FieldContent>`, or `null`. */
84
+ get content() {
85
+ return this.queryPart('content');
86
+ }
87
+ /** Its `<FieldTitle>`'s text, or `''` without one. */
88
+ get title() {
89
+ const title = this.queryPart('title');
90
+ return title ? textOf(title) : '';
91
+ }
92
+ }
93
+ /**
94
+ * Drives a `<FieldSet>` from `@ember-joinery/ember`: its legend and description, and the
95
+ * fields in it.
96
+ *
97
+ * const address = new FieldSetHarness('address') // <FieldSet @name="address">
98
+ * assert.strictEqual(address.legend, 'Address Information')
99
+ * assert.deepEqual(address.fields.map(field => field.label), ['Street Address', 'City'])
100
+ */
101
+ export class FieldSetHarness extends Harness {
102
+ static component = 'field-set';
103
+ /** All the text it shows, whitespace collapsed. */
104
+ get text() {
105
+ return textOf(this.element);
106
+ }
107
+ /** Its `<FieldLegend>`'s text, or `''` without one. */
108
+ get legend() {
109
+ const legend = this.queryPart('legend');
110
+ return legend ? textOf(legend) : '';
111
+ }
112
+ /** Its legend's `@variant`: `legend` or `label`, or `null` without a legend. */
113
+ get legendVariant() {
114
+ return this.queryPart('legend')?.getAttribute('data-variant') ?? null;
115
+ }
116
+ /** Its own `<FieldDescription>`s' text, joined with a space (not its fields'). */
117
+ get description() {
118
+ return this.parts('description').map(textOf).join(' ');
119
+ }
120
+ /** A harness for each field in it, in order, nested ones included. */
121
+ get fields() {
122
+ return this.findAll(FieldHarness);
123
+ }
124
+ /** Whether it is disabled, which disables every control in it (`<fieldset disabled>`). */
125
+ get isDisabled() {
126
+ return this.element.matches(':disabled');
127
+ }
128
+ }
129
+ /**
130
+ * Drives a `<FieldGroup>` from `@ember-joinery/ember`: the fields in it and the text of its
131
+ * separators.
132
+ *
133
+ * const group = new FieldGroupHarness()
134
+ * assert.deepEqual(group.separators, ['Or continue with'])
135
+ */
136
+ export class FieldGroupHarness extends Harness {
137
+ static component = 'field-group';
138
+ /** A harness for each field in it, in order, nested ones included. */
139
+ get fields() {
140
+ return this.findAll(FieldHarness);
141
+ }
142
+ /** A harness for each field set in it, in order. */
143
+ get fieldSets() {
144
+ return this.findAll(FieldSetHarness);
145
+ }
146
+ /** Each `<FieldSeparator>`'s text, in order: `''` for a plain line. */
147
+ get separators() {
148
+ return this.parts('separator').map(textOf);
149
+ }
150
+ }
@@ -0,0 +1,74 @@
1
+ import { Harness } from './harness.ts';
2
+ /**
3
+ * Drags `files` over `target`, as a user does from the desktop: `dragenter`, then `dragover`.
4
+ * Returns whether the page allows a drop there (it cancelled the `dragover`).
5
+ *
6
+ * await dragFilesOver(document.body, [new File(['…'], 'clip.mp4', { type: 'video/mp4' })])
7
+ */
8
+ export declare function dragFilesOver(target: Element | Document, files: File[]): Promise<boolean>;
9
+ /** Drags files away from `target` again: a `dragleave`. */
10
+ export declare function dragFilesAway(target: Element | Document, files?: File[]): Promise<void>;
11
+ /**
12
+ * Drops `files` on `target`: `dragenter`, `dragover`, then `drop`. Returns whether the page
13
+ * took the drop (it cancelled it, so the browser doesn't open the file in the tab).
14
+ */
15
+ export declare function dropFiles(target: Element | Document, files: File[]): Promise<boolean>;
16
+ /**
17
+ * Drives a `<FileDrop>` from `@ember-joinery/ember`, or the headless one from
18
+ * `@ember-joinery/primitives/file-drop`: picks files as the file picker does, and drags and
19
+ * drops them as a user does. For a `<DocumentFileDrop>`, which has no element, use
20
+ * `dropFiles(document.body, files)`.
21
+ *
22
+ * const zone = new FileDropHarness('avatar') // <FileDrop @name="avatar">
23
+ * await zone.drop([new File(['…'], 'me.png', { type: 'image/png' })])
24
+ */
25
+ export declare class FileDropHarness extends Harness {
26
+ static component: string;
27
+ /** The text it shows, which names its input. */
28
+ get text(): string;
29
+ /** Its visually hidden `<input type="file">`. */
30
+ get input(): HTMLInputElement;
31
+ /** Which files it takes (`accept`), or `''` for any. */
32
+ get accept(): string;
33
+ /** Whether it takes more than one file. */
34
+ get isMultiple(): boolean;
35
+ /** Whether it takes no files (its input is disabled). */
36
+ get isDisabled(): boolean;
37
+ /** Whether files are dragged over it (`data-dragging`). */
38
+ get isDragging(): boolean;
39
+ /** Whether its input has focus, which is how a keyboard user reaches the zone. */
40
+ get isFocused(): boolean;
41
+ /** Picks `files` in the file picker: its input's `change`. */
42
+ pick(files: File[]): Promise<void>;
43
+ /** Drags `files` over it. Returns whether it allows the drop. */
44
+ drag(files: File[]): Promise<boolean>;
45
+ /** Drags the files away again. */
46
+ leave(): Promise<void>;
47
+ /** Drops `files` on it. Returns whether it took the drop. */
48
+ drop(files: File[]): Promise<boolean>;
49
+ }
50
+ /**
51
+ * Drives the overlay of a `<DocumentFileDrop>` from `@ember-joinery/ember`, which shows only
52
+ * while files are dragged over the page: it drags and drops files on the page, as a user does.
53
+ * (The headless one from `@ember-joinery/primitives/file-drop` renders nothing of its own; use
54
+ * `dragFilesOver` and `dropFiles` on `document.body`.)
55
+ *
56
+ * const page = new DocumentFileDropHarness()
57
+ * await page.drag([file])
58
+ * assert.true(page.isShown)
59
+ * await page.drop([file])
60
+ */
61
+ export declare class DocumentFileDropHarness extends Harness {
62
+ static component: string;
63
+ /** Whether its overlay shows: files are dragged over the page. */
64
+ get isShown(): boolean;
65
+ /** What its overlay says, or `''` while it is hidden. */
66
+ get text(): string;
67
+ /** Drags `files` over the page. Returns whether the page allows the drop. */
68
+ drag(files: File[]): Promise<boolean>;
69
+ /** Drags the files away from the page again. */
70
+ leave(): Promise<void>;
71
+ /** Drops `files` on the page. Returns whether the page took the drop. */
72
+ drop(files: File[]): Promise<boolean>;
73
+ }
74
+ //# sourceMappingURL=file-drop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-drop.d.ts","sourceRoot":"","sources":["../src/file-drop.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAoBtC;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAK/F;AAED,2DAA2D;AAC3D,wBAAsB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,QAAQ,EAAE,KAAK,GAAE,IAAI,EAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAGjG;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAM3F;AAED;;;;;;;;GAQG;AACH,qBAAa,eAAgB,SAAQ,OAAO;IAC1C,OAAgB,SAAS,SAAc;IAEvC,gDAAgD;IAChD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,iDAAiD;IACjD,IAAI,KAAK,IAAI,gBAAgB,CAE5B;IAED,wDAAwD;IACxD,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,2CAA2C;IAC3C,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,yDAAyD;IACzD,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,2DAA2D;IAC3D,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,kFAAkF;IAClF,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,8DAA8D;IACxD,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC,iEAAiE;IAC3D,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3C,kCAAkC;IAC5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,6DAA6D;IACvD,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CAG5C;AAED;;;;;;;;;;GAUG;AACH,qBAAa,uBAAwB,SAAQ,OAAO;IAClD,OAAgB,SAAS,SAAuB;IAEhD,kEAAkE;IAClE,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,yDAAyD;IACzD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,6EAA6E;IACvE,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3C,gDAAgD;IAC1C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,yEAAyE;IACnE,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CAG5C"}
@@ -0,0 +1,137 @@
1
+ import { settled, triggerEvent } from '@ember/test-helpers';
2
+ import { Harness } from "./harness.js";
3
+ import { textOf } from "./-private/checkable.js";
4
+ /** A drag's data: the files, which also make its types include `Files`. */
5
+ function transferOf(files) {
6
+ const transfer = new DataTransfer();
7
+ for (const file of files)
8
+ transfer.items.add(file);
9
+ return transfer;
10
+ }
11
+ function dispatch(target, type, files) {
12
+ const event = new DragEvent(type, {
13
+ bubbles: true,
14
+ cancelable: true,
15
+ dataTransfer: transferOf(files),
16
+ });
17
+ target.dispatchEvent(event);
18
+ return event;
19
+ }
20
+ /**
21
+ * Drags `files` over `target`, as a user does from the desktop: `dragenter`, then `dragover`.
22
+ * Returns whether the page allows a drop there (it cancelled the `dragover`).
23
+ *
24
+ * await dragFilesOver(document.body, [new File(['…'], 'clip.mp4', { type: 'video/mp4' })])
25
+ */
26
+ export async function dragFilesOver(target, files) {
27
+ dispatch(target, 'dragenter', files);
28
+ const over = dispatch(target, 'dragover', files);
29
+ await settled();
30
+ return over.defaultPrevented;
31
+ }
32
+ /** Drags files away from `target` again: a `dragleave`. */
33
+ export async function dragFilesAway(target, files = []) {
34
+ dispatch(target, 'dragleave', files.length ? files : [new File([], 'file')]);
35
+ await settled();
36
+ }
37
+ /**
38
+ * Drops `files` on `target`: `dragenter`, `dragover`, then `drop`. Returns whether the page
39
+ * took the drop (it cancelled it, so the browser doesn't open the file in the tab).
40
+ */
41
+ export async function dropFiles(target, files) {
42
+ dispatch(target, 'dragenter', files);
43
+ dispatch(target, 'dragover', files);
44
+ const drop = dispatch(target, 'drop', files);
45
+ await settled();
46
+ return drop.defaultPrevented;
47
+ }
48
+ /**
49
+ * Drives a `<FileDrop>` from `@ember-joinery/ember`, or the headless one from
50
+ * `@ember-joinery/primitives/file-drop`: picks files as the file picker does, and drags and
51
+ * drops them as a user does. For a `<DocumentFileDrop>`, which has no element, use
52
+ * `dropFiles(document.body, files)`.
53
+ *
54
+ * const zone = new FileDropHarness('avatar') // <FileDrop @name="avatar">
55
+ * await zone.drop([new File(['…'], 'me.png', { type: 'image/png' })])
56
+ */
57
+ export class FileDropHarness extends Harness {
58
+ static component = 'file-drop';
59
+ /** The text it shows, which names its input. */
60
+ get text() {
61
+ return textOf(this.element);
62
+ }
63
+ /** Its visually hidden `<input type="file">`. */
64
+ get input() {
65
+ return this.part('input');
66
+ }
67
+ /** Which files it takes (`accept`), or `''` for any. */
68
+ get accept() {
69
+ return this.input.accept;
70
+ }
71
+ /** Whether it takes more than one file. */
72
+ get isMultiple() {
73
+ return this.input.multiple;
74
+ }
75
+ /** Whether it takes no files (its input is disabled). */
76
+ get isDisabled() {
77
+ return this.input.disabled;
78
+ }
79
+ /** Whether files are dragged over it (`data-dragging`). */
80
+ get isDragging() {
81
+ return this.element.hasAttribute('data-dragging');
82
+ }
83
+ /** Whether its input has focus, which is how a keyboard user reaches the zone. */
84
+ get isFocused() {
85
+ return this.element.ownerDocument.activeElement === this.input;
86
+ }
87
+ /** Picks `files` in the file picker: its input's `change`. */
88
+ async pick(files) {
89
+ await triggerEvent(this.input, 'change', { files });
90
+ }
91
+ /** Drags `files` over it. Returns whether it allows the drop. */
92
+ async drag(files) {
93
+ return dragFilesOver(this.element, files);
94
+ }
95
+ /** Drags the files away again. */
96
+ async leave() {
97
+ await dragFilesAway(this.element);
98
+ }
99
+ /** Drops `files` on it. Returns whether it took the drop. */
100
+ async drop(files) {
101
+ return dropFiles(this.element, files);
102
+ }
103
+ }
104
+ /**
105
+ * Drives the overlay of a `<DocumentFileDrop>` from `@ember-joinery/ember`, which shows only
106
+ * while files are dragged over the page: it drags and drops files on the page, as a user does.
107
+ * (The headless one from `@ember-joinery/primitives/file-drop` renders nothing of its own; use
108
+ * `dragFilesOver` and `dropFiles` on `document.body`.)
109
+ *
110
+ * const page = new DocumentFileDropHarness()
111
+ * await page.drag([file])
112
+ * assert.true(page.isShown)
113
+ * await page.drop([file])
114
+ */
115
+ export class DocumentFileDropHarness extends Harness {
116
+ static component = 'document-file-drop';
117
+ /** Whether its overlay shows: files are dragged over the page. */
118
+ get isShown() {
119
+ return this.exists;
120
+ }
121
+ /** What its overlay says, or `''` while it is hidden. */
122
+ get text() {
123
+ return this.exists ? textOf(this.element) : '';
124
+ }
125
+ /** Drags `files` over the page. Returns whether the page allows the drop. */
126
+ async drag(files) {
127
+ return dragFilesOver(document.body, files);
128
+ }
129
+ /** Drags the files away from the page again. */
130
+ async leave() {
131
+ await dragFilesAway(document.body);
132
+ }
133
+ /** Drops `files` on the page. Returns whether the page took the drop. */
134
+ async drop(files) {
135
+ return dropFiles(document.body, files);
136
+ }
137
+ }
@@ -0,0 +1,54 @@
1
+ /** The modifier keys held while a key is pressed. */
2
+ export interface KeyModifiers {
3
+ shiftKey?: boolean;
4
+ ctrlKey?: boolean;
5
+ altKey?: boolean;
6
+ metaKey?: boolean;
7
+ }
8
+ /**
9
+ * Presses one key on the focused element (or `<body>`): `keydown`, then `keyup` unless the
10
+ * key moved focus, which then goes to the element focused now. `key` is a `KeyboardEvent#key`
11
+ * value: `'ArrowDown'`, `'Home'`, `'a'`, `' '`. It sends only the key events, so it doesn't
12
+ * type into inputs or click buttons; use `typeIn` and `click` for those.
13
+ *
14
+ * await focus(harness.item('bold'))
15
+ * await pressKey('ArrowRight')
16
+ * assert.dom(harness.item('italic')).isFocused()
17
+ *
18
+ * @returns whether the page called `preventDefault()` on the `keydown`.
19
+ */
20
+ export declare function pressKey(key: string, modifiers?: KeyModifiers): Promise<boolean>;
21
+ /**
22
+ * Types each character of `text` as a key press on the focused element, for typeahead: in a
23
+ * menu, a listbox or a select, typing the start of an item's text moves to it.
24
+ *
25
+ * await typeKeys('ba') // to "Banana"
26
+ *
27
+ * Like `pressKey`, it sends key events only; it doesn't put text into an input (`typeIn` does).
28
+ */
29
+ export declare function typeKeys(text: string, modifiers?: KeyModifiers): Promise<void>;
30
+ /**
31
+ * The elements the Tab key visits in `within` (default: the whole page), in the order a
32
+ * browser visits them: positive `tabindex`es first, lowest first, then the rest in document
33
+ * order. Of each group of native radio buttons, only the checked one is in the order, or every
34
+ * one when none is checked (the browser stops at the first it comes to). The test runner's own
35
+ * controls (QUnit's toolbar, testem's frame) are left out.
36
+ *
37
+ * assert.deepEqual(tabOrder(form).map(e => e.id), ['name', 'email', 'save'])
38
+ */
39
+ export declare function tabOrder(within?: Element): HTMLElement[];
40
+ /**
41
+ * Presses Tab (or Shift+Tab, with `{ shift: true }`) as a browser does: the focused element
42
+ * gets the `keydown`, and unless the page prevents it, focus moves to the next element in the
43
+ * tab order (see `tabOrder`). Past the last element, focus leaves the page, as when the browser
44
+ * moves it to its own toolbar: nothing is focused afterwards. Tests can't press the real Tab
45
+ * key, so this is how they check a focus trap or a roving tab stop.
46
+ *
47
+ * await tab()
48
+ * assert.dom(dialog.closeButton).isFocused()
49
+ * await tab({ shift: true })
50
+ */
51
+ export declare function tab(options?: {
52
+ shift?: boolean;
53
+ }): Promise<void>;
54
+ //# sourceMappingURL=focus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus.d.ts","sourceRoot":"","sources":["../src/focus.ts"],"names":[],"mappings":"AAEA,qDAAqD;AACrD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AA0BD;;;;;;;;;;;GAWG;AACH,wBAAsB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,GAAE,YAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,CAM1F;AAED;;;;;;;GAOG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAExF;AAkDD;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,MAAM,GAAE,OAAuB,GAAG,WAAW,EAAE,CAcvE;AA2BD;;;;;;;;;;GAUG;AACH,wBAAsB,GAAG,CAAC,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAY1E"}
package/dist/focus.js ADDED
@@ -0,0 +1,174 @@
1
+ import { blur, focus, settled } from '@ember/test-helpers';
2
+ /** The element that has focus, or `<body>` when nothing does. */
3
+ function focused() {
4
+ return document.activeElement ?? document.body;
5
+ }
6
+ /** Dispatches one keyboard event the way a browser does, and returns it. */
7
+ function dispatchKey(target, type, key, modifiers) {
8
+ const event = new KeyboardEvent(type, {
9
+ key,
10
+ bubbles: true,
11
+ cancelable: true,
12
+ composed: true,
13
+ view: window,
14
+ ...modifiers,
15
+ });
16
+ target.dispatchEvent(event);
17
+ return event;
18
+ }
19
+ /**
20
+ * Presses one key on the focused element (or `<body>`): `keydown`, then `keyup` unless the
21
+ * key moved focus, which then goes to the element focused now. `key` is a `KeyboardEvent#key`
22
+ * value: `'ArrowDown'`, `'Home'`, `'a'`, `' '`. It sends only the key events, so it doesn't
23
+ * type into inputs or click buttons; use `typeIn` and `click` for those.
24
+ *
25
+ * await focus(harness.item('bold'))
26
+ * await pressKey('ArrowRight')
27
+ * assert.dom(harness.item('italic')).isFocused()
28
+ *
29
+ * @returns whether the page called `preventDefault()` on the `keydown`.
30
+ */
31
+ export async function pressKey(key, modifiers = {}) {
32
+ const down = dispatchKey(focused(), 'keydown', key, modifiers);
33
+ await settled();
34
+ dispatchKey(focused(), 'keyup', key, modifiers);
35
+ await settled();
36
+ return down.defaultPrevented;
37
+ }
38
+ /**
39
+ * Types each character of `text` as a key press on the focused element, for typeahead: in a
40
+ * menu, a listbox or a select, typing the start of an item's text moves to it.
41
+ *
42
+ * await typeKeys('ba') // to "Banana"
43
+ *
44
+ * Like `pressKey`, it sends key events only; it doesn't put text into an input (`typeIn` does).
45
+ */
46
+ export async function typeKeys(text, modifiers = {}) {
47
+ for (const character of text)
48
+ await pressKey(character, modifiers);
49
+ }
50
+ // ----- The Tab key ---------------------------------------------------------------------------
51
+ /**
52
+ * The test runner's own controls, which aren't part of the page under test: QUnit's toolbar
53
+ * and testem's connection frame.
54
+ */
55
+ const RUNNER = '#qunit, iframe[src*="/testem/"]';
56
+ /** Whether anything about the element or above it keeps it out of the tab order. */
57
+ function isHidden(element) {
58
+ if (element.closest('[inert]'))
59
+ return true;
60
+ for (let node = element; node; node = node.parentElement) {
61
+ if (node instanceof HTMLElement && node.hidden)
62
+ return true;
63
+ const parent = node.parentElement;
64
+ if (parent instanceof HTMLDetailsElement && !parent.open) {
65
+ if (node !== parent.querySelector(':scope > summary'))
66
+ return true;
67
+ }
68
+ }
69
+ const styles = getComputedStyle(element);
70
+ if (styles.visibility === 'hidden' || styles.display === 'none')
71
+ return true;
72
+ // checkVisibility() sees display: none and content-visibility on every ancestor.
73
+ return 'checkVisibility' in element && !element.checkVisibility();
74
+ }
75
+ /** Whether the browser's Tab key would stop at `element`, apart from radio groups. */
76
+ function isTabbable(element) {
77
+ if (!(element instanceof HTMLElement))
78
+ return false;
79
+ if (element.tabIndex < 0)
80
+ return false;
81
+ if (element.matches(':disabled'))
82
+ return false;
83
+ if (element instanceof HTMLInputElement && element.type === 'hidden')
84
+ return false;
85
+ if ((element instanceof HTMLAnchorElement || element instanceof HTMLAreaElement) &&
86
+ !element.hasAttribute('href') &&
87
+ !element.hasAttribute('tabindex')) {
88
+ return false;
89
+ }
90
+ return !isHidden(element) && !element.closest(RUNNER);
91
+ }
92
+ /** A native radio button that's in a named group. */
93
+ function groupOf(element) {
94
+ if (!(element instanceof HTMLInputElement) || element.type !== 'radio' || !element.name) {
95
+ return undefined;
96
+ }
97
+ return `${element.form ? 'form' : 'document'}:${element.name}`;
98
+ }
99
+ /**
100
+ * The elements the Tab key visits in `within` (default: the whole page), in the order a
101
+ * browser visits them: positive `tabindex`es first, lowest first, then the rest in document
102
+ * order. Of each group of native radio buttons, only the checked one is in the order, or every
103
+ * one when none is checked (the browser stops at the first it comes to). The test runner's own
104
+ * controls (QUnit's toolbar, testem's frame) are left out.
105
+ *
106
+ * assert.deepEqual(tabOrder(form).map(e => e.id), ['name', 'email', 'save'])
107
+ */
108
+ export function tabOrder(within = document.body) {
109
+ const elements = [...within.querySelectorAll('*')].filter(isTabbable);
110
+ const checked = new Set();
111
+ for (const element of elements) {
112
+ const group = groupOf(element);
113
+ if (group && element.checked)
114
+ checked.add(group);
115
+ }
116
+ const inOrder = elements.filter(element => {
117
+ const group = groupOf(element);
118
+ return !group || !checked.has(group) || element.checked;
119
+ });
120
+ const positive = inOrder.filter(element => element.tabIndex > 0);
121
+ positive.sort((a, b) => a.tabIndex - b.tabIndex);
122
+ return [...positive, ...inOrder.filter(element => element.tabIndex === 0)];
123
+ }
124
+ /** Where the Tab key goes from `current` through `order`; `undefined` past either end. */
125
+ function nextInOrder(order, current, backward) {
126
+ const index = order.indexOf(current);
127
+ if (index !== -1)
128
+ return order[index + (backward ? -1 : 1)];
129
+ if (current === document.body || current === document.documentElement) {
130
+ return backward ? order.at(-1) : order[0];
131
+ }
132
+ // From an element outside the order (tabindex="-1"), the next one after it in the document.
133
+ const after = (element) => Boolean(current.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_FOLLOWING);
134
+ const sequential = order.filter(element => element.tabIndex === 0);
135
+ if (backward)
136
+ return sequential.filter(element => !after(element) && element !== current).at(-1);
137
+ return sequential.find(after);
138
+ }
139
+ /** Focuses as `focus()` from `@ember/test-helpers` does, or directly where it won't (an iframe). */
140
+ async function focusOn(element) {
141
+ try {
142
+ await focus(element);
143
+ }
144
+ catch {
145
+ element.focus();
146
+ await settled();
147
+ }
148
+ }
149
+ /**
150
+ * Presses Tab (or Shift+Tab, with `{ shift: true }`) as a browser does: the focused element
151
+ * gets the `keydown`, and unless the page prevents it, focus moves to the next element in the
152
+ * tab order (see `tabOrder`). Past the last element, focus leaves the page, as when the browser
153
+ * moves it to its own toolbar: nothing is focused afterwards. Tests can't press the real Tab
154
+ * key, so this is how they check a focus trap or a roving tab stop.
155
+ *
156
+ * await tab()
157
+ * assert.dom(dialog.closeButton).isFocused()
158
+ * await tab({ shift: true })
159
+ */
160
+ export async function tab(options = {}) {
161
+ const modifiers = { shiftKey: options.shift ?? false };
162
+ const down = dispatchKey(focused(), 'keydown', 'Tab', modifiers);
163
+ await settled();
164
+ if (!down.defaultPrevented) {
165
+ const current = focused();
166
+ const next = nextInOrder(tabOrder(), current, modifiers.shiftKey);
167
+ if (next)
168
+ await focusOn(next);
169
+ else if (current !== document.body)
170
+ await blur(current);
171
+ }
172
+ dispatchKey(focused(), 'keyup', 'Tab', modifiers);
173
+ await settled();
174
+ }