@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pull-to-refresh.d.ts","sourceRoot":"","sources":["../src/pull-to-refresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC,uBAAuB;AACvB,MAAM,WAAW,WAAW;IAC1B,sEAAsE;IACtE,WAAW,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,OAAO,CAAA;CACxC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,oBAAqB,SAAQ,OAAO;;IAC/C,OAAgB,SAAS,SAAoB;IAU7C,6DAA6D;IAC7D,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAEzB;IAED,wCAAwC;IACxC,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,wEAAwE;IACxE,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,gCAAgC;IAChC,IAAI,SAAS,IAAI,WAAW,CAE3B;IAED,uBAAuB;IACvB,IAAI,MAAM,IAAI,WAAW,CAExB;IAED;;;OAGG;IACG,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,WAAqB,EAAE,GAAE,WAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAexF,sCAAsC;IAChC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B"}
@@ -0,0 +1,65 @@
1
+ import { Harness } from "./harness.js";
2
+ import { sendPointer } from "./send-pointer.js";
3
+ /**
4
+ * Drives a `<PullToRefresh>` from `@ember-joinery/ember`: reads its state and what it announces,
5
+ * and pulls it as a finger does.
6
+ *
7
+ * const feed = new PullToRefreshHarness('feed') // <PullToRefresh @name="feed">
8
+ * await feed.refresh()
9
+ * assert.true(feed.isRefreshing)
10
+ * assert.strictEqual(feed.announcement, 'Refreshing')
11
+ *
12
+ * It wraps the content, so the parts inside it still belong to the components around them; its
13
+ * own elements are found by their `data-jn-pull-to-refresh-*` attributes.
14
+ */
15
+ export class PullToRefreshHarness extends Harness {
16
+ static component = 'pull-to-refresh';
17
+ #own(name) {
18
+ const element = this.element.querySelector(`:scope > [data-jn-pull-to-refresh-${name}]`);
19
+ if (!element)
20
+ throw new Error(`Joinery harness: no ${name} in ${this}`);
21
+ return element;
22
+ }
23
+ /** Its state: `idle`, `pulling`, `armed` or `refreshing`. */
24
+ get state() {
25
+ return this.element.getAttribute('data-state');
26
+ }
27
+ /** Whether a refresh is in progress. */
28
+ get isRefreshing() {
29
+ return this.state === 'refreshing';
30
+ }
31
+ /** What its live region says: `Refreshing`, then `Updated`, or `''`. */
32
+ get announcement() {
33
+ return (this.status.textContent ?? '').trim();
34
+ }
35
+ /** The indicator at the top. */
36
+ get indicator() {
37
+ return this.#own('indicator');
38
+ }
39
+ /** The live region. */
40
+ get status() {
41
+ return this.#own('status');
42
+ }
43
+ /**
44
+ * Pulls it down by `distance` pixels of finger movement, then releases. The indicator moves
45
+ * half as far, so a pull refreshes when `distance` is twice the threshold or more.
46
+ */
47
+ async pull(distance, { pointerType = 'touch' } = {}) {
48
+ const target = this.element;
49
+ const rect = target.getBoundingClientRect();
50
+ const clientX = rect.left + rect.width / 2;
51
+ const at = (moved) => ({
52
+ clientX,
53
+ clientY: rect.top + 1 + moved,
54
+ pointerType,
55
+ });
56
+ await sendPointer(target, 'pointerdown', at(0));
57
+ await sendPointer(target, 'pointermove', at(distance / 2));
58
+ await sendPointer(target, 'pointermove', at(distance));
59
+ await sendPointer(target, 'pointerup', { ...at(distance), buttons: 0 });
60
+ }
61
+ /** Pulls it far enough to refresh. */
62
+ async refresh() {
63
+ await this.pull(1000);
64
+ }
65
+ }
@@ -0,0 +1,117 @@
1
+ import { Harness } from './harness.ts';
2
+ import { type KeyModifiers } from './focus.ts';
3
+ /** A navigation button, by the part it is. */
4
+ export type QuestionnaireButton = 'previous' | 'skip' | 'next' | 'submit';
5
+ /**
6
+ * Drives a `<Questionnaire>`, from `@ember-joinery/ember` or, headless, from
7
+ * `@ember-joinery/primitives/questionnaire`. It reads each item by its `@name` (the active one
8
+ * by default): its status, its answers and its error, through the fieldset's and the controls'
9
+ * ARIA and native state; it answers as a reader does, by clicking a choice or typing, and moves
10
+ * with the navigation buttons or the keyboard.
11
+ *
12
+ * const plan = new QuestionnaireHarness('plan') // <Questionnaire @name="plan">
13
+ * await plan.choose('tool-calls')
14
+ * await plan.next()
15
+ * assert.strictEqual(plan.activeItem, 'signals')
16
+ * assert.strictEqual(plan.progressText, 'Question 2 of 3')
17
+ */
18
+ export declare class QuestionnaireHarness extends Harness {
19
+ #private;
20
+ static component: string;
21
+ /**
22
+ * This questionnaire's parts named `part`, in document order: those inside its form and not
23
+ * in a questionnaire nested in it. Unlike `parts()`, it counts parts inside another
24
+ * component (a Card, a Dialog's header) that the questionnaire's parts sit in.
25
+ */
26
+ own<E extends HTMLElement = HTMLElement>(part: string): E[];
27
+ /** The `<form>`. */
28
+ get form(): HTMLFormElement;
29
+ /** What the form would submit now. */
30
+ get formData(): FormData;
31
+ /** Each item's `@name`, in document order. */
32
+ get itemNames(): string[];
33
+ /** An item's `<fieldset>`: the active one by default. Throws when there is none. */
34
+ item(name?: string | null): HTMLFieldSetElement;
35
+ /** The name of the item that shows, or `null`. */
36
+ get activeItem(): string | null;
37
+ /** Whether an item is the one that shows. */
38
+ isActive(name: string): boolean;
39
+ /** An item's status: `unanswered`, `answered` or `skipped`. */
40
+ status(name?: string | null): string | null;
41
+ /** Whether an item shows as invalid (`aria-invalid` on its fieldset). */
42
+ isInvalid(name?: string | null): boolean;
43
+ /** Whether an item must be answered. */
44
+ isRequired(name?: string | null): boolean;
45
+ /** Whether an item takes several answers. */
46
+ isMultiple(name?: string | null): boolean;
47
+ /** Whether an item is disabled (it doesn't apply). */
48
+ isDisabled(name: string): boolean;
49
+ /** Whether an item, or something in it, has focus. */
50
+ isFocused(name?: string | null): boolean;
51
+ /** Whether the item's fieldset itself has focus, as it does after moving to it. */
52
+ isItemFocused(name?: string | null): boolean;
53
+ /** An item's question. */
54
+ title(name?: string | null): string;
55
+ /** An item's description, or `''`. */
56
+ description(name?: string | null): string;
57
+ /** The names its fieldset's `aria-describedby` gives, as a screen reader hears them. */
58
+ describedBy(name?: string | null): string;
59
+ /** The error an item shows, or `''` while it shows none. */
60
+ error(name?: string | null): string;
61
+ /** An item's fixed answers' values, in order. */
62
+ choices(name?: string | null): string[];
63
+ /** A fixed answer's row (its `<label>`). */
64
+ choice(value: string, name?: string | null): HTMLLabelElement;
65
+ /** A fixed answer's radio or checkbox. */
66
+ choiceInput(value: string, name?: string | null): HTMLInputElement;
67
+ /** A fixed answer's text, without its shortcut key. */
68
+ choiceLabel(value: string, name?: string | null): string;
69
+ /** The values of the fixed answers checked in an item, in order. */
70
+ checked(name?: string | null): string[];
71
+ /** Whether a fixed answer is checked. */
72
+ isChecked(value: string, name?: string | null): boolean;
73
+ /** A fixed answer's shortcut key, or `null` when it shows none. */
74
+ shortcut(value: string, name?: string | null): string | null;
75
+ /** An item's freeform answer, or `null` without one. */
76
+ input(name?: string | null): HTMLInputElement | null;
77
+ /** The progress that shows (one may sit in each item, as in a card's header). */
78
+ get progress(): HTMLElement;
79
+ /** What the progress says to a screen reader: `Question 2 of 3`. */
80
+ get progressText(): string;
81
+ /** The active item's position, from 1. */
82
+ get current(): number;
83
+ /** How many items it steps through. */
84
+ get total(): number;
85
+ /** A navigation button. */
86
+ button(kind: QuestionnaireButton): HTMLButtonElement;
87
+ /** Whether a navigation button shows (each shows only where it applies). */
88
+ isShown(kind: QuestionnaireButton): boolean;
89
+ /** Whether Previous shows. */
90
+ get canGoBack(): boolean;
91
+ /** Whether Skip shows. */
92
+ get canSkip(): boolean;
93
+ /** Whether Next shows. */
94
+ get canGoNext(): boolean;
95
+ /** Whether Submit shows. */
96
+ get canSubmit(): boolean;
97
+ /** Clicks a fixed answer, as a reader does: checks a radio, toggles a checkbox. */
98
+ choose(value: string, name?: string | null): Promise<void>;
99
+ /** Types into an item's freeform answer, replacing what is there. */
100
+ fillIn(value: string, name?: string | null): Promise<void>;
101
+ /** Clicks Next. */
102
+ next(): Promise<void>;
103
+ /** Clicks Previous. */
104
+ previous(): Promise<void>;
105
+ /** Clicks Skip. */
106
+ skip(): Promise<void>;
107
+ /** Clicks Submit. */
108
+ submit(): Promise<void>;
109
+ /** Moves focus to a fixed answer's control. */
110
+ focusChoice(value: string, name?: string | null): Promise<void>;
111
+ /**
112
+ * Presses a key on the focused element, as the questionnaire's keyboard expects it:
113
+ * `ArrowDown`, `ArrowRight`, a shortcut letter, or `Enter` with `{ metaKey: true }`.
114
+ */
115
+ press(key: string, modifiers?: KeyModifiers): Promise<boolean>;
116
+ }
117
+ //# sourceMappingURL=questionnaire.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"questionnaire.d.ts","sourceRoot":"","sources":["../src/questionnaire.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAWxD,8CAA8C;AAC9C,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAA;AAEzE;;;;;;;;;;;;GAYG;AACH,qBAAa,oBAAqB,SAAQ,OAAO;;IAC/C,OAAgB,SAAS,SAAkB;IAE3C;;;;OAIG;IACH,GAAG,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE;IAO3D,oBAAoB;IACpB,IAAI,IAAI,IAAI,eAAe,CAE1B;IAED,sCAAsC;IACtC,IAAI,QAAQ,IAAI,QAAQ,CAEvB;IAED,8CAA8C;IAC9C,IAAI,SAAS,IAAI,MAAM,EAAE,CAExB;IAED,oFAAoF;IACpF,IAAI,CAAC,IAAI,GAAE,MAAM,GAAG,IAAsB,GAAG,mBAAmB;IAShE,kDAAkD;IAClD,IAAI,UAAU,IAAI,MAAM,GAAG,IAAI,CAG9B;IAED,6CAA6C;IAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI/B,+DAA+D;IAC/D,MAAM,CA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IACjB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/B,mBAAmB;IACb,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,qBAAqB;IACf,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B,+CAA+C;IACzC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,GAAG,IAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAItF;;;OAGG;IACG,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;CAGrE"}
@@ -0,0 +1,240 @@
1
+ import { click, fillIn, focus } from '@ember/test-helpers';
2
+ import { Harness } from "./harness.js";
3
+ import { pressKey } from "./focus.js";
4
+ function text(element) {
5
+ return (element?.textContent ?? '').replace(/\s+/g, ' ').trim();
6
+ }
7
+ /** Whether an element shows: neither it nor an ancestor is `hidden`. */
8
+ function shown(element) {
9
+ return !element.closest('[hidden]');
10
+ }
11
+ /**
12
+ * Drives a `<Questionnaire>`, from `@ember-joinery/ember` or, headless, from
13
+ * `@ember-joinery/primitives/questionnaire`. It reads each item by its `@name` (the active one
14
+ * by default): its status, its answers and its error, through the fieldset's and the controls'
15
+ * ARIA and native state; it answers as a reader does, by clicking a choice or typing, and moves
16
+ * with the navigation buttons or the keyboard.
17
+ *
18
+ * const plan = new QuestionnaireHarness('plan') // <Questionnaire @name="plan">
19
+ * await plan.choose('tool-calls')
20
+ * await plan.next()
21
+ * assert.strictEqual(plan.activeItem, 'signals')
22
+ * assert.strictEqual(plan.progressText, 'Question 2 of 3')
23
+ */
24
+ export class QuestionnaireHarness extends Harness {
25
+ static component = 'questionnaire';
26
+ /**
27
+ * This questionnaire's parts named `part`, in document order: those inside its form and not
28
+ * in a questionnaire nested in it. Unlike `parts()`, it counts parts inside another
29
+ * component (a Card, a Dialog's header) that the questionnaire's parts sit in.
30
+ */
31
+ own(part) {
32
+ const form = this.element;
33
+ return [...form.querySelectorAll(`[data-test-jn-part="${part}"]`)].filter(element => element.closest('[data-test-jn="questionnaire"]') === form);
34
+ }
35
+ /** The `<form>`. */
36
+ get form() {
37
+ return this.element;
38
+ }
39
+ /** What the form would submit now. */
40
+ get formData() {
41
+ return new FormData(this.form);
42
+ }
43
+ /** Each item's `@name`, in document order. */
44
+ get itemNames() {
45
+ return this.own('item').map(item => item.getAttribute('data-test-jn-value'));
46
+ }
47
+ /** An item's `<fieldset>`: the active one by default. Throws when there is none. */
48
+ item(name = this.activeItem) {
49
+ if (name === null)
50
+ throw new Error(`Joinery harness: ${this} shows no item`);
51
+ const item = this.own('item').find(element => element.getAttribute('data-test-jn-value') === name);
52
+ if (!item)
53
+ throw new Error(`Joinery harness: no item "${name}" in ${this}`);
54
+ return item;
55
+ }
56
+ /** The name of the item that shows, or `null`. */
57
+ get activeItem() {
58
+ const active = this.own('item').find(item => !item.hidden);
59
+ return active?.getAttribute('data-test-jn-value') ?? null;
60
+ }
61
+ /** Whether an item is the one that shows. */
62
+ isActive(name) {
63
+ return !this.item(name).hidden;
64
+ }
65
+ /** An item's status: `unanswered`, `answered` or `skipped`. */
66
+ status(name = this.activeItem) {
67
+ return this.item(name).getAttribute('data-status');
68
+ }
69
+ /** Whether an item shows as invalid (`aria-invalid` on its fieldset). */
70
+ isInvalid(name = this.activeItem) {
71
+ return this.item(name).getAttribute('aria-invalid') === 'true';
72
+ }
73
+ /** Whether an item must be answered. */
74
+ isRequired(name = this.activeItem) {
75
+ return this.item(name).hasAttribute('data-required');
76
+ }
77
+ /** Whether an item takes several answers. */
78
+ isMultiple(name = this.activeItem) {
79
+ return this.item(name).hasAttribute('data-multiple');
80
+ }
81
+ /** Whether an item is disabled (it doesn't apply). */
82
+ isDisabled(name) {
83
+ return this.item(name).disabled;
84
+ }
85
+ /** Whether an item, or something in it, has focus. */
86
+ isFocused(name = this.activeItem) {
87
+ const active = document.activeElement;
88
+ return Boolean(active && this.item(name).contains(active));
89
+ }
90
+ /** Whether the item's fieldset itself has focus, as it does after moving to it. */
91
+ isItemFocused(name = this.activeItem) {
92
+ return document.activeElement === this.item(name);
93
+ }
94
+ #within(name, part) {
95
+ const item = this.item(name);
96
+ return this.own(part).filter(element => item.contains(element));
97
+ }
98
+ /** An item's question. */
99
+ title(name = this.activeItem) {
100
+ return text(this.#within(name, 'title')[0]);
101
+ }
102
+ /** An item's description, or `''`. */
103
+ description(name = this.activeItem) {
104
+ return text(this.#within(name, 'description')[0]);
105
+ }
106
+ /** The names its fieldset's `aria-describedby` gives, as a screen reader hears them. */
107
+ describedBy(name = this.activeItem) {
108
+ const ids = this.item(name).getAttribute('aria-describedby')?.split(/\s+/) ?? [];
109
+ return ids
110
+ .map(id => text(document.getElementById(id)))
111
+ .filter(Boolean)
112
+ .join(' ');
113
+ }
114
+ /** The error an item shows, or `''` while it shows none. */
115
+ error(name = this.activeItem) {
116
+ const error = this.#within(name, 'error').find(element => !element.hidden);
117
+ return text(error);
118
+ }
119
+ /** An item's fixed answers' values, in order. */
120
+ choices(name = this.activeItem) {
121
+ return this.#within(name, 'choice').map(choice => choice.getAttribute('data-test-jn-value'));
122
+ }
123
+ /** A fixed answer's row (its `<label>`). */
124
+ choice(value, name = this.activeItem) {
125
+ const choice = this.#within(name, 'choice').find(element => element.getAttribute('data-test-jn-value') === value);
126
+ if (!choice)
127
+ throw new Error(`Joinery harness: no choice "${value}" in item "${name}"`);
128
+ return choice;
129
+ }
130
+ /** A fixed answer's radio or checkbox. */
131
+ choiceInput(value, name = this.activeItem) {
132
+ return this.choice(value, name).querySelector('[data-test-jn-part="choice-input"]');
133
+ }
134
+ /** A fixed answer's text, without its shortcut key. */
135
+ choiceLabel(value, name = this.activeItem) {
136
+ return text(this.choice(value, name).querySelector('[data-test-jn-part="choice-label"]'));
137
+ }
138
+ /** The values of the fixed answers checked in an item, in order. */
139
+ checked(name = this.activeItem) {
140
+ return this.choices(name).filter(value => this.choiceInput(value, name).checked);
141
+ }
142
+ /** Whether a fixed answer is checked. */
143
+ isChecked(value, name = this.activeItem) {
144
+ return this.choiceInput(value, name).checked;
145
+ }
146
+ /** A fixed answer's shortcut key, or `null` when it shows none. */
147
+ shortcut(value, name = this.activeItem) {
148
+ const key = this.choice(value, name).querySelector('[data-test-jn-part="shortcut"]');
149
+ return key && !key.hidden ? text(key) : null;
150
+ }
151
+ /** An item's freeform answer, or `null` without one. */
152
+ input(name = this.activeItem) {
153
+ return this.#within(name, 'input')[0] ?? null;
154
+ }
155
+ /** The progress that shows (one may sit in each item, as in a card's header). */
156
+ get progress() {
157
+ const progress = this.own('progress').find(shown);
158
+ if (!progress)
159
+ throw new Error(`Joinery harness: ${this} shows no progress`);
160
+ return progress;
161
+ }
162
+ /** What the progress says to a screen reader: `Question 2 of 3`. */
163
+ get progressText() {
164
+ return this.progress.getAttribute('aria-valuetext') ?? '';
165
+ }
166
+ /** The active item's position, from 1. */
167
+ get current() {
168
+ return Number(this.form.getAttribute('data-current'));
169
+ }
170
+ /** How many items it steps through. */
171
+ get total() {
172
+ return Number(this.form.getAttribute('data-total'));
173
+ }
174
+ /** A navigation button. */
175
+ button(kind) {
176
+ const button = this.own(kind)[0];
177
+ if (!button)
178
+ throw new Error(`Joinery harness: no "${kind}" button in ${this}`);
179
+ return button;
180
+ }
181
+ /** Whether a navigation button shows (each shows only where it applies). */
182
+ isShown(kind) {
183
+ const button = this.own(kind)[0];
184
+ return Boolean(button && shown(button));
185
+ }
186
+ /** Whether Previous shows. */
187
+ get canGoBack() {
188
+ return this.isShown('previous');
189
+ }
190
+ /** Whether Skip shows. */
191
+ get canSkip() {
192
+ return this.isShown('skip');
193
+ }
194
+ /** Whether Next shows. */
195
+ get canGoNext() {
196
+ return this.isShown('next');
197
+ }
198
+ /** Whether Submit shows. */
199
+ get canSubmit() {
200
+ return this.isShown('submit');
201
+ }
202
+ /** Clicks a fixed answer, as a reader does: checks a radio, toggles a checkbox. */
203
+ async choose(value, name = this.activeItem) {
204
+ await click(this.choiceInput(value, name));
205
+ }
206
+ /** Types into an item's freeform answer, replacing what is there. */
207
+ async fillIn(value, name = this.activeItem) {
208
+ const input = this.input(name);
209
+ if (!input)
210
+ throw new Error(`Joinery harness: item "${name}" has no freeform answer`);
211
+ await fillIn(input, value);
212
+ }
213
+ /** Clicks Next. */
214
+ async next() {
215
+ await click(this.button('next'));
216
+ }
217
+ /** Clicks Previous. */
218
+ async previous() {
219
+ await click(this.button('previous'));
220
+ }
221
+ /** Clicks Skip. */
222
+ async skip() {
223
+ await click(this.button('skip'));
224
+ }
225
+ /** Clicks Submit. */
226
+ async submit() {
227
+ await click(this.button('submit'));
228
+ }
229
+ /** Moves focus to a fixed answer's control. */
230
+ async focusChoice(value, name = this.activeItem) {
231
+ await focus(this.choiceInput(value, name));
232
+ }
233
+ /**
234
+ * Presses a key on the focused element, as the questionnaire's keyboard expects it:
235
+ * `ArrowDown`, `ArrowRight`, a shortcut letter, or `Enter` with `{ metaKey: true }`.
236
+ */
237
+ async press(key, modifiers) {
238
+ return pressKey(key, modifiers);
239
+ }
240
+ }
@@ -0,0 +1,53 @@
1
+ import { Harness } from './harness.ts';
2
+ import { type KeyModifiers } from './focus.ts';
3
+ /**
4
+ * Drives a `<RadioGroup>` from `@ember-joinery/ember`, or the headless one from
5
+ * `@ember-joinery/primitives/radio-group`. Items are found by their `@value`
6
+ * (`data-test-jn-value`), and state comes from ARIA: each item's `aria-checked`, the group's
7
+ * `aria-required` and `aria-orientation`.
8
+ *
9
+ * const spacing = new RadioGroupHarness('spacing') // <RadioGroup @name="spacing">
10
+ * await spacing.choose('compact')
11
+ * assert.strictEqual(spacing.value, 'compact')
12
+ * await spacing.press('ArrowUp') // focus, and the choice, move to the previous item
13
+ */
14
+ export declare class RadioGroupHarness extends Harness {
15
+ static component: string;
16
+ /** Each item's element, in order. */
17
+ get items(): HTMLElement[];
18
+ /** Each item's value, in order. */
19
+ get options(): string[];
20
+ /** The item with this value. Throws when there is none. */
21
+ item(value: string): HTMLElement;
22
+ /** The chosen item's value, or `null` when none is. */
23
+ get value(): string | null;
24
+ /** Whether the item with this value is chosen. */
25
+ isChecked(value: string): boolean;
26
+ /** Whether the item with this value can't be chosen. */
27
+ isItemDisabled(value: string): boolean;
28
+ /** Whether the item with this value is marked invalid (`aria-invalid`). */
29
+ isItemInvalid(value: string): boolean;
30
+ /** The accessible name of the item with this value: its `<label>`'s text, or its ARIA. */
31
+ labelOf(value: string): string;
32
+ /** The group's accessible name: `aria-label` or `aria-labelledby`. */
33
+ get label(): string;
34
+ /** Whether every item is disabled (the group's `@disabled`). */
35
+ get isDisabled(): boolean;
36
+ /** Whether a form needs a choice (`aria-required="true"`). */
37
+ get isRequired(): boolean;
38
+ /** `horizontal`, `vertical`, or `null` when every arrow key moves (`aria-orientation`). */
39
+ get orientation(): string | null;
40
+ /** The value of the item that has focus, or `null` when focus is elsewhere. */
41
+ get focused(): string | null;
42
+ /** The value of the item Tab enters on (`tabindex="0"`), or `null` before any has had focus. */
43
+ get tabStop(): string | null;
44
+ /** The hidden native radio the item with this value renders in a form, or `null`. */
45
+ inputOf(value: string): HTMLInputElement | null;
46
+ /** Clicks the item with this value, as a user would, which chooses it. */
47
+ choose(value: string): Promise<void>;
48
+ /** Moves focus to the item with this value, as a click would, without choosing it. */
49
+ focus(value: string): Promise<void>;
50
+ /** Presses a key on the focused item: an arrow moves focus and the choice. */
51
+ press(key: string, modifiers?: KeyModifiers): Promise<boolean>;
52
+ }
53
+ //# sourceMappingURL=radio-group.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"radio-group.d.ts","sourceRoot":"","sources":["../src/radio-group.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAGxD;;;;;;;;;;GAUG;AACH,qBAAa,iBAAkB,SAAQ,OAAO;IAC5C,OAAgB,SAAS,SAAgB;IAEzC,qCAAqC;IACrC,IAAI,K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"./harness.js";
3
+ import { attributes } from "./selectors.js";
4
+ import { pressKey } from "./focus.js";
5
+ import { accessibleName, hiddenInputOf, isDisabled, isInvalid } from "./-private/checkable.js";
6
+ /**
7
+ * Drives a `<RadioGroup>` from `@ember-joinery/ember`, or the headless one from
8
+ * `@ember-joinery/primitives/radio-group`. Items are found by their `@value`
9
+ * (`data-test-jn-value`), and state comes from ARIA: each item's `aria-checked`, the group's
10
+ * `aria-required` and `aria-orientation`.
11
+ *
12
+ * const spacing = new RadioGroupHarness('spacing') // <RadioGroup @name="spacing">
13
+ * await spacing.choose('compact')
14
+ * assert.strictEqual(spacing.value, 'compact')
15
+ * await spacing.press('ArrowUp') // focus, and the choice, move to the previous item
16
+ */
17
+ export class RadioGroupHarness extends Harness {
18
+ static component = 'radio-group';
19
+ /** Each item's element, in order. */
20
+ get items() {
21
+ return this.parts('item');
22
+ }
23
+ /** Each item's value, in order. */
24
+ get options() {
25
+ return this.values('item');
26
+ }
27
+ /** The item with this value. Throws when there is none. */
28
+ item(value) {
29
+ return this.part('item', value);
30
+ }
31
+ /** The chosen item's value, or `null` when none is. */
32
+ get value() {
33
+ const item = this.items.find(element => element.getAttribute('aria-checked') === 'true');
34
+ return item?.getAttribute(attributes.value) ?? null;
35
+ }
36
+ /** Whether the item with this value is chosen. */
37
+ isChecked(value) {
38
+ return this.item(value).getAttribute('aria-checked') === 'true';
39
+ }
40
+ /** Whether the item with this value can't be chosen. */
41
+ isItemDisabled(value) {
42
+ return isDisabled(this.item(value));
43
+ }
44
+ /** Whether the item with this value is marked invalid (`aria-invalid`). */
45
+ isItemInvalid(value) {
46
+ return isInvalid(this.item(value));
47
+ }
48
+ /** The accessible name of the item with this value: its `<label>`'s text, or its ARIA. */
49
+ labelOf(value) {
50
+ return accessibleName(this.item(value));
51
+ }
52
+ /** The group's accessible name: `aria-label` or `aria-labelledby`. */
53
+ get label() {
54
+ return accessibleName(this.element);
55
+ }
56
+ /** Whether every item is disabled (the group's `@disabled`). */
57
+ get isDisabled() {
58
+ return this.element.hasAttribute('data-disabled');
59
+ }
60
+ /** Whether a form needs a choice (`aria-required="true"`). */
61
+ get isRequired() {
62
+ return this.element.getAttribute('aria-required') === 'true';
63
+ }
64
+ /** `horizontal`, `vertical`, or `null` when every arrow key moves (`aria-orientation`). */
65
+ get orientation() {
66
+ return this.element.getAttribute('aria-orientation');
67
+ }
68
+ /** The value of the item that has focus, or `null` when focus is elsewhere. */
69
+ get focused() {
70
+ const active = document.activeElement;
71
+ const item = this.items.find(element => element === active);
72
+ return item?.getAttribute(attributes.value) ?? null;
73
+ }
74
+ /** The value of the item Tab enters on (`tabindex="0"`), or `null` before any has had focus. */
75
+ get tabStop() {
76
+ const item = this.items.find(element => element.getAttribute('tabindex') === '0');
77
+ return item?.getAttribute(attributes.value) ?? null;
78
+ }
79
+ /** The hidden native radio the item with this value renders in a form, or `null`. */
80
+ inputOf(value) {
81
+ return hiddenInputOf(this.item(value));
82
+ }
83
+ /** Clicks the item with this value, as a user would, which chooses it. */
84
+ async choose(value) {
85
+ await click(this.item(value));
86
+ }
87
+ /** Moves focus to the item with this value, as a click would, without choosing it. */
88
+ async focus(value) {
89
+ await focus(this.item(value));
90
+ }
91
+ /** Presses a key on the focused item: an arrow moves focus and the choice. */
92
+ async press(key, modifiers) {
93
+ return pressKey(key, modifiers);
94
+ }
95
+ }
@@ -0,0 +1,67 @@
1
+ import { Harness } from './harness.ts';
2
+ import { type KeyModifiers } from './focus.ts';
3
+ /**
4
+ * Drives a `<Rating>` from `@ember-joinery/ember`, or the headless one from
5
+ * `@ember-joinery/primitives/rating`. Its items are native radios, found by their value
6
+ * (`data-test-jn-value`); its rating is the root's `data-value`.
7
+ *
8
+ * const recipe = new RatingHarness('recipe') // <Rating @name="recipe">
9
+ * await recipe.select(4)
10
+ * assert.strictEqual(recipe.value, 4)
11
+ * assert.strictEqual(recipe.stars, '★ ★ ★ ★ ☆')
12
+ * await recipe.select(4) // picking it again clears it
13
+ * assert.strictEqual(recipe.value, 0)
14
+ */
15
+ export declare class RatingHarness extends Harness {
16
+ static component: string;
17
+ /** The current rating: `0` for none. */
18
+ get value(): number;
19
+ /** How many items it has (`data-total`). */
20
+ get total(): number;
21
+ /** Each item's value, in order. */
22
+ get options(): number[];
23
+ /** Each item's element, in order. */
24
+ get items(): HTMLElement[];
25
+ /** The item worth `value`. Throws when there is none. */
26
+ item(value: number): HTMLElement;
27
+ /** The radio of the item worth `value`. */
28
+ input(value: number): HTMLInputElement;
29
+ /** Each item as `★` while the rating reaches it, `☆` otherwise, joined with spaces. */
30
+ get stars(): string;
31
+ /**
32
+ * What each item shows, its icon's text (the part hidden from assistive technology), joined
33
+ * with spaces: `★ ★ ★ ★ ★`, or `1 2 3 4 5` for icons that show their value. An icon with no
34
+ * text, such as an `<svg>`, gives `''`.
35
+ */
36
+ get starTexts(): string;
37
+ /** How much of the item worth `value` the rating fills, from 0 to 100. */
38
+ percentOf(value: number): number;
39
+ /** The accessible name of the item worth `value`: `3 stars`. */
40
+ labelOf(value: number): string;
41
+ /** The group's accessible name: its legend, `aria-label` or `aria-labelledby`. */
42
+ get label(): string;
43
+ /** What a display-only rating says for assistive technology, or `''`: `Rated 3 out of 5`. */
44
+ get summary(): string;
45
+ /** Whether it can't be changed (`aria-readonly="true"`): readonly, or display-only. */
46
+ get isReadonly(): boolean;
47
+ /** Whether it is disabled (`<fieldset disabled>`). */
48
+ get isDisabled(): boolean;
49
+ /** The value of the item whose radio has focus, or `null`. */
50
+ get focused(): number | null;
51
+ /**
52
+ * Picks `value`, as a click on its item does: picking the current rating clears it. A value
53
+ * between the items' is filled in on the rating's range input (`rating.Range`), or on a
54
+ * number or range input of the block's own, when it has one.
55
+ */
56
+ select(value: number): Promise<void>;
57
+ /** Focuses the checked radio, or the first, as Tab does. */
58
+ focus(): Promise<void>;
59
+ /**
60
+ * Presses a key on the focused radio, and does what the browser does for a native radio
61
+ * group, which a test's events don't make it do: the arrow keys move focus to the next or
62
+ * previous item, going round, and pick it (a click), and Space picks the focused one. Right
63
+ * to left, the left and right arrows swap. Tests can't press real keys, as with `tab()`.
64
+ */
65
+ press(key: string, modifiers?: KeyModifiers): Promise<void>;
66
+ }
67
+ //# sourceMappingURL=rating.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rating.d.ts","sourceRoot":"","sources":["../src/rating.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAMxD;;;;;;;;;;;GAWG;AACH,qBAAa,aAAc,SAAQ,OAAO;IACxC,OAAgB,SAAS,SAAW;IAEpC,wCAAwC;IACxC,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,4CAA4C;IAC5C,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,mCAAmC;IACnC,IAAI,OAAO,IAAI,MAAM,EAAE,CAEtB;IAED,qCAAqC;IACrC,IAAI,KAAK,IAAI,WAAW,EAAE,CAEzB;IAED,yDAAyD;IACzD,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;IAIhC,2CAA2C;IAC3C,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB;IAItC,uFAAuF;IACvF,IAAI,KAAK,IAAI,MAAM,CAIlB;IAED;;;;OAIG;IACH,IAAI,SAAS,IAAI,MAAM,CAOtB;IAED,0EAA0E;IAC1E,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAIhC,gEAAgE;IAChE,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAI9B,kFAAkF;IAClF,IAAI,KAAK,IAAI,MAAM,CAOlB;IAED,6FAA6F;IAC7F,IAAI,OAAO,IAAI,MAAM,CAGpB;IAED,uFAAuF;IACvF,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,sDAAsD;IACtD,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,8DAA8D;IAC9D,IAAI,OAAO,IAAI,MAAM,GAA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