@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/label.js ADDED
@@ -0,0 +1,39 @@
1
+ import { click } from '@ember/test-helpers';
2
+ import { Harness } from "./harness.js";
3
+ function text(element) {
4
+ return (element.textContent ?? '').replace(/\s+/g, ' ').trim();
5
+ }
6
+ /**
7
+ * Drives a `<Label>`, from `@ember-joinery/ember` or `@ember-joinery/primitives/label`.
8
+ *
9
+ * const email = new LabelHarness('email')
10
+ * assert.strictEqual(email.text, 'Your email address')
11
+ * assert.strictEqual(email.control, find('#email'))
12
+ * await email.click() // focuses the input, as a press on a label does
13
+ */
14
+ export class LabelHarness extends Harness {
15
+ static component = 'label';
16
+ /** The text it shows, whitespace collapsed. */
17
+ get text() {
18
+ return text(this.element);
19
+ }
20
+ /**
21
+ * The control it labels, as the browser works it out: the element its `for` names, or the
22
+ * first control inside it. `null` when it labels nothing (or isn't a `<label>`).
23
+ */
24
+ get control() {
25
+ const element = this.element;
26
+ return element instanceof HTMLLabelElement ? element.control : null;
27
+ }
28
+ /** Whether the control it labels is disabled, which dims the label. */
29
+ get isControlDisabled() {
30
+ const control = this.control;
31
+ if (!control)
32
+ return false;
33
+ return ('disabled' in control && Boolean(control.disabled)) || control.matches(':disabled');
34
+ }
35
+ /** Clicks it, as a user would: the browser passes the click to its control. */
36
+ async click() {
37
+ await click(this.element);
38
+ }
39
+ }
@@ -0,0 +1,42 @@
1
+ import type { TestHooks } from './test-hooks.ts';
2
+ /**
3
+ * Presses Escape where focus is (or on `target`), as a user closing the top layer does. Only
4
+ * the top layer closes.
5
+ */
6
+ export declare function pressEscape(target?: Element): Promise<void>;
7
+ export interface PointerOptions {
8
+ /** `mouse` (the default), `pen` or `touch`. A touch dismisses on the click that follows. */
9
+ pointerType?: 'mouse' | 'pen' | 'touch';
10
+ }
11
+ /**
12
+ * A press on an element the way a pointer makes one: `pointerdown`, then `click()`'s
13
+ * `mousedown`, focus, `mouseup` and `click`, then `pointerup`. `click()` alone sends no
14
+ * pointer events, and the dismiss stack listens for `pointerdown`, as Radix's does.
15
+ */
16
+ export declare function press(target: Element, { pointerType }?: PointerOptions): Promise<void>;
17
+ /**
18
+ * A press outside every layer: on `target`, or else on the test's root element (outside any
19
+ * layer, which the top layer shows above it).
20
+ */
21
+ export declare function pressOutside(target?: Element, options?: PointerOptions): Promise<void>;
22
+ /** Whether an element is in the browser's top layer now: an open popover or a modal dialog. */
23
+ export declare function isInTopLayer(element: Element | null | undefined): boolean;
24
+ /** Where an anchored element was placed, from its `data-side` and `data-align`. */
25
+ export interface AnchorPlacement {
26
+ side: string | null;
27
+ align: string | null;
28
+ }
29
+ /** Where an anchored element was placed (after any flip), from `data-side` and `data-align`. */
30
+ export declare function placementOf(element: Element): AnchorPlacement;
31
+ /**
32
+ * Forces the Floating UI fallback for each test in a module, as CI's fallback run does for the
33
+ * whole suite, so one run covers both ways of positioning. It sets
34
+ * `globalThis.JOINERY_ANCHOR_FALLBACK` before each test and puts it back after.
35
+ *
36
+ * module('menu, Floating UI', function (hooks) {
37
+ * setupRenderingTest(hooks)
38
+ * setupAnchorFallback(hooks)
39
+ * })
40
+ */
41
+ export declare function setupAnchorFallback(hooks: TestHooks): void;
42
+ //# sourceMappingURL=layers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layers.d.ts","sourceRoot":"","sources":["../src/layers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD;;;GAGG;AACH,wBAAsB,WAAW,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAIjE;AAED,MAAM,WAAW,cAAc;IAC7B,4FAA4F;IAC5F,WAAW,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,OAAO,CAAA;CACxC;AAED;;;;GAIG;AACH,wBAAsB,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,WAAqB,EAAE,GAAE,cAAmB,iBAI1F;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAG5F;AAED,+FAA+F;AAC/F,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAOzE;AAED,mFAAmF;AACnF,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CACrB;AAED,gGAAgG;AAChG,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,CAE7D;AAID;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAa1D"}
package/dist/layers.js ADDED
@@ -0,0 +1,70 @@
1
+ import { click, getRootElement, triggerEvent, triggerKeyEvent } from '@ember/test-helpers';
2
+ /**
3
+ * Presses Escape where focus is (or on `target`), as a user closing the top layer does. Only
4
+ * the top layer closes.
5
+ */
6
+ export async function pressEscape(target) {
7
+ const where = target ?? document.activeElement ?? document.body;
8
+ await triggerKeyEvent(where, 'keydown', 'Escape');
9
+ await triggerKeyEvent(where, 'keyup', 'Escape');
10
+ }
11
+ /**
12
+ * A press on an element the way a pointer makes one: `pointerdown`, then `click()`'s
13
+ * `mousedown`, focus, `mouseup` and `click`, then `pointerup`. `click()` alone sends no
14
+ * pointer events, and the dismiss stack listens for `pointerdown`, as Radix's does.
15
+ */
16
+ export async function press(target, { pointerType = 'mouse' } = {}) {
17
+ await triggerEvent(target, 'pointerdown', { pointerType, isPrimary: true, button: 0 });
18
+ await click(target);
19
+ await triggerEvent(target, 'pointerup', { pointerType, isPrimary: true, button: 0 });
20
+ }
21
+ /**
22
+ * A press outside every layer: on `target`, or else on the test's root element (outside any
23
+ * layer, which the top layer shows above it).
24
+ */
25
+ export async function pressOutside(target, options) {
26
+ const root = getRootElement();
27
+ await press(target ?? (root instanceof Element ? root : root.body), options);
28
+ }
29
+ /** Whether an element is in the browser's top layer now: an open popover or a modal dialog. */
30
+ export function isInTopLayer(element) {
31
+ if (!element)
32
+ return false;
33
+ try {
34
+ return element.matches(':popover-open') || element.matches(':modal');
35
+ }
36
+ catch {
37
+ return false;
38
+ }
39
+ }
40
+ /** Where an anchored element was placed (after any flip), from `data-side` and `data-align`. */
41
+ export function placementOf(element) {
42
+ return { side: element.getAttribute('data-side'), align: element.getAttribute('data-align') };
43
+ }
44
+ const FLAG = 'JOINERY_ANCHOR_FALLBACK';
45
+ /**
46
+ * Forces the Floating UI fallback for each test in a module, as CI's fallback run does for the
47
+ * whole suite, so one run covers both ways of positioning. It sets
48
+ * `globalThis.JOINERY_ANCHOR_FALLBACK` before each test and puts it back after.
49
+ *
50
+ * module('menu, Floating UI', function (hooks) {
51
+ * setupRenderingTest(hooks)
52
+ * setupAnchorFallback(hooks)
53
+ * })
54
+ */
55
+ export function setupAnchorFallback(hooks) {
56
+ const global = globalThis;
57
+ let had = false;
58
+ let previous;
59
+ hooks.beforeEach(() => {
60
+ had = FLAG in global;
61
+ previous = global[FLAG];
62
+ global[FLAG] = true;
63
+ });
64
+ hooks.afterEach(() => {
65
+ if (had)
66
+ global[FLAG] = previous;
67
+ else
68
+ delete global[FLAG];
69
+ });
70
+ }
package/dist/link.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { Harness } from './harness.ts';
2
+ /**
3
+ * Drives a `<Link>` from `@ember-joinery/primitives/link`, internal or external: where it goes,
4
+ * whether it is the current page (read from `aria-current`), whether it leaves the app, and
5
+ * following it.
6
+ *
7
+ * const forum = new LinkHarness('forum') // <Link @name="forum">
8
+ * await forum.follow()
9
+ * assert.true(forum.isCurrent)
10
+ */
11
+ export declare class LinkHarness extends Harness {
12
+ static component: string | readonly string[];
13
+ /** Its `href`, as written. */
14
+ get href(): string | null;
15
+ /** The text it shows, whitespace collapsed. */
16
+ get text(): string;
17
+ /**
18
+ * Its `aria-current`: `page` on the current route, `true` wherever a link with
19
+ * `@activeOnSubPaths` is active (its own route included), and `null` when it isn't current.
20
+ */
21
+ get current(): string | null;
22
+ /** Whether it is the current page, or a section the current page is in (`aria-current`). */
23
+ get isCurrent(): boolean;
24
+ /** Whether it opens in a new tab (`target="_blank"`), as a link that leaves the app does. */
25
+ get opensInNewTab(): boolean;
26
+ /**
27
+ * Whether the page it opens is told nothing about this one: `rel` has `noopener` and
28
+ * `noreferrer`.
29
+ */
30
+ get isIsolated(): boolean;
31
+ /** Clicks it, as a user would: a link to one of the app's routes transitions. */
32
+ follow(): Promise<void>;
33
+ }
34
+ /**
35
+ * Drives an `<ExternalLink>` from `@ember-joinery/primitives/external-link`: a `LinkHarness`
36
+ * that drives only those.
37
+ *
38
+ * const mdn = new ExternalLinkHarness()
39
+ * assert.true(mdn.opensInNewTab && mdn.isIsolated)
40
+ */
41
+ export declare class ExternalLinkHarness extends LinkHarness {
42
+ static component: string;
43
+ }
44
+ //# sourceMappingURL=link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../src/link.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC;;;;;;;;GAQG;AACH,qBAAa,WAAY,SAAQ,OAAO;IACtC,OAAgB,SAAS,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAA4B;IAEjF,8BAA8B;IAC9B,IAAI,IAAI,IAAI,MAAM,GAAG,IAAI,CAExB;IAED,+CAA+C;IAC/C,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;OAGG;IACH,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAE3B;IAED,4FAA4F;IAC5F,IAAI,SAAS,IAAI,OAAO,CAGvB;IAED,6FAA6F;IAC7F,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED;;;OAGG;IACH,IAAI,UAAU,IAAI,OAAO,CAGxB;IAED,iFAAiF;IAC3E,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAG9B;AAED;;;;;;GAMG;AACH,qBAAa,mBAAoB,SAAQ,WAAW;IAClD,OAAgB,SAAS,SAAkB;CAC5C"}
package/dist/link.js ADDED
@@ -0,0 +1,60 @@
1
+ import { click } from '@ember/test-helpers';
2
+ import { Harness } from "./harness.js";
3
+ /**
4
+ * Drives a `<Link>` from `@ember-joinery/primitives/link`, internal or external: where it goes,
5
+ * whether it is the current page (read from `aria-current`), whether it leaves the app, and
6
+ * following it.
7
+ *
8
+ * const forum = new LinkHarness('forum') // <Link @name="forum">
9
+ * await forum.follow()
10
+ * assert.true(forum.isCurrent)
11
+ */
12
+ export class LinkHarness extends Harness {
13
+ static component = ['link', 'external-link'];
14
+ /** Its `href`, as written. */
15
+ get href() {
16
+ return this.element.getAttribute('href');
17
+ }
18
+ /** The text it shows, whitespace collapsed. */
19
+ get text() {
20
+ return (this.element.textContent ?? '').replace(/\s+/g, ' ').trim();
21
+ }
22
+ /**
23
+ * Its `aria-current`: `page` on the current route, `true` wherever a link with
24
+ * `@activeOnSubPaths` is active (its own route included), and `null` when it isn't current.
25
+ */
26
+ get current() {
27
+ return this.element.getAttribute('aria-current');
28
+ }
29
+ /** Whether it is the current page, or a section the current page is in (`aria-current`). */
30
+ get isCurrent() {
31
+ const current = this.current;
32
+ return current !== null && current !== 'false';
33
+ }
34
+ /** Whether it opens in a new tab (`target="_blank"`), as a link that leaves the app does. */
35
+ get opensInNewTab() {
36
+ return this.element.getAttribute('target') === '_blank';
37
+ }
38
+ /**
39
+ * Whether the page it opens is told nothing about this one: `rel` has `noopener` and
40
+ * `noreferrer`.
41
+ */
42
+ get isIsolated() {
43
+ const rel = (this.element.getAttribute('rel') ?? '').split(/\s+/);
44
+ return rel.includes('noopener') && rel.includes('noreferrer');
45
+ }
46
+ /** Clicks it, as a user would: a link to one of the app's routes transitions. */
47
+ async follow() {
48
+ await click(this.element);
49
+ }
50
+ }
51
+ /**
52
+ * Drives an `<ExternalLink>` from `@ember-joinery/primitives/external-link`: a `LinkHarness`
53
+ * that drives only those.
54
+ *
55
+ * const mdn = new ExternalLinkHarness()
56
+ * assert.true(mdn.opensInNewTab && mdn.isIsolated)
57
+ */
58
+ export class ExternalLinkHarness extends LinkHarness {
59
+ static component = 'external-link';
60
+ }
@@ -0,0 +1,42 @@
1
+ import { Harness } from './harness.ts';
2
+ /**
3
+ * Drives a `<Marker>` from `@ember-joinery/ember`, or an element made a marker with its
4
+ * `asMarker` modifier. It reads the marker's text, look and role, and clicks or focuses one
5
+ * that is a link or a button:
6
+ *
7
+ * const thinking = new MarkerHarness('thinking') // <Marker @name="thinking" role="status">
8
+ * assert.true(thinking.isStatus)
9
+ * assert.strictEqual(thinking.text, 'Thinking...')
10
+ */
11
+ export declare class MarkerHarness extends Harness {
12
+ static component: string;
13
+ /** All the text it shows, whitespace collapsed. */
14
+ get text(): string;
15
+ /** Its accessible name: its `aria-label`, else its text (the icon is hidden). */
16
+ get label(): string;
17
+ /** Its `@variant`: `default`, `separator` or `border`. */
18
+ get variant(): string | null;
19
+ /** The role it was given, such as `status`, or `null`. */
20
+ get role(): string | null;
21
+ /** Whether assistive technology announces it as it changes: `role="status"`. */
22
+ get isStatus(): boolean;
23
+ /** The icon's slot. Throws when it has none. */
24
+ get icon(): HTMLElement;
25
+ /** Whether it has an icon. */
26
+ get hasIcon(): boolean;
27
+ /** Its content. Throws when it has none. */
28
+ get content(): HTMLElement;
29
+ /** Whether it is a link: an `<a href>`. */
30
+ get isLink(): boolean;
31
+ /** Where it links to, or `null` when it isn't a link. */
32
+ get href(): string | null;
33
+ /** Whether it is a button. */
34
+ get isButton(): boolean;
35
+ /** Whether it has focus. */
36
+ get isFocused(): boolean;
37
+ /** Clicks it, as a user would: follows a link marker, presses a button one. */
38
+ click(): Promise<void>;
39
+ /** Moves focus to it, as tabbing to a link or button marker would. */
40
+ focus(): Promise<void>;
41
+ }
42
+ //# sourceMappingURL=marker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marker.d.ts","sourceRoot":"","sources":["../src/marker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAMtC;;;;;;;;GAQG;AACH,qBAAa,aAAc,SAAQ,OAAO;IACxC,OAAgB,SAAS,SAAW;IAEpC,mDAAmD;IACnD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,iFAAiF;IACjF,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,0DAA0D;IAC1D,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAE3B;IAED,0DAA0D;IAC1D,IAAI,IAAI,IAAI,MAAM,GAAG,IAAI,CAExB;IAED,gFAAgF;IAChF,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,gDAAgD;IAChD,IAAI,IAAI,IAAI,WAAW,CAEtB;IAED,8BAA8B;IAC9B,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,4CAA4C;IAC5C,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED,2CAA2C;IAC3C,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,yDAAyD;IACzD,IAAI,IAAI,IAAI,MAAM,GAAG,IAAI,CAExB;IAED,8BAA8B;IAC9B,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,4BAA4B;IAC5B,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,+EAA+E;IACzE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,sEAAsE;IAChE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
package/dist/marker.js ADDED
@@ -0,0 +1,73 @@
1
+ import { click, focus } from '@ember/test-helpers';
2
+ import { Harness } from "./harness.js";
3
+ function text(element) {
4
+ return (element?.textContent ?? '').replace(/\s+/g, ' ').trim();
5
+ }
6
+ /**
7
+ * Drives a `<Marker>` from `@ember-joinery/ember`, or an element made a marker with its
8
+ * `asMarker` modifier. It reads the marker's text, look and role, and clicks or focuses one
9
+ * that is a link or a button:
10
+ *
11
+ * const thinking = new MarkerHarness('thinking') // <Marker @name="thinking" role="status">
12
+ * assert.true(thinking.isStatus)
13
+ * assert.strictEqual(thinking.text, 'Thinking...')
14
+ */
15
+ export class MarkerHarness extends Harness {
16
+ static component = 'marker';
17
+ /** All the text it shows, whitespace collapsed. */
18
+ get text() {
19
+ return text(this.element);
20
+ }
21
+ /** Its accessible name: its `aria-label`, else its text (the icon is hidden). */
22
+ get label() {
23
+ return this.element.getAttribute('aria-label')?.trim() || this.text;
24
+ }
25
+ /** Its `@variant`: `default`, `separator` or `border`. */
26
+ get variant() {
27
+ return this.element.getAttribute('data-variant');
28
+ }
29
+ /** The role it was given, such as `status`, or `null`. */
30
+ get role() {
31
+ return this.element.getAttribute('role');
32
+ }
33
+ /** Whether assistive technology announces it as it changes: `role="status"`. */
34
+ get isStatus() {
35
+ return this.role === 'status';
36
+ }
37
+ /** The icon's slot. Throws when it has none. */
38
+ get icon() {
39
+ return this.part('icon');
40
+ }
41
+ /** Whether it has an icon. */
42
+ get hasIcon() {
43
+ return this.queryPart('icon') !== null;
44
+ }
45
+ /** Its content. Throws when it has none. */
46
+ get content() {
47
+ return this.part('content');
48
+ }
49
+ /** Whether it is a link: an `<a href>`. */
50
+ get isLink() {
51
+ return this.element instanceof HTMLAnchorElement && this.element.hasAttribute('href');
52
+ }
53
+ /** Where it links to, or `null` when it isn't a link. */
54
+ get href() {
55
+ return this.isLink ? this.element.getAttribute('href') : null;
56
+ }
57
+ /** Whether it is a button. */
58
+ get isButton() {
59
+ return this.element instanceof HTMLButtonElement;
60
+ }
61
+ /** Whether it has focus. */
62
+ get isFocused() {
63
+ return this.element.ownerDocument.activeElement === this.element;
64
+ }
65
+ /** Clicks it, as a user would: follows a link marker, presses a button one. */
66
+ async click() {
67
+ await click(this.element);
68
+ }
69
+ /** Moves focus to it, as tabbing to a link or button marker would. */
70
+ async focus() {
71
+ await focus(this.element);
72
+ }
73
+ }
@@ -0,0 +1,76 @@
1
+ import { Harness } from './harness.ts';
2
+ import { MenuLevel } from './-private/menu.ts';
3
+ /**
4
+ * One menu of a menubar: its trigger, in the bar, and its content and items, with a
5
+ * [Dropdown Menu harness's](./dropdown-menu.ts) members for those (`items`, `select()`,
6
+ * `sub()`…). Its content is found through the trigger's `aria-controls`, so it is `null` while
7
+ * the menu is closed.
8
+ */
9
+ export declare class MenubarMenuLevel extends MenuLevel {
10
+ #private;
11
+ constructor(trigger: () => HTMLElement);
12
+ /** Its trigger in the menubar. */
13
+ get trigger(): HTMLElement;
14
+ /** Whether it is open, from the trigger's `aria-expanded`. */
15
+ get isOpen(): boolean;
16
+ /** Whether its trigger is disabled. */
17
+ get isTriggerDisabled(): boolean;
18
+ /** The content's accessible name: its trigger's text. */
19
+ get label(): string;
20
+ /** The content's text, whitespace collapsed. */
21
+ get text(): string;
22
+ /**
23
+ * Presses the trigger as a pointer does: it opens the menu when it is closed, and closes it
24
+ * when it is open. Focus goes to the content, not an item.
25
+ */
26
+ toggle(): Promise<void>;
27
+ /** Opens it with a press on its trigger, unless it is open. */
28
+ open(): Promise<void>;
29
+ /** Closes it with a press on its trigger, unless it is closed. */
30
+ close(): Promise<void>;
31
+ /**
32
+ * Opens it from the keyboard: focus on its trigger, then `key` (Enter, Space or ArrowDown).
33
+ * Focus goes to its first item.
34
+ */
35
+ openWithKeyboard(key?: 'Enter' | ' ' | 'ArrowDown'): Promise<void>;
36
+ /** Moves the pointer onto its trigger: while another menu is open, that opens this one. */
37
+ hoverTrigger(): Promise<void>;
38
+ }
39
+ /**
40
+ * Drives a `<Menubar>` from `@ember-joinery/ember` or `@ember-joinery/primitives/menubar`. Its
41
+ * menus are found by their triggers' text, and read through ARIA: a trigger's `aria-expanded`
42
+ * says its menu is open, and the items' roles and `aria-checked` what they are.
43
+ *
44
+ * const menubar = new MenubarHarness()
45
+ * assert.deepEqual(menubar.menus, ['File', 'Edit', 'View'])
46
+ * const file = menubar.menu('File')
47
+ * await file.open()
48
+ * assert.deepEqual(file.items, ['New Tab', 'New Window', 'Share', 'Print...'])
49
+ * await pressKey('ArrowRight') // Edit opens
50
+ * assert.strictEqual(menubar.openMenu, 'Edit')
51
+ * await menubar.menu('Edit').select('Undo')
52
+ */
53
+ export declare class MenubarHarness extends Harness {
54
+ static component: string;
55
+ /** Each menu's trigger, in order. */
56
+ get triggers(): HTMLElement[];
57
+ /** Each menu's name: its trigger's text, in order. */
58
+ get menus(): string[];
59
+ /** The trigger whose text is `label`. Throws when there is none. */
60
+ trigger(label: string): HTMLElement;
61
+ /** The menu whose trigger's text is `label`. */
62
+ menu(label: string): MenubarMenuLevel;
63
+ /** The name of the menu that is open, or `null`. */
64
+ get openMenu(): string | null;
65
+ /** Whether a menu is open. */
66
+ get isOpen(): boolean;
67
+ /** The name of the menu whose trigger has focus, or `null`. */
68
+ get focusedTrigger(): string | null;
69
+ /** The name of the menu whose trigger Tab lands on (`tabindex="0"`), or `null`. */
70
+ get tabStop(): string | null;
71
+ /** Presses Escape where focus is: it closes the open menu. */
72
+ pressEscape(): Promise<void>;
73
+ /** A press outside the menubar and its menus. */
74
+ pressOutside(): Promise<void>;
75
+ }
76
+ //# sourceMappingURL=menubar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"menubar.d.ts","sourceRoot":"","sources":["../src/menubar.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAItC,OAAO,EAAE,SAAS,EAAkB,MAAM,oBAAoB,CAAA;AAI9D;;;;;GAKG;AACH,qBAAa,gBAAiB,SAAQ,SAAS;;gBAGjC,OAAO,EAAE,MAAM,WAAW;IAQtC,kCAAkC;IAClC,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED,8DAA8D;IAC9D,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,uCAAuC;IACvC,IAAI,iBAAiB,IAAI,OAAO,CAE/B;IAED,yDAAyD;IACzD,IAAI,KAAK,IAAI,MAAM,CAGlB;IAED,gDAAgD;IAChD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B,+DAA+D;IACzD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,kEAAkE;IAC5D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;;OAGG;IACG,gBAAgB,CAAC,GAAG,GAAE,OAAO,GAAG,GAAG,GAAG,WAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKjF,2FAA2F;IACrF,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAGpC;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,cAAe,SAAQ,OAAO;IACzC,OAAgB,SAAS,SAAY;IAErC,qCAAqC;IACrC,IAAI,QAAQ,IAAI,WAAW,EAAE,CAE5B;IAED,sDAAsD;IACtD,IAAI,KAAK,IAAI,MAAM,EAAE,CAEpB;IAED,oEAAoE;IACpE,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;IAUnC,gDAAgD;IAChD,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB;IAIrC,oDAAoD;IACpD,IAAI,QAAQ,IAAI,MAAM,GAAG,IAAI,CAG5B;IAED,8BAA8B;IAC9B,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,+DAA+D;IAC/D,IAAI,cAAc,IAAI,MAAM,GAAG,IAAI,CAIlC;IAED,mFAAmF;IACnF,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAG3B;IAED,8DAA8D;IACxD,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC,iDAAiD;IAC3C,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAGpC"}
@@ -0,0 +1,139 @@
1
+ import { focus } from '@ember/test-helpers';
2
+ import { Harness } from "./harness.js";
3
+ import { pressEscape, pressOutside } from "./layers.js";
4
+ import { hover } from "./pointer.js";
5
+ import { pressKey } from "./focus.js";
6
+ import { MenuLevel, pressAsBrowser } from "./-private/menu.js";
7
+ import { NotFoundError } from "./-private/tree.js";
8
+ import { accessibleName, text } from "./-private/overlay.js";
9
+ /**
10
+ * One menu of a menubar: its trigger, in the bar, and its content and items, with a
11
+ * [Dropdown Menu harness's](./dropdown-menu.ts) members for those (`items`, `select()`,
12
+ * `sub()`…). Its content is found through the trigger's `aria-controls`, so it is `null` while
13
+ * the menu is closed.
14
+ */
15
+ export class MenubarMenuLevel extends MenuLevel {
16
+ #trigger;
17
+ constructor(trigger) {
18
+ super(() => {
19
+ const id = trigger().getAttribute('aria-controls');
20
+ return id ? document.getElementById(id) : null;
21
+ });
22
+ this.#trigger = trigger;
23
+ }
24
+ /** Its trigger in the menubar. */
25
+ get trigger() {
26
+ return this.#trigger();
27
+ }
28
+ /** Whether it is open, from the trigger's `aria-expanded`. */
29
+ get isOpen() {
30
+ return this.trigger.getAttribute('aria-expanded') === 'true';
31
+ }
32
+ /** Whether its trigger is disabled. */
33
+ get isTriggerDisabled() {
34
+ return this.trigger.hasAttribute('data-disabled');
35
+ }
36
+ /** The content's accessible name: its trigger's text. */
37
+ get label() {
38
+ const content = this.content;
39
+ return content ? accessibleName(content) : '';
40
+ }
41
+ /** The content's text, whitespace collapsed. */
42
+ get text() {
43
+ return text(this.content);
44
+ }
45
+ /**
46
+ * Presses the trigger as a pointer does: it opens the menu when it is closed, and closes it
47
+ * when it is open. Focus goes to the content, not an item.
48
+ */
49
+ async toggle() {
50
+ await pressAsBrowser(this.trigger);
51
+ }
52
+ /** Opens it with a press on its trigger, unless it is open. */
53
+ async open() {
54
+ if (!this.isOpen)
55
+ await this.toggle();
56
+ }
57
+ /** Closes it with a press on its trigger, unless it is closed. */
58
+ async close() {
59
+ if (this.isOpen)
60
+ await this.toggle();
61
+ }
62
+ /**
63
+ * Opens it from the keyboard: focus on its trigger, then `key` (Enter, Space or ArrowDown).
64
+ * Focus goes to its first item.
65
+ */
66
+ async openWithKeyboard(key = 'Enter') {
67
+ await focus(this.trigger);
68
+ await pressKey(key);
69
+ }
70
+ /** Moves the pointer onto its trigger: while another menu is open, that opens this one. */
71
+ async hoverTrigger() {
72
+ await hover(this.trigger);
73
+ }
74
+ }
75
+ /**
76
+ * Drives a `<Menubar>` from `@ember-joinery/ember` or `@ember-joinery/primitives/menubar`. Its
77
+ * menus are found by their triggers' text, and read through ARIA: a trigger's `aria-expanded`
78
+ * says its menu is open, and the items' roles and `aria-checked` what they are.
79
+ *
80
+ * const menubar = new MenubarHarness()
81
+ * assert.deepEqual(menubar.menus, ['File', 'Edit', 'View'])
82
+ * const file = menubar.menu('File')
83
+ * await file.open()
84
+ * assert.deepEqual(file.items, ['New Tab', 'New Window', 'Share', 'Print...'])
85
+ * await pressKey('ArrowRight') // Edit opens
86
+ * assert.strictEqual(menubar.openMenu, 'Edit')
87
+ * await menubar.menu('Edit').select('Undo')
88
+ */
89
+ export class MenubarHarness extends Harness {
90
+ static component = 'menubar';
91
+ /** Each menu's trigger, in order. */
92
+ get triggers() {
93
+ return this.parts('trigger');
94
+ }
95
+ /** Each menu's name: its trigger's text, in order. */
96
+ get menus() {
97
+ return this.triggers.map(text);
98
+ }
99
+ /** The trigger whose text is `label`. Throws when there is none. */
100
+ trigger(label) {
101
+ const trigger = this.triggers.find(element => text(element) === label);
102
+ if (!trigger) {
103
+ throw new NotFoundError(`no menu "${label}" in ${this} (there are: ${this.menus.map(each => `"${each}"`).join(', ')})`);
104
+ }
105
+ return trigger;
106
+ }
107
+ /** The menu whose trigger's text is `label`. */
108
+ menu(label) {
109
+ return new MenubarMenuLevel(() => this.trigger(label));
110
+ }
111
+ /** The name of the menu that is open, or `null`. */
112
+ get openMenu() {
113
+ const open = this.triggers.find(trigger => trigger.getAttribute('aria-expanded') === 'true');
114
+ return open ? text(open) : null;
115
+ }
116
+ /** Whether a menu is open. */
117
+ get isOpen() {
118
+ return this.openMenu !== null;
119
+ }
120
+ /** The name of the menu whose trigger has focus, or `null`. */
121
+ get focusedTrigger() {
122
+ const active = document.activeElement;
123
+ const trigger = this.triggers.find(element => element === active);
124
+ return trigger ? text(trigger) : null;
125
+ }
126
+ /** The name of the menu whose trigger Tab lands on (`tabindex="0"`), or `null`. */
127
+ get tabStop() {
128
+ const trigger = this.triggers.find(element => element.getAttribute('tabindex') === '0');
129
+ return trigger ? text(trigger) : null;
130
+ }
131
+ /** Presses Escape where focus is: it closes the open menu. */
132
+ async pressEscape() {
133
+ await pressEscape();
134
+ }
135
+ /** A press outside the menubar and its menus. */
136
+ async pressOutside() {
137
+ await pressOutside();
138
+ }
139
+ }