@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/rating.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { click, fillIn, focus } from '@ember/test-helpers';
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
import { attributes } from "./selectors.js";
|
|
4
|
+
import { pressKey } from "./focus.js";
|
|
5
|
+
import { accessibleName, textOf } from "./-private/checkable.js";
|
|
6
|
+
const SELECTED = '★';
|
|
7
|
+
const UNSELECTED = '☆';
|
|
8
|
+
/**
|
|
9
|
+
* Drives a `<Rating>` from `@ember-joinery/ember`, or the headless one from
|
|
10
|
+
* `@ember-joinery/primitives/rating`. Its items are native radios, found by their value
|
|
11
|
+
* (`data-test-jn-value`); its rating is the root's `data-value`.
|
|
12
|
+
*
|
|
13
|
+
* const recipe = new RatingHarness('recipe') // <Rating @name="recipe">
|
|
14
|
+
* await recipe.select(4)
|
|
15
|
+
* assert.strictEqual(recipe.value, 4)
|
|
16
|
+
* assert.strictEqual(recipe.stars, '★ ★ ★ ★ ☆')
|
|
17
|
+
* await recipe.select(4) // picking it again clears it
|
|
18
|
+
* assert.strictEqual(recipe.value, 0)
|
|
19
|
+
*/
|
|
20
|
+
export class RatingHarness extends Harness {
|
|
21
|
+
static component = 'rating';
|
|
22
|
+
/** The current rating: `0` for none. */
|
|
23
|
+
get value() {
|
|
24
|
+
return parseFloat(this.element.getAttribute('data-value') ?? '0');
|
|
25
|
+
}
|
|
26
|
+
/** How many items it has (`data-total`). */
|
|
27
|
+
get total() {
|
|
28
|
+
return parseInt(this.element.getAttribute('data-total') ?? '0', 10);
|
|
29
|
+
}
|
|
30
|
+
/** Each item's value, in order. */
|
|
31
|
+
get options() {
|
|
32
|
+
return this.values('item').map(value => parseFloat(value));
|
|
33
|
+
}
|
|
34
|
+
/** Each item's element, in order. */
|
|
35
|
+
get items() {
|
|
36
|
+
return this.parts('item');
|
|
37
|
+
}
|
|
38
|
+
/** The item worth `value`. Throws when there is none. */
|
|
39
|
+
item(value) {
|
|
40
|
+
return this.part('item', String(value));
|
|
41
|
+
}
|
|
42
|
+
/** The radio of the item worth `value`. */
|
|
43
|
+
input(value) {
|
|
44
|
+
return this.item(value).querySelector('input[type="radio"]');
|
|
45
|
+
}
|
|
46
|
+
/** Each item as `★` while the rating reaches it, `☆` otherwise, joined with spaces. */
|
|
47
|
+
get stars() {
|
|
48
|
+
return this.items
|
|
49
|
+
.map(item => (item.hasAttribute('data-selected') ? SELECTED : UNSELECTED))
|
|
50
|
+
.join(' ');
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* What each item shows, its icon's text (the part hidden from assistive technology), joined
|
|
54
|
+
* with spaces: `★ ★ ★ ★ ★`, or `1 2 3 4 5` for icons that show their value. An icon with no
|
|
55
|
+
* text, such as an `<svg>`, gives `''`.
|
|
56
|
+
*/
|
|
57
|
+
get starTexts() {
|
|
58
|
+
return this.items
|
|
59
|
+
.map(item => {
|
|
60
|
+
const icon = item.querySelector('[aria-hidden="true"]');
|
|
61
|
+
return icon ? textOf(icon) : '';
|
|
62
|
+
})
|
|
63
|
+
.join(' ');
|
|
64
|
+
}
|
|
65
|
+
/** How much of the item worth `value` the rating fills, from 0 to 100. */
|
|
66
|
+
percentOf(value) {
|
|
67
|
+
return parseFloat(this.item(value).getAttribute('data-percent-selected') ?? '0');
|
|
68
|
+
}
|
|
69
|
+
/** The accessible name of the item worth `value`: `3 stars`. */
|
|
70
|
+
labelOf(value) {
|
|
71
|
+
return accessibleName(this.input(value));
|
|
72
|
+
}
|
|
73
|
+
/** The group's accessible name: its legend, `aria-label` or `aria-labelledby`. */
|
|
74
|
+
get label() {
|
|
75
|
+
const named = accessibleName(this.element);
|
|
76
|
+
if (this.element.hasAttribute('aria-label') || this.element.hasAttribute('aria-labelledby')) {
|
|
77
|
+
return named;
|
|
78
|
+
}
|
|
79
|
+
const legend = this.element.querySelector(':scope > legend');
|
|
80
|
+
return legend ? textOf(legend) : '';
|
|
81
|
+
}
|
|
82
|
+
/** What a display-only rating says for assistive technology, or `''`: `Rated 3 out of 5`. */
|
|
83
|
+
get summary() {
|
|
84
|
+
const summary = this.queryPart('summary');
|
|
85
|
+
return summary ? textOf(summary) : '';
|
|
86
|
+
}
|
|
87
|
+
/** Whether it can't be changed (`aria-readonly="true"`): readonly, or display-only. */
|
|
88
|
+
get isReadonly() {
|
|
89
|
+
return this.element.getAttribute('aria-readonly') === 'true';
|
|
90
|
+
}
|
|
91
|
+
/** Whether it is disabled (`<fieldset disabled>`). */
|
|
92
|
+
get isDisabled() {
|
|
93
|
+
return this.element.matches(':disabled');
|
|
94
|
+
}
|
|
95
|
+
/** The value of the item whose radio has focus, or `null`. */
|
|
96
|
+
get focused() {
|
|
97
|
+
const active = this.element.ownerDocument.activeElement;
|
|
98
|
+
if (!(active instanceof HTMLInputElement) || active.type !== 'radio')
|
|
99
|
+
return null;
|
|
100
|
+
if (!this.element.contains(active))
|
|
101
|
+
return null;
|
|
102
|
+
return parseFloat(active.value);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Picks `value`, as a click on its item does: picking the current rating clears it. A value
|
|
106
|
+
* between the items' is filled in on the rating's range input (`rating.Range`), or on a
|
|
107
|
+
* number or range input of the block's own, when it has one.
|
|
108
|
+
*/
|
|
109
|
+
async select(value) {
|
|
110
|
+
const item = this.queryPart('item', String(value));
|
|
111
|
+
if (item) {
|
|
112
|
+
await click(item.querySelector('input[type="radio"]'));
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const input = this.queryPart('range') ??
|
|
116
|
+
this.element.querySelector('input[type="number"], input[type="range"]');
|
|
117
|
+
if (input) {
|
|
118
|
+
await fillIn(input, String(value));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
throw new Error(`Joinery harness: ${this} has no item worth ${value}, and no number or range input (its items: ${this.values('item').join(', ')})`);
|
|
122
|
+
}
|
|
123
|
+
/** Focuses the checked radio, or the first, as Tab does. */
|
|
124
|
+
async focus() {
|
|
125
|
+
const checked = this.element.querySelector('input[type="radio"]:checked');
|
|
126
|
+
await focus(checked ?? this.element.querySelector('input[type="radio"]'));
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Presses a key on the focused radio, and does what the browser does for a native radio
|
|
130
|
+
* group, which a test's events don't make it do: the arrow keys move focus to the next or
|
|
131
|
+
* previous item, going round, and pick it (a click), and Space picks the focused one. Right
|
|
132
|
+
* to left, the left and right arrows swap. Tests can't press real keys, as with `tab()`.
|
|
133
|
+
*/
|
|
134
|
+
async press(key, modifiers = {}) {
|
|
135
|
+
const radios = [...this.element.querySelectorAll('input[type="radio"]')];
|
|
136
|
+
const active = this.element.ownerDocument.activeElement;
|
|
137
|
+
const index = active ? radios.indexOf(active) : -1;
|
|
138
|
+
const prevented = await pressKey(key, modifiers);
|
|
139
|
+
if (prevented || index === -1)
|
|
140
|
+
return;
|
|
141
|
+
if (key === ' ') {
|
|
142
|
+
await click(radios[index]);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const rtl = getComputedStyle(this.element).direction === 'rtl';
|
|
146
|
+
const forward = ['ArrowDown', rtl ? 'ArrowLeft' : 'ArrowRight'];
|
|
147
|
+
const backward = ['ArrowUp', rtl ? 'ArrowRight' : 'ArrowLeft'];
|
|
148
|
+
let next;
|
|
149
|
+
if (forward.includes(key))
|
|
150
|
+
next = (index + 1) % radios.length;
|
|
151
|
+
else if (backward.includes(key))
|
|
152
|
+
next = (index - 1 + radios.length) % radios.length;
|
|
153
|
+
else
|
|
154
|
+
return;
|
|
155
|
+
const radio = radios[next];
|
|
156
|
+
await focus(radio);
|
|
157
|
+
if (radio.getAttribute(attributes.part) === 'input')
|
|
158
|
+
await click(radio);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
import { type KeyModifiers } from './focus.ts';
|
|
3
|
+
/** Which handle: its index among the group's handles, counting from 0. */
|
|
4
|
+
type HandleIndex = number;
|
|
5
|
+
/** Which panel: its index, counting from 0, or its `@id`. */
|
|
6
|
+
type PanelKey = number | string;
|
|
7
|
+
/** How far to drag a handle: pixels along the group's axis, or `{ x, y }`. */
|
|
8
|
+
export type DragDistance = number | {
|
|
9
|
+
x?: number;
|
|
10
|
+
y?: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Drives a resizable group: `<Resizable>` from `@ember-joinery/primitives/resizable`, or
|
|
14
|
+
* `<ResizablePanelGroup>` from `@ember-joinery/ember`. Panels and handles are its parts. Sizes
|
|
15
|
+
* are read from the layout as rendered, and each handle's state from its ARIA (`aria-valuenow`
|
|
16
|
+
* is the size of the panel before it). Panels of a group nested in a panel belong to that
|
|
17
|
+
* group, which has a harness of its own.
|
|
18
|
+
*
|
|
19
|
+
* const layout = new ResizableHarness('workspace')
|
|
20
|
+
* await layout.drag(0, 40) // the first handle, 40px right (or down)
|
|
21
|
+
* await layout.press(0, 'ArrowLeft')
|
|
22
|
+
* assert.deepEqual(layout.sizes, [45, 55])
|
|
23
|
+
*/
|
|
24
|
+
export declare class ResizableHarness extends Harness {
|
|
25
|
+
static component: string;
|
|
26
|
+
/** `horizontal` (panels side by side) or `vertical` (stacked). */
|
|
27
|
+
get orientation(): 'horizontal' | 'vertical';
|
|
28
|
+
/** The panels, in order. */
|
|
29
|
+
get panels(): HTMLElement[];
|
|
30
|
+
/** The handles, in order. */
|
|
31
|
+
get handles(): HTMLElement[];
|
|
32
|
+
/** A panel, by its index or its `@id`. Throws when there is none. */
|
|
33
|
+
panel(key: PanelKey): HTMLElement;
|
|
34
|
+
/** A handle, by its index. Throws when there is none. */
|
|
35
|
+
handle(index?: HandleIndex): HTMLElement;
|
|
36
|
+
/**
|
|
37
|
+
* Each panel's share of the space the panels take, in percent, as rendered, to one decimal
|
|
38
|
+
* place. They add up to about 100.
|
|
39
|
+
*/
|
|
40
|
+
get sizes(): number[];
|
|
41
|
+
/** One panel's size, as `sizes` gives it. */
|
|
42
|
+
size(key: PanelKey): number;
|
|
43
|
+
/** A handle's `aria-valuenow`: the size of the panel before it, in percent. */
|
|
44
|
+
valueNow(index?: HandleIndex): number;
|
|
45
|
+
/** A handle's `aria-valuemin` and `aria-valuemax`: how small and large it can make its panel. */
|
|
46
|
+
range(index?: HandleIndex): {
|
|
47
|
+
min: number;
|
|
48
|
+
max: number;
|
|
49
|
+
};
|
|
50
|
+
/** The panel a handle resizes (`aria-controls`): the one before it. */
|
|
51
|
+
controls(index?: HandleIndex): HTMLElement | null;
|
|
52
|
+
/** A handle's state: `inactive`, `hover`, `focus`, `active` (dragging) or `disabled`. */
|
|
53
|
+
handleState(index?: HandleIndex): string | null;
|
|
54
|
+
/** Whether a handle can't be moved (`aria-disabled`). */
|
|
55
|
+
isHandleDisabled(index?: HandleIndex): boolean;
|
|
56
|
+
/** Whether a collapsible panel is collapsed (`data-collapsed`). */
|
|
57
|
+
isCollapsed(key: PanelKey): boolean;
|
|
58
|
+
/** Moves focus to a handle, as tabbing to it would. */
|
|
59
|
+
focus(index?: HandleIndex): Promise<void>;
|
|
60
|
+
/** Focuses a handle and presses a key on it: an arrow key, `Home`, `End`, `Enter` or `F6`. */
|
|
61
|
+
press(index: HandleIndex, key: string, modifiers?: KeyModifiers): Promise<boolean>;
|
|
62
|
+
/** Puts the pointer over a handle, and (with `false`) takes it away. */
|
|
63
|
+
hover(index?: HandleIndex, over?: boolean): Promise<void>;
|
|
64
|
+
/** Double-clicks a handle, which puts its panel back to its `@defaultSize`. */
|
|
65
|
+
doubleClick(index?: HandleIndex): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Drags a handle with the primary pointer: down on its middle, moved `distance` (CSS pixels
|
|
68
|
+
* along the axis, or `{ x, y }`) in `steps` moves, then up. Right and down are positive,
|
|
69
|
+
* whatever the text direction.
|
|
70
|
+
*/
|
|
71
|
+
drag(index: HandleIndex, distance: DragDistance, { steps }?: {
|
|
72
|
+
steps?: number | undefined;
|
|
73
|
+
}): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=resizable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resizable.d.ts","sourceRoot":"","sources":["../src/resizable.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAGxD,0EAA0E;AAC1E,KAAK,WAAW,GAAG,MAAM,CAAA;AAEzB,6DAA6D;AAC7D,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAA;AAE/B,8EAA8E;AAC9E,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAE9D;;;;;;;;;;;GAWG;AACH,qBAAa,gBAAiB,SAAQ,OAAO;IAC3C,OAAgB,SAAS,SAAc;IAEvC,kEAAkE;IAClE,IAAI,WAAW,IAAI,YAAY,GAAG,UAAU,CAE3C;IAED,4BAA4B;IAC5B,IAAI,MAAM,IAAI,WAAW,EAAE,CAE1B;IAED,6BAA6B;IAC7B,IAAI,OAAO,IAAI,WAAW,EAAE,CAE3B;IAED,qEAAqE;IACrE,KAAK,CAAC,GAAG,EAAE,QAAQ,GAAG,WAAW;IAOjC,yDAAyD;IACzD,MAAM,CAAC,KAAK,GAAE,WAAe,GAAG,WAAW;IAM3C;;;OAGG;IACH,IAAI,KAAK,IAAI,MAAM,EAAE,CAQpB;IAED,6CAA6C;IAC7C,IAAI,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM;IAK3B,+EAA+E;IAC/E,QAAQ,CAAC,KAAK,GAAE,WAAe,GAAG,MAAM;IAIxC,iGAAiG;IACjG,KAAK,CAAC,KAAK,GAAE,WAAe,GAAG;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE;IAQ3D,uEAAuE;IACvE,QAAQ,CAAC,KAAK,GAAE,WAAe,GAAG,WAAW,GAAG,IAAI;IAKpD,yFAAyF;IACzF,WAAW,CAAC,KAAK,GAAE,WAAe,GAAG,MAAM,GAAG,IAAI;IAIlD,yDAAyD;IACzD,gBAAgB,CAAC,KAAK,GAAE,WAAe,GAAG,OAAO;IAIjD,mEAAmE;IACnE,WAAW,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO;IAInC,uDAAuD;IACjD,KAAK,CAAC,KAAK,GAAE,WAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,8FAA8F;IACxF,KAAK,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,GAAE,YAAiB,GAAG,OAAO,CAAC,OAAO,CAAC;IAK5F,wEAAwE;IAClE,KAAK,CAAC,KAAK,GAAE,WAAe,EAAE,IAAI,UAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/D,+EAA+E;IACzE,WAAW,CAAC,KAAK,GAAE,WAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxD;;;;OAIG;IACG,IAAI,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,KAAS,EAAE;;KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;CAqB1F"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { isNumber, isString } from '@sindresorhus/is';
|
|
2
|
+
import { doubleClick, focus } from '@ember/test-helpers';
|
|
3
|
+
import { Harness } from "./harness.js";
|
|
4
|
+
import { pressKey } from "./focus.js";
|
|
5
|
+
import { sendPointer } from "./send-pointer.js";
|
|
6
|
+
/**
|
|
7
|
+
* Drives a resizable group: `<Resizable>` from `@ember-joinery/primitives/resizable`, or
|
|
8
|
+
* `<ResizablePanelGroup>` from `@ember-joinery/ember`. Panels and handles are its parts. Sizes
|
|
9
|
+
* are read from the layout as rendered, and each handle's state from its ARIA (`aria-valuenow`
|
|
10
|
+
* is the size of the panel before it). Panels of a group nested in a panel belong to that
|
|
11
|
+
* group, which has a harness of its own.
|
|
12
|
+
*
|
|
13
|
+
* const layout = new ResizableHarness('workspace')
|
|
14
|
+
* await layout.drag(0, 40) // the first handle, 40px right (or down)
|
|
15
|
+
* await layout.press(0, 'ArrowLeft')
|
|
16
|
+
* assert.deepEqual(layout.sizes, [45, 55])
|
|
17
|
+
*/
|
|
18
|
+
export class ResizableHarness extends Harness {
|
|
19
|
+
static component = 'resizable';
|
|
20
|
+
/** `horizontal` (panels side by side) or `vertical` (stacked). */
|
|
21
|
+
get orientation() {
|
|
22
|
+
return this.element.getAttribute('data-orientation') === 'vertical' ? 'vertical' : 'horizontal';
|
|
23
|
+
}
|
|
24
|
+
/** The panels, in order. */
|
|
25
|
+
get panels() {
|
|
26
|
+
return this.parts('panel');
|
|
27
|
+
}
|
|
28
|
+
/** The handles, in order. */
|
|
29
|
+
get handles() {
|
|
30
|
+
return this.parts('handle');
|
|
31
|
+
}
|
|
32
|
+
/** A panel, by its index or its `@id`. Throws when there is none. */
|
|
33
|
+
panel(key) {
|
|
34
|
+
if (isString(key))
|
|
35
|
+
return this.part('panel', key);
|
|
36
|
+
const panel = this.panels[key];
|
|
37
|
+
if (!panel)
|
|
38
|
+
throw new Error(`no panel #${key} in ${this}`);
|
|
39
|
+
return panel;
|
|
40
|
+
}
|
|
41
|
+
/** A handle, by its index. Throws when there is none. */
|
|
42
|
+
handle(index = 0) {
|
|
43
|
+
const handle = this.handles[index];
|
|
44
|
+
if (!handle)
|
|
45
|
+
throw new Error(`no handle #${index} in ${this}`);
|
|
46
|
+
return handle;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Each panel's share of the space the panels take, in percent, as rendered, to one decimal
|
|
50
|
+
* place. They add up to about 100.
|
|
51
|
+
*/
|
|
52
|
+
get sizes() {
|
|
53
|
+
const horizontal = this.orientation === 'horizontal';
|
|
54
|
+
const lengths = this.panels.map(panel => {
|
|
55
|
+
const box = panel.getBoundingClientRect();
|
|
56
|
+
return horizontal ? box.width : box.height;
|
|
57
|
+
});
|
|
58
|
+
const total = lengths.reduce((sum, length) => sum + length, 0);
|
|
59
|
+
return lengths.map(length => (total > 0 ? Math.round((length / total) * 1000) / 10 : 0));
|
|
60
|
+
}
|
|
61
|
+
/** One panel's size, as `sizes` gives it. */
|
|
62
|
+
size(key) {
|
|
63
|
+
const index = isNumber(key) ? key : this.panels.indexOf(this.panel(key));
|
|
64
|
+
return this.sizes[index];
|
|
65
|
+
}
|
|
66
|
+
/** A handle's `aria-valuenow`: the size of the panel before it, in percent. */
|
|
67
|
+
valueNow(index = 0) {
|
|
68
|
+
return Number(this.handle(index).getAttribute('aria-valuenow'));
|
|
69
|
+
}
|
|
70
|
+
/** A handle's `aria-valuemin` and `aria-valuemax`: how small and large it can make its panel. */
|
|
71
|
+
range(index = 0) {
|
|
72
|
+
const handle = this.handle(index);
|
|
73
|
+
return {
|
|
74
|
+
min: Number(handle.getAttribute('aria-valuemin')),
|
|
75
|
+
max: Number(handle.getAttribute('aria-valuemax')),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** The panel a handle resizes (`aria-controls`): the one before it. */
|
|
79
|
+
controls(index = 0) {
|
|
80
|
+
const id = this.handle(index).getAttribute('aria-controls');
|
|
81
|
+
return id ? this.element.ownerDocument.getElementById(id) : null;
|
|
82
|
+
}
|
|
83
|
+
/** A handle's state: `inactive`, `hover`, `focus`, `active` (dragging) or `disabled`. */
|
|
84
|
+
handleState(index = 0) {
|
|
85
|
+
return this.handle(index).getAttribute('data-separator');
|
|
86
|
+
}
|
|
87
|
+
/** Whether a handle can't be moved (`aria-disabled`). */
|
|
88
|
+
isHandleDisabled(index = 0) {
|
|
89
|
+
return this.handle(index).getAttribute('aria-disabled') === 'true';
|
|
90
|
+
}
|
|
91
|
+
/** Whether a collapsible panel is collapsed (`data-collapsed`). */
|
|
92
|
+
isCollapsed(key) {
|
|
93
|
+
return this.panel(key).hasAttribute('data-collapsed');
|
|
94
|
+
}
|
|
95
|
+
/** Moves focus to a handle, as tabbing to it would. */
|
|
96
|
+
async focus(index = 0) {
|
|
97
|
+
await focus(this.handle(index));
|
|
98
|
+
}
|
|
99
|
+
/** Focuses a handle and presses a key on it: an arrow key, `Home`, `End`, `Enter` or `F6`. */
|
|
100
|
+
async press(index, key, modifiers = {}) {
|
|
101
|
+
await this.focus(index);
|
|
102
|
+
return pressKey(key, modifiers);
|
|
103
|
+
}
|
|
104
|
+
/** Puts the pointer over a handle, and (with `false`) takes it away. */
|
|
105
|
+
async hover(index = 0, over = true) {
|
|
106
|
+
await sendPointer(this.handle(index), over ? 'pointerenter' : 'pointerleave');
|
|
107
|
+
}
|
|
108
|
+
/** Double-clicks a handle, which puts its panel back to its `@defaultSize`. */
|
|
109
|
+
async doubleClick(index = 0) {
|
|
110
|
+
await doubleClick(this.handle(index));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Drags a handle with the primary pointer: down on its middle, moved `distance` (CSS pixels
|
|
114
|
+
* along the axis, or `{ x, y }`) in `steps` moves, then up. Right and down are positive,
|
|
115
|
+
* whatever the text direction.
|
|
116
|
+
*/
|
|
117
|
+
async drag(index, distance, { steps = 4 } = {}) {
|
|
118
|
+
const handle = this.handle(index);
|
|
119
|
+
const box = handle.getBoundingClientRect();
|
|
120
|
+
const x0 = box.left + box.width / 2;
|
|
121
|
+
const y0 = box.top + box.height / 2;
|
|
122
|
+
const { x = 0, y = 0 } = isNumber(distance)
|
|
123
|
+
? this.orientation === 'horizontal'
|
|
124
|
+
? { x: distance }
|
|
125
|
+
: { y: distance }
|
|
126
|
+
: distance;
|
|
127
|
+
// The distance is in the page's CSS pixels; the pointer's are the screen's, which a
|
|
128
|
+
// transform (the test container's scale) makes differ.
|
|
129
|
+
const group = this.element;
|
|
130
|
+
const scale = group.offsetWidth ? group.getBoundingClientRect().width / group.offsetWidth : 1;
|
|
131
|
+
const at = (dx, dy) => ({ clientX: x0 + dx * scale, clientY: y0 + dy * scale });
|
|
132
|
+
await sendPointer(handle, 'pointerdown', at(0, 0));
|
|
133
|
+
for (let step = 1; step <= steps; step++) {
|
|
134
|
+
await sendPointer(handle, 'pointermove', at((x * step) / steps, (y * step) / steps));
|
|
135
|
+
}
|
|
136
|
+
await sendPointer(handle, 'pointerup', { ...at(x, y), buttons: 0 });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type Owner from '@ember/owner';
|
|
2
|
+
import type RouterService from '@ember/routing/router-service';
|
|
3
|
+
import type { DSLCallback } from '@ember/routing/lib/dsl';
|
|
4
|
+
/** The routes a test needs: the same callback `Router.map` takes. */
|
|
5
|
+
export type RouteMap = DSLCallback;
|
|
6
|
+
export interface SetupRoutingOptions {
|
|
7
|
+
/** The rootURL the app is served under, as the router's own. Default `/`. */
|
|
8
|
+
rootURL?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Gives the test its own routes, without scaffolding them in the app: a router with `map`'s
|
|
12
|
+
* routes (and `rootURL`), started so links, `qp` and `link` have a router to read. Call it at
|
|
13
|
+
* the start of the test, before `visit()` or `render()`:
|
|
14
|
+
*
|
|
15
|
+
* test('the tabs follow the URL', async function (assert) {
|
|
16
|
+
* setupRouting(this.owner, function () {
|
|
17
|
+
* this.route('settings', function () {
|
|
18
|
+
* this.route('profile')
|
|
19
|
+
* })
|
|
20
|
+
* })
|
|
21
|
+
* await visit('/settings/profile')
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* Routes need no files: Ember makes a default route for each. Register a template for the
|
|
25
|
+
* ones that render something, as `this.owner.register('template:application', …)`. For plain
|
|
26
|
+
* `<a href>` links to transition, as an app with `properLinks` does, also call
|
|
27
|
+
* `setupProperLinks(this.owner)` from `@ember-joinery/primitives/proper-links`.
|
|
28
|
+
*
|
|
29
|
+
* It is ember-primitives' `setupRouting`, which applies `properLinks` itself.
|
|
30
|
+
*
|
|
31
|
+
* @returns the router service
|
|
32
|
+
*/
|
|
33
|
+
export declare function setupRouting(owner: Owner, map: RouteMap, options?: SetupRoutingOptions): RouterService;
|
|
34
|
+
/** The router service, typed: `getRouter(this.owner).currentURL`. */
|
|
35
|
+
export declare function getRouter(owner: Owner): RouterService;
|
|
36
|
+
//# sourceMappingURL=routing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../src/routing.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,aAAa,MAAM,+BAA+B,CAAA;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEzD,qEAAqE;AACrE,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAA;AAElC,MAAM,WAAW,mBAAmB;IAClC,6EAA6E;IAC7E,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,QAAQ,EACb,OAAO,GAAE,mBAAwB,GAChC,aAAa,CAwBf;AAED,qEAAqE;AACrE,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,aAAa,CAErD"}
|
package/dist/routing.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import EmberRouter from '@ember/routing/router';
|
|
2
|
+
/**
|
|
3
|
+
* Gives the test its own routes, without scaffolding them in the app: a router with `map`'s
|
|
4
|
+
* routes (and `rootURL`), started so links, `qp` and `link` have a router to read. Call it at
|
|
5
|
+
* the start of the test, before `visit()` or `render()`:
|
|
6
|
+
*
|
|
7
|
+
* test('the tabs follow the URL', async function (assert) {
|
|
8
|
+
* setupRouting(this.owner, function () {
|
|
9
|
+
* this.route('settings', function () {
|
|
10
|
+
* this.route('profile')
|
|
11
|
+
* })
|
|
12
|
+
* })
|
|
13
|
+
* await visit('/settings/profile')
|
|
14
|
+
* })
|
|
15
|
+
*
|
|
16
|
+
* Routes need no files: Ember makes a default route for each. Register a template for the
|
|
17
|
+
* ones that render something, as `this.owner.register('template:application', …)`. For plain
|
|
18
|
+
* `<a href>` links to transition, as an app with `properLinks` does, also call
|
|
19
|
+
* `setupProperLinks(this.owner)` from `@ember-joinery/primitives/proper-links`.
|
|
20
|
+
*
|
|
21
|
+
* It is ember-primitives' `setupRouting`, which applies `properLinks` itself.
|
|
22
|
+
*
|
|
23
|
+
* @returns the router service
|
|
24
|
+
*/
|
|
25
|
+
export function setupRouting(owner, map, options = {}) {
|
|
26
|
+
const rootURL = options.rootURL ?? '/';
|
|
27
|
+
if (!rootURL.startsWith('/')) {
|
|
28
|
+
throw new Error(`Joinery: setupRouting's rootURL must start with "/", not "${rootURL}"`);
|
|
29
|
+
}
|
|
30
|
+
class TestRouter extends EmberRouter {
|
|
31
|
+
rootURL = rootURL;
|
|
32
|
+
location = 'none';
|
|
33
|
+
}
|
|
34
|
+
TestRouter.map(map);
|
|
35
|
+
// The app's own router is registered already; this test's replaces it. (An app instance has
|
|
36
|
+
// `unregister`, from its registry, though the Owner type leaves it out.)
|
|
37
|
+
const registry = owner;
|
|
38
|
+
registry.unregister?.('router:main');
|
|
39
|
+
owner.register('router:main', TestRouter);
|
|
40
|
+
// There is no public API to start a router outside an app's boot; this is the one
|
|
41
|
+
// `visit()` and Ember's own tests use.
|
|
42
|
+
// eslint-disable-next-line ember/no-private-routing-service
|
|
43
|
+
const router = owner.lookup('router:main');
|
|
44
|
+
router.setupRouter();
|
|
45
|
+
return getRouter(owner);
|
|
46
|
+
}
|
|
47
|
+
/** The router service, typed: `getRouter(this.owner).currentURL`. */
|
|
48
|
+
export function getRouter(owner) {
|
|
49
|
+
return owner.lookup('service:router');
|
|
50
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
import { type KeyModifiers } from './focus.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Drives a `<RovingFocusGroup>` from `@ember-joinery/primitives/roving-focus`: items that share
|
|
5
|
+
* one tab stop, with the arrow keys, Home and End moving between them. Items are found by their
|
|
6
|
+
* `data-test-jn-value` (their `@tabStopId`).
|
|
7
|
+
*
|
|
8
|
+
* const toolbar = new RovingFocusGroupHarness('format')
|
|
9
|
+
* await toolbar.focus('bold')
|
|
10
|
+
* await toolbar.press('ArrowRight')
|
|
11
|
+
* assert.strictEqual(toolbar.focused, 'italic')
|
|
12
|
+
* assert.strictEqual(toolbar.tabStop, 'italic') // where Tab comes back to
|
|
13
|
+
*/
|
|
14
|
+
export declare class RovingFocusGroupHarness extends Harness {
|
|
15
|
+
static component: string;
|
|
16
|
+
/** Each item's element, in order. */
|
|
17
|
+
get items(): HTMLElement[];
|
|
18
|
+
/** Each item's id, in order. */
|
|
19
|
+
get ids(): string[];
|
|
20
|
+
/** The item with this id. Throws when there is none. */
|
|
21
|
+
item(id: string): HTMLElement;
|
|
22
|
+
/** `horizontal`, `vertical`, or `undefined` when every arrow key moves focus. */
|
|
23
|
+
get orientation(): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* The id of the item in the tab order (`tabindex="0"`), which Tab lands on, or `null` when no
|
|
26
|
+
* item is: then the group itself takes the Tab and sends focus on to an item.
|
|
27
|
+
*/
|
|
28
|
+
get tabStop(): string | null;
|
|
29
|
+
/** Whether Tab stops on the group itself (`tabindex="0"`), on its way to an item. */
|
|
30
|
+
get isGroupTabbable(): boolean;
|
|
31
|
+
/** The id of the item that has focus, or `null` when focus is elsewhere. */
|
|
32
|
+
get focused(): string | null;
|
|
33
|
+
/** Focuses an item, as a click or a script would. */
|
|
34
|
+
focus(id: string): Promise<void>;
|
|
35
|
+
/** Presses a key on the focused item: `'ArrowRight'`, `'Home'`, `'End'`. */
|
|
36
|
+
press(key: string, modifiers?: KeyModifiers): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=roving-focus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roving-focus.d.ts","sourceRoot":"","sources":["../src/roving-focus.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAExD;;;;;;;;;;GAUG;AACH,qBAAa,uBAAwB,SAAQ,OAAO;IAClD,OAAgB,SAAS,SAAuB;IAEhD,qCAAqC;IACrC,IAAI,KAAK,IAAI,WAAW,EAAE,CAEzB;IAED,gCAAgC;IAChC,IAAI,GAAG,IAAI,MAAM,EAAE,CAElB;IAED,wDAAwD;IACxD,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW;IAI7B,iFAAiF;IACjF,IAAI,WAAW,IAAI,MAAM,GAAG,SAAS,CAEpC;IAED;;;OAGG;IACH,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAG3B;IAED,qFAAqF;IACrF,IAAI,eAAe,IAAI,OAAO,CAE7B;IAED,4EAA4E;IAC5E,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAI3B;IAED,qDAAqD;IAC/C,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItC,4EAA4E;IACtE,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;CAGlE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { focus } from '@ember/test-helpers';
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
import { attributes } from "./selectors.js";
|
|
4
|
+
import { pressKey } from "./focus.js";
|
|
5
|
+
/**
|
|
6
|
+
* Drives a `<RovingFocusGroup>` from `@ember-joinery/primitives/roving-focus`: items that share
|
|
7
|
+
* one tab stop, with the arrow keys, Home and End moving between them. Items are found by their
|
|
8
|
+
* `data-test-jn-value` (their `@tabStopId`).
|
|
9
|
+
*
|
|
10
|
+
* const toolbar = new RovingFocusGroupHarness('format')
|
|
11
|
+
* await toolbar.focus('bold')
|
|
12
|
+
* await toolbar.press('ArrowRight')
|
|
13
|
+
* assert.strictEqual(toolbar.focused, 'italic')
|
|
14
|
+
* assert.strictEqual(toolbar.tabStop, 'italic') // where Tab comes back to
|
|
15
|
+
*/
|
|
16
|
+
export class RovingFocusGroupHarness extends Harness {
|
|
17
|
+
static component = 'roving-focus-group';
|
|
18
|
+
/** Each item's element, in order. */
|
|
19
|
+
get items() {
|
|
20
|
+
return this.parts('item');
|
|
21
|
+
}
|
|
22
|
+
/** Each item's id, in order. */
|
|
23
|
+
get ids() {
|
|
24
|
+
return this.values('item');
|
|
25
|
+
}
|
|
26
|
+
/** The item with this id. Throws when there is none. */
|
|
27
|
+
item(id) {
|
|
28
|
+
return this.part('item', id);
|
|
29
|
+
}
|
|
30
|
+
/** `horizontal`, `vertical`, or `undefined` when every arrow key moves focus. */
|
|
31
|
+
get orientation() {
|
|
32
|
+
return this.element.getAttribute('data-orientation') ?? undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The id of the item in the tab order (`tabindex="0"`), which Tab lands on, or `null` when no
|
|
36
|
+
* item is: then the group itself takes the Tab and sends focus on to an item.
|
|
37
|
+
*/
|
|
38
|
+
get tabStop() {
|
|
39
|
+
const item = this.items.find(element => element.getAttribute('tabindex') === '0');
|
|
40
|
+
return item?.getAttribute(attributes.value) ?? null;
|
|
41
|
+
}
|
|
42
|
+
/** Whether Tab stops on the group itself (`tabindex="0"`), on its way to an item. */
|
|
43
|
+
get isGroupTabbable() {
|
|
44
|
+
return this.element.getAttribute('tabindex') === '0';
|
|
45
|
+
}
|
|
46
|
+
/** The id of the item that has focus, or `null` when focus is elsewhere. */
|
|
47
|
+
get focused() {
|
|
48
|
+
const active = document.activeElement;
|
|
49
|
+
const item = this.items.find(element => element === active || element.contains(active));
|
|
50
|
+
return item?.getAttribute(attributes.value) ?? null;
|
|
51
|
+
}
|
|
52
|
+
/** Focuses an item, as a click or a script would. */
|
|
53
|
+
async focus(id) {
|
|
54
|
+
await focus(this.item(id));
|
|
55
|
+
}
|
|
56
|
+
/** Presses a key on the focused item: `'ArrowRight'`, `'Home'`, `'End'`. */
|
|
57
|
+
async press(key, modifiers) {
|
|
58
|
+
await pressKey(key, modifiers);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
/** Which scrollbar: `vertical` (the default) or `horizontal`. */
|
|
3
|
+
export type ScrollbarOrientation = 'vertical' | 'horizontal';
|
|
4
|
+
/**
|
|
5
|
+
* Drives a scroll area: `<ScrollArea>` from `@ember-joinery/primitives/scroll-area`, or from
|
|
6
|
+
* `@ember-joinery/ember`. Its viewport scrolls natively; its scrollbars are parts that show for
|
|
7
|
+
* its `@type` (by default while the pointer is over it, so `hover()` first).
|
|
8
|
+
*
|
|
9
|
+
* const tags = new ScrollAreaHarness('tags')
|
|
10
|
+
* await tags.hover()
|
|
11
|
+
* assert.true(tags.isScrollbarVisible())
|
|
12
|
+
* await tags.scrollTo({ top: 200 })
|
|
13
|
+
* await tags.dragThumb('vertical', 40)
|
|
14
|
+
*/
|
|
15
|
+
export declare class ScrollAreaHarness extends Harness {
|
|
16
|
+
static component: string;
|
|
17
|
+
/** The element that scrolls. */
|
|
18
|
+
get viewport(): HTMLElement;
|
|
19
|
+
/** A scrollbar's element, or `null` while it isn't shown. */
|
|
20
|
+
scrollbar(orientation?: ScrollbarOrientation): HTMLElement | null;
|
|
21
|
+
/** A scrollbar's thumb, or `null` while it isn't shown. */
|
|
22
|
+
thumb(orientation?: ScrollbarOrientation): HTMLElement | null;
|
|
23
|
+
/** The corner between the scrollbars, or `null`. */
|
|
24
|
+
get corner(): HTMLElement | null;
|
|
25
|
+
/** Whether a scrollbar is shown now (rendered, with `data-state="visible"`). */
|
|
26
|
+
isScrollbarVisible(orientation?: ScrollbarOrientation): boolean;
|
|
27
|
+
/** How far the viewport is scrolled down, in pixels. */
|
|
28
|
+
get scrollTop(): number;
|
|
29
|
+
/** How far it is scrolled across, in pixels: negative right to left, as browsers give it. */
|
|
30
|
+
get scrollLeft(): number;
|
|
31
|
+
/** How far down it can scroll. */
|
|
32
|
+
get maxScrollTop(): number;
|
|
33
|
+
/** How far across it can scroll. */
|
|
34
|
+
get maxScrollLeft(): number;
|
|
35
|
+
/**
|
|
36
|
+
* How far the thumb is along its track, in CSS pixels, from the track's start: the top, or
|
|
37
|
+
* the left (also right to left, where scrolling starts at the right).
|
|
38
|
+
*/
|
|
39
|
+
thumbOffset(orientation?: ScrollbarOrientation): number;
|
|
40
|
+
/** The thumb's length along its track, in CSS pixels. */
|
|
41
|
+
thumbLength(orientation?: ScrollbarOrientation): number;
|
|
42
|
+
/** Puts the pointer over the area, as a user about to scroll does. */
|
|
43
|
+
hover(): Promise<void>;
|
|
44
|
+
/** Takes the pointer away; a `hover` scrollbar goes once the hide delay is up. */
|
|
45
|
+
unhover(): Promise<void>;
|
|
46
|
+
/** Scrolls the viewport, as the wheel or the keyboard would, and waits for its `scroll` event. */
|
|
47
|
+
scrollTo({ top, left }: {
|
|
48
|
+
top?: number;
|
|
49
|
+
left?: number;
|
|
50
|
+
}): Promise<void>;
|
|
51
|
+
/** Drags a scrollbar's thumb `distance` CSS pixels along its track (down or right). */
|
|
52
|
+
dragThumb(orientation: ScrollbarOrientation, distance: number): Promise<void>;
|
|
53
|
+
/** Presses a scrollbar's track at `fraction` of its length (0 the start, 1 the end). */
|
|
54
|
+
pressTrack(orientation: ScrollbarOrientation, fraction: number): Promise<void>;
|
|
55
|
+
/** Turns the wheel over a scrollbar by `delta` pixels, which scrolls the viewport. */
|
|
56
|
+
wheel(orientation: ScrollbarOrientation, delta: number): Promise<boolean>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=scroll-area.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll-area.d.ts","sourceRoot":"","sources":["../src/scroll-area.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC,iEAAiE;AACjE,MAAM,MAAM,oBAAoB,GAAG,UAAU,GAAG,YAAY,CAAA;AAiB5D;;;;;;;;;;GAUG;AACH,qBAAa,iBAAkB,SAAQ,OAAO;IAC5C,OAAgB,SAAS,SAAgB;IAEzC,gCAAgC;IAChC,IAAI,QAAQ,IAAI,WAAW,CAE1B;IAED,6DAA6D;IAC7D,SAAS,CAAC,WAAW,GAAE,oBAAiC,GAAG,WAAW,GAAG,IAAI;IAI7E,2DAA2D;IAC3D,KAAK,CAAC,WAAW,GAAE,oBAAiC,GAAG,WAAW,GAAG,IAAI;IAIzE,oDAAoD;IACpD,IAAI,MAAM,IAAI,WAAW,GAAG,IAAI,CAE/B;IAED,gFAAgF;IAChF,kBAAkB,CAAC,WAAW,GAAE,oBAAiC,GAAG,OAAO;IAI3E,wDAAwD;IACxD,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,6FAA6F;IAC7F,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,kCAAkC;IAClC,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,oCAAoC;IACpC,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED;;;OAGG;IACH,WAAW,CAAC,WAAW,GAAE,oBAAiC,GAAG,MAAM;IAanE,yDAAyD;IACzD,WAAW,CAAC,WAAW,GAAE,oBAAiC,GAAG,MAAM;IAMnE,sEAAsE;IAChE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,kFAAkF;IAC5E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,kGAAkG;IAC5F,QAAQ,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAO7E,uFAAuF;IACjF,SAAS,CAAC,WAAW,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBnF,wFAAwF;IAClF,UAAU,CAAC,WAAW,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAapF,sFAAsF;IAChF,KAAK,CAAC,WAAW,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAahF"}
|