@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,100 @@
|
|
|
1
|
+
import { blur, focus, select } from '@ember/test-helpers';
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
import { controlDescription, controlLabel, isMarkedInvalid, textOf } from "./-private/control.js";
|
|
4
|
+
/**
|
|
5
|
+
* Drives a `<NativeSelect>` from `@ember-joinery/ember`: the browser's own `<select>`, so it
|
|
6
|
+
* chooses an option the way the browser's menu does (`input` and `change` events). State comes
|
|
7
|
+
* from the element and its ARIA.
|
|
8
|
+
*
|
|
9
|
+
* const status = new NativeSelectHarness('status') // <NativeSelect @name="status">
|
|
10
|
+
* await status.select('done')
|
|
11
|
+
* assert.strictEqual(status.value, 'done')
|
|
12
|
+
* assert.strictEqual(status.selectedText, 'Done')
|
|
13
|
+
*/
|
|
14
|
+
export class NativeSelectHarness extends Harness {
|
|
15
|
+
static component = 'native-select';
|
|
16
|
+
/** The `<select>` itself (its root is the wrapper around it). */
|
|
17
|
+
get control() {
|
|
18
|
+
return this.part('select');
|
|
19
|
+
}
|
|
20
|
+
/** The icon at its end. */
|
|
21
|
+
get icon() {
|
|
22
|
+
return this.part('icon');
|
|
23
|
+
}
|
|
24
|
+
/** The value of the option chosen now (`''` for none). */
|
|
25
|
+
get value() {
|
|
26
|
+
return this.control.value;
|
|
27
|
+
}
|
|
28
|
+
/** The text of the option chosen now, or `''` for none. */
|
|
29
|
+
get selectedText() {
|
|
30
|
+
const option = this.control.selectedOptions[0];
|
|
31
|
+
return option ? textOf(option) : '';
|
|
32
|
+
}
|
|
33
|
+
/** Every option's value, in order. */
|
|
34
|
+
get options() {
|
|
35
|
+
return [...this.control.options].map(option => option.value);
|
|
36
|
+
}
|
|
37
|
+
/** Every option's text, in order. */
|
|
38
|
+
get optionTexts() {
|
|
39
|
+
return [...this.control.options].map(textOf);
|
|
40
|
+
}
|
|
41
|
+
/** Every group's `label`, in order. */
|
|
42
|
+
get groups() {
|
|
43
|
+
return [...this.control.querySelectorAll('optgroup')].map(group => group.label);
|
|
44
|
+
}
|
|
45
|
+
/** The values of the options in the group with this `label`, in order. */
|
|
46
|
+
optionsIn(group) {
|
|
47
|
+
const found = [...this.control.querySelectorAll('optgroup')].find(candidate => candidate.label === group);
|
|
48
|
+
return found ? [...found.querySelectorAll('option')].map(option => option.value) : [];
|
|
49
|
+
}
|
|
50
|
+
/** Whether the option with this value can't be chosen (it, or its group, is `disabled`). */
|
|
51
|
+
isOptionDisabled(value) {
|
|
52
|
+
const option = [...this.control.options].find(candidate => candidate.value === value);
|
|
53
|
+
if (!option)
|
|
54
|
+
throw new Error(`Joinery harness: no option "${value}" in ${this}`);
|
|
55
|
+
return option.disabled || Boolean(option.closest('optgroup')?.disabled);
|
|
56
|
+
}
|
|
57
|
+
/** Its `@size`: `default` or `sm`. */
|
|
58
|
+
get size() {
|
|
59
|
+
return this.element.getAttribute('data-size');
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Its accessible name, as assistive technology reads it: `aria-labelledby`'s text, else
|
|
63
|
+
* `aria-label`, else its `<label>`'s text, else `title`.
|
|
64
|
+
*/
|
|
65
|
+
get label() {
|
|
66
|
+
return controlLabel(this.control);
|
|
67
|
+
}
|
|
68
|
+
/** The text of what its `aria-describedby` names (a field's description and errors), or `''`. */
|
|
69
|
+
get description() {
|
|
70
|
+
return controlDescription(this.control);
|
|
71
|
+
}
|
|
72
|
+
/** Whether it is `disabled`. */
|
|
73
|
+
get isDisabled() {
|
|
74
|
+
return this.control.disabled;
|
|
75
|
+
}
|
|
76
|
+
/** Whether it is `required`. */
|
|
77
|
+
get isRequired() {
|
|
78
|
+
return this.control.required;
|
|
79
|
+
}
|
|
80
|
+
/** Whether it is marked invalid with `aria-invalid`. */
|
|
81
|
+
get isInvalid() {
|
|
82
|
+
return isMarkedInvalid(this.control);
|
|
83
|
+
}
|
|
84
|
+
/** Whether it has focus. */
|
|
85
|
+
get isFocused() {
|
|
86
|
+
return this.control.ownerDocument.activeElement === this.control;
|
|
87
|
+
}
|
|
88
|
+
/** Chooses the option with this value. Fails when the select is disabled, as a user can't. */
|
|
89
|
+
async select(value) {
|
|
90
|
+
await select(this.control, value);
|
|
91
|
+
}
|
|
92
|
+
/** Moves focus to it, as tabbing to it would. Fails if it can't take focus. */
|
|
93
|
+
async focus() {
|
|
94
|
+
await focus(this.control);
|
|
95
|
+
}
|
|
96
|
+
/** Moves focus away from it. */
|
|
97
|
+
async blur() {
|
|
98
|
+
await blur(this.control);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Drives a `<NavigationBar>` from `@ember-joinery/ember`: reads its title and its large title,
|
|
4
|
+
* and reaches its parts.
|
|
5
|
+
*
|
|
6
|
+
* const bar = new NavigationBarHarness('contacts') // <NavigationBar @name="contacts">
|
|
7
|
+
* assert.strictEqual(bar.title, 'Contacts')
|
|
8
|
+
* assert.true(bar.hasLargeTitle)
|
|
9
|
+
* await bar.find(ButtonHarness, 'add').click()
|
|
10
|
+
*/
|
|
11
|
+
export declare class NavigationBarHarness extends Harness {
|
|
12
|
+
static component: string;
|
|
13
|
+
/** The title's text, or `''` without one. */
|
|
14
|
+
get title(): string;
|
|
15
|
+
/** The title's element, a heading, or `null`. */
|
|
16
|
+
get titleElement(): HTMLElement | null;
|
|
17
|
+
/** The start of the bar, or `null`. */
|
|
18
|
+
get leading(): HTMLElement | null;
|
|
19
|
+
/** The end of the bar, or `null`. */
|
|
20
|
+
get trailing(): HTMLElement | null;
|
|
21
|
+
/** Whether the bar is for a screen with a large title (`@largeTitle`). */
|
|
22
|
+
get hasLargeTitle(): boolean;
|
|
23
|
+
/** The large title's element: the first one after the bar in the document, or `null`. */
|
|
24
|
+
get largeTitleElement(): HTMLElement | null;
|
|
25
|
+
/** The large title's text, or `''` without one. */
|
|
26
|
+
get largeTitle(): string;
|
|
27
|
+
/** Whether the bar stays at the top while the content scrolls (`position: sticky`). */
|
|
28
|
+
get isSticky(): boolean;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=navigation-bar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-bar.d.ts","sourceRoot":"","sources":["../src/navigation-bar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAMtC;;;;;;;;GAQG;AACH,qBAAa,oBAAqB,SAAQ,OAAO;IAC/C,OAAgB,SAAS,SAAmB;IAE5C,6CAA6C;IAC7C,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,iDAAiD;IACjD,IAAI,YAAY,IAAI,WAAW,GAAG,IAAI,CAErC;IAED,uCAAuC;IACvC,IAAI,OAAO,IAAI,WAAW,GAAG,IAAI,CAEhC;IAED,qCAAqC;IACrC,IAAI,QAAQ,IAAI,WAAW,GAAG,IAAI,CAEjC;IAED,0EAA0E;IAC1E,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED,yFAAyF;IACzF,IAAI,iBAAiB,IAAI,WAAW,GAAG,IAAI,CAW1C;IAED,mDAAmD;IACnD,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,uFAAuF;IACvF,IAAI,QAAQ,IAAI,OAAO,CAEtB;CACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Harness } from "./harness.js";
|
|
2
|
+
function text(element) {
|
|
3
|
+
return (element?.textContent ?? '').replace(/\s+/g, ' ').trim();
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Drives a `<NavigationBar>` from `@ember-joinery/ember`: reads its title and its large title,
|
|
7
|
+
* and reaches its parts.
|
|
8
|
+
*
|
|
9
|
+
* const bar = new NavigationBarHarness('contacts') // <NavigationBar @name="contacts">
|
|
10
|
+
* assert.strictEqual(bar.title, 'Contacts')
|
|
11
|
+
* assert.true(bar.hasLargeTitle)
|
|
12
|
+
* await bar.find(ButtonHarness, 'add').click()
|
|
13
|
+
*/
|
|
14
|
+
export class NavigationBarHarness extends Harness {
|
|
15
|
+
static component = 'navigation-bar';
|
|
16
|
+
/** The title's text, or `''` without one. */
|
|
17
|
+
get title() {
|
|
18
|
+
return text(this.titleElement);
|
|
19
|
+
}
|
|
20
|
+
/** The title's element, a heading, or `null`. */
|
|
21
|
+
get titleElement() {
|
|
22
|
+
return this.queryPart('title');
|
|
23
|
+
}
|
|
24
|
+
/** The start of the bar, or `null`. */
|
|
25
|
+
get leading() {
|
|
26
|
+
return this.queryPart('leading');
|
|
27
|
+
}
|
|
28
|
+
/** The end of the bar, or `null`. */
|
|
29
|
+
get trailing() {
|
|
30
|
+
return this.queryPart('trailing');
|
|
31
|
+
}
|
|
32
|
+
/** Whether the bar is for a screen with a large title (`@largeTitle`). */
|
|
33
|
+
get hasLargeTitle() {
|
|
34
|
+
return this.element.hasAttribute('data-large-title');
|
|
35
|
+
}
|
|
36
|
+
/** The large title's element: the first one after the bar in the document, or `null`. */
|
|
37
|
+
get largeTitleElement() {
|
|
38
|
+
if (!this.hasLargeTitle)
|
|
39
|
+
return null;
|
|
40
|
+
const bar = this.element;
|
|
41
|
+
const all = bar.ownerDocument.querySelectorAll('[data-slot="navigation-bar-large-title"]');
|
|
42
|
+
return ([...all].find(element => bar.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_FOLLOWING) ?? null);
|
|
43
|
+
}
|
|
44
|
+
/** The large title's text, or `''` without one. */
|
|
45
|
+
get largeTitle() {
|
|
46
|
+
return text(this.largeTitleElement);
|
|
47
|
+
}
|
|
48
|
+
/** Whether the bar stays at the top while the content scrolls (`position: sticky`). */
|
|
49
|
+
get isSticky() {
|
|
50
|
+
return getComputedStyle(this.element).position === 'sticky';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
/** One item of a navigation menu that opens a content: its trigger, and its content's links. */
|
|
3
|
+
export declare class NavigationMenuItemLevel {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(trigger: () => HTMLElement);
|
|
6
|
+
/** Its trigger. */
|
|
7
|
+
get trigger(): HTMLElement;
|
|
8
|
+
/** Its value (`data-test-jn-value`). */
|
|
9
|
+
get value(): string | null;
|
|
10
|
+
/** Whether its content is open, from the trigger's `aria-expanded`. */
|
|
11
|
+
get isOpen(): boolean;
|
|
12
|
+
/** Its content, through the trigger's `aria-controls`, or `null` while it isn't rendered. */
|
|
13
|
+
get content(): HTMLElement | null;
|
|
14
|
+
/** The content's accessible name: its trigger's text. */
|
|
15
|
+
get label(): string;
|
|
16
|
+
/** Which way the content is moving (`data-motion`): `from-start`, `to-end`…, or `null`. */
|
|
17
|
+
get motion(): string | null;
|
|
18
|
+
/** The content's links, as elements, in order. */
|
|
19
|
+
get linkElements(): HTMLElement[];
|
|
20
|
+
/** Each of the content's links' text. */
|
|
21
|
+
get links(): string[];
|
|
22
|
+
/** The content's link whose text is `label` (or the only one starting with it). */
|
|
23
|
+
link(label: string): HTMLElement;
|
|
24
|
+
/** Clicks the trigger: it opens the content, or closes it when it is open. */
|
|
25
|
+
toggle(): Promise<void>;
|
|
26
|
+
/** Opens it with a click on the trigger, unless it is open. */
|
|
27
|
+
open(): Promise<void>;
|
|
28
|
+
/** Closes it with a click on the trigger, unless it is closed. */
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
/** Rests the pointer on the trigger, which opens it after the menu's delay. */
|
|
31
|
+
hover(): Promise<void>;
|
|
32
|
+
/** Moves the pointer off the trigger (downwards, towards the content, unless `side` says). */
|
|
33
|
+
unhover(side?: 'top' | 'right' | 'bottom' | 'left'): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Toggles it from the keyboard: focus on the trigger, then Enter (or Space), which presses
|
|
36
|
+
* the button, as a browser does (`pressKey` sends only the key's events). Focus stays on the
|
|
37
|
+
* trigger; Tab or ArrowDown goes on into the content.
|
|
38
|
+
*/
|
|
39
|
+
openWithKeyboard(key?: 'Enter' | ' '): Promise<void>;
|
|
40
|
+
/** Clicks the content's link `label`: it follows it, and closes the content. */
|
|
41
|
+
select(label: string): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Drives a `<NavigationMenu>` from `@ember-joinery/ember` or
|
|
45
|
+
* `@ember-joinery/primitives/navigation-menu`. Its items are found by their triggers' text and
|
|
46
|
+
* its links by theirs, and read through ARIA (a trigger's `aria-expanded`, a link's
|
|
47
|
+
* `aria-current`).
|
|
48
|
+
*
|
|
49
|
+
* const nav = new NavigationMenuHarness()
|
|
50
|
+
* assert.deepEqual(nav.triggerLabels, ['Getting started', 'Components'])
|
|
51
|
+
* const start = nav.item('Getting started')
|
|
52
|
+
* await start.open()
|
|
53
|
+
* assert.deepEqual(start.links.length, 3)
|
|
54
|
+
* await nav.item('Components').hover()
|
|
55
|
+
* assert.strictEqual(nav.openItem, 'Components')
|
|
56
|
+
*/
|
|
57
|
+
export declare class NavigationMenuHarness extends Harness {
|
|
58
|
+
static component: string;
|
|
59
|
+
/** The `<ul>` of items. */
|
|
60
|
+
get list(): HTMLElement;
|
|
61
|
+
/** Each trigger, in order. */
|
|
62
|
+
get triggers(): HTMLElement[];
|
|
63
|
+
/** Each trigger's text, in order. */
|
|
64
|
+
get triggerLabels(): string[];
|
|
65
|
+
/** The links in the list itself (not in a content), as elements, in order. */
|
|
66
|
+
get listLinkElements(): HTMLElement[];
|
|
67
|
+
/** Each of the list's own links' text. */
|
|
68
|
+
get listLinks(): string[];
|
|
69
|
+
/** The list's own link whose text is `label`. */
|
|
70
|
+
listLink(label: string): HTMLElement;
|
|
71
|
+
/** The trigger whose text is `label`. Throws when there is none. */
|
|
72
|
+
trigger(label: string): HTMLElement;
|
|
73
|
+
/** The item whose trigger's text is `label`. */
|
|
74
|
+
item(label: string): NavigationMenuItemLevel;
|
|
75
|
+
/** The text of the trigger whose content is open, or `null`. */
|
|
76
|
+
get openItem(): string | null;
|
|
77
|
+
/** Whether a content is open. */
|
|
78
|
+
get isOpen(): boolean;
|
|
79
|
+
/** The open item, or `null`. */
|
|
80
|
+
get open(): NavigationMenuItemLevel | null;
|
|
81
|
+
/** The viewport, while it is rendered (a content is open), or `null`. */
|
|
82
|
+
get viewport(): HTMLElement | null;
|
|
83
|
+
/** The viewport's size, as the open content gives it (`--radix-navigation-menu-viewport-*`). */
|
|
84
|
+
get viewportSize(): {
|
|
85
|
+
width: number;
|
|
86
|
+
height: number;
|
|
87
|
+
} | null;
|
|
88
|
+
/** The indicator, while it is rendered, or `null`. */
|
|
89
|
+
get indicator(): HTMLElement | null;
|
|
90
|
+
/** The text of the trigger or link that has focus, or `null`. */
|
|
91
|
+
get focused(): string | null;
|
|
92
|
+
/** Presses Escape where focus is: it closes the open content. */
|
|
93
|
+
pressEscape(): Promise<void>;
|
|
94
|
+
/** A press outside the menu. */
|
|
95
|
+
pressOutside(): Promise<void>;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=navigation-menu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-menu.d.ts","sourceRoot":"","sources":["../src/navigation-menu.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { click, focus } from '@ember/test-helpers';
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
import { pressEscape, pressOutside } from "./layers.js";
|
|
4
|
+
import { hover, unhover } from "./pointer.js";
|
|
5
|
+
import { pressKey } from "./focus.js";
|
|
6
|
+
import { NotFoundError } from "./-private/tree.js";
|
|
7
|
+
import { accessibleName, text } from "./-private/overlay.js";
|
|
8
|
+
const LINK = '[data-test-jn-part="link"]';
|
|
9
|
+
/**
|
|
10
|
+
* The link among `links` whose text is `label`, or else the only one whose text starts with it
|
|
11
|
+
* (a link with a title and a description: `"Introduction"` for "Introduction Re-usable
|
|
12
|
+
* components…"). Throws when there is none, or more than one.
|
|
13
|
+
*/
|
|
14
|
+
function findLink(links, label, where) {
|
|
15
|
+
const exact = links.find(element => text(element) === label);
|
|
16
|
+
if (exact)
|
|
17
|
+
return exact;
|
|
18
|
+
const starting = links.filter(element => text(element).startsWith(`${label} `));
|
|
19
|
+
if (starting.length === 1)
|
|
20
|
+
return starting[0];
|
|
21
|
+
const names = links.map(each => `"${text(each)}"`).join(', ');
|
|
22
|
+
throw new NotFoundError(starting.length
|
|
23
|
+
? `more than one link starts with "${label}" in ${where}`
|
|
24
|
+
: `no link "${label}" in ${where} (there are: ${names})`);
|
|
25
|
+
}
|
|
26
|
+
/** One item of a navigation menu that opens a content: its trigger, and its content's links. */
|
|
27
|
+
export class NavigationMenuItemLevel {
|
|
28
|
+
#trigger;
|
|
29
|
+
constructor(trigger) {
|
|
30
|
+
this.#trigger = trigger;
|
|
31
|
+
}
|
|
32
|
+
/** Its trigger. */
|
|
33
|
+
get trigger() {
|
|
34
|
+
return this.#trigger();
|
|
35
|
+
}
|
|
36
|
+
/** Its value (`data-test-jn-value`). */
|
|
37
|
+
get value() {
|
|
38
|
+
return this.trigger.getAttribute('data-test-jn-value');
|
|
39
|
+
}
|
|
40
|
+
/** Whether its content is open, from the trigger's `aria-expanded`. */
|
|
41
|
+
get isOpen() {
|
|
42
|
+
return this.trigger.getAttribute('aria-expanded') === 'true';
|
|
43
|
+
}
|
|
44
|
+
/** Its content, through the trigger's `aria-controls`, or `null` while it isn't rendered. */
|
|
45
|
+
get content() {
|
|
46
|
+
const id = this.trigger.getAttribute('aria-controls');
|
|
47
|
+
return id ? document.getElementById(id) : null;
|
|
48
|
+
}
|
|
49
|
+
/** The content's accessible name: its trigger's text. */
|
|
50
|
+
get label() {
|
|
51
|
+
const content = this.content;
|
|
52
|
+
return content ? accessibleName(content) : '';
|
|
53
|
+
}
|
|
54
|
+
/** Which way the content is moving (`data-motion`): `from-start`, `to-end`…, or `null`. */
|
|
55
|
+
get motion() {
|
|
56
|
+
return this.content?.getAttribute('data-motion') ?? null;
|
|
57
|
+
}
|
|
58
|
+
/** The content's links, as elements, in order. */
|
|
59
|
+
get linkElements() {
|
|
60
|
+
const content = this.content;
|
|
61
|
+
return content ? [...content.querySelectorAll(LINK)] : [];
|
|
62
|
+
}
|
|
63
|
+
/** Each of the content's links' text. */
|
|
64
|
+
get links() {
|
|
65
|
+
return this.linkElements.map(text);
|
|
66
|
+
}
|
|
67
|
+
/** The content's link whose text is `label` (or the only one starting with it). */
|
|
68
|
+
link(label) {
|
|
69
|
+
return findLink(this.linkElements, label, `the content of "${text(this.trigger)}"`);
|
|
70
|
+
}
|
|
71
|
+
/** Clicks the trigger: it opens the content, or closes it when it is open. */
|
|
72
|
+
async toggle() {
|
|
73
|
+
await click(this.trigger);
|
|
74
|
+
}
|
|
75
|
+
/** Opens it with a click on the trigger, unless it is open. */
|
|
76
|
+
async open() {
|
|
77
|
+
if (!this.isOpen)
|
|
78
|
+
await this.toggle();
|
|
79
|
+
}
|
|
80
|
+
/** Closes it with a click on the trigger, unless it is closed. */
|
|
81
|
+
async close() {
|
|
82
|
+
if (this.isOpen)
|
|
83
|
+
await this.toggle();
|
|
84
|
+
}
|
|
85
|
+
/** Rests the pointer on the trigger, which opens it after the menu's delay. */
|
|
86
|
+
async hover() {
|
|
87
|
+
await hover(this.trigger);
|
|
88
|
+
}
|
|
89
|
+
/** Moves the pointer off the trigger (downwards, towards the content, unless `side` says). */
|
|
90
|
+
async unhover(side = 'top') {
|
|
91
|
+
await unhover(this.trigger, { side });
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Toggles it from the keyboard: focus on the trigger, then Enter (or Space), which presses
|
|
95
|
+
* the button, as a browser does (`pressKey` sends only the key's events). Focus stays on the
|
|
96
|
+
* trigger; Tab or ArrowDown goes on into the content.
|
|
97
|
+
*/
|
|
98
|
+
async openWithKeyboard(key = 'Enter') {
|
|
99
|
+
await focus(this.trigger);
|
|
100
|
+
const prevented = await pressKey(key);
|
|
101
|
+
if (!prevented)
|
|
102
|
+
await click(this.trigger);
|
|
103
|
+
}
|
|
104
|
+
/** Clicks the content's link `label`: it follows it, and closes the content. */
|
|
105
|
+
async select(label) {
|
|
106
|
+
await click(this.link(label));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Drives a `<NavigationMenu>` from `@ember-joinery/ember` or
|
|
111
|
+
* `@ember-joinery/primitives/navigation-menu`. Its items are found by their triggers' text and
|
|
112
|
+
* its links by theirs, and read through ARIA (a trigger's `aria-expanded`, a link's
|
|
113
|
+
* `aria-current`).
|
|
114
|
+
*
|
|
115
|
+
* const nav = new NavigationMenuHarness()
|
|
116
|
+
* assert.deepEqual(nav.triggerLabels, ['Getting started', 'Components'])
|
|
117
|
+
* const start = nav.item('Getting started')
|
|
118
|
+
* await start.open()
|
|
119
|
+
* assert.deepEqual(start.links.length, 3)
|
|
120
|
+
* await nav.item('Components').hover()
|
|
121
|
+
* assert.strictEqual(nav.openItem, 'Components')
|
|
122
|
+
*/
|
|
123
|
+
export class NavigationMenuHarness extends Harness {
|
|
124
|
+
static component = 'navigation-menu';
|
|
125
|
+
/** The `<ul>` of items. */
|
|
126
|
+
get list() {
|
|
127
|
+
return this.part('list');
|
|
128
|
+
}
|
|
129
|
+
/** Each trigger, in order. */
|
|
130
|
+
get triggers() {
|
|
131
|
+
return this.parts('trigger');
|
|
132
|
+
}
|
|
133
|
+
/** Each trigger's text, in order. */
|
|
134
|
+
get triggerLabels() {
|
|
135
|
+
return this.triggers.map(text);
|
|
136
|
+
}
|
|
137
|
+
/** The links in the list itself (not in a content), as elements, in order. */
|
|
138
|
+
get listLinkElements() {
|
|
139
|
+
return [...this.list.querySelectorAll(LINK)].filter(link => !link.closest('[data-test-jn-part="content"]'));
|
|
140
|
+
}
|
|
141
|
+
/** Each of the list's own links' text. */
|
|
142
|
+
get listLinks() {
|
|
143
|
+
return this.listLinkElements.map(text);
|
|
144
|
+
}
|
|
145
|
+
/** The list's own link whose text is `label`. */
|
|
146
|
+
listLink(label) {
|
|
147
|
+
return findLink(this.listLinkElements, label, `${this}`);
|
|
148
|
+
}
|
|
149
|
+
/** The trigger whose text is `label`. Throws when there is none. */
|
|
150
|
+
trigger(label) {
|
|
151
|
+
const trigger = this.triggers.find(element => text(element) === label);
|
|
152
|
+
if (!trigger) {
|
|
153
|
+
const names = this.triggerLabels.map(each => `"${each}"`).join(', ');
|
|
154
|
+
throw new NotFoundError(`no trigger "${label}" in ${this} (there are: ${names})`);
|
|
155
|
+
}
|
|
156
|
+
return trigger;
|
|
157
|
+
}
|
|
158
|
+
/** The item whose trigger's text is `label`. */
|
|
159
|
+
item(label) {
|
|
160
|
+
return new NavigationMenuItemLevel(() => this.trigger(label));
|
|
161
|
+
}
|
|
162
|
+
/** The text of the trigger whose content is open, or `null`. */
|
|
163
|
+
get openItem() {
|
|
164
|
+
const open = this.triggers.find(trigger => trigger.getAttribute('aria-expanded') === 'true');
|
|
165
|
+
return open ? text(open) : null;
|
|
166
|
+
}
|
|
167
|
+
/** Whether a content is open. */
|
|
168
|
+
get isOpen() {
|
|
169
|
+
return this.openItem !== null;
|
|
170
|
+
}
|
|
171
|
+
/** The open item, or `null`. */
|
|
172
|
+
get open() {
|
|
173
|
+
const label = this.openItem;
|
|
174
|
+
return label === null ? null : this.item(label);
|
|
175
|
+
}
|
|
176
|
+
/** The viewport, while it is rendered (a content is open), or `null`. */
|
|
177
|
+
get viewport() {
|
|
178
|
+
return this.queryPart('viewport');
|
|
179
|
+
}
|
|
180
|
+
/** The viewport's size, as the open content gives it (`--radix-navigation-menu-viewport-*`). */
|
|
181
|
+
get viewportSize() {
|
|
182
|
+
const viewport = this.viewport;
|
|
183
|
+
if (!viewport)
|
|
184
|
+
return null;
|
|
185
|
+
const read = (name) => Number.parseFloat(viewport.style.getPropertyValue(`--radix-navigation-menu-viewport-${name}`));
|
|
186
|
+
return { width: read('width'), height: read('height') };
|
|
187
|
+
}
|
|
188
|
+
/** The indicator, while it is rendered, or `null`. */
|
|
189
|
+
get indicator() {
|
|
190
|
+
return this.queryPart('indicator');
|
|
191
|
+
}
|
|
192
|
+
/** The text of the trigger or link that has focus, or `null`. */
|
|
193
|
+
get focused() {
|
|
194
|
+
const active = document.activeElement;
|
|
195
|
+
if (!(active instanceof HTMLElement) || !this.element.contains(active))
|
|
196
|
+
return null;
|
|
197
|
+
return text(active);
|
|
198
|
+
}
|
|
199
|
+
/** Presses Escape where focus is: it closes the open content. */
|
|
200
|
+
async pressEscape() {
|
|
201
|
+
await pressEscape();
|
|
202
|
+
}
|
|
203
|
+
/** A press outside the menu. */
|
|
204
|
+
async pressOutside() {
|
|
205
|
+
await pressOutside();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Drives a `<NavigationStack>` from `@ember-joinery/ember`: reads its depth and direction, and
|
|
4
|
+
* goes back with its back button or with an edge swipe.
|
|
5
|
+
*
|
|
6
|
+
* const stack = new NavigationStackHarness('contacts') // <NavigationStack @name="contacts">
|
|
7
|
+
* assert.strictEqual(stack.depth, 1)
|
|
8
|
+
* await stack.back()
|
|
9
|
+
* assert.strictEqual(stack.direction, 'pop')
|
|
10
|
+
*
|
|
11
|
+
* The stack wraps the app's screens, so the parts inside it still belong to the components
|
|
12
|
+
* around them. A page object can extend this class and declare the screens' components with
|
|
13
|
+
* `@child`.
|
|
14
|
+
*/
|
|
15
|
+
export declare class NavigationStackHarness extends Harness {
|
|
16
|
+
static component: string;
|
|
17
|
+
/** How many screens are below the current screen: 0 on the first screen. */
|
|
18
|
+
get depth(): number;
|
|
19
|
+
/** Whether there is a screen to go back to. */
|
|
20
|
+
get canGoBack(): boolean;
|
|
21
|
+
/** Which way the last change of depth went: `push` or `pop`. */
|
|
22
|
+
get direction(): string | null;
|
|
23
|
+
/** Whether a swipe from the inline-start edge goes back (`data-edge-swipe`). */
|
|
24
|
+
get isEdgeSwipeActive(): boolean;
|
|
25
|
+
/** The element that holds the screens, which a view transition slides. */
|
|
26
|
+
get content(): HTMLElement;
|
|
27
|
+
/** Its own back button, or `null` when the stack shows none: not one of a stack inside it. */
|
|
28
|
+
get backButton(): HTMLElement | null;
|
|
29
|
+
/** The back button's text, or `''` without one. */
|
|
30
|
+
get backLabel(): string;
|
|
31
|
+
/** Clicks the back button. Throws when the stack shows none. */
|
|
32
|
+
back(): Promise<void>;
|
|
33
|
+
/** Swipes with a touch from the inline-start edge, 120px toward the inline end. */
|
|
34
|
+
swipeBack(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=navigation-stack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-stack.d.ts","sourceRoot":"","sources":["../src/navigation-stack.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC;;;;;;;;;;;;GAYG;AACH,qBAAa,sBAAuB,SAAQ,OAAO;IACjD,OAAgB,SAAS,SAAqB;IAE9C,4EAA4E;IAC5E,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,+CAA+C;IAC/C,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,gEAAgE;IAChE,IAAI,SAAS,IAAI,MAAM,GAAG,IAAI,CAE7B;IAED,gFAAgF;IAChF,IAAI,iBAAiB,IAAI,OAAO,CAE/B;IAED,0EAA0E;IAC1E,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED,8FAA8F;IAC9F,IAAI,UAAU,IAAI,WAAW,GAAG,IAAI,CAOnC;IAED,mDAAmD;IACnD,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,gEAAgE;IAC1D,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAM3B,mFAAmF;IAC7E,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAWjC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { click } from '@ember/test-helpers';
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
import { sendPointer } from "./send-pointer.js";
|
|
4
|
+
/**
|
|
5
|
+
* Drives a `<NavigationStack>` from `@ember-joinery/ember`: reads its depth and direction, and
|
|
6
|
+
* goes back with its back button or with an edge swipe.
|
|
7
|
+
*
|
|
8
|
+
* const stack = new NavigationStackHarness('contacts') // <NavigationStack @name="contacts">
|
|
9
|
+
* assert.strictEqual(stack.depth, 1)
|
|
10
|
+
* await stack.back()
|
|
11
|
+
* assert.strictEqual(stack.direction, 'pop')
|
|
12
|
+
*
|
|
13
|
+
* The stack wraps the app's screens, so the parts inside it still belong to the components
|
|
14
|
+
* around them. A page object can extend this class and declare the screens' components with
|
|
15
|
+
* `@child`.
|
|
16
|
+
*/
|
|
17
|
+
export class NavigationStackHarness extends Harness {
|
|
18
|
+
static component = 'navigation-stack';
|
|
19
|
+
/** How many screens are below the current screen: 0 on the first screen. */
|
|
20
|
+
get depth() {
|
|
21
|
+
return Number(this.element.getAttribute('data-depth'));
|
|
22
|
+
}
|
|
23
|
+
/** Whether there is a screen to go back to. */
|
|
24
|
+
get canGoBack() {
|
|
25
|
+
return this.depth > 0;
|
|
26
|
+
}
|
|
27
|
+
/** Which way the last change of depth went: `push` or `pop`. */
|
|
28
|
+
get direction() {
|
|
29
|
+
return this.element.getAttribute('data-direction');
|
|
30
|
+
}
|
|
31
|
+
/** Whether a swipe from the inline-start edge goes back (`data-edge-swipe`). */
|
|
32
|
+
get isEdgeSwipeActive() {
|
|
33
|
+
return this.element.hasAttribute('data-edge-swipe');
|
|
34
|
+
}
|
|
35
|
+
/** The element that holds the screens, which a view transition slides. */
|
|
36
|
+
get content() {
|
|
37
|
+
return this.element.querySelector(':scope > [data-jn-navigation-stack-content]');
|
|
38
|
+
}
|
|
39
|
+
/** Its own back button, or `null` when the stack shows none: not one of a stack inside it. */
|
|
40
|
+
get backButton() {
|
|
41
|
+
const root = this.element;
|
|
42
|
+
return ([...root.querySelectorAll('[data-jn-navigation-stack-back]')].find(button => button.closest('[data-jn-navigation-stack]') === root) ?? null);
|
|
43
|
+
}
|
|
44
|
+
/** The back button's text, or `''` without one. */
|
|
45
|
+
get backLabel() {
|
|
46
|
+
return (this.backButton?.textContent ?? '').replace(/\s+/g, ' ').trim();
|
|
47
|
+
}
|
|
48
|
+
/** Clicks the back button. Throws when the stack shows none. */
|
|
49
|
+
async back() {
|
|
50
|
+
const button = this.backButton;
|
|
51
|
+
if (!button)
|
|
52
|
+
throw new Error(`Joinery harness: no back button in ${this}`);
|
|
53
|
+
await click(button);
|
|
54
|
+
}
|
|
55
|
+
/** Swipes with a touch from the inline-start edge, 120px toward the inline end. */
|
|
56
|
+
async swipeBack() {
|
|
57
|
+
const root = this.element;
|
|
58
|
+
const { left, right, top } = root.getBoundingClientRect();
|
|
59
|
+
const rtl = getComputedStyle(root).direction === 'rtl';
|
|
60
|
+
const from = rtl ? right - 5 : left + 5;
|
|
61
|
+
const to = rtl ? from - 120 : from + 120;
|
|
62
|
+
const init = { pointerType: 'touch', clientY: top + 5 };
|
|
63
|
+
await sendPointer(root, 'pointerdown', { ...init, clientX: from });
|
|
64
|
+
await sendPointer(root, 'pointermove', { ...init, clientX: to });
|
|
65
|
+
await sendPointer(root, 'pointerup', { ...init, clientX: to, buttons: 0 });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waits until `IntersectionObserver` and `ResizeObserver` have reported what changed: two
|
|
3
|
+
* frames, then `settled()`. `settled()` alone waits for an element's first report (Joinery's
|
|
4
|
+
* `viewport` and `onResize` register it), but not for the reports a scroll or a resize causes
|
|
5
|
+
* later, which the browser delivers in the next frame.
|
|
6
|
+
*
|
|
7
|
+
* box.style.width = '300px'
|
|
8
|
+
* await waitForObservers()
|
|
9
|
+
* assert.dom('output').hasText('300 × 120')
|
|
10
|
+
*/
|
|
11
|
+
export declare function waitForObservers(): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Scrolls `target` (an element, or a selector in the test's root) to the middle of its
|
|
14
|
+
* scrolling boxes and the window, as a user scrolling to it would, then waits for the observers
|
|
15
|
+
* to report it: what an `InViewport` holds renders.
|
|
16
|
+
*
|
|
17
|
+
* await scrollIntoView('[data-test-comments]')
|
|
18
|
+
* assert.dom('[data-test-comment]').exists({ count: 3 })
|
|
19
|
+
*/
|
|
20
|
+
export declare function scrollIntoView(target: Element | string): Promise<void>;
|
|
21
|
+
//# sourceMappingURL=observers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observers.d.ts","sourceRoot":"","sources":["../src/observers.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAKtD;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAK5E"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isString } from '@sindresorhus/is';
|
|
2
|
+
import { find, settled } from '@ember/test-helpers';
|
|
3
|
+
const frame = () => new Promise(resolve => requestAnimationFrame(() => resolve()));
|
|
4
|
+
/**
|
|
5
|
+
* Waits until `IntersectionObserver` and `ResizeObserver` have reported what changed: two
|
|
6
|
+
* frames, then `settled()`. `settled()` alone waits for an element's first report (Joinery's
|
|
7
|
+
* `viewport` and `onResize` register it), but not for the reports a scroll or a resize causes
|
|
8
|
+
* later, which the browser delivers in the next frame.
|
|
9
|
+
*
|
|
10
|
+
* box.style.width = '300px'
|
|
11
|
+
* await waitForObservers()
|
|
12
|
+
* assert.dom('output').hasText('300 × 120')
|
|
13
|
+
*/
|
|
14
|
+
export async function waitForObservers() {
|
|
15
|
+
await settled();
|
|
16
|
+
await frame();
|
|
17
|
+
await frame();
|
|
18
|
+
await settled();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Scrolls `target` (an element, or a selector in the test's root) to the middle of its
|
|
22
|
+
* scrolling boxes and the window, as a user scrolling to it would, then waits for the observers
|
|
23
|
+
* to report it: what an `InViewport` holds renders.
|
|
24
|
+
*
|
|
25
|
+
* await scrollIntoView('[data-test-comments]')
|
|
26
|
+
* assert.dom('[data-test-comment]').exists({ count: 3 })
|
|
27
|
+
*/
|
|
28
|
+
export async function scrollIntoView(target) {
|
|
29
|
+
const element = isString(target) ? find(target) : target;
|
|
30
|
+
if (!element)
|
|
31
|
+
throw new Error(`Joinery: scrollIntoView found nothing for ${String(target)}`);
|
|
32
|
+
element.scrollIntoView({ block: 'center', inline: 'center' });
|
|
33
|
+
await waitForObservers();
|
|
34
|
+
}
|