@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,299 @@
1
+ import { blur, click, focus } from '@ember/test-helpers';
2
+ import { Harness } from "./harness.js";
3
+ import { pressKey } from "./focus.js";
4
+ import { pressEscape } from "./layers.js";
5
+ import { hover, unhover } from "./pointer.js";
6
+ import { SheetHarness } from "./sheet.js";
7
+ import { accessibleDescription, accessibleName, text } from "./-private/overlay.js";
8
+ import { findWithin, logicalParent } from "./-private/tree.js";
9
+ /**
10
+ * Drives a menu's button or link in a `<SidebarProvider>` (`sidebar.MenuButton`, or your own
11
+ * element with `{{sidebar.menuButton}}`). It is a component root of its own, so it can be a
12
+ * Collapsible's or a Dropdown Menu's trigger too.
13
+ *
14
+ * const inbox = new SidebarMenuButtonHarness('inbox') // <sidebar.MenuButton @name="inbox">
15
+ * await inbox.click()
16
+ * assert.true(inbox.isActive)
17
+ */
18
+ export class SidebarMenuButtonHarness extends Harness {
19
+ static component = 'sidebar-menu-button';
20
+ /** Its accessible name: `aria-label`, `aria-labelledby`'s text, or its own text. */
21
+ get label() {
22
+ return accessibleName(this.element);
23
+ }
24
+ /** The text it shows, whitespace collapsed. */
25
+ get text() {
26
+ return text(this.element);
27
+ }
28
+ /** Whether it is highlighted as the current page's (`@isActive`, its `data-active`). */
29
+ get isActive() {
30
+ return this.element.getAttribute('data-active') === 'true';
31
+ }
32
+ /** Its `@size`: `default`, `sm` or `lg` (a submenu's: `sm` or `md`). */
33
+ get size() {
34
+ return this.element.getAttribute('data-size');
35
+ }
36
+ /** Its `@variant`, `default` or `outline`, from its class (upstream renders no attribute). */
37
+ get variant() {
38
+ const match = /jn-sidebar-menu-button-variant-(\w+)/.exec(this.element.className);
39
+ return match?.[1] ?? null;
40
+ }
41
+ /** Its `href`, for a link. */
42
+ get href() {
43
+ return this.element.getAttribute('href');
44
+ }
45
+ /**
46
+ * For one that opens something (a Collapsible's or a Dropdown Menu's trigger), whether that
47
+ * is open (`aria-expanded`); otherwise `undefined`.
48
+ */
49
+ get isExpanded() {
50
+ const expanded = this.element.getAttribute('aria-expanded');
51
+ return expanded === null ? undefined : expanded === 'true';
52
+ }
53
+ /** Whether it can't be used: `disabled`, or `aria-disabled="true"`. */
54
+ get isDisabled() {
55
+ const element = this.element;
56
+ if ('disabled' in element && element.disabled)
57
+ return true;
58
+ return element.getAttribute('aria-disabled') === 'true';
59
+ }
60
+ /**
61
+ * Its tooltip (`@tooltip`) while it is open, as a screen reader hears it: the text its
62
+ * `aria-describedby` names. `''` while closed.
63
+ */
64
+ get tooltip() {
65
+ return accessibleDescription(this.element);
66
+ }
67
+ /** The tooltip's element while it is open, or `null`. */
68
+ get tooltipElement() {
69
+ const id = this.element.getAttribute('aria-describedby');
70
+ return id ? this.element.ownerDocument.getElementById(id) : null;
71
+ }
72
+ /** Whether its tooltip shows: open, and not `hidden` (it hides while the sidebar is expanded). */
73
+ get isTooltipShown() {
74
+ const tooltip = this.tooltipElement;
75
+ return Boolean(tooltip && !tooltip.hidden && tooltip.matches(':popover-open'));
76
+ }
77
+ /** Whether it has focus. */
78
+ get isFocused() {
79
+ return this.element.ownerDocument.activeElement === this.element;
80
+ }
81
+ async click() {
82
+ await click(this.element);
83
+ }
84
+ async focus() {
85
+ await focus(this.element);
86
+ }
87
+ async blur() {
88
+ await blur(this.element);
89
+ }
90
+ /** Rests the pointer on it, as a mouse does, and waits out its tooltip's delay. */
91
+ async hover(options) {
92
+ await hover(this.element, options);
93
+ }
94
+ /** Moves the pointer off it. */
95
+ async unhover(options) {
96
+ await unhover(this.element, { ...options, away: this.tooltipElement });
97
+ }
98
+ }
99
+ /**
100
+ * Drives a submenu's link in a `<SidebarProvider>` (`sidebar.MenuSubButton`, or your own
101
+ * element with `{{sidebar.menuSubButton}}`): a `SidebarMenuButtonHarness` for
102
+ * `data-test-jn="sidebar-menu-sub-button"`.
103
+ */
104
+ export class SidebarMenuSubButtonHarness extends SidebarMenuButtonHarness {
105
+ static component = 'sidebar-menu-sub-button';
106
+ }
107
+ /** The sidebar an element is in: its nearest `data-test-jn="sidebar"` ancestor in the component tree. */
108
+ function sidebarOf(element) {
109
+ for (let node = logicalParent(element); node; node = logicalParent(node)) {
110
+ if (node.getAttribute('data-test-jn') === 'sidebar')
111
+ return node;
112
+ }
113
+ return null;
114
+ }
115
+ /**
116
+ * Drives a `<SidebarProvider>` from `@ember-joinery/ember` and the sidebar in it. It reads
117
+ * whether the sidebar is open through ARIA, from its trigger's `aria-expanded` (without a
118
+ * trigger, from the panel's `data-state`, or on mobile the sheet's), and acts as a user does:
119
+ * the trigger, the rail, ⌘B (Ctrl+B), and on mobile, Escape or a press outside the sheet.
120
+ *
121
+ * const sidebar = new SidebarHarness('app') // <SidebarProvider @name="app">
122
+ * await sidebar.toggle()
123
+ * assert.strictEqual(sidebar.state, 'collapsed')
124
+ * await sidebar.pressShortcut()
125
+ * assert.true(sidebar.isOpen)
126
+ * assert.deepEqual(sidebar.menuButtonLabels, ['Home', 'Inbox'])
127
+ */
128
+ export class SidebarHarness extends Harness {
129
+ static component = 'sidebar';
130
+ /**
131
+ * The sidebar's panel (`data-slot="sidebar"`): the desktop panel, the plain one with
132
+ * `@collapsible="none"`, or, on mobile, the sheet's content while it is open. `null` when
133
+ * the mobile sheet is closed.
134
+ */
135
+ get panel() {
136
+ return this.queryPart('sidebar') ?? (this.isMobile ? this.sheet.content : null);
137
+ }
138
+ /** The panel inside the desktop sidebar, which your attributes go on (`sidebar-container`). */
139
+ get container() {
140
+ return (this.panel?.querySelector(':scope > [data-slot="sidebar-container"]') ?? null);
141
+ }
142
+ /** The mobile sheet, for a sidebar below its mobile breakpoint. */
143
+ get sheet() {
144
+ return this.child(SheetHarness);
145
+ }
146
+ /** Whether the viewport is narrower than the mobile breakpoint, so the sidebar is a sheet. */
147
+ get isMobile() {
148
+ return !this.queryPart('sidebar') && this.sheet.exists;
149
+ }
150
+ /**
151
+ * `expanded` or `collapsed`: the desktop panel's `data-state`. On mobile, `expanded` while the
152
+ * sheet is open. `null` for a sidebar that doesn't collapse.
153
+ */
154
+ get state() {
155
+ if (this.isMobile)
156
+ return this.sheet.content?.getAttribute('data-state') === 'open' ? 'expanded' : 'collapsed';
157
+ const state = this.queryPart('sidebar')?.getAttribute('data-state');
158
+ return state === 'expanded' || state === 'collapsed' ? state : null;
159
+ }
160
+ /**
161
+ * Whether it is open: the desktop panel expanded, or the mobile sheet open. A screen reader
162
+ * hears it from the trigger's `aria-expanded`, so that is what it reads; with no trigger, the
163
+ * panel's `data-state` (on mobile, the sheet's).
164
+ */
165
+ get isOpen() {
166
+ const expanded = this.queryPart('trigger')?.getAttribute('aria-expanded');
167
+ if (expanded === 'true' || expanded === 'false')
168
+ return expanded === 'true';
169
+ if (this.isMobile)
170
+ return this.sheet.content?.getAttribute('data-state') === 'open';
171
+ return this.queryPart('sidebar')?.getAttribute('data-state') === 'expanded';
172
+ }
173
+ /**
174
+ * How it collapsed, while it is collapsed: `offcanvas` or `icon` (the panel's
175
+ * `data-collapsible`, which upstream leaves empty while it is expanded). `none` for one that
176
+ * doesn't collapse; `null` while expanded, and on mobile.
177
+ */
178
+ get collapsible() {
179
+ const panel = this.queryPart('sidebar');
180
+ if (!panel)
181
+ return null;
182
+ if (!panel.hasAttribute('data-state'))
183
+ return 'none';
184
+ return panel.getAttribute('data-collapsible') || null;
185
+ }
186
+ /** `sidebar`, `floating` or `inset` (`@variant`), on the desktop panel. */
187
+ get variant() {
188
+ return this.queryPart('sidebar')?.getAttribute('data-variant') ?? null;
189
+ }
190
+ /** `left` or `right` (`@side`): the desktop panel's `data-side`, or the sheet's on mobile. */
191
+ get side() {
192
+ const panel = this.queryPart('sidebar');
193
+ if (panel)
194
+ return panel.getAttribute('data-side');
195
+ return this.isMobile ? this.sheet.side : null;
196
+ }
197
+ /** The trigger: `sidebar.Trigger`, or your own element with `{{sidebar.trigger}}`. */
198
+ get trigger() {
199
+ return this.part('trigger');
200
+ }
201
+ /** The rail along the sidebar's edge, or `null`. */
202
+ get rail() {
203
+ return this.queryPart('rail');
204
+ }
205
+ /** The page beside the sidebar (`sidebar.Inset`), or `null`. */
206
+ get inset() {
207
+ return this.queryPart('inset');
208
+ }
209
+ /**
210
+ * The sidebar's elements of one kind, by upstream's `data-sidebar` (`group`, `group-label`,
211
+ * `menu`, `menu-item`, `menu-sub`, `menu-badge`…), in document order. Unlike `parts()`, it
212
+ * looks through any component between, such as a Collapsible around a group or the mobile
213
+ * Sheet, whose own parts a sidebar's often are; not into a sidebar inside this one.
214
+ */
215
+ elements(name) {
216
+ const root = this.element;
217
+ return findWithin(root, `[data-sidebar="${CSS.escape(name)}"]`).filter(element => sidebarOf(element) === root);
218
+ }
219
+ /** The text of each group's label, in order. */
220
+ get groupLabels() {
221
+ return this.elements('group-label').map(element => text(element));
222
+ }
223
+ /** Every menu button in the sidebar (not the submenus'), in order. */
224
+ get menuButtons() {
225
+ return this.findAll(SidebarMenuButtonHarness);
226
+ }
227
+ /** Every submenu button in the sidebar, in order: those in closed collapsibles aren't there. */
228
+ get menuSubButtons() {
229
+ return this.findAll(SidebarMenuSubButtonHarness);
230
+ }
231
+ /** Each menu button's label, in order. */
232
+ get menuButtonLabels() {
233
+ return this.menuButtons.map(button => button.label);
234
+ }
235
+ /** Each submenu button's label, in order. */
236
+ get menuSubButtonLabels() {
237
+ return this.menuSubButtons.map(button => button.label);
238
+ }
239
+ /** The menu button labelled `label`. Throws when there is none. */
240
+ menuButton(label) {
241
+ const found = this.menuButtons.find(button => button.label === label);
242
+ if (!found) {
243
+ throw new Error(`Joinery harness: no menu button "${label}" in ${this} (there are ${JSON.stringify(this.menuButtonLabels)})`);
244
+ }
245
+ return found;
246
+ }
247
+ /** The submenu button labelled `label`. Throws when there is none. */
248
+ menuSubButton(label) {
249
+ const found = this.menuSubButtons.find(button => button.label === label);
250
+ if (!found) {
251
+ throw new Error(`Joinery harness: no submenu button "${label}" in ${this} (there are ${JSON.stringify(this.menuSubButtonLabels)})`);
252
+ }
253
+ return found;
254
+ }
255
+ /** The text of each menu badge, in order. */
256
+ get badges() {
257
+ return this.elements('menu-badge').map(element => text(element));
258
+ }
259
+ /** Clicks the trigger, as a user does: it opens or closes the sidebar (the sheet, on mobile). */
260
+ async toggle() {
261
+ await click(this.trigger);
262
+ }
263
+ /** Opens it with the trigger, unless it is open. */
264
+ async open() {
265
+ if (!this.isOpen)
266
+ await this.toggle();
267
+ }
268
+ /** Closes it with the trigger (on mobile, Escape), unless it is closed. */
269
+ async close() {
270
+ if (!this.isOpen)
271
+ return;
272
+ if (this.isMobile)
273
+ await pressEscape();
274
+ else
275
+ await this.toggle();
276
+ }
277
+ /** Clicks the rail. */
278
+ async toggleWithRail() {
279
+ const rail = this.rail;
280
+ if (!rail)
281
+ throw new Error(`Joinery harness: ${this} has no rail`);
282
+ await click(rail);
283
+ }
284
+ /**
285
+ * Presses the keyboard shortcut, ⌘ (`metaKey`) or Ctrl (`ctrlKey`) with `key` (default
286
+ * `b`), on the focused element.
287
+ */
288
+ async pressShortcut({ key = 'b', metaKey = false, } = {}) {
289
+ return pressKey(key, metaKey ? { metaKey: true } : { ctrlKey: true });
290
+ }
291
+ /** On mobile, presses outside the open sheet (on its overlay), which closes it. */
292
+ async pressOutside() {
293
+ await this.sheet.pressOutside();
294
+ }
295
+ /** Moves focus to the trigger. */
296
+ async focusTrigger() {
297
+ await focus(this.trigger);
298
+ }
299
+ }
@@ -0,0 +1,18 @@
1
+ import { Harness } from './harness.ts';
2
+ /**
3
+ * Drives a `<Skeleton>` from `@ember-joinery/ember`: a placeholder shown while content loads.
4
+ * It has no ARIA of its own (mark the region that is loading with `aria-busy`), so a test
5
+ * counts and measures them.
6
+ *
7
+ * assert.strictEqual(SkeletonHarness.findAll().length, 3)
8
+ */
9
+ export declare class SkeletonHarness extends Harness {
10
+ static component: string;
11
+ /** Its laid-out width, border included, in CSS pixels (a transform on the page doesn't change it). */
12
+ get width(): number;
13
+ /** Its laid-out height, border included, in CSS pixels. */
14
+ get height(): number;
15
+ /** Whether it pulses: its animation runs (a `prefers-reduced-motion` rule of yours can stop it). */
16
+ get isPulsing(): boolean;
17
+ }
18
+ //# sourceMappingURL=skeleton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skeleton.d.ts","sourceRoot":"","sources":["../src/skeleton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC;;;;;;GAMG;AACH,qBAAa,eAAgB,SAAQ,OAAO;IAC1C,OAAgB,SAAS,SAAa;IAEtC,sGAAsG;IACtG,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,2DAA2D;IAC3D,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,oGAAoG;IACpG,IAAI,SAAS,IAAI,OAAO,CAGvB;CACF"}
@@ -0,0 +1,25 @@
1
+ import { Harness } from "./harness.js";
2
+ import { borderBox } from "./-private/size.js";
3
+ /**
4
+ * Drives a `<Skeleton>` from `@ember-joinery/ember`: a placeholder shown while content loads.
5
+ * It has no ARIA of its own (mark the region that is loading with `aria-busy`), so a test
6
+ * counts and measures them.
7
+ *
8
+ * assert.strictEqual(SkeletonHarness.findAll().length, 3)
9
+ */
10
+ export class SkeletonHarness extends Harness {
11
+ static component = 'skeleton';
12
+ /** Its laid-out width, border included, in CSS pixels (a transform on the page doesn't change it). */
13
+ get width() {
14
+ return borderBox(this.element).width;
15
+ }
16
+ /** Its laid-out height, border included, in CSS pixels. */
17
+ get height() {
18
+ return borderBox(this.element).height;
19
+ }
20
+ /** Whether it pulses: its animation runs (a `prefers-reduced-motion` rule of yours can stop it). */
21
+ get isPulsing() {
22
+ const style = getComputedStyle(this.element);
23
+ return style.animationName !== 'none' && style.animationDuration !== '0s';
24
+ }
25
+ }
@@ -0,0 +1,66 @@
1
+ import { Harness } from './harness.ts';
2
+ import { type KeyModifiers } from './focus.ts';
3
+ /**
4
+ * Drives a `<Slider>` from `@ember-joinery/ember`, or the primitives' `Slider`. Each thumb is a
5
+ * `role="slider"`, read through its ARIA; the keys and the pointer move them as a user does.
6
+ *
7
+ * const volume = new SliderHarness('volume') // <Slider @name="volume">
8
+ * await volume.focus()
9
+ * await volume.press('ArrowRight')
10
+ * assert.deepEqual(volume.value, [76])
11
+ * await volume.slideTo(25) // a press at 25% along the track
12
+ */
13
+ export declare class SliderHarness extends Harness {
14
+ static component: string;
15
+ /** Each thumb's element (its `role="slider"`), in order. */
16
+ get thumbs(): HTMLElement[];
17
+ /** The thumb that moves the value at `index` (default 0). Throws when there is none. */
18
+ thumb(index?: number): HTMLElement;
19
+ /**
20
+ * Its value, as Radix's: each thumb's (`aria-valuenow`), in order. A one-thumb slider's is
21
+ * `value[0]`.
22
+ */
23
+ get value(): number[];
24
+ /** Its lowest value (`aria-valuemin`). */
25
+ get min(): number | undefined;
26
+ /** Its highest value (`aria-valuemax`). */
27
+ get max(): number | undefined;
28
+ /** Each thumb's accessible name, in order. */
29
+ get labels(): string[];
30
+ /** `horizontal` or `vertical`. */
31
+ get orientation(): string | null;
32
+ /** Whether it can't be moved: `data-disabled`, and its thumbs out of the tab order. */
33
+ get isDisabled(): boolean;
34
+ /** The index of the thumb that has focus, or `null` when focus is elsewhere. */
35
+ get focused(): number | null;
36
+ /** Focuses a thumb (default the first), as tabbing to it would. */
37
+ focus(index?: number): Promise<void>;
38
+ /** Moves focus away from it. */
39
+ blur(): Promise<void>;
40
+ /**
41
+ * Presses a key on the focused thumb: `ArrowRight`, `PageUp`, `Home`… Focus a thumb first
42
+ * (`focus()`), or give its index here.
43
+ */
44
+ press(key: string, modifiers?: KeyModifiers & {
45
+ thumb?: number;
46
+ }): Promise<void>;
47
+ /**
48
+ * Where along the slider a share of its length is, from where its values start: the left
49
+ * (the right, right to left) or the bottom. For an inverted slider, that is the far end.
50
+ */
51
+ pointAt(percent: number): {
52
+ clientX: number;
53
+ clientY: number;
54
+ };
55
+ /**
56
+ * Presses the slider at `percent` of its length (see `pointAt`) and lets go, as a click on
57
+ * the track: the nearest thumb moves there.
58
+ */
59
+ slideTo(percent: number): Promise<void>;
60
+ /** Drags a thumb (default the first) to `percent` of the slider's length, and lets go. */
61
+ drag(to: number, { thumb, from }?: {
62
+ thumb?: number;
63
+ from?: number;
64
+ }): Promise<void>;
65
+ }
66
+ //# sourceMappingURL=slider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slider.d.ts","sourceRoot":"","sources":["../src/slider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AA4BxD;;;;;;;;;GASG;AACH,qBAAa,aAAc,SAAQ,OAAO;IACxC,OAAgB,SAAS,SAAW;IAEpC,4DAA4D;IAC5D,IAAI,MAAM,IAAI,WAAW,EAAE,CAE1B;IAED,wFAAwF;IACxF,KAAK,CAAC,KAAK,SAAI,GAAG,WAAW;IAI7B;;;OAGG;IACH,IAAI,KAAK,IAAI,MAAM,EAAE,CAIpB;IAED,0CAA0C;IAC1C,IAAI,GAAG,IAAI,MAAM,GAAG,SAAS,CAG5B;IAED,2CAA2C;IAC3C,IAAI,GAAG,IAAI,MAAM,GAAG,SAAS,CAG5B;IAED,8CAA8C;IAC9C,IAAI,MAAM,IAAI,MAAM,EAAE,CAWrB;IAED,kCAAkC;IAClC,IAAI,WAAW,IAAI,MAAM,GAAG,IAAI,CAE/B;IAED,uFAAuF;IACvF,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,gFAAgF;IAChF,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAG3B;IAED,mEAAmE;IAC7D,KAAK,CAAC,KAAK,SAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrC,gCAAgC;IAC1B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3B;;;OAGG;IACG,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,YAAY,GAAG;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtF;;;OAGG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;IAY9D;;;OAGG;IACG,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7C,0FAA0F;IACpF,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,KAAS,EAAE,IAAI,EAAE,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO;CAenF"}
package/dist/slider.js ADDED
@@ -0,0 +1,155 @@
1
+ import { blur, focus, settled } from '@ember/test-helpers';
2
+ import { Harness } from "./harness.js";
3
+ import { pressKey } from "./focus.js";
4
+ /** A number from an attribute, or `undefined` when it's missing or isn't one. */
5
+ function numberOf(element, name) {
6
+ const value = element.getAttribute(name);
7
+ if (value === null || value.trim() === '')
8
+ return undefined;
9
+ const number = Number(value);
10
+ return Number.isFinite(number) ? number : undefined;
11
+ }
12
+ /** Sends one pointer event, as a pointer does. */
13
+ function pointer(target, type, clientX, clientY) {
14
+ target.dispatchEvent(new PointerEvent(type, {
15
+ bubbles: true,
16
+ cancelable: true,
17
+ composed: true,
18
+ pointerId: 1,
19
+ pointerType: 'mouse',
20
+ isPrimary: true,
21
+ button: 0,
22
+ buttons: type === 'pointerup' ? 0 : 1,
23
+ clientX,
24
+ clientY,
25
+ }));
26
+ }
27
+ /**
28
+ * Drives a `<Slider>` from `@ember-joinery/ember`, or the primitives' `Slider`. Each thumb is a
29
+ * `role="slider"`, read through its ARIA; the keys and the pointer move them as a user does.
30
+ *
31
+ * const volume = new SliderHarness('volume') // <Slider @name="volume">
32
+ * await volume.focus()
33
+ * await volume.press('ArrowRight')
34
+ * assert.deepEqual(volume.value, [76])
35
+ * await volume.slideTo(25) // a press at 25% along the track
36
+ */
37
+ export class SliderHarness extends Harness {
38
+ static component = 'slider';
39
+ /** Each thumb's element (its `role="slider"`), in order. */
40
+ get thumbs() {
41
+ return this.parts('thumb');
42
+ }
43
+ /** The thumb that moves the value at `index` (default 0). Throws when there is none. */
44
+ thumb(index = 0) {
45
+ return this.part('thumb', String(index));
46
+ }
47
+ /**
48
+ * Its value, as Radix's: each thumb's (`aria-valuenow`), in order. A one-thumb slider's is
49
+ * `value[0]`.
50
+ */
51
+ get value() {
52
+ return this.thumbs
53
+ .map(thumb => numberOf(thumb, 'aria-valuenow'))
54
+ .filter((value) => value !== undefined);
55
+ }
56
+ /** Its lowest value (`aria-valuemin`). */
57
+ get min() {
58
+ const [thumb] = this.thumbs;
59
+ return thumb ? numberOf(thumb, 'aria-valuemin') : undefined;
60
+ }
61
+ /** Its highest value (`aria-valuemax`). */
62
+ get max() {
63
+ const [thumb] = this.thumbs;
64
+ return thumb ? numberOf(thumb, 'aria-valuemax') : undefined;
65
+ }
66
+ /** Each thumb's accessible name, in order. */
67
+ get labels() {
68
+ return this.thumbs.map(thumb => {
69
+ const labelledBy = thumb.getAttribute('aria-labelledby');
70
+ if (labelledBy) {
71
+ return labelledBy
72
+ .split(/\s+/)
73
+ .map(id => thumb.ownerDocument.getElementById(id)?.textContent?.trim() ?? '')
74
+ .join(' ');
75
+ }
76
+ return thumb.getAttribute('aria-label') ?? '';
77
+ });
78
+ }
79
+ /** `horizontal` or `vertical`. */
80
+ get orientation() {
81
+ return this.element.getAttribute('data-orientation');
82
+ }
83
+ /** Whether it can't be moved: `data-disabled`, and its thumbs out of the tab order. */
84
+ get isDisabled() {
85
+ return this.element.hasAttribute('data-disabled');
86
+ }
87
+ /** The index of the thumb that has focus, or `null` when focus is elsewhere. */
88
+ get focused() {
89
+ const index = this.thumbs.indexOf(document.activeElement);
90
+ return index === -1 ? null : index;
91
+ }
92
+ /** Focuses a thumb (default the first), as tabbing to it would. */
93
+ async focus(index = 0) {
94
+ await focus(this.thumb(index));
95
+ }
96
+ /** Moves focus away from it. */
97
+ async blur() {
98
+ const index = this.focused;
99
+ if (index !== null)
100
+ await blur(this.thumb(index));
101
+ }
102
+ /**
103
+ * Presses a key on the focused thumb: `ArrowRight`, `PageUp`, `Home`… Focus a thumb first
104
+ * (`focus()`), or give its index here.
105
+ */
106
+ async press(key, modifiers) {
107
+ if (modifiers?.thumb !== undefined)
108
+ await this.focus(modifiers.thumb);
109
+ else if (this.focused === null)
110
+ await this.focus();
111
+ await pressKey(key, modifiers);
112
+ }
113
+ /**
114
+ * Where along the slider a share of its length is, from where its values start: the left
115
+ * (the right, right to left) or the bottom. For an inverted slider, that is the far end.
116
+ */
117
+ pointAt(percent) {
118
+ const element = this.element;
119
+ const rect = element.getBoundingClientRect();
120
+ const share = percent / 100;
121
+ if (this.orientation === 'vertical') {
122
+ return { clientX: rect.left + rect.width / 2, clientY: rect.bottom - rect.height * share };
123
+ }
124
+ const rtl = getComputedStyle(element).direction === 'rtl';
125
+ const clientX = rtl ? rect.right - rect.width * share : rect.left + rect.width * share;
126
+ return { clientX, clientY: rect.top + rect.height / 2 };
127
+ }
128
+ /**
129
+ * Presses the slider at `percent` of its length (see `pointAt`) and lets go, as a click on
130
+ * the track: the nearest thumb moves there.
131
+ */
132
+ async slideTo(percent) {
133
+ const { clientX, clientY } = this.pointAt(percent);
134
+ const target = this.element.querySelector('[data-test-jn-part="track"]') ?? this.element;
135
+ pointer(target, 'pointerdown', clientX, clientY);
136
+ await settled();
137
+ pointer(target, 'pointerup', clientX, clientY);
138
+ await settled();
139
+ }
140
+ /** Drags a thumb (default the first) to `percent` of the slider's length, and lets go. */
141
+ async drag(to, { thumb = 0, from } = {}) {
142
+ const element = this.thumb(thumb);
143
+ const box = element.getBoundingClientRect();
144
+ const start = from === undefined
145
+ ? { clientX: box.left + box.width / 2, clientY: box.top + box.height / 2 }
146
+ : this.pointAt(from);
147
+ pointer(element, 'pointerdown', start.clientX, start.clientY);
148
+ await settled();
149
+ const { clientX, clientY } = this.pointAt(to);
150
+ pointer(element, 'pointermove', clientX, clientY);
151
+ await settled();
152
+ pointer(element, 'pointerup', clientX, clientY);
153
+ await settled();
154
+ }
155
+ }
@@ -0,0 +1,10 @@
1
+ import { Harness } from './harness.ts';
2
+ /** Drives a `<Spinner>` from `@ember-joinery/ember`: a loading indicator with the `status` role. */
3
+ export declare class SpinnerHarness extends Harness {
4
+ static component: string;
5
+ /** What it announces: its `aria-label` (`Loading` unless given `@label`). */
6
+ get label(): string;
7
+ /** Its role, `status`, so screen readers announce it. */
8
+ get role(): string | null;
9
+ }
10
+ //# sourceMappingURL=spinner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spinner.d.ts","sourceRoot":"","sources":["../src/spinner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,oGAAoG;AACpG,qBAAa,cAAe,SAAQ,OAAO;IACzC,OAAgB,SAAS,SAAY;IAErC,6EAA6E;IAC7E,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,yDAAyD;IACzD,IAAI,IAAI,IAAI,MAAM,GAAG,IAAI,CAExB;CACF"}
@@ -0,0 +1,13 @@
1
+ import { Harness } from "./harness.js";
2
+ /** Drives a `<Spinner>` from `@ember-joinery/ember`: a loading indicator with the `status` role. */
3
+ export class SpinnerHarness extends Harness {
4
+ static component = 'spinner';
5
+ /** What it announces: its `aria-label` (`Loading` unless given `@label`). */
6
+ get label() {
7
+ return this.element.getAttribute('aria-label') ?? '';
8
+ }
9
+ /** Its role, `status`, so screen readers announce it. */
10
+ get role() {
11
+ return this.element.getAttribute('role');
12
+ }
13
+ }