@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.
- package/CHANGELOG.md +550 -0
- package/LICENSE.md +9 -0
- package/NOTICE +532 -0
- package/README.md +356 -2
- package/addon-main.cjs +4 -0
- package/dist/-private/checkable.d.ts +21 -0
- package/dist/-private/checkable.d.ts.map +1 -0
- package/dist/-private/checkable.js +80 -0
- package/dist/-private/control.d.ts +18 -0
- package/dist/-private/control.d.ts.map +1 -0
- package/dist/-private/control.js +55 -0
- package/dist/-private/menu.d.ts +145 -0
- package/dist/-private/menu.d.ts.map +1 -0
- package/dist/-private/menu.js +322 -0
- package/dist/-private/overlay.d.ts +9 -0
- package/dist/-private/overlay.d.ts.map +1 -0
- package/dist/-private/overlay.js +39 -0
- package/dist/-private/showing.d.ts +7 -0
- package/dist/-private/showing.d.ts.map +1 -0
- package/dist/-private/showing.js +10 -0
- package/dist/-private/size.d.ts +10 -0
- package/dist/-private/size.d.ts.map +1 -0
- package/dist/-private/size.js +24 -0
- package/dist/-private/tree.d.ts +34 -0
- package/dist/-private/tree.d.ts.map +1 -0
- package/dist/-private/tree.js +80 -0
- package/dist/accordion.d.ts +62 -0
- package/dist/accordion.d.ts.map +1 -0
- package/dist/accordion.js +112 -0
- package/dist/alert-dialog.d.ts +24 -0
- package/dist/alert-dialog.d.ts.map +1 -0
- package/dist/alert-dialog.js +37 -0
- package/dist/alert.d.ts +27 -0
- package/dist/alert.d.ts.map +1 -0
- package/dist/alert.js +43 -0
- package/dist/aspect-ratio.d.ts +21 -0
- package/dist/aspect-ratio.d.ts.map +1 -0
- package/dist/aspect-ratio.js +30 -0
- package/dist/attachment.d.ts +86 -0
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +156 -0
- package/dist/avatar.d.ts +65 -0
- package/dist/avatar.d.ts.map +1 -0
- package/dist/avatar.js +106 -0
- package/dist/badge.d.ts +29 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +49 -0
- package/dist/breadcrumb.d.ts +36 -0
- package/dist/breadcrumb.d.ts.map +1 -0
- package/dist/breadcrumb.js +80 -0
- package/dist/bubble.d.ts +56 -0
- package/dist/bubble.d.ts.map +1 -0
- package/dist/bubble.js +94 -0
- package/dist/button-group.d.ts +34 -0
- package/dist/button-group.d.ts.map +1 -0
- package/dist/button-group.js +62 -0
- package/dist/button.d.ts +37 -0
- package/dist/button.d.ts.map +1 -0
- package/dist/button.js +77 -0
- package/dist/calendar.d.ts +115 -0
- package/dist/calendar.d.ts.map +1 -0
- package/dist/calendar.js +276 -0
- package/dist/card.d.ts +31 -0
- package/dist/card.d.ts.map +1 -0
- package/dist/card.js +49 -0
- package/dist/checkbox.d.ts +46 -0
- package/dist/checkbox.d.ts.map +1 -0
- package/dist/checkbox.js +84 -0
- package/dist/child.d.ts +29 -0
- package/dist/child.d.ts.map +1 -0
- package/dist/child.js +27 -0
- package/dist/collapsible.d.ts +44 -0
- package/dist/collapsible.d.ts.map +1 -0
- package/dist/collapsible.js +83 -0
- package/dist/color-scheme.d.ts +44 -0
- package/dist/color-scheme.d.ts.map +1 -0
- package/dist/color-scheme.js +123 -0
- package/dist/combobox.d.ts +114 -0
- package/dist/combobox.d.ts.map +1 -0
- package/dist/combobox.js +293 -0
- package/dist/command.d.ts +92 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +183 -0
- package/dist/context-menu.d.ts +37 -0
- package/dist/context-menu.d.ts.map +1 -0
- package/dist/context-menu.js +59 -0
- package/dist/date-picker.d.ts +48 -0
- package/dist/date-picker.d.ts.map +1 -0
- package/dist/date-picker.js +136 -0
- package/dist/dialog.d.ts +64 -0
- package/dist/dialog.d.ts.map +1 -0
- package/dist/dialog.js +142 -0
- package/dist/drawer.d.ts +63 -0
- package/dist/drawer.d.ts.map +1 -0
- package/dist/drawer.js +136 -0
- package/dist/dropdown-menu.d.ts +35 -0
- package/dist/dropdown-menu.d.ts.map +1 -0
- package/dist/dropdown-menu.js +49 -0
- package/dist/empty.d.ts +29 -0
- package/dist/empty.d.ts.map +1 -0
- package/dist/empty.js +47 -0
- package/dist/field.d.ts +86 -0
- package/dist/field.d.ts.map +1 -0
- package/dist/field.js +150 -0
- package/dist/file-drop.d.ts +74 -0
- package/dist/file-drop.d.ts.map +1 -0
- package/dist/file-drop.js +137 -0
- package/dist/focus.d.ts +54 -0
- package/dist/focus.d.ts.map +1 -0
- package/dist/focus.js +174 -0
- package/dist/harness.d.ts +90 -0
- package/dist/harness.d.ts.map +1 -0
- package/dist/harness.js +189 -0
- package/dist/heading.d.ts +16 -0
- package/dist/heading.d.ts.map +1 -0
- package/dist/heading.js +19 -0
- package/dist/hero.d.ts +21 -0
- package/dist/hero.d.ts.map +1 -0
- package/dist/hero.js +28 -0
- package/dist/hover-card.d.ts +46 -0
- package/dist/hover-card.d.ts.map +1 -0
- package/dist/hover-card.js +85 -0
- package/dist/icon.d.ts +10 -0
- package/dist/icon.d.ts.map +1 -0
- package/dist/icon.js +13 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +87 -0
- package/dist/input-group.d.ts +55 -0
- package/dist/input-group.d.ts.map +1 -0
- package/dist/input-group.js +103 -0
- package/dist/input-otp.d.ts +103 -0
- package/dist/input-otp.d.ts.map +1 -0
- package/dist/input-otp.js +293 -0
- package/dist/input.d.ts +53 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +90 -0
- package/dist/item.d.ts +63 -0
- package/dist/item.d.ts.map +1 -0
- package/dist/item.js +104 -0
- package/dist/kbd.d.ts +28 -0
- package/dist/kbd.d.ts.map +1 -0
- package/dist/kbd.js +36 -0
- package/dist/keys.d.ts +20 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +32 -0
- package/dist/label.d.ts +24 -0
- package/dist/label.d.ts.map +1 -0
- package/dist/label.js +39 -0
- package/dist/layers.d.ts +42 -0
- package/dist/layers.d.ts.map +1 -0
- package/dist/layers.js +70 -0
- package/dist/link.d.ts +44 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +60 -0
- package/dist/marker.d.ts +42 -0
- package/dist/marker.d.ts.map +1 -0
- package/dist/marker.js +73 -0
- package/dist/menubar.d.ts +76 -0
- package/dist/menubar.d.ts.map +1 -0
- package/dist/menubar.js +139 -0
- package/dist/message-scroller.d.ts +101 -0
- package/dist/message-scroller.d.ts.map +1 -0
- package/dist/message-scroller.js +215 -0
- package/dist/message.d.ts +48 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +72 -0
- package/dist/native-form.d.ts +44 -0
- package/dist/native-form.d.ts.map +1 -0
- package/dist/native-form.js +111 -0
- package/dist/native-select.d.ts +56 -0
- package/dist/native-select.d.ts.map +1 -0
- package/dist/native-select.js +100 -0
- package/dist/navigation-menu.d.ts +97 -0
- package/dist/navigation-menu.d.ts.map +1 -0
- package/dist/navigation-menu.js +207 -0
- package/dist/observers.d.ts +21 -0
- package/dist/observers.d.ts.map +1 -0
- package/dist/observers.js +34 -0
- package/dist/pagination.d.ts +39 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +71 -0
- package/dist/pointer.d.ts +38 -0
- package/dist/pointer.d.ts.map +1 -0
- package/dist/pointer.js +82 -0
- package/dist/popover.d.ts +50 -0
- package/dist/popover.d.ts.map +1 -0
- package/dist/popover.js +90 -0
- package/dist/progress.d.ts +38 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +81 -0
- package/dist/questionnaire.d.ts +117 -0
- package/dist/questionnaire.d.ts.map +1 -0
- package/dist/questionnaire.js +240 -0
- package/dist/radio-group.d.ts +53 -0
- package/dist/radio-group.d.ts.map +1 -0
- package/dist/radio-group.js +95 -0
- package/dist/rating.d.ts +67 -0
- package/dist/rating.d.ts.map +1 -0
- package/dist/rating.js +160 -0
- package/dist/resizable.d.ts +76 -0
- package/dist/resizable.d.ts.map +1 -0
- package/dist/resizable.js +138 -0
- package/dist/routing.d.ts +36 -0
- package/dist/routing.d.ts.map +1 -0
- package/dist/routing.js +50 -0
- package/dist/roving-focus.d.ts +38 -0
- package/dist/roving-focus.d.ts.map +1 -0
- package/dist/roving-focus.js +60 -0
- package/dist/scroll-area.d.ts +58 -0
- package/dist/scroll-area.d.ts.map +1 -0
- package/dist/scroll-area.js +153 -0
- package/dist/scroller.d.ts +41 -0
- package/dist/scroller.d.ts.map +1 -0
- package/dist/scroller.js +65 -0
- package/dist/select.d.ts +98 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +203 -0
- package/dist/selectors.d.ts +44 -0
- package/dist/selectors.d.ts.map +1 -0
- package/dist/selectors.js +63 -0
- package/dist/send-pointer.d.ts +17 -0
- package/dist/send-pointer.d.ts.map +1 -0
- package/dist/send-pointer.js +35 -0
- package/dist/separator.d.ts +26 -0
- package/dist/separator.d.ts.map +1 -0
- package/dist/separator.js +40 -0
- package/dist/shadowed.d.ts +55 -0
- package/dist/shadowed.d.ts.map +1 -0
- package/dist/shadowed.js +97 -0
- package/dist/sheet.d.ts +14 -0
- package/dist/sheet.d.ts.map +1 -0
- package/dist/sheet.js +15 -0
- package/dist/sidebar.d.ts +159 -0
- package/dist/sidebar.d.ts.map +1 -0
- package/dist/sidebar.js +299 -0
- package/dist/skeleton.d.ts +18 -0
- package/dist/skeleton.d.ts.map +1 -0
- package/dist/skeleton.js +25 -0
- package/dist/slider.d.ts +66 -0
- package/dist/slider.d.ts.map +1 -0
- package/dist/slider.js +155 -0
- package/dist/spinner.d.ts +10 -0
- package/dist/spinner.d.ts.map +1 -0
- package/dist/spinner.js +13 -0
- package/dist/sticky-footer.d.ts +33 -0
- package/dist/sticky-footer.d.ts.map +1 -0
- package/dist/sticky-footer.js +65 -0
- package/dist/switch.d.ts +44 -0
- package/dist/switch.d.ts.map +1 -0
- package/dist/switch.js +77 -0
- package/dist/table.d.ts +41 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +100 -0
- package/dist/tabs.d.ts +66 -0
- package/dist/tabs.d.ts.map +1 -0
- package/dist/tabs.js +149 -0
- package/dist/test-hooks.d.ts +9 -0
- package/dist/test-hooks.d.ts.map +1 -0
- package/dist/test-hooks.js +1 -0
- package/dist/textarea.d.ts +47 -0
- package/dist/textarea.d.ts.map +1 -0
- package/dist/textarea.js +78 -0
- package/dist/toaster.d.ts +172 -0
- package/dist/toaster.d.ts.map +1 -0
- package/dist/toaster.js +307 -0
- package/dist/toggle-group.d.ts +51 -0
- package/dist/toggle-group.d.ts.map +1 -0
- package/dist/toggle-group.js +97 -0
- package/dist/toggle.d.ts +21 -0
- package/dist/toggle.d.ts.map +1 -0
- package/dist/toggle.js +26 -0
- package/dist/tooltip.d.ts +48 -0
- package/dist/tooltip.d.ts.map +1 -0
- package/dist/tooltip.js +91 -0
- package/dist/trace.d.ts +118 -0
- package/dist/trace.d.ts.map +1 -0
- package/dist/trace.js +196 -0
- package/dist/translator.d.ts +34 -0
- package/dist/translator.d.ts.map +1 -0
- package/dist/translator.js +75 -0
- package/dist/zoetrope.d.ts +51 -0
- package/dist/zoetrope.d.ts.map +1 -0
- package/dist/zoetrope.js +94 -0
- package/package.json +68 -3
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"}
|
package/dist/spinner.js
ADDED
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Drives a `<StickyFooter>` from `@ember-joinery/primitives/sticky-footer`: its content and
|
|
4
|
+
* footer, whether the content overflows, and where the footer is. A StickyFooter wraps content,
|
|
5
|
+
* so the parts inside it still belong to the component around it; its own elements are found by
|
|
6
|
+
* their `data-jn-sticky-footer-*` attributes.
|
|
7
|
+
*
|
|
8
|
+
* const layout = new StickyFooterHarness()
|
|
9
|
+
* assert.true(layout.isFooterAtBottom) // little content: the footer is at the bottom
|
|
10
|
+
* await layout.scrollToEnd() // a lot of content: the footer is below it
|
|
11
|
+
*/
|
|
12
|
+
export declare class StickyFooterHarness extends Harness {
|
|
13
|
+
#private;
|
|
14
|
+
static component: string;
|
|
15
|
+
/** The element the `<:content>` block renders in. */
|
|
16
|
+
get content(): HTMLElement;
|
|
17
|
+
/** The element the `<:footer>` block renders in. */
|
|
18
|
+
get footer(): HTMLElement;
|
|
19
|
+
/** Whether the content and footer are taller than the wrapper, so it scrolls. */
|
|
20
|
+
get overflows(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Whether the footer's bottom is at the bottom of the wrapper's view, to within a pixel: true
|
|
23
|
+
* while the content is short, and once scrolled to the end when it isn't.
|
|
24
|
+
*/
|
|
25
|
+
get isFooterAtBottom(): boolean;
|
|
26
|
+
/** Whether any of the footer is in the wrapper's view. */
|
|
27
|
+
get isFooterVisible(): boolean;
|
|
28
|
+
/** Scrolls the wrapper to the end, as a user would, to the footer. */
|
|
29
|
+
scrollToEnd(): Promise<void>;
|
|
30
|
+
/** Scrolls the wrapper back to the top. */
|
|
31
|
+
scrollToTop(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=sticky-footer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sticky-footer.d.ts","sourceRoot":"","sources":["../src/sticky-footer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC;;;;;;;;;GASG;AACH,qBAAa,mBAAoB,SAAQ,OAAO;;IAC9C,OAAgB,SAAS,SAAkB;IAU3C,qDAAqD;IACrD,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED,oDAAoD;IACpD,IAAI,MAAM,IAAI,WAAW,CAExB;IAED,iFAAiF;IACjF,IAAI,SAAS,IAAI,OAAO,CAGvB;IAED;;;OAGG;IACH,IAAI,gBAAgB,IAAI,OAAO,CAS9B;IAED,0DAA0D;IAC1D,IAAI,eAAe,IAAI,OAAO,CAI7B;IAED,sEAAsE;IAChE,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAMlC,2CAA2C;IACrC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAInC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Harness } from "./harness.js";
|
|
2
|
+
import { waitForObservers } from "./observers.js";
|
|
3
|
+
/**
|
|
4
|
+
* Drives a `<StickyFooter>` from `@ember-joinery/primitives/sticky-footer`: its content and
|
|
5
|
+
* footer, whether the content overflows, and where the footer is. A StickyFooter wraps content,
|
|
6
|
+
* so the parts inside it still belong to the component around it; its own elements are found by
|
|
7
|
+
* their `data-jn-sticky-footer-*` attributes.
|
|
8
|
+
*
|
|
9
|
+
* const layout = new StickyFooterHarness()
|
|
10
|
+
* assert.true(layout.isFooterAtBottom) // little content: the footer is at the bottom
|
|
11
|
+
* await layout.scrollToEnd() // a lot of content: the footer is below it
|
|
12
|
+
*/
|
|
13
|
+
export class StickyFooterHarness extends Harness {
|
|
14
|
+
static component = 'sticky-footer';
|
|
15
|
+
#slot(name) {
|
|
16
|
+
const element = this.element.querySelector(`:scope > [data-jn-sticky-footer-container] > [data-jn-${name}]`);
|
|
17
|
+
if (!element)
|
|
18
|
+
throw new Error(`Joinery harness: no ${name} in ${this}`);
|
|
19
|
+
return element;
|
|
20
|
+
}
|
|
21
|
+
/** The element the `<:content>` block renders in. */
|
|
22
|
+
get content() {
|
|
23
|
+
return this.#slot('sticky-footer-content');
|
|
24
|
+
}
|
|
25
|
+
/** The element the `<:footer>` block renders in. */
|
|
26
|
+
get footer() {
|
|
27
|
+
return this.#slot('sticky-footer-footer');
|
|
28
|
+
}
|
|
29
|
+
/** Whether the content and footer are taller than the wrapper, so it scrolls. */
|
|
30
|
+
get overflows() {
|
|
31
|
+
const { scrollHeight, clientHeight } = this.element;
|
|
32
|
+
return scrollHeight > clientHeight + 1;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Whether the footer's bottom is at the bottom of the wrapper's view, to within a pixel: true
|
|
36
|
+
* while the content is short, and once scrolled to the end when it isn't.
|
|
37
|
+
*/
|
|
38
|
+
get isFooterAtBottom() {
|
|
39
|
+
const footer = this.footer.getBoundingClientRect();
|
|
40
|
+
const wrapper = this.element;
|
|
41
|
+
const view = wrapper.getBoundingClientRect();
|
|
42
|
+
// The boxes the browser reports are scaled with the page (a test's container is scaled
|
|
43
|
+
// down); the wrapper's own sizes aren't.
|
|
44
|
+
const scale = wrapper.offsetHeight > 0 ? view.height / wrapper.offsetHeight : 1;
|
|
45
|
+
const bottom = view.top + (wrapper.clientTop + wrapper.clientHeight) * scale;
|
|
46
|
+
return Math.abs(footer.bottom - bottom) <= scale;
|
|
47
|
+
}
|
|
48
|
+
/** Whether any of the footer is in the wrapper's view. */
|
|
49
|
+
get isFooterVisible() {
|
|
50
|
+
const footer = this.footer.getBoundingClientRect();
|
|
51
|
+
const view = this.element.getBoundingClientRect();
|
|
52
|
+
return footer.bottom > view.top && footer.top < view.bottom;
|
|
53
|
+
}
|
|
54
|
+
/** Scrolls the wrapper to the end, as a user would, to the footer. */
|
|
55
|
+
async scrollToEnd() {
|
|
56
|
+
const wrapper = this.element;
|
|
57
|
+
wrapper.scrollTo({ top: wrapper.scrollHeight, behavior: 'instant' });
|
|
58
|
+
await waitForObservers();
|
|
59
|
+
}
|
|
60
|
+
/** Scrolls the wrapper back to the top. */
|
|
61
|
+
async scrollToTop() {
|
|
62
|
+
this.element.scrollTo({ top: 0, behavior: 'instant' });
|
|
63
|
+
await waitForObservers();
|
|
64
|
+
}
|
|
65
|
+
}
|
package/dist/switch.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Drives a `<Switch>` from `@ember-joinery/ember`, or the headless one from
|
|
4
|
+
* `@ember-joinery/primitives/switch`. State comes from its ARIA: `aria-checked`,
|
|
5
|
+
* `aria-required` and `aria-invalid`.
|
|
6
|
+
*
|
|
7
|
+
* const airplane = new SwitchHarness('airplane-mode') // <Switch @name="airplane-mode">
|
|
8
|
+
* await airplane.toggle()
|
|
9
|
+
* assert.true(airplane.isChecked)
|
|
10
|
+
*/
|
|
11
|
+
export declare class SwitchHarness extends Harness {
|
|
12
|
+
static component: string;
|
|
13
|
+
/** Whether it is on (`aria-checked="true"`). */
|
|
14
|
+
get isChecked(): boolean;
|
|
15
|
+
/** Its accessible name: `aria-label`, `aria-labelledby`, or its `<label>`'s text. */
|
|
16
|
+
get label(): string;
|
|
17
|
+
/** Its `@size`, `default` or `sm`, for the styled switch; `null` for the headless one. */
|
|
18
|
+
get size(): string | null;
|
|
19
|
+
/** Whether it can't be changed. */
|
|
20
|
+
get isDisabled(): boolean;
|
|
21
|
+
/** Whether a form needs it on (`aria-required="true"`). */
|
|
22
|
+
get isRequired(): boolean;
|
|
23
|
+
/** Whether it is marked invalid (`aria-invalid`). */
|
|
24
|
+
get isInvalid(): boolean;
|
|
25
|
+
/** Whether it has focus. */
|
|
26
|
+
get isFocused(): boolean;
|
|
27
|
+
/** The part that slides, or `null` when a headless switch renders none. */
|
|
28
|
+
get thumb(): HTMLElement | null;
|
|
29
|
+
/** The hidden native checkbox it renders in a form, which the form submits, or `null`. */
|
|
30
|
+
get input(): HTMLInputElement | null;
|
|
31
|
+
/** Clicks it, as a user would: it toggles. */
|
|
32
|
+
click(): Promise<void>;
|
|
33
|
+
/** Toggles it with a click. */
|
|
34
|
+
toggle(): Promise<void>;
|
|
35
|
+
/** Clicks it unless it is on already. */
|
|
36
|
+
check(): Promise<void>;
|
|
37
|
+
/** Clicks it if it is on. */
|
|
38
|
+
uncheck(): Promise<void>;
|
|
39
|
+
/** Moves focus to it, as tabbing to it would. */
|
|
40
|
+
focus(): Promise<void>;
|
|
41
|
+
/** Moves focus away from it. */
|
|
42
|
+
blur(): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=switch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../src/switch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC;;;;;;;;GAQG;AACH,qBAAa,aAAc,SAAQ,OAAO;IACxC,OAAgB,SAAS,SAAW;IAEpC,gDAAgD;IAChD,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,qFAAqF;IACrF,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,0FAA0F;IAC1F,IAAI,IAAI,IAAI,MAAM,GAAG,IAAI,CAExB;IAED,mCAAmC;IACnC,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,2DAA2D;IAC3D,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,qDAAqD;IACrD,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,4BAA4B;IAC5B,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,2EAA2E;IAC3E,IAAI,KAAK,IAAI,WAAW,GAAG,IAAI,CAE9B;IAED,0FAA0F;IAC1F,IAAI,KAAK,IAAI,gBAAgB,GAAG,IAAI,CAEnC;IAED,8CAA8C;IACxC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,+BAA+B;IACzB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B,yCAAyC;IACnC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,6BAA6B;IACvB,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"}
|
package/dist/switch.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
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 `<Switch>` from `@ember-joinery/ember`, or the headless one from
|
|
6
|
+
* `@ember-joinery/primitives/switch`. State comes from its ARIA: `aria-checked`,
|
|
7
|
+
* `aria-required` and `aria-invalid`.
|
|
8
|
+
*
|
|
9
|
+
* const airplane = new SwitchHarness('airplane-mode') // <Switch @name="airplane-mode">
|
|
10
|
+
* await airplane.toggle()
|
|
11
|
+
* assert.true(airplane.isChecked)
|
|
12
|
+
*/
|
|
13
|
+
export class SwitchHarness extends Harness {
|
|
14
|
+
static component = 'switch';
|
|
15
|
+
/** Whether it is on (`aria-checked="true"`). */
|
|
16
|
+
get isChecked() {
|
|
17
|
+
return this.element.getAttribute('aria-checked') === 'true';
|
|
18
|
+
}
|
|
19
|
+
/** Its accessible name: `aria-label`, `aria-labelledby`, or its `<label>`'s text. */
|
|
20
|
+
get label() {
|
|
21
|
+
return accessibleName(this.element);
|
|
22
|
+
}
|
|
23
|
+
/** Its `@size`, `default` or `sm`, for the styled switch; `null` for the headless one. */
|
|
24
|
+
get size() {
|
|
25
|
+
return this.element.getAttribute('data-size');
|
|
26
|
+
}
|
|
27
|
+
/** Whether it can't be changed. */
|
|
28
|
+
get isDisabled() {
|
|
29
|
+
return isDisabled(this.element);
|
|
30
|
+
}
|
|
31
|
+
/** Whether a form needs it on (`aria-required="true"`). */
|
|
32
|
+
get isRequired() {
|
|
33
|
+
return this.element.getAttribute('aria-required') === 'true';
|
|
34
|
+
}
|
|
35
|
+
/** Whether it is marked invalid (`aria-invalid`). */
|
|
36
|
+
get isInvalid() {
|
|
37
|
+
return isInvalid(this.element);
|
|
38
|
+
}
|
|
39
|
+
/** Whether it has focus. */
|
|
40
|
+
get isFocused() {
|
|
41
|
+
return this.element.ownerDocument.activeElement === this.element;
|
|
42
|
+
}
|
|
43
|
+
/** The part that slides, or `null` when a headless switch renders none. */
|
|
44
|
+
get thumb() {
|
|
45
|
+
return this.queryPart('thumb');
|
|
46
|
+
}
|
|
47
|
+
/** The hidden native checkbox it renders in a form, which the form submits, or `null`. */
|
|
48
|
+
get input() {
|
|
49
|
+
return hiddenInputOf(this.element);
|
|
50
|
+
}
|
|
51
|
+
/** Clicks it, as a user would: it toggles. */
|
|
52
|
+
async click() {
|
|
53
|
+
await click(this.element);
|
|
54
|
+
}
|
|
55
|
+
/** Toggles it with a click. */
|
|
56
|
+
async toggle() {
|
|
57
|
+
await this.click();
|
|
58
|
+
}
|
|
59
|
+
/** Clicks it unless it is on already. */
|
|
60
|
+
async check() {
|
|
61
|
+
if (!this.isChecked)
|
|
62
|
+
await this.click();
|
|
63
|
+
}
|
|
64
|
+
/** Clicks it if it is on. */
|
|
65
|
+
async uncheck() {
|
|
66
|
+
if (this.isChecked)
|
|
67
|
+
await this.click();
|
|
68
|
+
}
|
|
69
|
+
/** Moves focus to it, as tabbing to it would. */
|
|
70
|
+
async focus() {
|
|
71
|
+
await focus(this.element);
|
|
72
|
+
}
|
|
73
|
+
/** Moves focus away from it. */
|
|
74
|
+
async blur() {
|
|
75
|
+
await blur(this.element);
|
|
76
|
+
}
|
|
77
|
+
}
|
package/dist/table.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Drives a `<Table>` from `@ember-joinery/ember`. It reads the table as a screen reader does,
|
|
4
|
+
* through its native structure: the caption, the header row's cells, and each row of the body
|
|
5
|
+
* and the footer.
|
|
6
|
+
*
|
|
7
|
+
* const invoices = new TableHarness('invoices') // <Table @name="invoices">
|
|
8
|
+
* assert.deepEqual(invoices.columns, ['Invoice', 'Status', 'Method', 'Amount'])
|
|
9
|
+
* assert.strictEqual(invoices.cell(0, 'Amount').textContent, '$250.00')
|
|
10
|
+
* assert.deepEqual(invoices.column('Status'), ['Paid', 'Pending', 'Unpaid'])
|
|
11
|
+
*/
|
|
12
|
+
export declare class TableHarness extends Harness {
|
|
13
|
+
#private;
|
|
14
|
+
static component: string;
|
|
15
|
+
/** The table element itself: `element`, typed. */
|
|
16
|
+
get table(): HTMLTableElement;
|
|
17
|
+
/** The element around the table that scrolls it sideways when it is too wide (`table-container`). */
|
|
18
|
+
get container(): HTMLElement;
|
|
19
|
+
/** The caption's text, or `null` without one. */
|
|
20
|
+
get caption(): string | null;
|
|
21
|
+
/** The text of each cell in the header's last row: the columns' names. */
|
|
22
|
+
get columns(): string[];
|
|
23
|
+
/** The body's rows (`tr`), in order. */
|
|
24
|
+
get rowElements(): HTMLTableRowElement[];
|
|
25
|
+
/** The text of each body row's cells, row by row. */
|
|
26
|
+
get rows(): string[][];
|
|
27
|
+
/** How many rows the body has. */
|
|
28
|
+
get rowCount(): number;
|
|
29
|
+
/** The text of each footer row's cells, row by row (`[]` without a footer). */
|
|
30
|
+
get footer(): string[][];
|
|
31
|
+
/** The body's row at `index`, counting from 0. Throws when there is none. */
|
|
32
|
+
row(index: number): HTMLTableRowElement;
|
|
33
|
+
/**
|
|
34
|
+
* The cell of the body's row `index` in a column, given by its position or its name (a header
|
|
35
|
+
* cell's text). It counts cells, so a cell spanning columns (`colspan`) counts once.
|
|
36
|
+
*/
|
|
37
|
+
cell(index: number, column: number | string): HTMLTableCellElement;
|
|
38
|
+
/** The text of every body row's cell in a column, given by its position or its name. */
|
|
39
|
+
column(column: number | string): string[];
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../src/table.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAYtC;;;;;;;;;GASG;AACH,qBAAa,YAAa,SAAQ,OAAO;;IACvC,OAAgB,SAAS,SAAU;IAEnC,kDAAkD;IAClD,IAAI,KAAK,IAAI,gBAAgB,CAE5B;IAED,qGAAqG;IACrG,IAAI,SAAS,IAAI,WAAW,CAM3B;IAED,iDAAiD;IACjD,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAG3B;IAED,0EAA0E;IAC1E,IAAI,OAAO,IAAI,MAAM,EAAE,CAItB;IAED,wCAAwC;IACxC,IAAI,WAAW,IAAI,mBAAmB,EAAE,CAEvC;IAED,qDAAqD;IACrD,IAAI,IAAI,IAAI,MAAM,EAAE,EAAE,CAErB;IAED,kCAAkC;IAClC,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,+EAA+E;IAC/E,IAAI,MAAM,IAAI,MAAM,EAAE,EAAE,CAEvB;IAED,6EAA6E;IAC7E,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB;IAMvC;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,oBAAoB;IAOlE,wFAAwF;IACxF,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE;CAmB1C"}
|
package/dist/table.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { isNumber } from '@sindresorhus/is';
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
import { NotFoundError } from "./-private/tree.js";
|
|
4
|
+
function text(element) {
|
|
5
|
+
return (element.textContent ?? '').replace(/\s+/g, ' ').trim();
|
|
6
|
+
}
|
|
7
|
+
/** A row's cells, `th` and `td`, in order. */
|
|
8
|
+
function cellsOf(row) {
|
|
9
|
+
return [...row.cells];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Drives a `<Table>` from `@ember-joinery/ember`. It reads the table as a screen reader does,
|
|
13
|
+
* through its native structure: the caption, the header row's cells, and each row of the body
|
|
14
|
+
* and the footer.
|
|
15
|
+
*
|
|
16
|
+
* const invoices = new TableHarness('invoices') // <Table @name="invoices">
|
|
17
|
+
* assert.deepEqual(invoices.columns, ['Invoice', 'Status', 'Method', 'Amount'])
|
|
18
|
+
* assert.strictEqual(invoices.cell(0, 'Amount').textContent, '$250.00')
|
|
19
|
+
* assert.deepEqual(invoices.column('Status'), ['Paid', 'Pending', 'Unpaid'])
|
|
20
|
+
*/
|
|
21
|
+
export class TableHarness extends Harness {
|
|
22
|
+
static component = 'table';
|
|
23
|
+
/** The table element itself: `element`, typed. */
|
|
24
|
+
get table() {
|
|
25
|
+
return this.element;
|
|
26
|
+
}
|
|
27
|
+
/** The element around the table that scrolls it sideways when it is too wide (`table-container`). */
|
|
28
|
+
get container() {
|
|
29
|
+
const container = this.element.parentElement;
|
|
30
|
+
if (!container || container.getAttribute('data-slot') !== 'table-container') {
|
|
31
|
+
throw new NotFoundError(`no table container around ${this}`);
|
|
32
|
+
}
|
|
33
|
+
return container;
|
|
34
|
+
}
|
|
35
|
+
/** The caption's text, or `null` without one. */
|
|
36
|
+
get caption() {
|
|
37
|
+
const caption = this.table.caption;
|
|
38
|
+
return caption ? text(caption) : null;
|
|
39
|
+
}
|
|
40
|
+
/** The text of each cell in the header's last row: the columns' names. */
|
|
41
|
+
get columns() {
|
|
42
|
+
const rows = this.#rowsOf(this.table.tHead);
|
|
43
|
+
const last = rows.at(-1);
|
|
44
|
+
return last ? cellsOf(last).map(text) : [];
|
|
45
|
+
}
|
|
46
|
+
/** The body's rows (`tr`), in order. */
|
|
47
|
+
get rowElements() {
|
|
48
|
+
return [...this.table.tBodies].flatMap(body => this.#rowsOf(body));
|
|
49
|
+
}
|
|
50
|
+
/** The text of each body row's cells, row by row. */
|
|
51
|
+
get rows() {
|
|
52
|
+
return this.rowElements.map(row => cellsOf(row).map(text));
|
|
53
|
+
}
|
|
54
|
+
/** How many rows the body has. */
|
|
55
|
+
get rowCount() {
|
|
56
|
+
return this.rowElements.length;
|
|
57
|
+
}
|
|
58
|
+
/** The text of each footer row's cells, row by row (`[]` without a footer). */
|
|
59
|
+
get footer() {
|
|
60
|
+
return this.#rowsOf(this.table.tFoot).map(row => cellsOf(row).map(text));
|
|
61
|
+
}
|
|
62
|
+
/** The body's row at `index`, counting from 0. Throws when there is none. */
|
|
63
|
+
row(index) {
|
|
64
|
+
const row = this.rowElements[index];
|
|
65
|
+
if (!row)
|
|
66
|
+
throw new NotFoundError(`no row ${index} in ${this} (it has ${this.rowCount})`);
|
|
67
|
+
return row;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The cell of the body's row `index` in a column, given by its position or its name (a header
|
|
71
|
+
* cell's text). It counts cells, so a cell spanning columns (`colspan`) counts once.
|
|
72
|
+
*/
|
|
73
|
+
cell(index, column) {
|
|
74
|
+
const position = this.#columnIndex(column);
|
|
75
|
+
const cell = cellsOf(this.row(index))[position];
|
|
76
|
+
if (!cell)
|
|
77
|
+
throw new NotFoundError(`no cell ${position} in row ${index} of ${this}`);
|
|
78
|
+
return cell;
|
|
79
|
+
}
|
|
80
|
+
/** The text of every body row's cell in a column, given by its position or its name. */
|
|
81
|
+
column(column) {
|
|
82
|
+
const position = this.#columnIndex(column);
|
|
83
|
+
return this.rowElements.map(row => {
|
|
84
|
+
const cell = cellsOf(row)[position];
|
|
85
|
+
return cell ? text(cell) : '';
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
#columnIndex(column) {
|
|
89
|
+
if (isNumber(column))
|
|
90
|
+
return column;
|
|
91
|
+
const index = this.columns.indexOf(column);
|
|
92
|
+
if (index === -1)
|
|
93
|
+
throw new NotFoundError(`no column "${column}" in ${this}`);
|
|
94
|
+
return index;
|
|
95
|
+
}
|
|
96
|
+
/** A section's own rows: not a nested table's. */
|
|
97
|
+
#rowsOf(section) {
|
|
98
|
+
return section ? [...section.rows] : [];
|
|
99
|
+
}
|
|
100
|
+
}
|
package/dist/tabs.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
import { type KeyModifiers } from './focus.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Drives a `<Tabs>` from `@ember-joinery/ember`, or the primitives' `Tabs`. Its tabs and panels
|
|
5
|
+
* are found by their `@value` (`data-test-jn-value`), and read through ARIA: the selected tab by
|
|
6
|
+
* `aria-selected`, its panel by the tab's `aria-controls`.
|
|
7
|
+
*
|
|
8
|
+
* const settings = new TabsHarness('settings') // <Tabs @name="settings">
|
|
9
|
+
* await settings.select('password')
|
|
10
|
+
* assert.strictEqual(settings.selected, 'password')
|
|
11
|
+
* assert.strictEqual(settings.panelText, 'Change your password here.')
|
|
12
|
+
* await settings.press('ArrowLeft')
|
|
13
|
+
* assert.strictEqual(settings.focused, 'account')
|
|
14
|
+
*/
|
|
15
|
+
export declare class TabsHarness extends Harness {
|
|
16
|
+
static component: string;
|
|
17
|
+
/** The tab list (`role="tablist"`). */
|
|
18
|
+
get list(): HTMLElement;
|
|
19
|
+
/** Each tab's element, in order. */
|
|
20
|
+
get triggers(): HTMLElement[];
|
|
21
|
+
/** Each tab's value, in order. */
|
|
22
|
+
get tabValues(): string[];
|
|
23
|
+
/** The tab whose `@value` this is. Throws when there is none. */
|
|
24
|
+
trigger(value: string): HTMLElement;
|
|
25
|
+
/** The panel whose `@value` this is, shown or not. Throws when there is none. */
|
|
26
|
+
content(value: string): HTMLElement;
|
|
27
|
+
/** The value of the selected tab (`aria-selected="true"`), or `null` when none is. */
|
|
28
|
+
get selected(): string | null;
|
|
29
|
+
/** Whether the tab with this value is selected (`aria-selected`). */
|
|
30
|
+
isSelected(value: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* The panel shown now: the one the selected tab's `aria-controls` names, unless it is
|
|
33
|
+
* `hidden` (or isn't rendered), else `null`.
|
|
34
|
+
*/
|
|
35
|
+
get panel(): HTMLElement | null;
|
|
36
|
+
/** The text of the panel shown now, whitespace collapsed, or `''` when none is. */
|
|
37
|
+
get panelText(): string;
|
|
38
|
+
/** Whether the panel for this value is rendered and not `hidden`. */
|
|
39
|
+
isShown(value: string): boolean;
|
|
40
|
+
/** Whether the tab can't be selected: `disabled`, or `aria-disabled="true"` on a link. */
|
|
41
|
+
isDisabled(value: string): boolean;
|
|
42
|
+
/** Whether the tab is a link tab (an `<a href>`, such as a `LinkTo`). */
|
|
43
|
+
isLink(value: string): boolean;
|
|
44
|
+
/** A tab's accessible name: its `aria-label`, else `aria-labelledby`'s text, else its text. */
|
|
45
|
+
label(value: string): string;
|
|
46
|
+
/** The tab list's accessible name: its `aria-label` or `aria-labelledby`, else `''`. */
|
|
47
|
+
get listLabel(): string;
|
|
48
|
+
/** `horizontal` or `vertical`: the tab list's `aria-orientation`. */
|
|
49
|
+
get orientation(): string | null;
|
|
50
|
+
/** The styled tab list's `@variant` (`default` or `line`), or `null` on the primitive. */
|
|
51
|
+
get variant(): string | null;
|
|
52
|
+
/** The value of the tab Tab lands on (`tabindex="0"`), or `null` while the list itself does. */
|
|
53
|
+
get tabStop(): string | null;
|
|
54
|
+
/** The value of the tab that has focus, or `null` when focus is elsewhere. */
|
|
55
|
+
get focused(): string | null;
|
|
56
|
+
/**
|
|
57
|
+
* Clicks a tab, as a user selects it. A disabled `<button>` ignores the click, as in a
|
|
58
|
+
* browser (`click()` from `@ember/test-helpers` would throw on one).
|
|
59
|
+
*/
|
|
60
|
+
select(value: string): Promise<void>;
|
|
61
|
+
/** Focuses a tab, as a click or the arrow keys would (in `automatic` mode, that selects it). */
|
|
62
|
+
focus(value: string): Promise<void>;
|
|
63
|
+
/** Presses a key on the focused element: `'ArrowRight'`, `'Home'`, `'Enter'`, `' '`. */
|
|
64
|
+
press(key: string, modifiers?: KeyModifiers): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=tabs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs.d.ts","sourceRoot":"","sources":["../src/tabs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAsBxD;;;;;;;;;;;GAWG;AACH,qBAAa,WAAY,SAAQ,OAAO;IACtC,OAAgB,SAAS,SAAS;IAElC,uCAAuC;IACvC,IAAI,IAAI,IAAI,WAAW,CAEtB;IAED,oCAAoC;IACpC,IAAI,QAAQ,IAAI,WAAW,EAAE,CAE5B;IAED,kCAAkC;IAClC,IAAI,SAAS,IAAI,MAAM,EAAE,CAExB;IAED,iEAAiE;IACjE,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;IAInC,iFAAiF;IACjF,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;IAInC,sFAAsF;IACtF,IAAI,QAAQ,IAAI,MAAM,GAAG,IAAI,CAG5B;IAED,qEAAqE;IACrE,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIlC;;;OAGG;IACH,IAAI,KAAK,IAAI,WAAW,GAAG,IAAI,CAM9B;IAED,mFAAmF;IACnF,IAAI,SAAS,IAAI,MAAM,CAGtB;IAED,qEAAqE;IACrE,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAK/B,0FAA0F;IAC1F,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAMlC,yEAAyE;IACzE,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAK9B,+FAA+F;IAC/F,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAI5B,wFAAwF;IACxF,IAAI,SAAS,IAAI,MAAM,CAItB;IAED,qEAAqE;IACrE,IAAI,WAAW,IAAI,MAAM,GAAG,IAAI,CAE/B;IAED,0FAA0F;IAC1F,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAE3B;IAED,gGAAgG;IAChG,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAG3B;IAED,8EAA8E;IAC9E,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAI3B;IAED;;;OAGG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM1C,gGAAgG;IAC1F,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,wFAAwF;IAClF,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;CAGlE"}
|