@ember-joinery/test-support 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +574 -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/app-shell.d.ts +43 -0
- package/dist/app-shell.d.ts.map +1 -0
- package/dist/app-shell.js +78 -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 +98 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +99 -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/inspector.d.ts +47 -0
- package/dist/inspector.d.ts.map +1 -0
- package/dist/inspector.js +97 -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-bar.d.ts +30 -0
- package/dist/navigation-bar.d.ts.map +1 -0
- package/dist/navigation-bar.js +52 -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/navigation-stack.d.ts +36 -0
- package/dist/navigation-stack.d.ts.map +1 -0
- package/dist/navigation-stack.js +67 -0
- package/dist/observers.d.ts +21 -0
- package/dist/observers.d.ts.map +1 -0
- package/dist/observers.js +34 -0
- package/dist/page.d.ts +38 -0
- package/dist/page.d.ts.map +1 -0
- package/dist/page.js +68 -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/pull-to-refresh.d.ts +40 -0
- package/dist/pull-to-refresh.d.ts.map +1 -0
- package/dist/pull-to-refresh.js +65 -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/split-view.d.ts +77 -0
- package/dist/split-view.d.ts.map +1 -0
- package/dist/split-view.js +145 -0
- package/dist/status-bar.d.ts +25 -0
- package/dist/status-bar.d.ts.map +1 -0
- package/dist/status-bar.js +42 -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/tab-bar.d.ts +38 -0
- package/dist/tab-bar.d.ts.map +1 -0
- package/dist/tab-bar.js +78 -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/title-bar.d.ts +43 -0
- package/dist/title-bar.d.ts.map +1 -0
- package/dist/title-bar.js +74 -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/toolbar.d.ts +40 -0
- package/dist/toolbar.d.ts.map +1 -0
- package/dist/toolbar.js +67 -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/window-frame.d.ts +40 -0
- package/dist/window-frame.d.ts.map +1 -0
- package/dist/window-frame.js +66 -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
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { Harness, type ChildOptions } from './harness.ts';
|
|
2
|
+
import type { TestHooks } from './test-hooks.ts';
|
|
3
|
+
/** A direction a toast can be swiped off in. */
|
|
4
|
+
export type ToastSwipe = 'left' | 'right' | 'up' | 'down';
|
|
5
|
+
export interface ToastSwipeOptions {
|
|
6
|
+
/** How far the pointer moves, in pixels. Default 100 (sonner dismisses from 45). */
|
|
7
|
+
distance?: number;
|
|
8
|
+
/**
|
|
9
|
+
* How long the swipe takes, in milliseconds, before the pointer lifts. Default 0. A short,
|
|
10
|
+
* slow swipe (under 45px, and slower than 0.11px per millisecond) springs back.
|
|
11
|
+
*/
|
|
12
|
+
duration?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Drives one toast in a `<Toaster>` (from `@ember-joinery/ember` or
|
|
16
|
+
* `@ember-joinery/primitives/toast`): an `<li data-test-jn="toast">`, named by its id. State
|
|
17
|
+
* comes from sonner's data attributes and the toast's text.
|
|
18
|
+
*
|
|
19
|
+
* const toast = new ToasterHarness().toast() // the newest
|
|
20
|
+
* assert.strictEqual(toast.title, 'Event has been created')
|
|
21
|
+
* await toast.clickAction()
|
|
22
|
+
*
|
|
23
|
+
* new ToastHarness('saved') // toast('Saved', { id: 'saved' })
|
|
24
|
+
*/
|
|
25
|
+
export declare class ToastHarness extends Harness {
|
|
26
|
+
#private;
|
|
27
|
+
static component: string;
|
|
28
|
+
/** Its id, as `toast()` returned it (or as you gave it), as a string. */
|
|
29
|
+
get id(): string;
|
|
30
|
+
/** Its title, whitespace collapsed. */
|
|
31
|
+
get title(): string;
|
|
32
|
+
/** Its description, or `null` without one. */
|
|
33
|
+
get description(): string | null;
|
|
34
|
+
/** Its type (`success`, `error`, `loading`…), or `null` for a plain toast. */
|
|
35
|
+
get type(): string | null;
|
|
36
|
+
/** Where it shows, as `top-center` or `bottom-right`. */
|
|
37
|
+
get position(): string;
|
|
38
|
+
/** Whether it is the newest in its stack, the one in front. */
|
|
39
|
+
get isFront(): boolean;
|
|
40
|
+
/** Whether it is among the toasts the stack shows (`@visibleToasts`, 3 by default). */
|
|
41
|
+
get isVisible(): boolean;
|
|
42
|
+
/** Whether its stack is expanded (hovered, focused from the keyboard, or `@expand`). */
|
|
43
|
+
get isExpanded(): boolean;
|
|
44
|
+
/** Whether it has finished coming in. */
|
|
45
|
+
get isMounted(): boolean;
|
|
46
|
+
/** Whether it is on its way out. */
|
|
47
|
+
get isRemoved(): boolean;
|
|
48
|
+
/** Whether it was swiped away. */
|
|
49
|
+
get isSwipedOut(): boolean;
|
|
50
|
+
/** Whether it is coloured by its type. */
|
|
51
|
+
get hasRichColors(): boolean;
|
|
52
|
+
/** Whether it is inverted. */
|
|
53
|
+
get isInverted(): boolean;
|
|
54
|
+
/** Whether the user can close it (`dismissible`). */
|
|
55
|
+
get isDismissible(): boolean;
|
|
56
|
+
/** Whether it shows sonner's look (`false` for `unstyled` and custom toasts). */
|
|
57
|
+
get isStyled(): boolean;
|
|
58
|
+
/** Whether it follows a promise (`toast.promise()`). */
|
|
59
|
+
get isPromise(): boolean;
|
|
60
|
+
/** Whether it is loading (`toast.loading()`, or a promise that hasn't settled). */
|
|
61
|
+
get isLoading(): boolean;
|
|
62
|
+
/** Its icon's box (`[data-icon]`), or `null` without one. */
|
|
63
|
+
get icon(): HTMLElement | null;
|
|
64
|
+
/** Its action button, or `null`. */
|
|
65
|
+
get action(): HTMLButtonElement | null;
|
|
66
|
+
/** Its cancel button, or `null`. */
|
|
67
|
+
get cancel(): HTMLButtonElement | null;
|
|
68
|
+
/** Its close button, or `null` without one (`closeButton`). */
|
|
69
|
+
get closeButton(): HTMLButtonElement | null;
|
|
70
|
+
/** Presses its action button. The toast closes, unless the handler prevents it. */
|
|
71
|
+
clickAction(): Promise<void>;
|
|
72
|
+
/** Presses its cancel button. The toast closes. */
|
|
73
|
+
clickCancel(): Promise<void>;
|
|
74
|
+
/** Presses its close button. The toast closes. */
|
|
75
|
+
close(): Promise<void>;
|
|
76
|
+
/** Moves focus to it, as tabbing to it would. */
|
|
77
|
+
focus(): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Swipes it with a pointer, as a finger would: down on it, across, and up. Far enough (45px,
|
|
80
|
+
* or fast enough) towards a side it can leave by, it goes; otherwise it springs back.
|
|
81
|
+
*/
|
|
82
|
+
swipe(direction: ToastSwipe, options?: ToastSwipeOptions): Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
/** The data attributes a toaster's list (`<ol data-sonner-toaster>`) carries. */
|
|
85
|
+
export interface ToasterListState {
|
|
86
|
+
/** Its position, as `bottom-right`. */
|
|
87
|
+
position: string;
|
|
88
|
+
/** `light` or `dark`. */
|
|
89
|
+
theme: string | null;
|
|
90
|
+
/** `ltr` or `rtl`. */
|
|
91
|
+
dir: string | null;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Drives a `<Toaster>` (from `@ember-joinery/ember` or `@ember-joinery/primitives/toast`): the
|
|
95
|
+
* live region, its lists (one per position in use) and its toasts.
|
|
96
|
+
*
|
|
97
|
+
* const toaster = new ToasterHarness()
|
|
98
|
+
* await click(saveButton)
|
|
99
|
+
* assert.deepEqual(toaster.titles, ['Saved'])
|
|
100
|
+
* await toaster.hover() // expands the stack and pauses the timers
|
|
101
|
+
*
|
|
102
|
+
* Toasts belong to the app, so give each test its own with `setupToaster(hooks)`.
|
|
103
|
+
*/
|
|
104
|
+
export declare class ToasterHarness extends Harness {
|
|
105
|
+
#private;
|
|
106
|
+
static component: string;
|
|
107
|
+
/** The region's name: `Notifications alt+T` unless given `@containerAriaLabel`. */
|
|
108
|
+
get label(): string;
|
|
109
|
+
/** Its lists (`<ol>`), one for each position with toasts, in document order. */
|
|
110
|
+
get lists(): HTMLOListElement[];
|
|
111
|
+
/** The positions it shows toasts in now. */
|
|
112
|
+
get positions(): string[];
|
|
113
|
+
/** What each list says about itself: its position, theme and direction. */
|
|
114
|
+
get listStates(): ToasterListState[];
|
|
115
|
+
/** Its theme (`light` or `dark`), from its lists; `null` while it shows no toasts. */
|
|
116
|
+
get theme(): string | null;
|
|
117
|
+
/** Every toast it shows (and any on its way out), newest first in each list. */
|
|
118
|
+
get toasts(): ToastHarness[];
|
|
119
|
+
/** The toasts' titles, newest first in each list. */
|
|
120
|
+
get titles(): string[];
|
|
121
|
+
/** How many toasts it shows, not counting any on their way out. */
|
|
122
|
+
get count(): number;
|
|
123
|
+
/**
|
|
124
|
+
* One toast: the newest without options, else by its id (`toast('…', { id })`) or its index
|
|
125
|
+
* among the toasts (newest first).
|
|
126
|
+
*/
|
|
127
|
+
toast(options?: ChildOptions): ToastHarness;
|
|
128
|
+
/** Whether its stack is expanded. */
|
|
129
|
+
get isExpanded(): boolean;
|
|
130
|
+
/** Puts the pointer on a list (the first, or the one at `position`): it expands and pauses. */
|
|
131
|
+
hover(position?: string): Promise<void>;
|
|
132
|
+
/** Takes the pointer off a list: it collapses, and the timers run again. */
|
|
133
|
+
unhover(position?: string): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Presses the hotkey, which expands the stack and moves focus to it. Give the keys as the
|
|
136
|
+
* Toaster's `@hotkey` names them: modifier properties and key codes. Default Alt+T,
|
|
137
|
+
* `['altKey', 'KeyT']`, sonner's.
|
|
138
|
+
*/
|
|
139
|
+
pressHotkey(hotkey?: readonly string[]): Promise<void>;
|
|
140
|
+
/** Waits until it shows a toast with this title (or any toast), as one made after a delay. */
|
|
141
|
+
waitForToast(title?: string, options?: {
|
|
142
|
+
timeout?: number;
|
|
143
|
+
}): Promise<ToastHarness>;
|
|
144
|
+
/** Waits until every toast has gone, as their time runs out. */
|
|
145
|
+
waitForNoToasts(options?: {
|
|
146
|
+
timeout?: number;
|
|
147
|
+
}): Promise<void>;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Gives each test in a module its own toasts. `toast()` is called from anywhere, so it finds
|
|
151
|
+
* its app through the rendered `<Toaster>`; this points it at the test's owner from the start
|
|
152
|
+
* of each test, so a toast made before a Toaster renders (or in a test that renders none) goes
|
|
153
|
+
* to the test, and never to another one. It sets `globalThis.JOINERY_TOAST_OWNER`, which
|
|
154
|
+
* `@ember-joinery/primitives/toast` reads each time a toast is made, and takes it away after.
|
|
155
|
+
* Call it after `setupRenderingTest(hooks)` or `setupApplicationTest(hooks)`.
|
|
156
|
+
*
|
|
157
|
+
* module('saving', function (hooks) {
|
|
158
|
+
* setupRenderingTest(hooks)
|
|
159
|
+
* setupToaster(hooks)
|
|
160
|
+
*
|
|
161
|
+
* test('it says so', async function (assert) {
|
|
162
|
+
* await render(<template><SaveButton /><Toaster /></template>)
|
|
163
|
+
* await click('button')
|
|
164
|
+
* assert.deepEqual(new ToasterHarness().titles, ['Saved'])
|
|
165
|
+
* })
|
|
166
|
+
* })
|
|
167
|
+
*
|
|
168
|
+
* The toasts themselves are the owner's, so they, and their timers, go with it at the end of
|
|
169
|
+
* the test.
|
|
170
|
+
*/
|
|
171
|
+
export declare function setupToaster(hooks: TestHooks): void;
|
|
172
|
+
//# sourceMappingURL=toaster.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toaster.d.ts","sourceRoot":"","sources":["../src/toaster.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAMhD,gDAAgD;AAChD,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,CAAA;AAEzD,MAAM,WAAW,iBAAiB;IAChC,oFAAoF;IACpF,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;;;;;;;;;GAUG;AACH,qBAAa,YAAa,SAAQ,OAAO;;IACvC,OAAgB,SAAS,SAAU;IAEnC,yEAAyE;IACzE,IAAI,EAAE,IAAI,MAAM,CAEf;IAED,uCAAuC;IACvC,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,8CAA8C;IAC9C,IAAI,WAAW,IAAI,MAAM,GAAG,IAAI,CAG/B;IAED,8EAA8E;IAC9E,IAAI,IAAI,IAAI,MAAM,GAAG,IAAI,CAExB;IAED,yDAAyD;IACzD,IAAI,QAAQ,IAAI,MAAM,CAIrB;IAMD,+DAA+D;IAC/D,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,uFAAuF;IACvF,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,wFAAwF;IACxF,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,yCAAyC;IACzC,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,oCAAoC;IACpC,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,kCAAkC;IAClC,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,0CAA0C;IAC1C,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED,8BAA8B;IAC9B,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,qDAAqD;IACrD,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED,iFAAiF;IACjF,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,wDAAwD;IACxD,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,mFAAmF;IACnF,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,6DAA6D;IAC7D,IAAI,IAAI,IAAI,WAAW,GAAG,IAAI,CAE7B;IAED,oCAAoC;IACpC,IAAI,MAAM,IAAI,iBAAiB,GAAG,IAAI,CAErC;IAED,oCAAoC;IACpC,IAAI,MAAM,IAAI,iBAAiB,GAAG,IAAI,CAErC;IAED,+DAA+D;IAC/D,IAAI,WAAW,IAAI,iBAAiB,GAAG,IAAI,CAE1C;IAOD,mFAAmF;IAC7E,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC,mDAAmD;IAC7C,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC,kDAAkD;IAC5C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,iDAAiD;IAC3C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;;OAGG;IACG,KAAK,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;CA0BnF;AAED,iFAAiF;AACjF,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAA;IAChB,yBAAyB;IACzB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,sBAAsB;IACtB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CACnB;AAED;;;;;;;;;;GAUG;AACH,qBAAa,cAAe,SAAQ,OAAO;;IACzC,OAAgB,SAAS,SAAY;IAErC,mFAAmF;IACnF,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,gFAAgF;IAChF,IAAI,KAAK,IAAI,gBAAgB,EAAE,CAE9B;IAED,4CAA4C;IAC5C,IAAI,SAAS,IAAI,MAAM,EAAE,CAExB;IAED,2EAA2E;IAC3E,IAAI,UAAU,IAAI,gBAAgB,EAAE,CAMnC;IAED,sFAAsF;IACtF,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAEzB;IAED,gFAAgF;IAChF,IAAI,MAAM,IAAI,YAAY,EAAE,CAE3B;IAED,qDAAqD;IACrD,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAED,mEAAmE;IACnE,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,YAAY;IAI3C,qCAAqC;IACrC,IAAI,UAAU,IAAI,OAAO,CAExB;IAWD,+FAA+F;IACzF,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM7C,4EAA4E;IACtE,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C;;;;OAIG;IACG,WAAW,CAAC,MAAM,GAAE,SAAS,MAAM,EAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IAYhF,8FAA8F;IACxF,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,YAAY,CAAC;IAQ7F,gEAAgE;IAC1D,eAAe,CAAC,OAAO,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAOzE;AAID;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAcnD"}
|
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"}
|