@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/toaster.js
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { click, focus, getContext, settled, triggerEvent, waitUntil } from '@ember/test-helpers';
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
function text(element) {
|
|
4
|
+
return (element?.textContent ?? '').replace(/\s+/g, ' ').trim();
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Drives one toast in a `<Toaster>` (from `@ember-joinery/ember` or
|
|
8
|
+
* `@ember-joinery/primitives/toast`): an `<li data-test-jn="toast">`, named by its id. State
|
|
9
|
+
* comes from sonner's data attributes and the toast's text.
|
|
10
|
+
*
|
|
11
|
+
* const toast = new ToasterHarness().toast() // the newest
|
|
12
|
+
* assert.strictEqual(toast.title, 'Event has been created')
|
|
13
|
+
* await toast.clickAction()
|
|
14
|
+
*
|
|
15
|
+
* new ToastHarness('saved') // toast('Saved', { id: 'saved' })
|
|
16
|
+
*/
|
|
17
|
+
export class ToastHarness extends Harness {
|
|
18
|
+
static component = 'toast';
|
|
19
|
+
/** Its id, as `toast()` returned it (or as you gave it), as a string. */
|
|
20
|
+
get id() {
|
|
21
|
+
return this.element.getAttribute('data-test-jn-name') ?? '';
|
|
22
|
+
}
|
|
23
|
+
/** Its title, whitespace collapsed. */
|
|
24
|
+
get title() {
|
|
25
|
+
return text(this.queryPart('title'));
|
|
26
|
+
}
|
|
27
|
+
/** Its description, or `null` without one. */
|
|
28
|
+
get description() {
|
|
29
|
+
const description = this.queryPart('description');
|
|
30
|
+
return description ? text(description) : null;
|
|
31
|
+
}
|
|
32
|
+
/** Its type (`success`, `error`, `loading`…), or `null` for a plain toast. */
|
|
33
|
+
get type() {
|
|
34
|
+
return this.element.getAttribute('data-type');
|
|
35
|
+
}
|
|
36
|
+
/** Where it shows, as `top-center` or `bottom-right`. */
|
|
37
|
+
get position() {
|
|
38
|
+
const y = this.element.getAttribute('data-y-position');
|
|
39
|
+
const x = this.element.getAttribute('data-x-position');
|
|
40
|
+
return `${y}-${x}`;
|
|
41
|
+
}
|
|
42
|
+
#flag(name) {
|
|
43
|
+
return this.element.getAttribute(name) === 'true';
|
|
44
|
+
}
|
|
45
|
+
/** Whether it is the newest in its stack, the one in front. */
|
|
46
|
+
get isFront() {
|
|
47
|
+
return this.#flag('data-front');
|
|
48
|
+
}
|
|
49
|
+
/** Whether it is among the toasts the stack shows (`@visibleToasts`, 3 by default). */
|
|
50
|
+
get isVisible() {
|
|
51
|
+
return this.#flag('data-visible');
|
|
52
|
+
}
|
|
53
|
+
/** Whether its stack is expanded (hovered, focused from the keyboard, or `@expand`). */
|
|
54
|
+
get isExpanded() {
|
|
55
|
+
return this.#flag('data-expanded');
|
|
56
|
+
}
|
|
57
|
+
/** Whether it has finished coming in. */
|
|
58
|
+
get isMounted() {
|
|
59
|
+
return this.#flag('data-mounted');
|
|
60
|
+
}
|
|
61
|
+
/** Whether it is on its way out. */
|
|
62
|
+
get isRemoved() {
|
|
63
|
+
return this.#flag('data-removed');
|
|
64
|
+
}
|
|
65
|
+
/** Whether it was swiped away. */
|
|
66
|
+
get isSwipedOut() {
|
|
67
|
+
return this.#flag('data-swipe-out');
|
|
68
|
+
}
|
|
69
|
+
/** Whether it is coloured by its type. */
|
|
70
|
+
get hasRichColors() {
|
|
71
|
+
return this.#flag('data-rich-colors');
|
|
72
|
+
}
|
|
73
|
+
/** Whether it is inverted. */
|
|
74
|
+
get isInverted() {
|
|
75
|
+
return this.#flag('data-invert');
|
|
76
|
+
}
|
|
77
|
+
/** Whether the user can close it (`dismissible`). */
|
|
78
|
+
get isDismissible() {
|
|
79
|
+
return this.#flag('data-dismissible');
|
|
80
|
+
}
|
|
81
|
+
/** Whether it shows sonner's look (`false` for `unstyled` and custom toasts). */
|
|
82
|
+
get isStyled() {
|
|
83
|
+
return this.#flag('data-styled');
|
|
84
|
+
}
|
|
85
|
+
/** Whether it follows a promise (`toast.promise()`). */
|
|
86
|
+
get isPromise() {
|
|
87
|
+
return this.#flag('data-promise');
|
|
88
|
+
}
|
|
89
|
+
/** Whether it is loading (`toast.loading()`, or a promise that hasn't settled). */
|
|
90
|
+
get isLoading() {
|
|
91
|
+
return this.type === 'loading';
|
|
92
|
+
}
|
|
93
|
+
/** Its icon's box (`[data-icon]`), or `null` without one. */
|
|
94
|
+
get icon() {
|
|
95
|
+
return this.queryPart('icon');
|
|
96
|
+
}
|
|
97
|
+
/** Its action button, or `null`. */
|
|
98
|
+
get action() {
|
|
99
|
+
return this.queryPart('action');
|
|
100
|
+
}
|
|
101
|
+
/** Its cancel button, or `null`. */
|
|
102
|
+
get cancel() {
|
|
103
|
+
return this.queryPart('cancel');
|
|
104
|
+
}
|
|
105
|
+
/** Its close button, or `null` without one (`closeButton`). */
|
|
106
|
+
get closeButton() {
|
|
107
|
+
return this.queryPart('close');
|
|
108
|
+
}
|
|
109
|
+
#button(button, name) {
|
|
110
|
+
if (!button)
|
|
111
|
+
throw new Error(`${this} has no ${name} button`);
|
|
112
|
+
return button;
|
|
113
|
+
}
|
|
114
|
+
/** Presses its action button. The toast closes, unless the handler prevents it. */
|
|
115
|
+
async clickAction() {
|
|
116
|
+
await click(this.#button(this.action, 'action'));
|
|
117
|
+
}
|
|
118
|
+
/** Presses its cancel button. The toast closes. */
|
|
119
|
+
async clickCancel() {
|
|
120
|
+
await click(this.#button(this.cancel, 'cancel'));
|
|
121
|
+
}
|
|
122
|
+
/** Presses its close button. The toast closes. */
|
|
123
|
+
async close() {
|
|
124
|
+
await click(this.#button(this.closeButton, 'close'));
|
|
125
|
+
}
|
|
126
|
+
/** Moves focus to it, as tabbing to it would. */
|
|
127
|
+
async focus() {
|
|
128
|
+
await focus(this.element);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Swipes it with a pointer, as a finger would: down on it, across, and up. Far enough (45px,
|
|
132
|
+
* or fast enough) towards a side it can leave by, it goes; otherwise it springs back.
|
|
133
|
+
*/
|
|
134
|
+
async swipe(direction, options = {}) {
|
|
135
|
+
const { distance = 100, duration = 0 } = options;
|
|
136
|
+
const element = this.element;
|
|
137
|
+
const box = element.getBoundingClientRect();
|
|
138
|
+
const start = { x: box.left + box.width / 2, y: box.top + box.height / 2 };
|
|
139
|
+
const delta = {
|
|
140
|
+
left: [-distance, 0],
|
|
141
|
+
right: [distance, 0],
|
|
142
|
+
up: [0, -distance],
|
|
143
|
+
down: [0, distance],
|
|
144
|
+
}[direction];
|
|
145
|
+
const pointer = { pointerId: 1, pointerType: 'touch', isPrimary: true, button: 0 };
|
|
146
|
+
await triggerEvent(element, 'pointerdown', { ...pointer, clientX: start.x, clientY: start.y });
|
|
147
|
+
const steps = 4;
|
|
148
|
+
for (let step = 1; step <= steps; step++) {
|
|
149
|
+
await triggerEvent(element, 'pointermove', {
|
|
150
|
+
...pointer,
|
|
151
|
+
clientX: start.x + (delta[0] * step) / steps,
|
|
152
|
+
clientY: start.y + (delta[1] * step) / steps,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
if (duration > 0)
|
|
156
|
+
await new Promise(resolve => setTimeout(resolve, duration));
|
|
157
|
+
const end = { clientX: start.x + delta[0], clientY: start.y + delta[1] };
|
|
158
|
+
// triggerEvent settles, so a dismissed toast has gone (its exit is a test waiter).
|
|
159
|
+
await triggerEvent(element, 'pointerup', { ...pointer, ...end });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Drives a `<Toaster>` (from `@ember-joinery/ember` or `@ember-joinery/primitives/toast`): the
|
|
164
|
+
* live region, its lists (one per position in use) and its toasts.
|
|
165
|
+
*
|
|
166
|
+
* const toaster = new ToasterHarness()
|
|
167
|
+
* await click(saveButton)
|
|
168
|
+
* assert.deepEqual(toaster.titles, ['Saved'])
|
|
169
|
+
* await toaster.hover() // expands the stack and pauses the timers
|
|
170
|
+
*
|
|
171
|
+
* Toasts belong to the app, so give each test its own with `setupToaster(hooks)`.
|
|
172
|
+
*/
|
|
173
|
+
export class ToasterHarness extends Harness {
|
|
174
|
+
static component = 'toaster';
|
|
175
|
+
/** The region's name: `Notifications alt+T` unless given `@containerAriaLabel`. */
|
|
176
|
+
get label() {
|
|
177
|
+
return this.element.getAttribute('aria-label') ?? '';
|
|
178
|
+
}
|
|
179
|
+
/** Its lists (`<ol>`), one for each position with toasts, in document order. */
|
|
180
|
+
get lists() {
|
|
181
|
+
return this.parts('list');
|
|
182
|
+
}
|
|
183
|
+
/** The positions it shows toasts in now. */
|
|
184
|
+
get positions() {
|
|
185
|
+
return this.values('list');
|
|
186
|
+
}
|
|
187
|
+
/** What each list says about itself: its position, theme and direction. */
|
|
188
|
+
get listStates() {
|
|
189
|
+
return this.lists.map(list => ({
|
|
190
|
+
position: list.getAttribute('data-test-jn-value') ?? '',
|
|
191
|
+
theme: list.getAttribute('data-sonner-theme'),
|
|
192
|
+
dir: list.getAttribute('dir'),
|
|
193
|
+
}));
|
|
194
|
+
}
|
|
195
|
+
/** Its theme (`light` or `dark`), from its lists; `null` while it shows no toasts. */
|
|
196
|
+
get theme() {
|
|
197
|
+
return this.lists[0]?.getAttribute('data-sonner-theme') ?? null;
|
|
198
|
+
}
|
|
199
|
+
/** Every toast it shows (and any on its way out), newest first in each list. */
|
|
200
|
+
get toasts() {
|
|
201
|
+
return this.findAll(ToastHarness);
|
|
202
|
+
}
|
|
203
|
+
/** The toasts' titles, newest first in each list. */
|
|
204
|
+
get titles() {
|
|
205
|
+
return this.toasts.map(toast => toast.title);
|
|
206
|
+
}
|
|
207
|
+
/** How many toasts it shows, not counting any on their way out. */
|
|
208
|
+
get count() {
|
|
209
|
+
return this.toasts.filter(toast => !toast.isRemoved).length;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* One toast: the newest without options, else by its id (`toast('…', { id })`) or its index
|
|
213
|
+
* among the toasts (newest first).
|
|
214
|
+
*/
|
|
215
|
+
toast(options) {
|
|
216
|
+
return this.find(ToastHarness, options);
|
|
217
|
+
}
|
|
218
|
+
/** Whether its stack is expanded. */
|
|
219
|
+
get isExpanded() {
|
|
220
|
+
return this.toasts.some(toast => toast.isExpanded);
|
|
221
|
+
}
|
|
222
|
+
#list(position) {
|
|
223
|
+
const lists = this.lists;
|
|
224
|
+
const list = position
|
|
225
|
+
? lists.find(each => each.getAttribute('data-test-jn-value') === position)
|
|
226
|
+
: lists[0];
|
|
227
|
+
if (!list)
|
|
228
|
+
throw new Error(`${this} shows no toasts${position ? ` at ${position}` : ''}`);
|
|
229
|
+
return list;
|
|
230
|
+
}
|
|
231
|
+
/** Puts the pointer on a list (the first, or the one at `position`): it expands and pauses. */
|
|
232
|
+
async hover(position) {
|
|
233
|
+
const list = this.#list(position);
|
|
234
|
+
await triggerEvent(list, 'mouseenter');
|
|
235
|
+
await triggerEvent(list, 'mousemove');
|
|
236
|
+
}
|
|
237
|
+
/** Takes the pointer off a list: it collapses, and the timers run again. */
|
|
238
|
+
async unhover(position) {
|
|
239
|
+
await triggerEvent(this.#list(position), 'mouseleave');
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Presses the hotkey, which expands the stack and moves focus to it. Give the keys as the
|
|
243
|
+
* Toaster's `@hotkey` names them: modifier properties and key codes. Default Alt+T,
|
|
244
|
+
* `['altKey', 'KeyT']`, sonner's.
|
|
245
|
+
*/
|
|
246
|
+
async pressHotkey(hotkey = ['altKey', 'KeyT']) {
|
|
247
|
+
const options = {};
|
|
248
|
+
for (const key of hotkey) {
|
|
249
|
+
if (/Key$/.test(key))
|
|
250
|
+
options[key] = true;
|
|
251
|
+
else {
|
|
252
|
+
options['code'] = key;
|
|
253
|
+
options['key'] = key.replace(/^Key|^Digit/, '').toLowerCase();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
await triggerEvent(document, 'keydown', options);
|
|
257
|
+
}
|
|
258
|
+
/** Waits until it shows a toast with this title (or any toast), as one made after a delay. */
|
|
259
|
+
async waitForToast(title, options = {}) {
|
|
260
|
+
await waitUntil(() => this.exists && this.toasts.some(toast => title === undefined || toast.title === title), { timeout: options.timeout ?? 3000, timeoutMessage: `${this} showed no toast "${title}"` });
|
|
261
|
+
return this.toasts.find(toast => title === undefined || toast.title === title);
|
|
262
|
+
}
|
|
263
|
+
/** Waits until every toast has gone, as their time runs out. */
|
|
264
|
+
async waitForNoToasts(options = {}) {
|
|
265
|
+
await waitUntil(() => !this.exists || this.toasts.length === 0, {
|
|
266
|
+
timeout: options.timeout ?? 6000,
|
|
267
|
+
timeoutMessage: `${this} still shows toasts`,
|
|
268
|
+
});
|
|
269
|
+
await settled();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const OWNER = 'JOINERY_TOAST_OWNER';
|
|
273
|
+
/**
|
|
274
|
+
* Gives each test in a module its own toasts. `toast()` is called from anywhere, so it finds
|
|
275
|
+
* its app through the rendered `<Toaster>`; this points it at the test's owner from the start
|
|
276
|
+
* of each test, so a toast made before a Toaster renders (or in a test that renders none) goes
|
|
277
|
+
* to the test, and never to another one. It sets `globalThis.JOINERY_TOAST_OWNER`, which
|
|
278
|
+
* `@ember-joinery/primitives/toast` reads each time a toast is made, and takes it away after.
|
|
279
|
+
* Call it after `setupRenderingTest(hooks)` or `setupApplicationTest(hooks)`.
|
|
280
|
+
*
|
|
281
|
+
* module('saving', function (hooks) {
|
|
282
|
+
* setupRenderingTest(hooks)
|
|
283
|
+
* setupToaster(hooks)
|
|
284
|
+
*
|
|
285
|
+
* test('it says so', async function (assert) {
|
|
286
|
+
* await render(<template><SaveButton /><Toaster /></template>)
|
|
287
|
+
* await click('button')
|
|
288
|
+
* assert.deepEqual(new ToasterHarness().titles, ['Saved'])
|
|
289
|
+
* })
|
|
290
|
+
* })
|
|
291
|
+
*
|
|
292
|
+
* The toasts themselves are the owner's, so they, and their timers, go with it at the end of
|
|
293
|
+
* the test.
|
|
294
|
+
*/
|
|
295
|
+
export function setupToaster(hooks) {
|
|
296
|
+
const global = globalThis;
|
|
297
|
+
hooks.beforeEach(() => {
|
|
298
|
+
const context = getContext();
|
|
299
|
+
if (!context?.owner) {
|
|
300
|
+
throw new Error('Joinery: setupToaster(hooks) found no test owner; call it after setupRenderingTest(hooks) or setupApplicationTest(hooks)');
|
|
301
|
+
}
|
|
302
|
+
global[OWNER] = context.owner;
|
|
303
|
+
});
|
|
304
|
+
hooks.afterEach(() => {
|
|
305
|
+
delete global[OWNER];
|
|
306
|
+
});
|
|
307
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
import { type KeyModifiers } from './focus.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Drives a `<ToggleGroup>` from `@ember-joinery/ember`, or the primitives' `ToggleGroup`. Its
|
|
5
|
+
* items are found by their `@value` (`data-test-jn-value`), and read through ARIA: a `multiple`
|
|
6
|
+
* group's items by `aria-pressed`, a `single` group's (radios) by `aria-checked`.
|
|
7
|
+
*
|
|
8
|
+
* const format = new ToggleGroupHarness('format') // <ToggleGroup @name="format">
|
|
9
|
+
* await format.toggle('bold')
|
|
10
|
+
* assert.deepEqual(format.value, ['bold'])
|
|
11
|
+
* await format.press('ArrowRight')
|
|
12
|
+
* assert.strictEqual(format.focused, 'italic')
|
|
13
|
+
*/
|
|
14
|
+
export declare class ToggleGroupHarness extends Harness {
|
|
15
|
+
static component: string;
|
|
16
|
+
/** Each item's element, in order. */
|
|
17
|
+
get items(): HTMLElement[];
|
|
18
|
+
/** Each item's value, in order. */
|
|
19
|
+
get itemValues(): string[];
|
|
20
|
+
/** The item whose `@value` this is. Throws when there is none. */
|
|
21
|
+
item(value: string): HTMLElement;
|
|
22
|
+
/** `single` when its items are radios (`role="radio"`), else `multiple`. */
|
|
23
|
+
get type(): 'single' | 'multiple';
|
|
24
|
+
/** Whether an item is pressed: `aria-pressed`, or `aria-checked` in a `single` group. */
|
|
25
|
+
isPressed(value: string): boolean;
|
|
26
|
+
/** The values of the items pressed now, in order. */
|
|
27
|
+
get value(): string[];
|
|
28
|
+
/** Whether an item can't be pressed, or, without a value, whether none can. */
|
|
29
|
+
isDisabled(value?: string): boolean;
|
|
30
|
+
/** An item's accessible name: its `aria-label`, else its text. */
|
|
31
|
+
label(value: string): string;
|
|
32
|
+
/** `horizontal` or `vertical` (`data-orientation`). */
|
|
33
|
+
get orientation(): string | null;
|
|
34
|
+
/** The styled group's `@variant`, if it was given one. */
|
|
35
|
+
get variant(): string | null;
|
|
36
|
+
/** The styled group's `@size`, if it was given one. */
|
|
37
|
+
get size(): string | null;
|
|
38
|
+
/** The styled group's `@spacing`. */
|
|
39
|
+
get spacing(): number | undefined;
|
|
40
|
+
/** The value of the item Tab lands on (`tabindex="0"`), or `null` when none is yet. */
|
|
41
|
+
get tabStop(): string | null;
|
|
42
|
+
/** The value of the item that has focus, or `null` when focus is elsewhere. */
|
|
43
|
+
get focused(): string | null;
|
|
44
|
+
/** Presses an item, as a click does: pressed becomes unpressed, and the other way. */
|
|
45
|
+
toggle(value: string): Promise<void>;
|
|
46
|
+
/** Focuses an item, as a click or a script would. */
|
|
47
|
+
focus(value: string): Promise<void>;
|
|
48
|
+
/** Presses a key on the focused item: `'ArrowRight'`, `'Home'`, `' '`. */
|
|
49
|
+
press(key: string, modifiers?: KeyModifiers): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=toggle-group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle-group.d.ts","sourceRoot":"","sources":["../src/toggle-group.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAMxD;;;;;;;;;;GAUG;AACH,qBAAa,kBAAmB,SAAQ,OAAO;IAC7C,OAAgB,SAAS,SAAiB;IAE1C,qCAAqC;IACrC,IAAI,KAAK,IAAI,WAAW,EAAE,CAEzB;IAED,mCAAmC;IACnC,IAAI,UAAU,IAAI,MAAM,EAAE,CAEzB;IAED,kEAAkE;IAClE,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;IAIhC,4EAA4E;IAC5E,IAAI,IAAI,IAAI,QAAQ,GAAG,UAAU,CAEhC;IAED,yFAAyF;IACzF,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAMjC,qDAAqD;IACrD,IAAI,KAAK,IAAI,MAAM,EAAE,CAEpB;IAED,+EAA+E;IAC/E,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO;IAKnC,kEAAkE;IAClE,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAK5B,uDAAuD;IACvD,IAAI,WAAW,IAAI,MAAM,GAAG,IAAI,CAE/B;IAED,0DAA0D;IAC1D,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAE3B;IAED,uDAAuD;IACvD,IAAI,IAAI,IAAI,MAAM,GAAG,IAAI,CAExB;IAED,qCAAqC;IACrC,IAAI,OAAO,IAAI,MAAM,GAAG,SAAS,CAGhC;IAED,uFAAuF;IACvF,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAG3B;IAED,+EAA+E;IAC/E,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAI3B;IAED,sFAAsF;IAChF,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,qDAAqD;IAC/C,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,0EAA0E;IACpE,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;CAGlE"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { click, focus } from '@ember/test-helpers';
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
import { attributes } from "./selectors.js";
|
|
4
|
+
import { pressKey } from "./focus.js";
|
|
5
|
+
function text(element) {
|
|
6
|
+
return (element.textContent ?? '').replace(/\s+/g, ' ').trim();
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Drives a `<ToggleGroup>` from `@ember-joinery/ember`, or the primitives' `ToggleGroup`. Its
|
|
10
|
+
* items are found by their `@value` (`data-test-jn-value`), and read through ARIA: a `multiple`
|
|
11
|
+
* group's items by `aria-pressed`, a `single` group's (radios) by `aria-checked`.
|
|
12
|
+
*
|
|
13
|
+
* const format = new ToggleGroupHarness('format') // <ToggleGroup @name="format">
|
|
14
|
+
* await format.toggle('bold')
|
|
15
|
+
* assert.deepEqual(format.value, ['bold'])
|
|
16
|
+
* await format.press('ArrowRight')
|
|
17
|
+
* assert.strictEqual(format.focused, 'italic')
|
|
18
|
+
*/
|
|
19
|
+
export class ToggleGroupHarness extends Harness {
|
|
20
|
+
static component = 'toggle-group';
|
|
21
|
+
/** Each item's element, in order. */
|
|
22
|
+
get items() {
|
|
23
|
+
return this.parts('item');
|
|
24
|
+
}
|
|
25
|
+
/** Each item's value, in order. */
|
|
26
|
+
get itemValues() {
|
|
27
|
+
return this.values('item');
|
|
28
|
+
}
|
|
29
|
+
/** The item whose `@value` this is. Throws when there is none. */
|
|
30
|
+
item(value) {
|
|
31
|
+
return this.part('item', value);
|
|
32
|
+
}
|
|
33
|
+
/** `single` when its items are radios (`role="radio"`), else `multiple`. */
|
|
34
|
+
get type() {
|
|
35
|
+
return this.items.some(item => item.getAttribute('role') === 'radio') ? 'single' : 'multiple';
|
|
36
|
+
}
|
|
37
|
+
/** Whether an item is pressed: `aria-pressed`, or `aria-checked` in a `single` group. */
|
|
38
|
+
isPressed(value) {
|
|
39
|
+
const item = this.item(value);
|
|
40
|
+
const state = item.getAttribute('role') === 'radio' ? 'aria-checked' : 'aria-pressed';
|
|
41
|
+
return item.getAttribute(state) === 'true';
|
|
42
|
+
}
|
|
43
|
+
/** The values of the items pressed now, in order. */
|
|
44
|
+
get value() {
|
|
45
|
+
return this.itemValues.filter(value => this.isPressed(value));
|
|
46
|
+
}
|
|
47
|
+
/** Whether an item can't be pressed, or, without a value, whether none can. */
|
|
48
|
+
isDisabled(value) {
|
|
49
|
+
const items = value === undefined ? this.items : [this.item(value)];
|
|
50
|
+
return items.length > 0 && items.every(item => item.hasAttribute('data-disabled'));
|
|
51
|
+
}
|
|
52
|
+
/** An item's accessible name: its `aria-label`, else its text. */
|
|
53
|
+
label(value) {
|
|
54
|
+
const item = this.item(value);
|
|
55
|
+
return item.getAttribute('aria-label')?.trim() || text(item);
|
|
56
|
+
}
|
|
57
|
+
/** `horizontal` or `vertical` (`data-orientation`). */
|
|
58
|
+
get orientation() {
|
|
59
|
+
return this.element.getAttribute('data-orientation');
|
|
60
|
+
}
|
|
61
|
+
/** The styled group's `@variant`, if it was given one. */
|
|
62
|
+
get variant() {
|
|
63
|
+
return this.element.getAttribute('data-variant');
|
|
64
|
+
}
|
|
65
|
+
/** The styled group's `@size`, if it was given one. */
|
|
66
|
+
get size() {
|
|
67
|
+
return this.element.getAttribute('data-size');
|
|
68
|
+
}
|
|
69
|
+
/** The styled group's `@spacing`. */
|
|
70
|
+
get spacing() {
|
|
71
|
+
const spacing = this.element.getAttribute('data-spacing');
|
|
72
|
+
return spacing === null ? undefined : Number(spacing);
|
|
73
|
+
}
|
|
74
|
+
/** The value of the item Tab lands on (`tabindex="0"`), or `null` when none is yet. */
|
|
75
|
+
get tabStop() {
|
|
76
|
+
const item = this.items.find(element => element.getAttribute('tabindex') === '0');
|
|
77
|
+
return item?.getAttribute(attributes.value) ?? null;
|
|
78
|
+
}
|
|
79
|
+
/** The value of the item that has focus, or `null` when focus is elsewhere. */
|
|
80
|
+
get focused() {
|
|
81
|
+
const active = document.activeElement;
|
|
82
|
+
const item = this.items.find(element => element === active || element.contains(active));
|
|
83
|
+
return item?.getAttribute(attributes.value) ?? null;
|
|
84
|
+
}
|
|
85
|
+
/** Presses an item, as a click does: pressed becomes unpressed, and the other way. */
|
|
86
|
+
async toggle(value) {
|
|
87
|
+
await click(this.item(value));
|
|
88
|
+
}
|
|
89
|
+
/** Focuses an item, as a click or a script would. */
|
|
90
|
+
async focus(value) {
|
|
91
|
+
await focus(this.item(value));
|
|
92
|
+
}
|
|
93
|
+
/** Presses a key on the focused item: `'ArrowRight'`, `'Home'`, `' '`. */
|
|
94
|
+
async press(key, modifiers) {
|
|
95
|
+
await pressKey(key, modifiers);
|
|
96
|
+
}
|
|
97
|
+
}
|
package/dist/toggle.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ButtonHarness } from './button.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Drives a `<Toggle>` from `@ember-joinery/ember`, the primitives' `Toggle`, or an element made
|
|
4
|
+
* a toggle with `asToggle`. It is a button (every `ButtonHarness` member works: `variant` is
|
|
5
|
+
* `default` or `outline`, `size` `default`, `sm` or `lg`), whose pressed state is read from
|
|
6
|
+
* `aria-pressed`.
|
|
7
|
+
*
|
|
8
|
+
* const bold = new ToggleHarness('bold') // <Toggle @name="bold">
|
|
9
|
+
* await bold.toggle()
|
|
10
|
+
* assert.true(bold.isPressed)
|
|
11
|
+
*/
|
|
12
|
+
export declare class ToggleHarness extends ButtonHarness {
|
|
13
|
+
static component: string;
|
|
14
|
+
/** Whether it is pressed (`aria-pressed="true"`). */
|
|
15
|
+
get isPressed(): boolean;
|
|
16
|
+
/** Radix's `data-state`: `on` or `off`. */
|
|
17
|
+
get state(): string | null;
|
|
18
|
+
/** Presses it, as a click does: on becomes off, and off on. */
|
|
19
|
+
toggle(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=toggle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle.d.ts","sourceRoot":"","sources":["../src/toggle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C;;;;;;;;;GASG;AACH,qBAAa,aAAc,SAAQ,aAAa;IAC9C,OAAgB,SAAS,SAAW;IAEpC,qDAAqD;IACrD,IAAa,SAAS,IAAI,OAAO,CAEhC;IAED,2CAA2C;IAC3C,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAEzB;IAED,+DAA+D;IACzD,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAG9B"}
|
package/dist/toggle.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ButtonHarness } from "./button.js";
|
|
2
|
+
/**
|
|
3
|
+
* Drives a `<Toggle>` from `@ember-joinery/ember`, the primitives' `Toggle`, or an element made
|
|
4
|
+
* a toggle with `asToggle`. It is a button (every `ButtonHarness` member works: `variant` is
|
|
5
|
+
* `default` or `outline`, `size` `default`, `sm` or `lg`), whose pressed state is read from
|
|
6
|
+
* `aria-pressed`.
|
|
7
|
+
*
|
|
8
|
+
* const bold = new ToggleHarness('bold') // <Toggle @name="bold">
|
|
9
|
+
* await bold.toggle()
|
|
10
|
+
* assert.true(bold.isPressed)
|
|
11
|
+
*/
|
|
12
|
+
export class ToggleHarness extends ButtonHarness {
|
|
13
|
+
static component = 'toggle';
|
|
14
|
+
/** Whether it is pressed (`aria-pressed="true"`). */
|
|
15
|
+
get isPressed() {
|
|
16
|
+
return this.element.getAttribute('aria-pressed') === 'true';
|
|
17
|
+
}
|
|
18
|
+
/** Radix's `data-state`: `on` or `off`. */
|
|
19
|
+
get state() {
|
|
20
|
+
return this.element.getAttribute('data-state');
|
|
21
|
+
}
|
|
22
|
+
/** Presses it, as a click does: on becomes off, and off on. */
|
|
23
|
+
async toggle() {
|
|
24
|
+
await this.click();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
import { type HoverOptions } from './pointer.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Drives a `<Tooltip>` from `@ember-joinery/ember` or `@ember-joinery/primitives/tooltip`. It
|
|
5
|
+
* reads the state from the trigger's `data-state` and what the trigger's `aria-describedby`
|
|
6
|
+
* names, and acts as a user does: resting the pointer on the trigger, moving it away, focus.
|
|
7
|
+
*
|
|
8
|
+
* const tooltip = new TooltipHarness()
|
|
9
|
+
* await tooltip.hover() // waits out the open delay
|
|
10
|
+
* assert.strictEqual(tooltip.description, 'Add to library')
|
|
11
|
+
* await tooltip.unhover()
|
|
12
|
+
*/
|
|
13
|
+
export declare class TooltipHarness extends Harness {
|
|
14
|
+
static component: string;
|
|
15
|
+
/** The trigger: the `Trigger` part, or your own element with the `trigger` modifier. */
|
|
16
|
+
get trigger(): HTMLElement;
|
|
17
|
+
/** The tooltip, or `null` while it isn't rendered. */
|
|
18
|
+
get content(): HTMLElement | null;
|
|
19
|
+
/** How it is open, from the trigger's `data-state`: `delayed-open`, `instant-open` or `closed`. */
|
|
20
|
+
get state(): string | null;
|
|
21
|
+
/** Whether it is open. */
|
|
22
|
+
get isOpen(): boolean;
|
|
23
|
+
/** Whether the tooltip is showing in the browser's top layer. */
|
|
24
|
+
get isShown(): boolean;
|
|
25
|
+
/** The trigger's accessible description while it is open: what a screen reader announces. */
|
|
26
|
+
get description(): string;
|
|
27
|
+
/** The tooltip's text, whitespace collapsed. */
|
|
28
|
+
get text(): string;
|
|
29
|
+
/** The side it was placed on, after any flip (`data-side`). */
|
|
30
|
+
get side(): string | null;
|
|
31
|
+
/** Its alignment along that side (`data-align`). */
|
|
32
|
+
get align(): string | null;
|
|
33
|
+
/** The arrow's element (a `<span>` around an `<svg>`), or `null`. */
|
|
34
|
+
get arrow(): HTMLElement | null;
|
|
35
|
+
/** Rests the pointer on the trigger, and waits out the delay. */
|
|
36
|
+
hover(options?: HoverOptions): Promise<void>;
|
|
37
|
+
/** Moves the pointer off the trigger, away from the tooltip. */
|
|
38
|
+
unhover(options?: HoverOptions): Promise<void>;
|
|
39
|
+
/** Moves the pointer from the trigger onto the tooltip, as a user reading it does. */
|
|
40
|
+
hoverContent(): Promise<void>;
|
|
41
|
+
/** Focuses the trigger, as tabbing to it does: it opens at once. */
|
|
42
|
+
focus(): Promise<void>;
|
|
43
|
+
/** Moves focus away from the trigger: it closes. */
|
|
44
|
+
blur(): Promise<void>;
|
|
45
|
+
/** Presses Escape where focus is. */
|
|
46
|
+
pressEscape(): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=tooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../src/tooltip.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AAGhE;;;;;;;;;GASG;AACH,qBAAa,cAAe,SAAQ,OAAO;IACzC,OAAgB,SAAS,SAAY;IAErC,wFAAwF;IACxF,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED,sDAAsD;IACtD,IAAI,OAAO,IAAI,WAAW,GAAG,IAAI,CAEhC;IAED,mGAAmG;IACnG,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAEzB;IAED,0BAA0B;IAC1B,IAAI,MAAM,IAAI,OAAO,CAGpB;IAED,iEAAiE;IACjE,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,6FAA6F;IAC7F,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,gDAAgD;IAChD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,+DAA+D;IAC/D,IAAI,IAAI,IAAI,MAAM,GAAG,IAAI,CAExB;IAED,oDAAoD;IACpD,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAEzB;IAED,qEAAqE;IACrE,IAAI,KAAK,IAAI,WAAW,GAAG,IAAI,CAE9B;IAED,iEAAiE;IAC3D,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,gEAAgE;IAC1D,OAAO,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpD,sFAAsF;IAChF,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAWnC,oEAAoE;IAC9D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,oDAAoD;IAC9C,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,qCAAqC;IAC/B,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAGnC"}
|
package/dist/tooltip.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { blur, focus } from '@ember/test-helpers';
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
import { pressEscape } from "./layers.js";
|
|
4
|
+
import { hover, unhover } from "./pointer.js";
|
|
5
|
+
import { accessibleDescription, shownInTopLayer, text } from "./-private/overlay.js";
|
|
6
|
+
/**
|
|
7
|
+
* Drives a `<Tooltip>` from `@ember-joinery/ember` or `@ember-joinery/primitives/tooltip`. It
|
|
8
|
+
* reads the state from the trigger's `data-state` and what the trigger's `aria-describedby`
|
|
9
|
+
* names, and acts as a user does: resting the pointer on the trigger, moving it away, focus.
|
|
10
|
+
*
|
|
11
|
+
* const tooltip = new TooltipHarness()
|
|
12
|
+
* await tooltip.hover() // waits out the open delay
|
|
13
|
+
* assert.strictEqual(tooltip.description, 'Add to library')
|
|
14
|
+
* await tooltip.unhover()
|
|
15
|
+
*/
|
|
16
|
+
export class TooltipHarness extends Harness {
|
|
17
|
+
static component = 'tooltip';
|
|
18
|
+
/** The trigger: the `Trigger` part, or your own element with the `trigger` modifier. */
|
|
19
|
+
get trigger() {
|
|
20
|
+
return this.part('trigger');
|
|
21
|
+
}
|
|
22
|
+
/** The tooltip, or `null` while it isn't rendered. */
|
|
23
|
+
get content() {
|
|
24
|
+
return this.queryPart('content');
|
|
25
|
+
}
|
|
26
|
+
/** How it is open, from the trigger's `data-state`: `delayed-open`, `instant-open` or `closed`. */
|
|
27
|
+
get state() {
|
|
28
|
+
return this.trigger.getAttribute('data-state');
|
|
29
|
+
}
|
|
30
|
+
/** Whether it is open. */
|
|
31
|
+
get isOpen() {
|
|
32
|
+
const state = this.state;
|
|
33
|
+
return state === 'delayed-open' || state === 'instant-open';
|
|
34
|
+
}
|
|
35
|
+
/** Whether the tooltip is showing in the browser's top layer. */
|
|
36
|
+
get isShown() {
|
|
37
|
+
return shownInTopLayer(this.content);
|
|
38
|
+
}
|
|
39
|
+
/** The trigger's accessible description while it is open: what a screen reader announces. */
|
|
40
|
+
get description() {
|
|
41
|
+
return accessibleDescription(this.trigger);
|
|
42
|
+
}
|
|
43
|
+
/** The tooltip's text, whitespace collapsed. */
|
|
44
|
+
get text() {
|
|
45
|
+
return text(this.content);
|
|
46
|
+
}
|
|
47
|
+
/** The side it was placed on, after any flip (`data-side`). */
|
|
48
|
+
get side() {
|
|
49
|
+
return this.content?.getAttribute('data-side') ?? null;
|
|
50
|
+
}
|
|
51
|
+
/** Its alignment along that side (`data-align`). */
|
|
52
|
+
get align() {
|
|
53
|
+
return this.content?.getAttribute('data-align') ?? null;
|
|
54
|
+
}
|
|
55
|
+
/** The arrow's element (a `<span>` around an `<svg>`), or `null`. */
|
|
56
|
+
get arrow() {
|
|
57
|
+
return this.queryPart('arrow');
|
|
58
|
+
}
|
|
59
|
+
/** Rests the pointer on the trigger, and waits out the delay. */
|
|
60
|
+
async hover(options) {
|
|
61
|
+
await hover(this.trigger, options);
|
|
62
|
+
}
|
|
63
|
+
/** Moves the pointer off the trigger, away from the tooltip. */
|
|
64
|
+
async unhover(options) {
|
|
65
|
+
await unhover(this.trigger, { ...options, away: this.content });
|
|
66
|
+
}
|
|
67
|
+
/** Moves the pointer from the trigger onto the tooltip, as a user reading it does. */
|
|
68
|
+
async hoverContent() {
|
|
69
|
+
const content = this.content;
|
|
70
|
+
if (!content)
|
|
71
|
+
throw new Error(`Joinery harness: ${this} isn't open`);
|
|
72
|
+
await unhover(this.trigger, {
|
|
73
|
+
away: null,
|
|
74
|
+
side: this.side === 'bottom' ? 'bottom' : 'top',
|
|
75
|
+
distance: 1,
|
|
76
|
+
});
|
|
77
|
+
await hover(content);
|
|
78
|
+
}
|
|
79
|
+
/** Focuses the trigger, as tabbing to it does: it opens at once. */
|
|
80
|
+
async focus() {
|
|
81
|
+
await focus(this.trigger);
|
|
82
|
+
}
|
|
83
|
+
/** Moves focus away from the trigger: it closes. */
|
|
84
|
+
async blur() {
|
|
85
|
+
await blur(this.trigger);
|
|
86
|
+
}
|
|
87
|
+
/** Presses Escape where focus is. */
|
|
88
|
+
async pressEscape() {
|
|
89
|
+
await pressEscape();
|
|
90
|
+
}
|
|
91
|
+
}
|