@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
package/dist/index.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Generated by scripts/gen-barrels.mjs from the modules in this folder. Do not edit it:
|
|
2
|
+
// the build rewrites it. See "Generated files" in CONTRIBUTING.md.
|
|
3
|
+
export * from "./accordion.js";
|
|
4
|
+
export * from "./alert-dialog.js";
|
|
5
|
+
export * from "./alert.js";
|
|
6
|
+
export * from "./app-shell.js";
|
|
7
|
+
export * from "./aspect-ratio.js";
|
|
8
|
+
export * from "./attachment.js";
|
|
9
|
+
export * from "./avatar.js";
|
|
10
|
+
export * from "./badge.js";
|
|
11
|
+
export * from "./breadcrumb.js";
|
|
12
|
+
export * from "./bubble.js";
|
|
13
|
+
export * from "./button-group.js";
|
|
14
|
+
export * from "./button.js";
|
|
15
|
+
export * from "./calendar.js";
|
|
16
|
+
export * from "./card.js";
|
|
17
|
+
export * from "./checkbox.js";
|
|
18
|
+
export * from "./child.js";
|
|
19
|
+
export * from "./collapsible.js";
|
|
20
|
+
export * from "./color-scheme.js";
|
|
21
|
+
export * from "./combobox.js";
|
|
22
|
+
export * from "./command.js";
|
|
23
|
+
export * from "./context-menu.js";
|
|
24
|
+
export * from "./date-picker.js";
|
|
25
|
+
export * from "./dialog.js";
|
|
26
|
+
export * from "./drawer.js";
|
|
27
|
+
export * from "./dropdown-menu.js";
|
|
28
|
+
export * from "./empty.js";
|
|
29
|
+
export * from "./field.js";
|
|
30
|
+
export * from "./file-drop.js";
|
|
31
|
+
export * from "./focus.js";
|
|
32
|
+
export * from "./harness.js";
|
|
33
|
+
export * from "./heading.js";
|
|
34
|
+
export * from "./hero.js";
|
|
35
|
+
export * from "./hover-card.js";
|
|
36
|
+
export * from "./icon.js";
|
|
37
|
+
export * from "./input-group.js";
|
|
38
|
+
export * from "./input-otp.js";
|
|
39
|
+
export * from "./input.js";
|
|
40
|
+
export * from "./inspector.js";
|
|
41
|
+
export * from "./item.js";
|
|
42
|
+
export * from "./kbd.js";
|
|
43
|
+
export * from "./keys.js";
|
|
44
|
+
export * from "./label.js";
|
|
45
|
+
export * from "./layers.js";
|
|
46
|
+
export * from "./link.js";
|
|
47
|
+
export * from "./marker.js";
|
|
48
|
+
export * from "./menubar.js";
|
|
49
|
+
export * from "./message-scroller.js";
|
|
50
|
+
export * from "./message.js";
|
|
51
|
+
export * from "./native-form.js";
|
|
52
|
+
export * from "./native-select.js";
|
|
53
|
+
export * from "./navigation-bar.js";
|
|
54
|
+
export * from "./navigation-menu.js";
|
|
55
|
+
export * from "./navigation-stack.js";
|
|
56
|
+
export * from "./observers.js";
|
|
57
|
+
export * from "./page.js";
|
|
58
|
+
export * from "./pagination.js";
|
|
59
|
+
export * from "./pointer.js";
|
|
60
|
+
export * from "./popover.js";
|
|
61
|
+
export * from "./progress.js";
|
|
62
|
+
export * from "./pull-to-refresh.js";
|
|
63
|
+
export * from "./questionnaire.js";
|
|
64
|
+
export * from "./radio-group.js";
|
|
65
|
+
export * from "./rating.js";
|
|
66
|
+
export * from "./resizable.js";
|
|
67
|
+
export * from "./routing.js";
|
|
68
|
+
export * from "./roving-focus.js";
|
|
69
|
+
export * from "./scroll-area.js";
|
|
70
|
+
export * from "./scroller.js";
|
|
71
|
+
export * from "./select.js";
|
|
72
|
+
export * from "./selectors.js";
|
|
73
|
+
export * from "./send-pointer.js";
|
|
74
|
+
export * from "./separator.js";
|
|
75
|
+
export * from "./shadowed.js";
|
|
76
|
+
export * from "./sheet.js";
|
|
77
|
+
export * from "./sidebar.js";
|
|
78
|
+
export * from "./skeleton.js";
|
|
79
|
+
export * from "./slider.js";
|
|
80
|
+
export * from "./spinner.js";
|
|
81
|
+
export * from "./split-view.js";
|
|
82
|
+
export * from "./status-bar.js";
|
|
83
|
+
export * from "./sticky-footer.js";
|
|
84
|
+
export * from "./switch.js";
|
|
85
|
+
export * from "./tab-bar.js";
|
|
86
|
+
export * from "./table.js";
|
|
87
|
+
export * from "./tabs.js";
|
|
88
|
+
export * from "./test-hooks.js";
|
|
89
|
+
export * from "./textarea.js";
|
|
90
|
+
export * from "./title-bar.js";
|
|
91
|
+
export * from "./toaster.js";
|
|
92
|
+
export * from "./toggle-group.js";
|
|
93
|
+
export * from "./toggle.js";
|
|
94
|
+
export * from "./toolbar.js";
|
|
95
|
+
export * from "./tooltip.js";
|
|
96
|
+
export * from "./trace.js";
|
|
97
|
+
export * from "./translator.js";
|
|
98
|
+
export * from "./window-frame.js";
|
|
99
|
+
export * from "./zoetrope.js";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
/** Where an addon goes, as `@align` names it. */
|
|
3
|
+
export type InputGroupAlign = 'inline-start' | 'inline-end' | 'block-start' | 'block-end';
|
|
4
|
+
/**
|
|
5
|
+
* Drives an `<InputGroup>` from `@ember-joinery/ember`: its control (the input or textarea,
|
|
6
|
+
* `data-slot="input-group-control"`), its addons and their text. Reach the components inside
|
|
7
|
+
* it, such as its buttons, with `find()` or `@child`:
|
|
8
|
+
*
|
|
9
|
+
* const search = new InputGroupHarness('search') // <InputGroup @name="search">
|
|
10
|
+
* await search.fillIn('shadcn')
|
|
11
|
+
* assert.strictEqual(search.addonText('inline-end'), '12 results')
|
|
12
|
+
* await search.find(ButtonHarness, 'copy').click()
|
|
13
|
+
*/
|
|
14
|
+
export declare class InputGroupHarness extends Harness {
|
|
15
|
+
static component: string;
|
|
16
|
+
/** The group's control: its input, its textarea, or a control of your own. */
|
|
17
|
+
get control(): HTMLInputElement | HTMLTextAreaElement;
|
|
18
|
+
/** What the control holds. */
|
|
19
|
+
get value(): string;
|
|
20
|
+
/** The control's `placeholder`, or `''`. */
|
|
21
|
+
get placeholder(): string;
|
|
22
|
+
/** The control's accessible name: its label, `aria-label`, `title` or placeholder. */
|
|
23
|
+
get label(): string;
|
|
24
|
+
/** The text of what the control's `aria-describedby` names, or `''`. */
|
|
25
|
+
get description(): string;
|
|
26
|
+
/** Whether the control is `disabled`. */
|
|
27
|
+
get isDisabled(): boolean;
|
|
28
|
+
/** Whether the control is marked invalid (`aria-invalid`), which rings the whole group. */
|
|
29
|
+
get isInvalid(): boolean;
|
|
30
|
+
/** Whether the control has focus. */
|
|
31
|
+
get isFocused(): boolean;
|
|
32
|
+
/** Its addons, in document order. */
|
|
33
|
+
get addons(): HTMLElement[];
|
|
34
|
+
/** The first addon at `align` (default: the first addon). Throws when there is none. */
|
|
35
|
+
addon(align?: InputGroupAlign): HTMLElement;
|
|
36
|
+
/** Each addon's `@align`, in document order. */
|
|
37
|
+
get aligns(): string[];
|
|
38
|
+
/** An addon's text, whitespace collapsed. */
|
|
39
|
+
addonText(align?: InputGroupAlign): string;
|
|
40
|
+
/** The text of each `Text` part, in document order. */
|
|
41
|
+
get texts(): string[];
|
|
42
|
+
/** Clicks an addon (by `@align`, or the first), which focuses the input unless it is on a button. */
|
|
43
|
+
clickAddon(align?: InputGroupAlign): Promise<void>;
|
|
44
|
+
/** Replaces what the control holds with `text`, as pasting does. */
|
|
45
|
+
fillIn(text: string): Promise<void>;
|
|
46
|
+
/** Types `text` one key at a time after what the control holds. */
|
|
47
|
+
typeIn(text: string): Promise<void>;
|
|
48
|
+
/** Moves focus to the control. */
|
|
49
|
+
focus(): Promise<void>;
|
|
50
|
+
/** Moves focus away from the control. */
|
|
51
|
+
blur(): Promise<void>;
|
|
52
|
+
/** The icons it shows (lucide's, drawn by `<Icon>`), in document order. */
|
|
53
|
+
get icons(): SVGSVGElement[];
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=input-group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-group.d.ts","sourceRoot":"","sources":["../src/input-group.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAKtC,iDAAiD;AACjD,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,YAAY,GAAG,aAAa,GAAG,WAAW,CAAA;AAEzF;;;;;;;;;GASG;AACH,qBAAa,iBAAkB,SAAQ,OAAO;IAC5C,OAAgB,SAAS,SAAgB;IAEzC,8EAA8E;IAC9E,IAAI,OAAO,IAAI,gBAAgB,GAAG,mBAAmB,CAMpD;IAED,8BAA8B;IAC9B,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,4CAA4C;IAC5C,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,sFAAsF;IACtF,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,wEAAwE;IACxE,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,yCAAyC;IACzC,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,2FAA2F;IAC3F,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,qCAAqC;IACrC,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,qCAAqC;IACrC,IAAI,MAAM,IAAI,WAAW,EAAE,CAE1B;IAED,wFAAwF;IACxF,KAAK,CAAC,KAAK,CAAC,EAAE,eAAe,GAAG,WAAW;IAU3C,gDAAgD;IAChD,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAED,6CAA6C;IAC7C,SAAS,CAAC,KAAK,CAAC,EAAE,eAAe,GAAG,MAAM;IAI1C,uDAAuD;IACvD,IAAI,KAAK,IAAI,MAAM,EAAE,CAEpB;IAED,qGAAqG;IAC/F,UAAU,CAAC,KAAK,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxD,oEAAoE;IAC9D,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,mEAAmE;IAC7D,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,kCAAkC;IAC5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,yCAAyC;IACnC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,2EAA2E;IAC3E,IAAI,KAAK,IAAI,aAAa,EAAE,CAE3B;CACF"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { blur, click, fillIn, focus, typeIn } from '@ember/test-helpers';
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
import { NotFoundError } from "./-private/tree.js";
|
|
4
|
+
import { controlDescription, controlLabel, isMarkedInvalid, textOf } from "./-private/control.js";
|
|
5
|
+
import { selectors } from "./selectors.js";
|
|
6
|
+
/**
|
|
7
|
+
* Drives an `<InputGroup>` from `@ember-joinery/ember`: its control (the input or textarea,
|
|
8
|
+
* `data-slot="input-group-control"`), its addons and their text. Reach the components inside
|
|
9
|
+
* it, such as its buttons, with `find()` or `@child`:
|
|
10
|
+
*
|
|
11
|
+
* const search = new InputGroupHarness('search') // <InputGroup @name="search">
|
|
12
|
+
* await search.fillIn('shadcn')
|
|
13
|
+
* assert.strictEqual(search.addonText('inline-end'), '12 results')
|
|
14
|
+
* await search.find(ButtonHarness, 'copy').click()
|
|
15
|
+
*/
|
|
16
|
+
export class InputGroupHarness extends Harness {
|
|
17
|
+
static component = 'input-group';
|
|
18
|
+
/** The group's control: its input, its textarea, or a control of your own. */
|
|
19
|
+
get control() {
|
|
20
|
+
const control = this.element.querySelector('[data-slot="input-group-control"]');
|
|
21
|
+
if (!control)
|
|
22
|
+
throw new NotFoundError(`no control found in ${this}`);
|
|
23
|
+
return control;
|
|
24
|
+
}
|
|
25
|
+
/** What the control holds. */
|
|
26
|
+
get value() {
|
|
27
|
+
return this.control.value;
|
|
28
|
+
}
|
|
29
|
+
/** The control's `placeholder`, or `''`. */
|
|
30
|
+
get placeholder() {
|
|
31
|
+
return this.control.getAttribute('placeholder') ?? '';
|
|
32
|
+
}
|
|
33
|
+
/** The control's accessible name: its label, `aria-label`, `title` or placeholder. */
|
|
34
|
+
get label() {
|
|
35
|
+
return controlLabel(this.control);
|
|
36
|
+
}
|
|
37
|
+
/** The text of what the control's `aria-describedby` names, or `''`. */
|
|
38
|
+
get description() {
|
|
39
|
+
return controlDescription(this.control);
|
|
40
|
+
}
|
|
41
|
+
/** Whether the control is `disabled`. */
|
|
42
|
+
get isDisabled() {
|
|
43
|
+
return this.control.disabled;
|
|
44
|
+
}
|
|
45
|
+
/** Whether the control is marked invalid (`aria-invalid`), which rings the whole group. */
|
|
46
|
+
get isInvalid() {
|
|
47
|
+
return isMarkedInvalid(this.control);
|
|
48
|
+
}
|
|
49
|
+
/** Whether the control has focus. */
|
|
50
|
+
get isFocused() {
|
|
51
|
+
return this.control.ownerDocument.activeElement === this.control;
|
|
52
|
+
}
|
|
53
|
+
/** Its addons, in document order. */
|
|
54
|
+
get addons() {
|
|
55
|
+
return this.parts('addon');
|
|
56
|
+
}
|
|
57
|
+
/** The first addon at `align` (default: the first addon). Throws when there is none. */
|
|
58
|
+
addon(align) {
|
|
59
|
+
const addon = align
|
|
60
|
+
? this.addons.find(element => element.getAttribute('data-align') === align)
|
|
61
|
+
: this.addons[0];
|
|
62
|
+
if (!addon) {
|
|
63
|
+
throw new NotFoundError(`no ${align ? `"${align}" ` : ''}addon found in ${this}`);
|
|
64
|
+
}
|
|
65
|
+
return addon;
|
|
66
|
+
}
|
|
67
|
+
/** Each addon's `@align`, in document order. */
|
|
68
|
+
get aligns() {
|
|
69
|
+
return this.addons.map(addon => addon.getAttribute('data-align') ?? '');
|
|
70
|
+
}
|
|
71
|
+
/** An addon's text, whitespace collapsed. */
|
|
72
|
+
addonText(align) {
|
|
73
|
+
return textOf(this.addon(align));
|
|
74
|
+
}
|
|
75
|
+
/** The text of each `Text` part, in document order. */
|
|
76
|
+
get texts() {
|
|
77
|
+
return this.parts('text').map(text => textOf(text));
|
|
78
|
+
}
|
|
79
|
+
/** Clicks an addon (by `@align`, or the first), which focuses the input unless it is on a button. */
|
|
80
|
+
async clickAddon(align) {
|
|
81
|
+
await click(this.addon(align));
|
|
82
|
+
}
|
|
83
|
+
/** Replaces what the control holds with `text`, as pasting does. */
|
|
84
|
+
async fillIn(text) {
|
|
85
|
+
await fillIn(this.control, text);
|
|
86
|
+
}
|
|
87
|
+
/** Types `text` one key at a time after what the control holds. */
|
|
88
|
+
async typeIn(text) {
|
|
89
|
+
await typeIn(this.control, text);
|
|
90
|
+
}
|
|
91
|
+
/** Moves focus to the control. */
|
|
92
|
+
async focus() {
|
|
93
|
+
await focus(this.control);
|
|
94
|
+
}
|
|
95
|
+
/** Moves focus away from the control. */
|
|
96
|
+
async blur() {
|
|
97
|
+
await blur(this.control);
|
|
98
|
+
}
|
|
99
|
+
/** The icons it shows (lucide's, drawn by `<Icon>`), in document order. */
|
|
100
|
+
get icons() {
|
|
101
|
+
return [...this.element.querySelectorAll(selectors.component('icon'))];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
/** The keys `InputOTPHarness#press` edits and moves with, as a browser's text input does. */
|
|
3
|
+
export type InputOTPKey = 'Backspace' | 'Delete' | 'ArrowLeft' | 'ArrowRight' | 'Home' | 'End';
|
|
4
|
+
/**
|
|
5
|
+
* Drives an `<InputOTP>` from `@ember-joinery/ember`, or the headless one from
|
|
6
|
+
* `@ember-joinery/primitives/input-otp`: one native `<input>` laid over its slots. State comes
|
|
7
|
+
* from the input and its ARIA, and from the slots' `data-active`. It types, deletes and moves the
|
|
8
|
+
* caret the way a browser edits the input, and pastes and autofills a code as a browser does:
|
|
9
|
+
*
|
|
10
|
+
* const otp = new InputOTPHarness('verification') // <InputOTP @name="verification">
|
|
11
|
+
* await otp.typeIn('123')
|
|
12
|
+
* assert.deepEqual(otp.chars, ['1', '2', '3', '', '', ''])
|
|
13
|
+
* assert.strictEqual(otp.activeIndex, 3)
|
|
14
|
+
* await otp.paste('456')
|
|
15
|
+
* assert.true(otp.isComplete)
|
|
16
|
+
*/
|
|
17
|
+
export declare class InputOTPHarness extends Harness {
|
|
18
|
+
static component: string;
|
|
19
|
+
/** The native `<input>` that holds the code. */
|
|
20
|
+
get input(): HTMLInputElement;
|
|
21
|
+
/** The code it holds. */
|
|
22
|
+
get value(): string;
|
|
23
|
+
/** How many characters the code has (`@maxLength`). */
|
|
24
|
+
get maxLength(): number;
|
|
25
|
+
/** Whether the code has all its characters. */
|
|
26
|
+
get isComplete(): boolean;
|
|
27
|
+
/** The slots, in document order. */
|
|
28
|
+
get slots(): HTMLElement[];
|
|
29
|
+
/** The slot for one character of the code, from 0. Throws when there is none. */
|
|
30
|
+
slot(index: number): HTMLElement;
|
|
31
|
+
/** What each slot shows, in document order (`''` for an empty one). */
|
|
32
|
+
get chars(): string[];
|
|
33
|
+
/** The indexes of the slots the selection is on (`data-active="true"`). */
|
|
34
|
+
get activeIndexes(): number[];
|
|
35
|
+
/** The index of the first active slot, or `null` while none is (it doesn't have focus). */
|
|
36
|
+
get activeIndex(): number | null;
|
|
37
|
+
/** Whether a slot draws the caret: the styled slot's, where the next character goes. */
|
|
38
|
+
hasCaret(index: number): boolean;
|
|
39
|
+
/** Its groups of slots (the styled component's), in document order. */
|
|
40
|
+
get groups(): HTMLElement[];
|
|
41
|
+
/** The separators between its groups (the styled component's). */
|
|
42
|
+
get separators(): HTMLElement[];
|
|
43
|
+
/** The input's accessible name: its label, `aria-label` or `aria-labelledby`. */
|
|
44
|
+
get label(): string;
|
|
45
|
+
/** The text of what its `aria-describedby` names, or `''`. */
|
|
46
|
+
get description(): string;
|
|
47
|
+
/** Whether it is `disabled`. */
|
|
48
|
+
get isDisabled(): boolean;
|
|
49
|
+
/** Whether a form needs it filled (`required`). */
|
|
50
|
+
get isRequired(): boolean;
|
|
51
|
+
/** Whether it is marked invalid: `aria-invalid` on the input, or on any slot (as upstream's example marks it). */
|
|
52
|
+
get isInvalid(): boolean;
|
|
53
|
+
/** Whether the input has focus. */
|
|
54
|
+
get isFocused(): boolean;
|
|
55
|
+
/** Moves focus to it, as tabbing does: the selection goes to the last character, or after it. */
|
|
56
|
+
focus(): Promise<void>;
|
|
57
|
+
/** Moves focus away. */
|
|
58
|
+
blur(): Promise<void>;
|
|
59
|
+
/** Replaces the whole code, in one `input` event, as `fillIn` does an input's value. */
|
|
60
|
+
fillIn(code: string): Promise<void>;
|
|
61
|
+
/** Empties it. */
|
|
62
|
+
clear(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Types `text` a key at a time into the selection, as a browser does: each key replaces the
|
|
65
|
+
* selected character (or goes after the caret), within `maxlength`. It focuses the input first.
|
|
66
|
+
*/
|
|
67
|
+
typeIn(text: string): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Presses a key that edits or moves through the code, as a browser does in a text input:
|
|
70
|
+
* Backspace and Delete delete, the arrows, Home and End move the caret. Right to left,
|
|
71
|
+
* `InputOTP` turns the arrows round, so ArrowLeft moves to the next slot, on the left.
|
|
72
|
+
*/
|
|
73
|
+
press(key: InputOTPKey): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Clicks over one slot, as a user does in Chromium: the click lands on the input above it.
|
|
76
|
+
* A click that focuses the input leaves what focus selects when that is a character (the
|
|
77
|
+
* code is complete, and focus selects its last one), as the browser leaves a selection a
|
|
78
|
+
* focus handler makes. Otherwise the caret goes where the browser puts it for a click at
|
|
79
|
+
* that point (`caretPositionFromPoint`), and the input selects a character from there. The
|
|
80
|
+
* input's text is squeezed into a sliver (input-otp's styles, which hide it), so that is at
|
|
81
|
+
* one end of the code whichever slot the click is over: left to right, after it, so a click
|
|
82
|
+
* selects the last character or the slot after it, as on ui.shadcn.com. To reach another
|
|
83
|
+
* character, `press` the arrow keys. Where the browser can't say (the slot is off screen),
|
|
84
|
+
* the caret goes after the code.
|
|
85
|
+
*/
|
|
86
|
+
clickSlot(index: number): Promise<void>;
|
|
87
|
+
/** Pastes `text` from the clipboard into the selection, as Ctrl+V does. It focuses the input first. */
|
|
88
|
+
paste(text: string): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Fills the whole code in, as a browser's autofill does with a code it was sent: the value at
|
|
91
|
+
* once, then an `input` event with no typing, and `change`. It doesn't move focus.
|
|
92
|
+
*/
|
|
93
|
+
autofill(code: string): Promise<void>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Fills an OTP input with `code`, as ember-primitives' `fillOTP` does: the only `InputOTP` in
|
|
97
|
+
* the test, or the one in `within` (a selector or an element) when there are several.
|
|
98
|
+
*
|
|
99
|
+
* await fillOTP('123456')
|
|
100
|
+
* await fillOTP('123456', '[data-test-login]')
|
|
101
|
+
*/
|
|
102
|
+
export declare function fillOTP(code: string, within?: string | Element): Promise<void>;
|
|
103
|
+
//# sourceMappingURL=input-otp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-otp.d.ts","sourceRoot":"","sources":["../src/input-otp.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAItC,6FAA6F;AAC7F,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,YAAY,GAAG,MAAM,GAAG,KAAK,CAAA;AA4E9F;;;;;;;;;;;;GAYG;AACH,qBAAa,eAAgB,SAAQ,OAAO;IAC1C,OAAgB,SAAS,SAAc;IAEvC,gDAAgD;IAChD,IAAI,KAAK,IAAI,gBAAgB,CAE5B;IAED,yBAAyB;IACzB,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,uDAAuD;IACvD,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,+CAA+C;IAC/C,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,oCAAoC;IACpC,IAAI,KAAK,IAAI,WAAW,EAAE,CAEzB;IAED,iFAAiF;IACjF,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;IAIhC,uEAAuE;IACvE,IAAI,KAAK,IAAI,MAAM,EAAE,CAEpB;IAED,2EAA2E;IAC3E,IAAI,aAAa,IAAI,MAAM,EAAE,CAI5B;IAED,2FAA2F;IAC3F,IAAI,WAAW,IAAI,MAAM,GAAG,IAAI,CAE/B;IAED,wFAAwF;IACxF,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIhC,uEAAuE;IACvE,IAAI,MAAM,IAAI,WAAW,EAAE,CAE1B;IAED,kEAAkE;IAClE,IAAI,UAAU,IAAI,WAAW,EAAE,CAE9B;IAED,iFAAiF;IACjF,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,8DAA8D;IAC9D,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,gCAAgC;IAChC,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,mDAAmD;IACnD,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,kHAAkH;IAClH,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,mCAAmC;IACnC,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,iGAAiG;IAC3F,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,wBAAwB;IAClB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,wFAAwF;IAClF,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,kBAAkB;IACZ,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;;OAGG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWzC;;;;OAIG;IACG,KAAK,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5C;;;;;;;;;;;OAWG;IACG,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAe7C,uGAAuG;IACjG,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUxC;;;OAGG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAO5C;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAUpF"}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { isString } from '@sindresorhus/is';
|
|
2
|
+
import { blur, click, fillIn, find, focus, getRootElement, settled } from '@ember/test-helpers';
|
|
3
|
+
import { Harness } from "./harness.js";
|
|
4
|
+
import { controlDescription, controlLabel, isMarkedInvalid, textOf } from "./-private/control.js";
|
|
5
|
+
import { selectors } from "./selectors.js";
|
|
6
|
+
function keyEvent(input, type, key) {
|
|
7
|
+
const event = new KeyboardEvent(type, { key, bubbles: true, cancelable: true, view: window });
|
|
8
|
+
input.dispatchEvent(event);
|
|
9
|
+
return event;
|
|
10
|
+
}
|
|
11
|
+
/** Tells the page the selection moved, as the browser does after a caret move. */
|
|
12
|
+
function selectionMoved(input) {
|
|
13
|
+
input.ownerDocument.dispatchEvent(new Event('selectionchange'));
|
|
14
|
+
}
|
|
15
|
+
/** Replaces the input's selection with `text`, as typing does: within `maxlength`, then `input`. */
|
|
16
|
+
function insert(input, text, inputType) {
|
|
17
|
+
const value = input.value;
|
|
18
|
+
const start = input.selectionStart ?? value.length;
|
|
19
|
+
const end = input.selectionEnd ?? start;
|
|
20
|
+
const max = input.maxLength;
|
|
21
|
+
const room = max < 0 ? text.length : max - (value.length - (end - start));
|
|
22
|
+
const inserted = text.slice(0, Math.max(0, room));
|
|
23
|
+
if (!inserted)
|
|
24
|
+
return;
|
|
25
|
+
input.value = value.slice(0, start) + inserted + value.slice(end);
|
|
26
|
+
const caret = start + inserted.length;
|
|
27
|
+
input.setSelectionRange(caret, caret);
|
|
28
|
+
input.dispatchEvent(new InputEvent('input', { bubbles: true, inputType, data: inserted }));
|
|
29
|
+
selectionMoved(input);
|
|
30
|
+
}
|
|
31
|
+
/** Deletes the selection, or the character before (or after) the caret, as a browser does. */
|
|
32
|
+
function remove(input, forward) {
|
|
33
|
+
const value = input.value;
|
|
34
|
+
let start = input.selectionStart ?? value.length;
|
|
35
|
+
let end = input.selectionEnd ?? start;
|
|
36
|
+
if (start === end) {
|
|
37
|
+
if (forward)
|
|
38
|
+
end = Math.min(value.length, end + 1);
|
|
39
|
+
else
|
|
40
|
+
start = Math.max(0, start - 1);
|
|
41
|
+
}
|
|
42
|
+
if (start === end)
|
|
43
|
+
return;
|
|
44
|
+
input.value = value.slice(0, start) + value.slice(end);
|
|
45
|
+
input.setSelectionRange(start, start);
|
|
46
|
+
const inputType = forward ? 'deleteContentForward' : 'deleteContentBackward';
|
|
47
|
+
input.dispatchEvent(new InputEvent('input', { bubbles: true, inputType }));
|
|
48
|
+
selectionMoved(input);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Moves the caret, as an arrow key, Home or End does in a browser's text input holding a code.
|
|
52
|
+
* A code (digits, Latin letters) is a left-to-right run in either direction, so the browser's
|
|
53
|
+
* ArrowLeft goes back through it and ArrowRight on, right to left too. `InputOTP` turns the
|
|
54
|
+
* arrows round itself right to left, where its slots run from the right, so there its keydown
|
|
55
|
+
* is `defaultPrevented` and this doesn't run.
|
|
56
|
+
*/
|
|
57
|
+
function move(input, key) {
|
|
58
|
+
const length = input.value.length;
|
|
59
|
+
const start = input.selectionStart ?? length;
|
|
60
|
+
const end = input.selectionEnd ?? start;
|
|
61
|
+
let caret;
|
|
62
|
+
if (key === 'Home')
|
|
63
|
+
caret = 0;
|
|
64
|
+
else if (key === 'End')
|
|
65
|
+
caret = length;
|
|
66
|
+
else if (start !== end)
|
|
67
|
+
caret = key === 'ArrowLeft' ? start : end;
|
|
68
|
+
else
|
|
69
|
+
caret = key === 'ArrowLeft' ? Math.max(0, start - 1) : Math.min(length, end + 1);
|
|
70
|
+
input.setSelectionRange(caret, caret);
|
|
71
|
+
selectionMoved(input);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Where a click at a point puts the caret in `input`, as the browser works it out, or `null`
|
|
75
|
+
* when it can't say (the point is off screen, or over something else).
|
|
76
|
+
*/
|
|
77
|
+
function caretAt(input, x, y) {
|
|
78
|
+
const position = input.ownerDocument.caretPositionFromPoint(x, y);
|
|
79
|
+
if (!position || position.offsetNode !== input)
|
|
80
|
+
return null;
|
|
81
|
+
return position.offset;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Drives an `<InputOTP>` from `@ember-joinery/ember`, or the headless one from
|
|
85
|
+
* `@ember-joinery/primitives/input-otp`: one native `<input>` laid over its slots. State comes
|
|
86
|
+
* from the input and its ARIA, and from the slots' `data-active`. It types, deletes and moves the
|
|
87
|
+
* caret the way a browser edits the input, and pastes and autofills a code as a browser does:
|
|
88
|
+
*
|
|
89
|
+
* const otp = new InputOTPHarness('verification') // <InputOTP @name="verification">
|
|
90
|
+
* await otp.typeIn('123')
|
|
91
|
+
* assert.deepEqual(otp.chars, ['1', '2', '3', '', '', ''])
|
|
92
|
+
* assert.strictEqual(otp.activeIndex, 3)
|
|
93
|
+
* await otp.paste('456')
|
|
94
|
+
* assert.true(otp.isComplete)
|
|
95
|
+
*/
|
|
96
|
+
export class InputOTPHarness extends Harness {
|
|
97
|
+
static component = 'input-otp';
|
|
98
|
+
/** The native `<input>` that holds the code. */
|
|
99
|
+
get input() {
|
|
100
|
+
return this.part('input');
|
|
101
|
+
}
|
|
102
|
+
/** The code it holds. */
|
|
103
|
+
get value() {
|
|
104
|
+
return this.input.value;
|
|
105
|
+
}
|
|
106
|
+
/** How many characters the code has (`@maxLength`). */
|
|
107
|
+
get maxLength() {
|
|
108
|
+
return this.input.maxLength;
|
|
109
|
+
}
|
|
110
|
+
/** Whether the code has all its characters. */
|
|
111
|
+
get isComplete() {
|
|
112
|
+
return this.value.length === this.maxLength;
|
|
113
|
+
}
|
|
114
|
+
/** The slots, in document order. */
|
|
115
|
+
get slots() {
|
|
116
|
+
return this.parts('slot');
|
|
117
|
+
}
|
|
118
|
+
/** The slot for one character of the code, from 0. Throws when there is none. */
|
|
119
|
+
slot(index) {
|
|
120
|
+
return this.part('slot', String(index));
|
|
121
|
+
}
|
|
122
|
+
/** What each slot shows, in document order (`''` for an empty one). */
|
|
123
|
+
get chars() {
|
|
124
|
+
return this.slots.map(slot => textOf(slot));
|
|
125
|
+
}
|
|
126
|
+
/** The indexes of the slots the selection is on (`data-active="true"`). */
|
|
127
|
+
get activeIndexes() {
|
|
128
|
+
return this.slots
|
|
129
|
+
.filter(slot => slot.getAttribute('data-active') === 'true')
|
|
130
|
+
.map(slot => Number(slot.getAttribute('data-test-jn-value')));
|
|
131
|
+
}
|
|
132
|
+
/** The index of the first active slot, or `null` while none is (it doesn't have focus). */
|
|
133
|
+
get activeIndex() {
|
|
134
|
+
return this.activeIndexes[0] ?? null;
|
|
135
|
+
}
|
|
136
|
+
/** Whether a slot draws the caret: the styled slot's, where the next character goes. */
|
|
137
|
+
hasCaret(index) {
|
|
138
|
+
return Boolean(this.slot(index).querySelector(selectors.part('caret')));
|
|
139
|
+
}
|
|
140
|
+
/** Its groups of slots (the styled component's), in document order. */
|
|
141
|
+
get groups() {
|
|
142
|
+
return this.parts('group');
|
|
143
|
+
}
|
|
144
|
+
/** The separators between its groups (the styled component's). */
|
|
145
|
+
get separators() {
|
|
146
|
+
return this.parts('separator');
|
|
147
|
+
}
|
|
148
|
+
/** The input's accessible name: its label, `aria-label` or `aria-labelledby`. */
|
|
149
|
+
get label() {
|
|
150
|
+
return controlLabel(this.input);
|
|
151
|
+
}
|
|
152
|
+
/** The text of what its `aria-describedby` names, or `''`. */
|
|
153
|
+
get description() {
|
|
154
|
+
return controlDescription(this.input);
|
|
155
|
+
}
|
|
156
|
+
/** Whether it is `disabled`. */
|
|
157
|
+
get isDisabled() {
|
|
158
|
+
return this.input.disabled;
|
|
159
|
+
}
|
|
160
|
+
/** Whether a form needs it filled (`required`). */
|
|
161
|
+
get isRequired() {
|
|
162
|
+
return this.input.required;
|
|
163
|
+
}
|
|
164
|
+
/** Whether it is marked invalid: `aria-invalid` on the input, or on any slot (as upstream's example marks it). */
|
|
165
|
+
get isInvalid() {
|
|
166
|
+
return isMarkedInvalid(this.input) || this.slots.some(slot => isMarkedInvalid(slot));
|
|
167
|
+
}
|
|
168
|
+
/** Whether the input has focus. */
|
|
169
|
+
get isFocused() {
|
|
170
|
+
return this.input.ownerDocument.activeElement === this.input;
|
|
171
|
+
}
|
|
172
|
+
/** Moves focus to it, as tabbing does: the selection goes to the last character, or after it. */
|
|
173
|
+
async focus() {
|
|
174
|
+
await focus(this.input);
|
|
175
|
+
}
|
|
176
|
+
/** Moves focus away. */
|
|
177
|
+
async blur() {
|
|
178
|
+
await blur(this.input);
|
|
179
|
+
}
|
|
180
|
+
/** Replaces the whole code, in one `input` event, as `fillIn` does an input's value. */
|
|
181
|
+
async fillIn(code) {
|
|
182
|
+
await fillIn(this.input, code);
|
|
183
|
+
}
|
|
184
|
+
/** Empties it. */
|
|
185
|
+
async clear() {
|
|
186
|
+
await fillIn(this.input, '');
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Types `text` a key at a time into the selection, as a browser does: each key replaces the
|
|
190
|
+
* selected character (or goes after the caret), within `maxlength`. It focuses the input first.
|
|
191
|
+
*/
|
|
192
|
+
async typeIn(text) {
|
|
193
|
+
if (!this.isFocused)
|
|
194
|
+
await this.focus();
|
|
195
|
+
for (const character of text) {
|
|
196
|
+
const input = this.input;
|
|
197
|
+
const down = keyEvent(input, 'keydown', character);
|
|
198
|
+
if (!down.defaultPrevented)
|
|
199
|
+
insert(input, character, 'insertText');
|
|
200
|
+
keyEvent(input, 'keyup', character);
|
|
201
|
+
await settled();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Presses a key that edits or moves through the code, as a browser does in a text input:
|
|
206
|
+
* Backspace and Delete delete, the arrows, Home and End move the caret. Right to left,
|
|
207
|
+
* `InputOTP` turns the arrows round, so ArrowLeft moves to the next slot, on the left.
|
|
208
|
+
*/
|
|
209
|
+
async press(key) {
|
|
210
|
+
if (!this.isFocused)
|
|
211
|
+
await this.focus();
|
|
212
|
+
const input = this.input;
|
|
213
|
+
const down = keyEvent(input, 'keydown', key);
|
|
214
|
+
if (!down.defaultPrevented) {
|
|
215
|
+
if (key === 'Backspace' || key === 'Delete')
|
|
216
|
+
remove(input, key === 'Delete');
|
|
217
|
+
else
|
|
218
|
+
move(input, key);
|
|
219
|
+
}
|
|
220
|
+
keyEvent(input, 'keyup', key);
|
|
221
|
+
await settled();
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Clicks over one slot, as a user does in Chromium: the click lands on the input above it.
|
|
225
|
+
* A click that focuses the input leaves what focus selects when that is a character (the
|
|
226
|
+
* code is complete, and focus selects its last one), as the browser leaves a selection a
|
|
227
|
+
* focus handler makes. Otherwise the caret goes where the browser puts it for a click at
|
|
228
|
+
* that point (`caretPositionFromPoint`), and the input selects a character from there. The
|
|
229
|
+
* input's text is squeezed into a sliver (input-otp's styles, which hide it), so that is at
|
|
230
|
+
* one end of the code whichever slot the click is over: left to right, after it, so a click
|
|
231
|
+
* selects the last character or the slot after it, as on ui.shadcn.com. To reach another
|
|
232
|
+
* character, `press` the arrow keys. Where the browser can't say (the slot is off screen),
|
|
233
|
+
* the caret goes after the code.
|
|
234
|
+
*/
|
|
235
|
+
async clickSlot(index) {
|
|
236
|
+
const input = this.input;
|
|
237
|
+
const box = this.slot(index).getBoundingClientRect();
|
|
238
|
+
const clientX = box.left + box.width / 2;
|
|
239
|
+
const clientY = box.top + box.height / 2;
|
|
240
|
+
// Where the click lands, in the layout it lands on (focus restyles the input after it).
|
|
241
|
+
const caret = caretAt(input, clientX, clientY) ?? input.value.length;
|
|
242
|
+
const focusing = !this.isFocused;
|
|
243
|
+
await click(input, { clientX, clientY });
|
|
244
|
+
if (focusing && input.selectionStart !== input.selectionEnd)
|
|
245
|
+
return;
|
|
246
|
+
input.setSelectionRange(caret, caret);
|
|
247
|
+
selectionMoved(input);
|
|
248
|
+
await settled();
|
|
249
|
+
}
|
|
250
|
+
/** Pastes `text` from the clipboard into the selection, as Ctrl+V does. It focuses the input first. */
|
|
251
|
+
async paste(text) {
|
|
252
|
+
if (!this.isFocused)
|
|
253
|
+
await this.focus();
|
|
254
|
+
const clipboardData = new DataTransfer();
|
|
255
|
+
clipboardData.setData('text/plain', text);
|
|
256
|
+
const event = new ClipboardEvent('paste', { clipboardData, bubbles: true, cancelable: true });
|
|
257
|
+
const input = this.input;
|
|
258
|
+
if (input.dispatchEvent(event))
|
|
259
|
+
insert(input, text, 'insertFromPaste');
|
|
260
|
+
await settled();
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Fills the whole code in, as a browser's autofill does with a code it was sent: the value at
|
|
264
|
+
* once, then an `input` event with no typing, and `change`. It doesn't move focus.
|
|
265
|
+
*/
|
|
266
|
+
async autofill(code) {
|
|
267
|
+
const input = this.input;
|
|
268
|
+
input.value = code;
|
|
269
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
270
|
+
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
271
|
+
await settled();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Fills an OTP input with `code`, as ember-primitives' `fillOTP` does: the only `InputOTP` in
|
|
276
|
+
* the test, or the one in `within` (a selector or an element) when there are several.
|
|
277
|
+
*
|
|
278
|
+
* await fillOTP('123456')
|
|
279
|
+
* await fillOTP('123456', '[data-test-login]')
|
|
280
|
+
*/
|
|
281
|
+
export async function fillOTP(code, within) {
|
|
282
|
+
const scope = isString(within) ? find(within) : (within ?? getRootElement());
|
|
283
|
+
if (!scope)
|
|
284
|
+
throw new Error(`fillOTP: nothing matches ${String(within)}`);
|
|
285
|
+
const component = selectors.component('input-otp');
|
|
286
|
+
const root = scope instanceof Element && scope.matches(component) ? scope : scope.querySelector(component);
|
|
287
|
+
if (!root)
|
|
288
|
+
throw new Error('fillOTP: no InputOTP found');
|
|
289
|
+
const input = root.querySelector(selectors.part('input'));
|
|
290
|
+
if (!input)
|
|
291
|
+
throw new Error('fillOTP: the InputOTP has no input');
|
|
292
|
+
await fillIn(input, code);
|
|
293
|
+
}
|