@ember-joinery/test-support 0.0.0-stage → 1.0.1

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 (285) hide show
  1. package/CHANGELOG.md +550 -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/aspect-ratio.d.ts +21 -0
  37. package/dist/aspect-ratio.d.ts.map +1 -0
  38. package/dist/aspect-ratio.js +30 -0
  39. package/dist/attachment.d.ts +86 -0
  40. package/dist/attachment.d.ts.map +1 -0
  41. package/dist/attachment.js +156 -0
  42. package/dist/avatar.d.ts +65 -0
  43. package/dist/avatar.d.ts.map +1 -0
  44. package/dist/avatar.js +106 -0
  45. package/dist/badge.d.ts +29 -0
  46. package/dist/badge.d.ts.map +1 -0
  47. package/dist/badge.js +49 -0
  48. package/dist/breadcrumb.d.ts +36 -0
  49. package/dist/breadcrumb.d.ts.map +1 -0
  50. package/dist/breadcrumb.js +80 -0
  51. package/dist/bubble.d.ts +56 -0
  52. package/dist/bubble.d.ts.map +1 -0
  53. package/dist/bubble.js +94 -0
  54. package/dist/button-group.d.ts +34 -0
  55. package/dist/button-group.d.ts.map +1 -0
  56. package/dist/button-group.js +62 -0
  57. package/dist/button.d.ts +37 -0
  58. package/dist/button.d.ts.map +1 -0
  59. package/dist/button.js +77 -0
  60. package/dist/calendar.d.ts +115 -0
  61. package/dist/calendar.d.ts.map +1 -0
  62. package/dist/calendar.js +276 -0
  63. package/dist/card.d.ts +31 -0
  64. package/dist/card.d.ts.map +1 -0
  65. package/dist/card.js +49 -0
  66. package/dist/checkbox.d.ts +46 -0
  67. package/dist/checkbox.d.ts.map +1 -0
  68. package/dist/checkbox.js +84 -0
  69. package/dist/child.d.ts +29 -0
  70. package/dist/child.d.ts.map +1 -0
  71. package/dist/child.js +27 -0
  72. package/dist/collapsible.d.ts +44 -0
  73. package/dist/collapsible.d.ts.map +1 -0
  74. package/dist/collapsible.js +83 -0
  75. package/dist/color-scheme.d.ts +44 -0
  76. package/dist/color-scheme.d.ts.map +1 -0
  77. package/dist/color-scheme.js +123 -0
  78. package/dist/combobox.d.ts +114 -0
  79. package/dist/combobox.d.ts.map +1 -0
  80. package/dist/combobox.js +293 -0
  81. package/dist/command.d.ts +92 -0
  82. package/dist/command.d.ts.map +1 -0
  83. package/dist/command.js +183 -0
  84. package/dist/context-menu.d.ts +37 -0
  85. package/dist/context-menu.d.ts.map +1 -0
  86. package/dist/context-menu.js +59 -0
  87. package/dist/date-picker.d.ts +48 -0
  88. package/dist/date-picker.d.ts.map +1 -0
  89. package/dist/date-picker.js +136 -0
  90. package/dist/dialog.d.ts +64 -0
  91. package/dist/dialog.d.ts.map +1 -0
  92. package/dist/dialog.js +142 -0
  93. package/dist/drawer.d.ts +63 -0
  94. package/dist/drawer.d.ts.map +1 -0
  95. package/dist/drawer.js +136 -0
  96. package/dist/dropdown-menu.d.ts +35 -0
  97. package/dist/dropdown-menu.d.ts.map +1 -0
  98. package/dist/dropdown-menu.js +49 -0
  99. package/dist/empty.d.ts +29 -0
  100. package/dist/empty.d.ts.map +1 -0
  101. package/dist/empty.js +47 -0
  102. package/dist/field.d.ts +86 -0
  103. package/dist/field.d.ts.map +1 -0
  104. package/dist/field.js +150 -0
  105. package/dist/file-drop.d.ts +74 -0
  106. package/dist/file-drop.d.ts.map +1 -0
  107. package/dist/file-drop.js +137 -0
  108. package/dist/focus.d.ts +54 -0
  109. package/dist/focus.d.ts.map +1 -0
  110. package/dist/focus.js +174 -0
  111. package/dist/harness.d.ts +90 -0
  112. package/dist/harness.d.ts.map +1 -0
  113. package/dist/harness.js +189 -0
  114. package/dist/heading.d.ts +16 -0
  115. package/dist/heading.d.ts.map +1 -0
  116. package/dist/heading.js +19 -0
  117. package/dist/hero.d.ts +21 -0
  118. package/dist/hero.d.ts.map +1 -0
  119. package/dist/hero.js +28 -0
  120. package/dist/hover-card.d.ts +46 -0
  121. package/dist/hover-card.d.ts.map +1 -0
  122. package/dist/hover-card.js +85 -0
  123. package/dist/icon.d.ts +10 -0
  124. package/dist/icon.d.ts.map +1 -0
  125. package/dist/icon.js +13 -0
  126. package/dist/index.d.ts +86 -0
  127. package/dist/index.d.ts.map +1 -0
  128. package/dist/index.js +87 -0
  129. package/dist/input-group.d.ts +55 -0
  130. package/dist/input-group.d.ts.map +1 -0
  131. package/dist/input-group.js +103 -0
  132. package/dist/input-otp.d.ts +103 -0
  133. package/dist/input-otp.d.ts.map +1 -0
  134. package/dist/input-otp.js +293 -0
  135. package/dist/input.d.ts +53 -0
  136. package/dist/input.d.ts.map +1 -0
  137. package/dist/input.js +90 -0
  138. package/dist/item.d.ts +63 -0
  139. package/dist/item.d.ts.map +1 -0
  140. package/dist/item.js +104 -0
  141. package/dist/kbd.d.ts +28 -0
  142. package/dist/kbd.d.ts.map +1 -0
  143. package/dist/kbd.js +36 -0
  144. package/dist/keys.d.ts +20 -0
  145. package/dist/keys.d.ts.map +1 -0
  146. package/dist/keys.js +32 -0
  147. package/dist/label.d.ts +24 -0
  148. package/dist/label.d.ts.map +1 -0
  149. package/dist/label.js +39 -0
  150. package/dist/layers.d.ts +42 -0
  151. package/dist/layers.d.ts.map +1 -0
  152. package/dist/layers.js +70 -0
  153. package/dist/link.d.ts +44 -0
  154. package/dist/link.d.ts.map +1 -0
  155. package/dist/link.js +60 -0
  156. package/dist/marker.d.ts +42 -0
  157. package/dist/marker.d.ts.map +1 -0
  158. package/dist/marker.js +73 -0
  159. package/dist/menubar.d.ts +76 -0
  160. package/dist/menubar.d.ts.map +1 -0
  161. package/dist/menubar.js +139 -0
  162. package/dist/message-scroller.d.ts +101 -0
  163. package/dist/message-scroller.d.ts.map +1 -0
  164. package/dist/message-scroller.js +215 -0
  165. package/dist/message.d.ts +48 -0
  166. package/dist/message.d.ts.map +1 -0
  167. package/dist/message.js +72 -0
  168. package/dist/native-form.d.ts +44 -0
  169. package/dist/native-form.d.ts.map +1 -0
  170. package/dist/native-form.js +111 -0
  171. package/dist/native-select.d.ts +56 -0
  172. package/dist/native-select.d.ts.map +1 -0
  173. package/dist/native-select.js +100 -0
  174. package/dist/navigation-menu.d.ts +97 -0
  175. package/dist/navigation-menu.d.ts.map +1 -0
  176. package/dist/navigation-menu.js +207 -0
  177. package/dist/observers.d.ts +21 -0
  178. package/dist/observers.d.ts.map +1 -0
  179. package/dist/observers.js +34 -0
  180. package/dist/pagination.d.ts +39 -0
  181. package/dist/pagination.d.ts.map +1 -0
  182. package/dist/pagination.js +71 -0
  183. package/dist/pointer.d.ts +38 -0
  184. package/dist/pointer.d.ts.map +1 -0
  185. package/dist/pointer.js +82 -0
  186. package/dist/popover.d.ts +50 -0
  187. package/dist/popover.d.ts.map +1 -0
  188. package/dist/popover.js +90 -0
  189. package/dist/progress.d.ts +38 -0
  190. package/dist/progress.d.ts.map +1 -0
  191. package/dist/progress.js +81 -0
  192. package/dist/questionnaire.d.ts +117 -0
  193. package/dist/questionnaire.d.ts.map +1 -0
  194. package/dist/questionnaire.js +240 -0
  195. package/dist/radio-group.d.ts +53 -0
  196. package/dist/radio-group.d.ts.map +1 -0
  197. package/dist/radio-group.js +95 -0
  198. package/dist/rating.d.ts +67 -0
  199. package/dist/rating.d.ts.map +1 -0
  200. package/dist/rating.js +160 -0
  201. package/dist/resizable.d.ts +76 -0
  202. package/dist/resizable.d.ts.map +1 -0
  203. package/dist/resizable.js +138 -0
  204. package/dist/routing.d.ts +36 -0
  205. package/dist/routing.d.ts.map +1 -0
  206. package/dist/routing.js +50 -0
  207. package/dist/roving-focus.d.ts +38 -0
  208. package/dist/roving-focus.d.ts.map +1 -0
  209. package/dist/roving-focus.js +60 -0
  210. package/dist/scroll-area.d.ts +58 -0
  211. package/dist/scroll-area.d.ts.map +1 -0
  212. package/dist/scroll-area.js +153 -0
  213. package/dist/scroller.d.ts +41 -0
  214. package/dist/scroller.d.ts.map +1 -0
  215. package/dist/scroller.js +65 -0
  216. package/dist/select.d.ts +98 -0
  217. package/dist/select.d.ts.map +1 -0
  218. package/dist/select.js +203 -0
  219. package/dist/selectors.d.ts +44 -0
  220. package/dist/selectors.d.ts.map +1 -0
  221. package/dist/selectors.js +63 -0
  222. package/dist/send-pointer.d.ts +17 -0
  223. package/dist/send-pointer.d.ts.map +1 -0
  224. package/dist/send-pointer.js +35 -0
  225. package/dist/separator.d.ts +26 -0
  226. package/dist/separator.d.ts.map +1 -0
  227. package/dist/separator.js +40 -0
  228. package/dist/shadowed.d.ts +55 -0
  229. package/dist/shadowed.d.ts.map +1 -0
  230. package/dist/shadowed.js +97 -0
  231. package/dist/sheet.d.ts +14 -0
  232. package/dist/sheet.d.ts.map +1 -0
  233. package/dist/sheet.js +15 -0
  234. package/dist/sidebar.d.ts +159 -0
  235. package/dist/sidebar.d.ts.map +1 -0
  236. package/dist/sidebar.js +299 -0
  237. package/dist/skeleton.d.ts +18 -0
  238. package/dist/skeleton.d.ts.map +1 -0
  239. package/dist/skeleton.js +25 -0
  240. package/dist/slider.d.ts +66 -0
  241. package/dist/slider.d.ts.map +1 -0
  242. package/dist/slider.js +155 -0
  243. package/dist/spinner.d.ts +10 -0
  244. package/dist/spinner.d.ts.map +1 -0
  245. package/dist/spinner.js +13 -0
  246. package/dist/sticky-footer.d.ts +33 -0
  247. package/dist/sticky-footer.d.ts.map +1 -0
  248. package/dist/sticky-footer.js +65 -0
  249. package/dist/switch.d.ts +44 -0
  250. package/dist/switch.d.ts.map +1 -0
  251. package/dist/switch.js +77 -0
  252. package/dist/table.d.ts +41 -0
  253. package/dist/table.d.ts.map +1 -0
  254. package/dist/table.js +100 -0
  255. package/dist/tabs.d.ts +66 -0
  256. package/dist/tabs.d.ts.map +1 -0
  257. package/dist/tabs.js +149 -0
  258. package/dist/test-hooks.d.ts +9 -0
  259. package/dist/test-hooks.d.ts.map +1 -0
  260. package/dist/test-hooks.js +1 -0
  261. package/dist/textarea.d.ts +47 -0
  262. package/dist/textarea.d.ts.map +1 -0
  263. package/dist/textarea.js +78 -0
  264. package/dist/toaster.d.ts +172 -0
  265. package/dist/toaster.d.ts.map +1 -0
  266. package/dist/toaster.js +307 -0
  267. package/dist/toggle-group.d.ts +51 -0
  268. package/dist/toggle-group.d.ts.map +1 -0
  269. package/dist/toggle-group.js +97 -0
  270. package/dist/toggle.d.ts +21 -0
  271. package/dist/toggle.d.ts.map +1 -0
  272. package/dist/toggle.js +26 -0
  273. package/dist/tooltip.d.ts +48 -0
  274. package/dist/tooltip.d.ts.map +1 -0
  275. package/dist/tooltip.js +91 -0
  276. package/dist/trace.d.ts +118 -0
  277. package/dist/trace.d.ts.map +1 -0
  278. package/dist/trace.js +196 -0
  279. package/dist/translator.d.ts +34 -0
  280. package/dist/translator.d.ts.map +1 -0
  281. package/dist/translator.js +75 -0
  282. package/dist/zoetrope.d.ts +51 -0
  283. package/dist/zoetrope.d.ts.map +1 -0
  284. package/dist/zoetrope.js +94 -0
  285. package/package.json +68 -3
@@ -0,0 +1,276 @@
1
+ import { isNumber, isString } from '@sindresorhus/is';
2
+ import { click, focus, select as selectOption, settled } from '@ember/test-helpers';
3
+ import { Harness } from "./harness.js";
4
+ import { pressKey } from "./focus.js";
5
+ function pad(value, length = 2) {
6
+ return String(value).padStart(length, '0');
7
+ }
8
+ /** The day as `yyyy-MM-dd`, the key a calendar's days carry in `data-test-jn-value`. */
9
+ function iso(day) {
10
+ if (isString(day))
11
+ return day;
12
+ return `${pad(day.getFullYear(), 4)}-${pad(day.getMonth() + 1)}-${pad(day.getDate())}`;
13
+ }
14
+ /** A `yyyy-MM-dd` key as a date at local midnight. */
15
+ function parse(value) {
16
+ const [year, month, day] = value.split('-').map(Number);
17
+ const date = new Date(2000, 0, 1);
18
+ date.setFullYear(year, month - 1, day);
19
+ return date;
20
+ }
21
+ function text(element) {
22
+ return (element.textContent ?? '').replace(/\s+/g, ' ').trim();
23
+ }
24
+ /**
25
+ * Drives a `<Calendar>` from `@ember-joinery/ember` or `@ember-joinery/primitives/calendar`. It
26
+ * reads the state from each day's cell and button (`aria-selected`, `disabled`, `data-today`,
27
+ * `data-outside`) and the grid's ARIA, and acts as a user does: presses on the days, the
28
+ * previous and next buttons and the dropdowns, and the arrow keys on the focused day.
29
+ *
30
+ * const calendar = new CalendarHarness('booking') // <Calendar @name="booking">
31
+ * await calendar.select('2026-01-12')
32
+ * assert.deepEqual(calendar.selectedDays, ['2026-01-12'])
33
+ * await calendar.press('ArrowRight')
34
+ * assert.strictEqual(calendar.focusedDay, '2026-01-13')
35
+ *
36
+ * A day is a `Date` or `yyyy-MM-dd`. Where a day shows twice (an outside day of one month is a
37
+ * day of the next one shown), the harness takes the one in its own month.
38
+ */
39
+ export class CalendarHarness extends Harness {
40
+ static component = 'calendar';
41
+ /** Its `@mode` (`single`, `multiple`, `range`), or `null` when its days aren't buttons. */
42
+ get mode() {
43
+ return this.element.getAttribute('data-mode');
44
+ }
45
+ /** Each month shown: its grid. */
46
+ get grids() {
47
+ return this.parts('grid');
48
+ }
49
+ /** Each month's caption, in order: `January 2026`. */
50
+ get captions() {
51
+ return this.parts('caption').map(text);
52
+ }
53
+ /** The first month's caption. */
54
+ get caption() {
55
+ return this.captions[0] ?? '';
56
+ }
57
+ /** Each month's grid's name (`aria-label`), in order. */
58
+ get monthLabels() {
59
+ return this.grids.map(grid => grid.getAttribute('aria-label') ?? '');
60
+ }
61
+ /** The first day of each month shown, as `yyyy-MM-dd`, in order. */
62
+ get months() {
63
+ return this.values('month');
64
+ }
65
+ /** The column headings, as shown (`Su`, `Mo`…). */
66
+ get weekdays() {
67
+ const first = this.grids[0];
68
+ if (!first)
69
+ return [];
70
+ return this.parts('weekday')
71
+ .filter(cell => first.contains(cell))
72
+ .map(text);
73
+ }
74
+ /** The columns' full names (`Sunday`…), from their `aria-label`. */
75
+ get weekdayLabels() {
76
+ const first = this.grids[0];
77
+ if (!first)
78
+ return [];
79
+ return this.parts('weekday')
80
+ .filter(cell => first.contains(cell))
81
+ .map(cell => cell.getAttribute('aria-label') ?? '');
82
+ }
83
+ /** The week numbers shown, in order, as shown (`01`). */
84
+ get weekNumbers() {
85
+ return this.parts('week-number').map(text);
86
+ }
87
+ /** Every day cell (`role="gridcell"`) of every month, in order. */
88
+ get cells() {
89
+ return this.parts('day');
90
+ }
91
+ /**
92
+ * A day's cell: the one in its own month, or else the first showing it. Throws when no month
93
+ * shows it.
94
+ */
95
+ cell(day) {
96
+ const key = iso(day);
97
+ const cells = this.cells.filter(cell => cell.getAttribute('data-test-jn-value') === key);
98
+ const cell = cells.find(found => !found.hasAttribute('data-outside')) ?? cells[0];
99
+ if (!cell)
100
+ throw new Error(`${this}: no month shown has the day ${key}`);
101
+ return cell;
102
+ }
103
+ /** A day's button. Throws when the day has none (it's hidden, or the calendar has no mode). */
104
+ button(day) {
105
+ const button = this.cell(day).querySelector('[data-test-jn-part="day-button"]');
106
+ if (!button)
107
+ throw new Error(`${this}: the day ${iso(day)} has no button`);
108
+ return button;
109
+ }
110
+ /** What a day shows, whitespace collapsed. */
111
+ dayText(day) {
112
+ return text(this.cell(day));
113
+ }
114
+ /** A day's name, as assistive technology reads it: its button's, or its cell's. */
115
+ dayLabel(day) {
116
+ const cell = this.cell(day);
117
+ const button = cell.querySelector('[data-test-jn-part="day-button"]');
118
+ return (button ?? cell).getAttribute('aria-label') ?? '';
119
+ }
120
+ /** Whether a day is selected (`aria-selected`). */
121
+ isSelected(day) {
122
+ return this.cell(day).getAttribute('aria-selected') === 'true';
123
+ }
124
+ /** Whether a day can't be selected (its button is `disabled`). */
125
+ isDisabled(day) {
126
+ return this.cell(day).hasAttribute('data-disabled');
127
+ }
128
+ /** Whether a day is today (`data-today`). */
129
+ isToday(day) {
130
+ return this.cell(day).hasAttribute('data-today');
131
+ }
132
+ /** Whether a day belongs to a month around the one it's shown in (`data-outside`). */
133
+ isOutside(day) {
134
+ return this.cell(day).hasAttribute('data-outside');
135
+ }
136
+ /** Whether a day's cell is there but hidden (`data-hidden`). */
137
+ isHidden(day) {
138
+ return this.cell(day).hasAttribute('data-hidden');
139
+ }
140
+ /** Where a day is in a selected range: `start`, `middle`, `end`, or `null`. */
141
+ rangePosition(day) {
142
+ const button = this.cell(day).querySelector('[data-test-jn-part="day-button"]');
143
+ if (!button)
144
+ return null;
145
+ if (button.getAttribute('data-range-start') === 'true')
146
+ return 'start';
147
+ if (button.getAttribute('data-range-end') === 'true')
148
+ return 'end';
149
+ if (button.getAttribute('data-range-middle') === 'true')
150
+ return 'middle';
151
+ return null;
152
+ }
153
+ /** The selected days shown, as `yyyy-MM-dd`, once each, in order. */
154
+ get selectedDays() {
155
+ const days = this.cells
156
+ .filter(cell => cell.getAttribute('aria-selected') === 'true')
157
+ .map(cell => cell.getAttribute('data-test-jn-value') ?? '');
158
+ return [...new Set(days)].sort();
159
+ }
160
+ /** The selected days shown, as dates. */
161
+ get selected() {
162
+ return this.selectedDays.map(parse);
163
+ }
164
+ /** The disabled days shown, as `yyyy-MM-dd`, once each. */
165
+ get disabledDays() {
166
+ const days = this.cells
167
+ .filter(cell => cell.hasAttribute('data-disabled'))
168
+ .map(cell => cell.getAttribute('data-test-jn-value') ?? '');
169
+ return [...new Set(days)].sort();
170
+ }
171
+ /** The day whose button has focus, as `yyyy-MM-dd`, or `null`. */
172
+ get focusedDay() {
173
+ const active = this.element.ownerDocument.activeElement;
174
+ if (!active || !this.element.contains(active))
175
+ return null;
176
+ return active.closest('[data-test-jn-part="day"]')?.getAttribute('data-test-jn-value') ?? null;
177
+ }
178
+ /** The day in the tab order (the one button with `tabindex="0"`), as `yyyy-MM-dd`, or `null`. */
179
+ get tabStop() {
180
+ const button = this.parts('day-button').find(found => found.getAttribute('tabindex') === '0');
181
+ return button?.getAttribute('data-test-jn-value') ?? null;
182
+ }
183
+ /** The previous-month button. */
184
+ get previousButton() {
185
+ return this.part('previous');
186
+ }
187
+ /** The next-month button. */
188
+ get nextButton() {
189
+ return this.part('next');
190
+ }
191
+ /** Whether the previous button goes anywhere (it isn't `aria-disabled`). */
192
+ get canGoPrevious() {
193
+ return this.previousButton.getAttribute('aria-disabled') !== 'true';
194
+ }
195
+ /** Whether the next button goes anywhere. */
196
+ get canGoNext() {
197
+ return this.nextButton.getAttribute('aria-disabled') !== 'true';
198
+ }
199
+ /** Presses the previous-month button. */
200
+ async previous() {
201
+ await click(this.previousButton);
202
+ }
203
+ /** Presses the next-month button. */
204
+ async next() {
205
+ await click(this.nextButton);
206
+ }
207
+ /** A month's month dropdown (the first month's by default), or `null` when it has none. */
208
+ monthDropdown(index = 0) {
209
+ return this.parts('month-dropdown')[index] ?? null;
210
+ }
211
+ /** A month's year dropdown, or `null` when it has none. */
212
+ yearDropdown(index = 0) {
213
+ return this.parts('year-dropdown')[index] ?? null;
214
+ }
215
+ /** The options of a month's month dropdown, as shown (`Jan`…). */
216
+ monthOptions(index = 0) {
217
+ return [...(this.monthDropdown(index)?.options ?? [])].map(option => text(option));
218
+ }
219
+ /** The options of a month's year dropdown, as shown. */
220
+ yearOptions(index = 0) {
221
+ return [...(this.yearDropdown(index)?.options ?? [])].map(option => text(option));
222
+ }
223
+ /**
224
+ * Picks a month in a month's month dropdown: its index in the year (0 for the first) or the
225
+ * option's text (`Mar`), as choosing it does.
226
+ */
227
+ async chooseMonth(month, index = 0) {
228
+ const select = this.monthDropdown(index);
229
+ if (!select)
230
+ throw new Error(`${this}: month ${index + 1} has no month dropdown`);
231
+ const option = isNumber(month)
232
+ ? select.options[month]
233
+ : [...select.options].find(found => text(found) === month);
234
+ if (!option)
235
+ throw new Error(`${this}: the month dropdown has no option ${month}`);
236
+ await selectOption(select, option.value);
237
+ }
238
+ /** Picks a year in a month's year dropdown, by its number or its text. */
239
+ async chooseYear(year, index = 0) {
240
+ const select = this.yearDropdown(index);
241
+ if (!select)
242
+ throw new Error(`${this}: month ${index + 1} has no year dropdown`);
243
+ const option = [...select.options].find(found => found.value === String(year) || text(found) === String(year));
244
+ if (!option)
245
+ throw new Error(`${this}: the year dropdown has no option ${year}`);
246
+ await selectOption(select, option.value);
247
+ }
248
+ /** Presses a day's button, as a click selects it (or lets it go). */
249
+ async select(day) {
250
+ await click(this.button(day));
251
+ }
252
+ /** Presses each day in turn: the ends of a range, or several days. */
253
+ async selectAll(...days) {
254
+ for (const day of days)
255
+ await this.select(day);
256
+ }
257
+ /** Moves focus to a day's button. */
258
+ async focus(day) {
259
+ await focus(this.button(day));
260
+ }
261
+ /**
262
+ * Presses a key on the focused day (focusing the tab stop first when no day has focus):
263
+ * the arrow keys, `PageUp`, `PageDown`, `Home` and `End`, with `shiftKey` for months and
264
+ * years.
265
+ */
266
+ async press(key, modifiers = {}) {
267
+ if (this.focusedDay === null) {
268
+ const stop = this.tabStop;
269
+ if (!stop)
270
+ throw new Error(`${this}: no day can take focus`);
271
+ await this.focus(stop);
272
+ }
273
+ await pressKey(key, modifiers);
274
+ await settled();
275
+ }
276
+ }
package/dist/card.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { Harness } from './harness.ts';
2
+ /**
3
+ * Drives a `<Card>` from `@ember-joinery/ember`. It reads the title and description, reaches
4
+ * each part, and finds what is inside, such as a footer's buttons, with `find()`:
5
+ *
6
+ * const card = new CardHarness('login') // <Card @name="login">
7
+ * assert.strictEqual(card.title, 'Login to your account')
8
+ * await card.find(ButtonHarness, 'submit').click()
9
+ *
10
+ * A page object can extend it and declare the card's own components with `@child`.
11
+ */
12
+ export declare class CardHarness extends Harness {
13
+ static component: string;
14
+ /** All the text it shows, whitespace collapsed. */
15
+ get text(): string;
16
+ /** Its title's text, or `''` without one. */
17
+ get title(): string;
18
+ /** Its description's text, or `''` without one. */
19
+ get description(): string;
20
+ /** Its `@size`: `default` or `sm`. */
21
+ get size(): string | null;
22
+ /** The header. Throws when it has none. */
23
+ get header(): HTMLElement;
24
+ /** The action's container, in the header. Throws when it has none. */
25
+ get action(): HTMLElement;
26
+ /** The content. Throws when it has none. */
27
+ get content(): HTMLElement;
28
+ /** The footer. Throws when it has none. */
29
+ get footer(): HTMLElement;
30
+ }
31
+ //# sourceMappingURL=card.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../src/card.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAMtC;;;;;;;;;GASG;AACH,qBAAa,WAAY,SAAQ,OAAO;IACtC,OAAgB,SAAS,SAAS;IAElC,mDAAmD;IACnD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,6CAA6C;IAC7C,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,mDAAmD;IACnD,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,sCAAsC;IACtC,IAAI,IAAI,IAAI,MAAM,GAAG,IAAI,CAExB;IAED,2CAA2C;IAC3C,IAAI,MAAM,IAAI,WAAW,CAExB;IAED,sEAAsE;IACtE,IAAI,MAAM,IAAI,WAAW,CAExB;IAED,4CAA4C;IAC5C,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED,2CAA2C;IAC3C,IAAI,MAAM,IAAI,WAAW,CAExB;CACF"}
package/dist/card.js ADDED
@@ -0,0 +1,49 @@
1
+ import { Harness } from "./harness.js";
2
+ function text(element) {
3
+ return (element?.textContent ?? '').replace(/\s+/g, ' ').trim();
4
+ }
5
+ /**
6
+ * Drives a `<Card>` from `@ember-joinery/ember`. It reads the title and description, reaches
7
+ * each part, and finds what is inside, such as a footer's buttons, with `find()`:
8
+ *
9
+ * const card = new CardHarness('login') // <Card @name="login">
10
+ * assert.strictEqual(card.title, 'Login to your account')
11
+ * await card.find(ButtonHarness, 'submit').click()
12
+ *
13
+ * A page object can extend it and declare the card's own components with `@child`.
14
+ */
15
+ export class CardHarness extends Harness {
16
+ static component = 'card';
17
+ /** All the text it shows, whitespace collapsed. */
18
+ get text() {
19
+ return text(this.element);
20
+ }
21
+ /** Its title's text, or `''` without one. */
22
+ get title() {
23
+ return text(this.queryPart('title'));
24
+ }
25
+ /** Its description's text, or `''` without one. */
26
+ get description() {
27
+ return text(this.queryPart('description'));
28
+ }
29
+ /** Its `@size`: `default` or `sm`. */
30
+ get size() {
31
+ return this.element.getAttribute('data-size');
32
+ }
33
+ /** The header. Throws when it has none. */
34
+ get header() {
35
+ return this.part('header');
36
+ }
37
+ /** The action's container, in the header. Throws when it has none. */
38
+ get action() {
39
+ return this.part('action');
40
+ }
41
+ /** The content. Throws when it has none. */
42
+ get content() {
43
+ return this.part('content');
44
+ }
45
+ /** The footer. Throws when it has none. */
46
+ get footer() {
47
+ return this.part('footer');
48
+ }
49
+ }
@@ -0,0 +1,46 @@
1
+ import { Harness } from './harness.ts';
2
+ /**
3
+ * Drives a `<Checkbox>` from `@ember-joinery/ember`, or the headless one from
4
+ * `@ember-joinery/primitives/checkbox`. State comes from its ARIA: `aria-checked` (`mixed`
5
+ * while indeterminate), `aria-required` and `aria-invalid`.
6
+ *
7
+ * const terms = new CheckboxHarness('terms') // <Checkbox @name="terms">
8
+ * await terms.check()
9
+ * assert.true(terms.isChecked)
10
+ */
11
+ export declare class CheckboxHarness extends Harness {
12
+ static component: string;
13
+ /** `checked`, `unchecked` or `indeterminate`, from `aria-checked`. */
14
+ get state(): 'checked' | 'unchecked' | 'indeterminate';
15
+ /** Whether it is checked (`aria-checked="true"`); an indeterminate one isn't. */
16
+ get isChecked(): boolean;
17
+ /** Whether it is indeterminate (`aria-checked="mixed"`). */
18
+ get isIndeterminate(): boolean;
19
+ /** Its accessible name: `aria-label`, `aria-labelledby`, or its `<label>`'s text. */
20
+ get label(): string;
21
+ /** Whether it can't be changed. */
22
+ get isDisabled(): boolean;
23
+ /** Whether a form needs it checked (`aria-required="true"`). */
24
+ get isRequired(): boolean;
25
+ /** Whether it is marked invalid (`aria-invalid`). */
26
+ get isInvalid(): boolean;
27
+ /** Whether it has focus. */
28
+ get isFocused(): boolean;
29
+ /** Its mark, while it shows (checked or indeterminate), or `null`. */
30
+ get indicator(): HTMLElement | null;
31
+ /** The hidden native checkbox it renders in a form, which the form submits, or `null`. */
32
+ get input(): HTMLInputElement | null;
33
+ /** Clicks it, as a user would: it toggles (an indeterminate one becomes checked). */
34
+ click(): Promise<void>;
35
+ /** Toggles it with a click. */
36
+ toggle(): Promise<void>;
37
+ /** Clicks it unless it is checked already. */
38
+ check(): Promise<void>;
39
+ /** Clicks it until it is unchecked: twice from indeterminate, which a click checks first. */
40
+ uncheck(): Promise<void>;
41
+ /** Moves focus to it, as tabbing to it would. */
42
+ focus(): Promise<void>;
43
+ /** Moves focus away from it. */
44
+ blur(): Promise<void>;
45
+ }
46
+ //# sourceMappingURL=checkbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkbox.d.ts","sourceRoot":"","sources":["../src/checkbox.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC;;;;;;;;GAQG;AACH,qBAAa,eAAgB,SAAQ,OAAO;IAC1C,OAAgB,SAAS,SAAa;IAEtC,sEAAsE;IACtE,IAAI,KAAK,IAAI,SAAS,GAAG,WAAW,GAAG,eAAe,CAIrD;IAED,iFAAiF;IACjF,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,4DAA4D;IAC5D,IAAI,eAAe,IAAI,OAAO,CAE7B;IAED,qFAAqF;IACrF,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,mCAAmC;IACnC,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,gEAAgE;IAChE,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,qDAAqD;IACrD,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,4BAA4B;IAC5B,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,sEAAsE;IACtE,IAAI,SAAS,IAAI,WAAW,GAAG,IAAI,CAElC;IAED,0FAA0F;IAC1F,IAAI,KAAK,IAAI,gBAAgB,GAAG,IAAI,CAEnC;IAED,qFAAqF;IAC/E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,+BAA+B;IACzB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B,8CAA8C;IACxC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,6FAA6F;IACvF,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,iDAAiD;IAC3C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,gCAAgC;IAC1B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5B"}
@@ -0,0 +1,84 @@
1
+ import { blur, click, focus } from '@ember/test-helpers';
2
+ import { Harness } from "./harness.js";
3
+ import { accessibleName, hiddenInputOf, isDisabled, isInvalid } from "./-private/checkable.js";
4
+ /**
5
+ * Drives a `<Checkbox>` from `@ember-joinery/ember`, or the headless one from
6
+ * `@ember-joinery/primitives/checkbox`. State comes from its ARIA: `aria-checked` (`mixed`
7
+ * while indeterminate), `aria-required` and `aria-invalid`.
8
+ *
9
+ * const terms = new CheckboxHarness('terms') // <Checkbox @name="terms">
10
+ * await terms.check()
11
+ * assert.true(terms.isChecked)
12
+ */
13
+ export class CheckboxHarness extends Harness {
14
+ static component = 'checkbox';
15
+ /** `checked`, `unchecked` or `indeterminate`, from `aria-checked`. */
16
+ get state() {
17
+ const checked = this.element.getAttribute('aria-checked');
18
+ if (checked === 'mixed')
19
+ return 'indeterminate';
20
+ return checked === 'true' ? 'checked' : 'unchecked';
21
+ }
22
+ /** Whether it is checked (`aria-checked="true"`); an indeterminate one isn't. */
23
+ get isChecked() {
24
+ return this.state === 'checked';
25
+ }
26
+ /** Whether it is indeterminate (`aria-checked="mixed"`). */
27
+ get isIndeterminate() {
28
+ return this.state === 'indeterminate';
29
+ }
30
+ /** Its accessible name: `aria-label`, `aria-labelledby`, or its `<label>`'s text. */
31
+ get label() {
32
+ return accessibleName(this.element);
33
+ }
34
+ /** Whether it can't be changed. */
35
+ get isDisabled() {
36
+ return isDisabled(this.element);
37
+ }
38
+ /** Whether a form needs it checked (`aria-required="true"`). */
39
+ get isRequired() {
40
+ return this.element.getAttribute('aria-required') === 'true';
41
+ }
42
+ /** Whether it is marked invalid (`aria-invalid`). */
43
+ get isInvalid() {
44
+ return isInvalid(this.element);
45
+ }
46
+ /** Whether it has focus. */
47
+ get isFocused() {
48
+ return this.element.ownerDocument.activeElement === this.element;
49
+ }
50
+ /** Its mark, while it shows (checked or indeterminate), or `null`. */
51
+ get indicator() {
52
+ return this.queryPart('indicator');
53
+ }
54
+ /** The hidden native checkbox it renders in a form, which the form submits, or `null`. */
55
+ get input() {
56
+ return hiddenInputOf(this.element);
57
+ }
58
+ /** Clicks it, as a user would: it toggles (an indeterminate one becomes checked). */
59
+ async click() {
60
+ await click(this.element);
61
+ }
62
+ /** Toggles it with a click. */
63
+ async toggle() {
64
+ await this.click();
65
+ }
66
+ /** Clicks it unless it is checked already. */
67
+ async check() {
68
+ if (!this.isChecked)
69
+ await this.click();
70
+ }
71
+ /** Clicks it until it is unchecked: twice from indeterminate, which a click checks first. */
72
+ async uncheck() {
73
+ for (let clicks = 0; clicks < 2 && this.state !== 'unchecked'; clicks++)
74
+ await this.click();
75
+ }
76
+ /** Moves focus to it, as tabbing to it would. */
77
+ async focus() {
78
+ await focus(this.element);
79
+ }
80
+ /** Moves focus away from it. */
81
+ async blur() {
82
+ await blur(this.element);
83
+ }
84
+ }
@@ -0,0 +1,29 @@
1
+ import type { ChildOptions, Harness, HarnessClass } from './harness.ts';
2
+ /**
3
+ * A decorator that works with both decorator implementations in use: the legacy ones Ember
4
+ * apps compile with (`@child(ButtonHarness) declare save: ButtonHarness`, or a bare field in
5
+ * JavaScript) and standard decorators (`@child(ButtonHarness) accessor save!: ButtonHarness`).
6
+ */
7
+ export interface HarnessDecorator<T> {
8
+ <This extends Harness>(target: ClassAccessorDecoratorTarget<This, T>, context: ClassAccessorDecoratorContext<This, T>): ClassAccessorDecoratorResult<This, T>;
9
+ (prototype: Harness, key: string | symbol, descriptor?: PropertyDescriptor): void;
10
+ }
11
+ /**
12
+ * Declares a component inside this one. Reading the property gives its harness, created the
13
+ * first time and kept, so it is the same object for the life of the parent. The lookup behind
14
+ * it is live, and scoped to the parent: its root, and every part the parent owns wherever that
15
+ * is rendered (`data-test-jn-owner`).
16
+ *
17
+ * class EditProfile extends DialogHarness {
18
+ * static named = 'edit-profile'
19
+ * @child(ButtonHarness, 'save') declare save: ButtonHarness // <Button @name="save">
20
+ * @child(InputHarness) declare email: InputHarness // the first input
21
+ * @child(ButtonHarness, { index: 1 }) declare second: ButtonHarness
22
+ * }
23
+ *
24
+ * @param Type the child's harness class
25
+ * @param options the child's `@name`, or `{ name, index }`. Without a name, the class's
26
+ * `static named`, or else the first instance inside the parent.
27
+ */
28
+ export declare function child<T extends Harness>(Type: HarnessClass<T>, options?: ChildOptions): HarnessDecorator<T>;
29
+ //# sourceMappingURL=child.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"child.d.ts","sourceRoot":"","sources":["../src/child.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAEvE;;;;GAIG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,CAAC,IAAI,SAAS,OAAO,EACnB,MAAM,EAAE,4BAA4B,CAAC,IAAI,EAAE,CAAC,CAAC,EAC7C,OAAO,EAAE,6BAA6B,CAAC,IAAI,EAAE,CAAC,CAAC,GAC9C,4BAA4B,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IAGxC,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,UAAU,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAA;CAClF;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,OAAO,EACrC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EACrB,OAAO,CAAC,EAAE,YAAY,GACrB,gBAAgB,CAAC,CAAC,CAAC,CAQrB"}
package/dist/child.js ADDED
@@ -0,0 +1,27 @@
1
+ import { isObject } from '@sindresorhus/is';
2
+ /**
3
+ * Declares a component inside this one. Reading the property gives its harness, created the
4
+ * first time and kept, so it is the same object for the life of the parent. The lookup behind
5
+ * it is live, and scoped to the parent: its root, and every part the parent owns wherever that
6
+ * is rendered (`data-test-jn-owner`).
7
+ *
8
+ * class EditProfile extends DialogHarness {
9
+ * static named = 'edit-profile'
10
+ * @child(ButtonHarness, 'save') declare save: ButtonHarness // <Button @name="save">
11
+ * @child(InputHarness) declare email: InputHarness // the first input
12
+ * @child(ButtonHarness, { index: 1 }) declare second: ButtonHarness
13
+ * }
14
+ *
15
+ * @param Type the child's harness class
16
+ * @param options the child's `@name`, or `{ name, index }`. Without a name, the class's
17
+ * `static named`, or else the first instance inside the parent.
18
+ */
19
+ export function child(Type, options) {
20
+ return ((_target, contextOrKey) => {
21
+ function get() {
22
+ return this.child(Type, options);
23
+ }
24
+ // A standard decorator gets a context object; a legacy one, the property key.
25
+ return isObject(contextOrKey) ? { get } : { configurable: true, enumerable: true, get };
26
+ });
27
+ }
@@ -0,0 +1,44 @@
1
+ import { Harness } from './harness.ts';
2
+ /**
3
+ * Drives a `<Collapsible>`, from `@ember-joinery/ember` or, headless, from
4
+ * `@ember-joinery/primitives/collapsible`. Its state is read from the trigger's
5
+ * `aria-expanded`, so every test also checks what assistive technology hears.
6
+ *
7
+ * const details = new CollapsibleHarness('order') // <Collapsible @name="order">
8
+ * await details.open()
9
+ * assert.true(details.isOpen)
10
+ * assert.strictEqual(details.text, '100 Market St, San Francisco')
11
+ */
12
+ export declare class CollapsibleHarness extends Harness {
13
+ static component: string;
14
+ /** The trigger: `c.Trigger`, or your own element with `{{c.trigger}}`. */
15
+ get trigger(): HTMLElement;
16
+ /**
17
+ * The content's element, which is there (`hidden`) while closed. `null` before it renders.
18
+ * Content that sits inside another component, as in a `FieldGroup` (upstream's settings
19
+ * panel), is that component's part as far as the tree goes, so it is found through the
20
+ * element the trigger's `aria-controls` names instead.
21
+ */
22
+ get content(): HTMLElement | null;
23
+ /** Whether it is open, from the trigger's `aria-expanded`. */
24
+ get isOpen(): boolean;
25
+ /** Whether its content shows: open, or still animating out. */
26
+ get isShown(): boolean;
27
+ /** Whether the trigger can't open or close it. */
28
+ get isDisabled(): boolean;
29
+ /** The trigger's text, whitespace collapsed. */
30
+ get label(): string;
31
+ /** The content's text, whitespace collapsed: `''` while it is closed. */
32
+ get text(): string;
33
+ /** Whether the trigger names the content in `aria-controls`, as the ARIA pattern asks. */
34
+ get controlsContent(): boolean;
35
+ /** Clicks the trigger, as a user does. */
36
+ toggle(): Promise<void>;
37
+ /** Opens it with the trigger, unless it is open. */
38
+ open(): Promise<void>;
39
+ /** Closes it with the trigger, unless it is closed. */
40
+ close(): Promise<void>;
41
+ /** Moves focus to the trigger. */
42
+ focus(): Promise<void>;
43
+ }
44
+ //# sourceMappingURL=collapsible.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collapsible.d.ts","sourceRoot":"","sources":["../src/collapsible.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAOtC;;;;;;;;;GASG;AACH,qBAAa,kBAAmB,SAAQ,OAAO;IAC7C,OAAgB,SAAS,SAAgB;IAEzC,0EAA0E;IAC1E,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED;;;;;OAKG;IACH,IAAI,OAAO,IAAI,WAAW,GAAG,IAAI,CAMhC;IAED,8DAA8D;IAC9D,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,+DAA+D;IAC/D,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,kDAAkD;IAClD,IAAI,UAAU,IAAI,OAAO,CAGxB;IAED,gDAAgD;IAChD,IAAI,KAAK,IAAI,MAAM,CAGlB;IAED,yEAAyE;IACzE,IAAI,IAAI,IAAI,MAAM,CAGjB;IAED,0FAA0F;IAC1F,IAAI,eAAe,IAAI,OAAO,CAG7B;IAED,0CAA0C;IACpC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B,oDAAoD;IAC9C,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,uDAAuD;IACjD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,kCAAkC;IAC5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}