@ember-joinery/test-support 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +550 -0
- package/LICENSE.md +9 -0
- package/NOTICE +532 -0
- package/README.md +356 -2
- package/addon-main.cjs +4 -0
- package/dist/-private/checkable.d.ts +21 -0
- package/dist/-private/checkable.d.ts.map +1 -0
- package/dist/-private/checkable.js +80 -0
- package/dist/-private/control.d.ts +18 -0
- package/dist/-private/control.d.ts.map +1 -0
- package/dist/-private/control.js +55 -0
- package/dist/-private/menu.d.ts +145 -0
- package/dist/-private/menu.d.ts.map +1 -0
- package/dist/-private/menu.js +322 -0
- package/dist/-private/overlay.d.ts +9 -0
- package/dist/-private/overlay.d.ts.map +1 -0
- package/dist/-private/overlay.js +39 -0
- package/dist/-private/showing.d.ts +7 -0
- package/dist/-private/showing.d.ts.map +1 -0
- package/dist/-private/showing.js +10 -0
- package/dist/-private/size.d.ts +10 -0
- package/dist/-private/size.d.ts.map +1 -0
- package/dist/-private/size.js +24 -0
- package/dist/-private/tree.d.ts +34 -0
- package/dist/-private/tree.d.ts.map +1 -0
- package/dist/-private/tree.js +80 -0
- package/dist/accordion.d.ts +62 -0
- package/dist/accordion.d.ts.map +1 -0
- package/dist/accordion.js +112 -0
- package/dist/alert-dialog.d.ts +24 -0
- package/dist/alert-dialog.d.ts.map +1 -0
- package/dist/alert-dialog.js +37 -0
- package/dist/alert.d.ts +27 -0
- package/dist/alert.d.ts.map +1 -0
- package/dist/alert.js +43 -0
- package/dist/aspect-ratio.d.ts +21 -0
- package/dist/aspect-ratio.d.ts.map +1 -0
- package/dist/aspect-ratio.js +30 -0
- package/dist/attachment.d.ts +86 -0
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +156 -0
- package/dist/avatar.d.ts +65 -0
- package/dist/avatar.d.ts.map +1 -0
- package/dist/avatar.js +106 -0
- package/dist/badge.d.ts +29 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +49 -0
- package/dist/breadcrumb.d.ts +36 -0
- package/dist/breadcrumb.d.ts.map +1 -0
- package/dist/breadcrumb.js +80 -0
- package/dist/bubble.d.ts +56 -0
- package/dist/bubble.d.ts.map +1 -0
- package/dist/bubble.js +94 -0
- package/dist/button-group.d.ts +34 -0
- package/dist/button-group.d.ts.map +1 -0
- package/dist/button-group.js +62 -0
- package/dist/button.d.ts +37 -0
- package/dist/button.d.ts.map +1 -0
- package/dist/button.js +77 -0
- package/dist/calendar.d.ts +115 -0
- package/dist/calendar.d.ts.map +1 -0
- package/dist/calendar.js +276 -0
- package/dist/card.d.ts +31 -0
- package/dist/card.d.ts.map +1 -0
- package/dist/card.js +49 -0
- package/dist/checkbox.d.ts +46 -0
- package/dist/checkbox.d.ts.map +1 -0
- package/dist/checkbox.js +84 -0
- package/dist/child.d.ts +29 -0
- package/dist/child.d.ts.map +1 -0
- package/dist/child.js +27 -0
- package/dist/collapsible.d.ts +44 -0
- package/dist/collapsible.d.ts.map +1 -0
- package/dist/collapsible.js +83 -0
- package/dist/color-scheme.d.ts +44 -0
- package/dist/color-scheme.d.ts.map +1 -0
- package/dist/color-scheme.js +123 -0
- package/dist/combobox.d.ts +114 -0
- package/dist/combobox.d.ts.map +1 -0
- package/dist/combobox.js +293 -0
- package/dist/command.d.ts +92 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +183 -0
- package/dist/context-menu.d.ts +37 -0
- package/dist/context-menu.d.ts.map +1 -0
- package/dist/context-menu.js +59 -0
- package/dist/date-picker.d.ts +48 -0
- package/dist/date-picker.d.ts.map +1 -0
- package/dist/date-picker.js +136 -0
- package/dist/dialog.d.ts +64 -0
- package/dist/dialog.d.ts.map +1 -0
- package/dist/dialog.js +142 -0
- package/dist/drawer.d.ts +63 -0
- package/dist/drawer.d.ts.map +1 -0
- package/dist/drawer.js +136 -0
- package/dist/dropdown-menu.d.ts +35 -0
- package/dist/dropdown-menu.d.ts.map +1 -0
- package/dist/dropdown-menu.js +49 -0
- package/dist/empty.d.ts +29 -0
- package/dist/empty.d.ts.map +1 -0
- package/dist/empty.js +47 -0
- package/dist/field.d.ts +86 -0
- package/dist/field.d.ts.map +1 -0
- package/dist/field.js +150 -0
- package/dist/file-drop.d.ts +74 -0
- package/dist/file-drop.d.ts.map +1 -0
- package/dist/file-drop.js +137 -0
- package/dist/focus.d.ts +54 -0
- package/dist/focus.d.ts.map +1 -0
- package/dist/focus.js +174 -0
- package/dist/harness.d.ts +90 -0
- package/dist/harness.d.ts.map +1 -0
- package/dist/harness.js +189 -0
- package/dist/heading.d.ts +16 -0
- package/dist/heading.d.ts.map +1 -0
- package/dist/heading.js +19 -0
- package/dist/hero.d.ts +21 -0
- package/dist/hero.d.ts.map +1 -0
- package/dist/hero.js +28 -0
- package/dist/hover-card.d.ts +46 -0
- package/dist/hover-card.d.ts.map +1 -0
- package/dist/hover-card.js +85 -0
- package/dist/icon.d.ts +10 -0
- package/dist/icon.d.ts.map +1 -0
- package/dist/icon.js +13 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +87 -0
- package/dist/input-group.d.ts +55 -0
- package/dist/input-group.d.ts.map +1 -0
- package/dist/input-group.js +103 -0
- package/dist/input-otp.d.ts +103 -0
- package/dist/input-otp.d.ts.map +1 -0
- package/dist/input-otp.js +293 -0
- package/dist/input.d.ts +53 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +90 -0
- package/dist/item.d.ts +63 -0
- package/dist/item.d.ts.map +1 -0
- package/dist/item.js +104 -0
- package/dist/kbd.d.ts +28 -0
- package/dist/kbd.d.ts.map +1 -0
- package/dist/kbd.js +36 -0
- package/dist/keys.d.ts +20 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +32 -0
- package/dist/label.d.ts +24 -0
- package/dist/label.d.ts.map +1 -0
- package/dist/label.js +39 -0
- package/dist/layers.d.ts +42 -0
- package/dist/layers.d.ts.map +1 -0
- package/dist/layers.js +70 -0
- package/dist/link.d.ts +44 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +60 -0
- package/dist/marker.d.ts +42 -0
- package/dist/marker.d.ts.map +1 -0
- package/dist/marker.js +73 -0
- package/dist/menubar.d.ts +76 -0
- package/dist/menubar.d.ts.map +1 -0
- package/dist/menubar.js +139 -0
- package/dist/message-scroller.d.ts +101 -0
- package/dist/message-scroller.d.ts.map +1 -0
- package/dist/message-scroller.js +215 -0
- package/dist/message.d.ts +48 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +72 -0
- package/dist/native-form.d.ts +44 -0
- package/dist/native-form.d.ts.map +1 -0
- package/dist/native-form.js +111 -0
- package/dist/native-select.d.ts +56 -0
- package/dist/native-select.d.ts.map +1 -0
- package/dist/native-select.js +100 -0
- package/dist/navigation-menu.d.ts +97 -0
- package/dist/navigation-menu.d.ts.map +1 -0
- package/dist/navigation-menu.js +207 -0
- package/dist/observers.d.ts +21 -0
- package/dist/observers.d.ts.map +1 -0
- package/dist/observers.js +34 -0
- package/dist/pagination.d.ts +39 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +71 -0
- package/dist/pointer.d.ts +38 -0
- package/dist/pointer.d.ts.map +1 -0
- package/dist/pointer.js +82 -0
- package/dist/popover.d.ts +50 -0
- package/dist/popover.d.ts.map +1 -0
- package/dist/popover.js +90 -0
- package/dist/progress.d.ts +38 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +81 -0
- package/dist/questionnaire.d.ts +117 -0
- package/dist/questionnaire.d.ts.map +1 -0
- package/dist/questionnaire.js +240 -0
- package/dist/radio-group.d.ts +53 -0
- package/dist/radio-group.d.ts.map +1 -0
- package/dist/radio-group.js +95 -0
- package/dist/rating.d.ts +67 -0
- package/dist/rating.d.ts.map +1 -0
- package/dist/rating.js +160 -0
- package/dist/resizable.d.ts +76 -0
- package/dist/resizable.d.ts.map +1 -0
- package/dist/resizable.js +138 -0
- package/dist/routing.d.ts +36 -0
- package/dist/routing.d.ts.map +1 -0
- package/dist/routing.js +50 -0
- package/dist/roving-focus.d.ts +38 -0
- package/dist/roving-focus.d.ts.map +1 -0
- package/dist/roving-focus.js +60 -0
- package/dist/scroll-area.d.ts +58 -0
- package/dist/scroll-area.d.ts.map +1 -0
- package/dist/scroll-area.js +153 -0
- package/dist/scroller.d.ts +41 -0
- package/dist/scroller.d.ts.map +1 -0
- package/dist/scroller.js +65 -0
- package/dist/select.d.ts +98 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +203 -0
- package/dist/selectors.d.ts +44 -0
- package/dist/selectors.d.ts.map +1 -0
- package/dist/selectors.js +63 -0
- package/dist/send-pointer.d.ts +17 -0
- package/dist/send-pointer.d.ts.map +1 -0
- package/dist/send-pointer.js +35 -0
- package/dist/separator.d.ts +26 -0
- package/dist/separator.d.ts.map +1 -0
- package/dist/separator.js +40 -0
- package/dist/shadowed.d.ts +55 -0
- package/dist/shadowed.d.ts.map +1 -0
- package/dist/shadowed.js +97 -0
- package/dist/sheet.d.ts +14 -0
- package/dist/sheet.d.ts.map +1 -0
- package/dist/sheet.js +15 -0
- package/dist/sidebar.d.ts +159 -0
- package/dist/sidebar.d.ts.map +1 -0
- package/dist/sidebar.js +299 -0
- package/dist/skeleton.d.ts +18 -0
- package/dist/skeleton.d.ts.map +1 -0
- package/dist/skeleton.js +25 -0
- package/dist/slider.d.ts +66 -0
- package/dist/slider.d.ts.map +1 -0
- package/dist/slider.js +155 -0
- package/dist/spinner.d.ts +10 -0
- package/dist/spinner.d.ts.map +1 -0
- package/dist/spinner.js +13 -0
- package/dist/sticky-footer.d.ts +33 -0
- package/dist/sticky-footer.d.ts.map +1 -0
- package/dist/sticky-footer.js +65 -0
- package/dist/switch.d.ts +44 -0
- package/dist/switch.d.ts.map +1 -0
- package/dist/switch.js +77 -0
- package/dist/table.d.ts +41 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +100 -0
- package/dist/tabs.d.ts +66 -0
- package/dist/tabs.d.ts.map +1 -0
- package/dist/tabs.js +149 -0
- package/dist/test-hooks.d.ts +9 -0
- package/dist/test-hooks.d.ts.map +1 -0
- package/dist/test-hooks.js +1 -0
- package/dist/textarea.d.ts +47 -0
- package/dist/textarea.d.ts.map +1 -0
- package/dist/textarea.js +78 -0
- package/dist/toaster.d.ts +172 -0
- package/dist/toaster.d.ts.map +1 -0
- package/dist/toaster.js +307 -0
- package/dist/toggle-group.d.ts +51 -0
- package/dist/toggle-group.d.ts.map +1 -0
- package/dist/toggle-group.js +97 -0
- package/dist/toggle.d.ts +21 -0
- package/dist/toggle.d.ts.map +1 -0
- package/dist/toggle.js +26 -0
- package/dist/tooltip.d.ts +48 -0
- package/dist/tooltip.d.ts.map +1 -0
- package/dist/tooltip.js +91 -0
- package/dist/trace.d.ts +118 -0
- package/dist/trace.d.ts.map +1 -0
- package/dist/trace.js +196 -0
- package/dist/translator.d.ts +34 -0
- package/dist/translator.d.ts.map +1 -0
- package/dist/translator.js +75 -0
- package/dist/zoetrope.d.ts +51 -0
- package/dist/zoetrope.d.ts.map +1 -0
- package/dist/zoetrope.js +94 -0
- package/package.json +68 -3
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { click, focus } from '@ember/test-helpers';
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
import { attributes } from "./selectors.js";
|
|
4
|
+
import { pressKey } from "./focus.js";
|
|
5
|
+
import { accessibleName, hiddenInputOf, isDisabled, isInvalid } from "./-private/checkable.js";
|
|
6
|
+
/**
|
|
7
|
+
* Drives a `<RadioGroup>` from `@ember-joinery/ember`, or the headless one from
|
|
8
|
+
* `@ember-joinery/primitives/radio-group`. Items are found by their `@value`
|
|
9
|
+
* (`data-test-jn-value`), and state comes from ARIA: each item's `aria-checked`, the group's
|
|
10
|
+
* `aria-required` and `aria-orientation`.
|
|
11
|
+
*
|
|
12
|
+
* const spacing = new RadioGroupHarness('spacing') // <RadioGroup @name="spacing">
|
|
13
|
+
* await spacing.choose('compact')
|
|
14
|
+
* assert.strictEqual(spacing.value, 'compact')
|
|
15
|
+
* await spacing.press('ArrowUp') // focus, and the choice, move to the previous item
|
|
16
|
+
*/
|
|
17
|
+
export class RadioGroupHarness extends Harness {
|
|
18
|
+
static component = 'radio-group';
|
|
19
|
+
/** Each item's element, in order. */
|
|
20
|
+
get items() {
|
|
21
|
+
return this.parts('item');
|
|
22
|
+
}
|
|
23
|
+
/** Each item's value, in order. */
|
|
24
|
+
get options() {
|
|
25
|
+
return this.values('item');
|
|
26
|
+
}
|
|
27
|
+
/** The item with this value. Throws when there is none. */
|
|
28
|
+
item(value) {
|
|
29
|
+
return this.part('item', value);
|
|
30
|
+
}
|
|
31
|
+
/** The chosen item's value, or `null` when none is. */
|
|
32
|
+
get value() {
|
|
33
|
+
const item = this.items.find(element => element.getAttribute('aria-checked') === 'true');
|
|
34
|
+
return item?.getAttribute(attributes.value) ?? null;
|
|
35
|
+
}
|
|
36
|
+
/** Whether the item with this value is chosen. */
|
|
37
|
+
isChecked(value) {
|
|
38
|
+
return this.item(value).getAttribute('aria-checked') === 'true';
|
|
39
|
+
}
|
|
40
|
+
/** Whether the item with this value can't be chosen. */
|
|
41
|
+
isItemDisabled(value) {
|
|
42
|
+
return isDisabled(this.item(value));
|
|
43
|
+
}
|
|
44
|
+
/** Whether the item with this value is marked invalid (`aria-invalid`). */
|
|
45
|
+
isItemInvalid(value) {
|
|
46
|
+
return isInvalid(this.item(value));
|
|
47
|
+
}
|
|
48
|
+
/** The accessible name of the item with this value: its `<label>`'s text, or its ARIA. */
|
|
49
|
+
labelOf(value) {
|
|
50
|
+
return accessibleName(this.item(value));
|
|
51
|
+
}
|
|
52
|
+
/** The group's accessible name: `aria-label` or `aria-labelledby`. */
|
|
53
|
+
get label() {
|
|
54
|
+
return accessibleName(this.element);
|
|
55
|
+
}
|
|
56
|
+
/** Whether every item is disabled (the group's `@disabled`). */
|
|
57
|
+
get isDisabled() {
|
|
58
|
+
return this.element.hasAttribute('data-disabled');
|
|
59
|
+
}
|
|
60
|
+
/** Whether a form needs a choice (`aria-required="true"`). */
|
|
61
|
+
get isRequired() {
|
|
62
|
+
return this.element.getAttribute('aria-required') === 'true';
|
|
63
|
+
}
|
|
64
|
+
/** `horizontal`, `vertical`, or `null` when every arrow key moves (`aria-orientation`). */
|
|
65
|
+
get orientation() {
|
|
66
|
+
return this.element.getAttribute('aria-orientation');
|
|
67
|
+
}
|
|
68
|
+
/** The value of the item that has focus, or `null` when focus is elsewhere. */
|
|
69
|
+
get focused() {
|
|
70
|
+
const active = document.activeElement;
|
|
71
|
+
const item = this.items.find(element => element === active);
|
|
72
|
+
return item?.getAttribute(attributes.value) ?? null;
|
|
73
|
+
}
|
|
74
|
+
/** The value of the item Tab enters on (`tabindex="0"`), or `null` before any has had focus. */
|
|
75
|
+
get tabStop() {
|
|
76
|
+
const item = this.items.find(element => element.getAttribute('tabindex') === '0');
|
|
77
|
+
return item?.getAttribute(attributes.value) ?? null;
|
|
78
|
+
}
|
|
79
|
+
/** The hidden native radio the item with this value renders in a form, or `null`. */
|
|
80
|
+
inputOf(value) {
|
|
81
|
+
return hiddenInputOf(this.item(value));
|
|
82
|
+
}
|
|
83
|
+
/** Clicks the item with this value, as a user would, which chooses it. */
|
|
84
|
+
async choose(value) {
|
|
85
|
+
await click(this.item(value));
|
|
86
|
+
}
|
|
87
|
+
/** Moves focus to the item with this value, as a click would, without choosing it. */
|
|
88
|
+
async focus(value) {
|
|
89
|
+
await focus(this.item(value));
|
|
90
|
+
}
|
|
91
|
+
/** Presses a key on the focused item: an arrow moves focus and the choice. */
|
|
92
|
+
async press(key, modifiers) {
|
|
93
|
+
return pressKey(key, modifiers);
|
|
94
|
+
}
|
|
95
|
+
}
|
package/dist/rating.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
import { type KeyModifiers } from './focus.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Drives a `<Rating>` from `@ember-joinery/ember`, or the headless one from
|
|
5
|
+
* `@ember-joinery/primitives/rating`. Its items are native radios, found by their value
|
|
6
|
+
* (`data-test-jn-value`); its rating is the root's `data-value`.
|
|
7
|
+
*
|
|
8
|
+
* const recipe = new RatingHarness('recipe') // <Rating @name="recipe">
|
|
9
|
+
* await recipe.select(4)
|
|
10
|
+
* assert.strictEqual(recipe.value, 4)
|
|
11
|
+
* assert.strictEqual(recipe.stars, '★ ★ ★ ★ ☆')
|
|
12
|
+
* await recipe.select(4) // picking it again clears it
|
|
13
|
+
* assert.strictEqual(recipe.value, 0)
|
|
14
|
+
*/
|
|
15
|
+
export declare class RatingHarness extends Harness {
|
|
16
|
+
static component: string;
|
|
17
|
+
/** The current rating: `0` for none. */
|
|
18
|
+
get value(): number;
|
|
19
|
+
/** How many items it has (`data-total`). */
|
|
20
|
+
get total(): number;
|
|
21
|
+
/** Each item's value, in order. */
|
|
22
|
+
get options(): number[];
|
|
23
|
+
/** Each item's element, in order. */
|
|
24
|
+
get items(): HTMLElement[];
|
|
25
|
+
/** The item worth `value`. Throws when there is none. */
|
|
26
|
+
item(value: number): HTMLElement;
|
|
27
|
+
/** The radio of the item worth `value`. */
|
|
28
|
+
input(value: number): HTMLInputElement;
|
|
29
|
+
/** Each item as `★` while the rating reaches it, `☆` otherwise, joined with spaces. */
|
|
30
|
+
get stars(): string;
|
|
31
|
+
/**
|
|
32
|
+
* What each item shows, its icon's text (the part hidden from assistive technology), joined
|
|
33
|
+
* with spaces: `★ ★ ★ ★ ★`, or `1 2 3 4 5` for icons that show their value. An icon with no
|
|
34
|
+
* text, such as an `<svg>`, gives `''`.
|
|
35
|
+
*/
|
|
36
|
+
get starTexts(): string;
|
|
37
|
+
/** How much of the item worth `value` the rating fills, from 0 to 100. */
|
|
38
|
+
percentOf(value: number): number;
|
|
39
|
+
/** The accessible name of the item worth `value`: `3 stars`. */
|
|
40
|
+
labelOf(value: number): string;
|
|
41
|
+
/** The group's accessible name: its legend, `aria-label` or `aria-labelledby`. */
|
|
42
|
+
get label(): string;
|
|
43
|
+
/** What a display-only rating says for assistive technology, or `''`: `Rated 3 out of 5`. */
|
|
44
|
+
get summary(): string;
|
|
45
|
+
/** Whether it can't be changed (`aria-readonly="true"`): readonly, or display-only. */
|
|
46
|
+
get isReadonly(): boolean;
|
|
47
|
+
/** Whether it is disabled (`<fieldset disabled>`). */
|
|
48
|
+
get isDisabled(): boolean;
|
|
49
|
+
/** The value of the item whose radio has focus, or `null`. */
|
|
50
|
+
get focused(): number | null;
|
|
51
|
+
/**
|
|
52
|
+
* Picks `value`, as a click on its item does: picking the current rating clears it. A value
|
|
53
|
+
* between the items' is filled in on the rating's range input (`rating.Range`), or on a
|
|
54
|
+
* number or range input of the block's own, when it has one.
|
|
55
|
+
*/
|
|
56
|
+
select(value: number): Promise<void>;
|
|
57
|
+
/** Focuses the checked radio, or the first, as Tab does. */
|
|
58
|
+
focus(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Presses a key on the focused radio, and does what the browser does for a native radio
|
|
61
|
+
* group, which a test's events don't make it do: the arrow keys move focus to the next or
|
|
62
|
+
* previous item, going round, and pick it (a click), and Space picks the focused one. Right
|
|
63
|
+
* to left, the left and right arrows swap. Tests can't press real keys, as with `tab()`.
|
|
64
|
+
*/
|
|
65
|
+
press(key: string, modifiers?: KeyModifiers): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=rating.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rating.d.ts","sourceRoot":"","sources":["../src/rating.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAMxD;;;;;;;;;;;GAWG;AACH,qBAAa,aAAc,SAAQ,OAAO;IACxC,OAAgB,SAAS,SAAW;IAEpC,wCAAwC;IACxC,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,4CAA4C;IAC5C,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,mCAAmC;IACnC,IAAI,OAAO,IAAI,MAAM,EAAE,CAEtB;IAED,qCAAqC;IACrC,IAAI,KAAK,IAAI,WAAW,EAAE,CAEzB;IAED,yDAAyD;IACzD,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;IAIhC,2CAA2C;IAC3C,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB;IAItC,uFAAuF;IACvF,IAAI,KAAK,IAAI,MAAM,CAIlB;IAED;;;;OAIG;IACH,IAAI,SAAS,IAAI,MAAM,CAOtB;IAED,0EAA0E;IAC1E,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAIhC,gEAAgE;IAChE,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAI9B,kFAAkF;IAClF,IAAI,KAAK,IAAI,MAAM,CAOlB;IAED,6FAA6F;IAC7F,IAAI,OAAO,IAAI,MAAM,CAGpB;IAED,uFAAuF;IACvF,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,sDAAsD;IACtD,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,8DAA8D;IAC9D,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAK3B;IAED;;;;OAIG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkB1C,4DAA4D;IACtD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5B;;;;;OAKG;IACG,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CAqBtE"}
|
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
|
+
}
|