@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,215 @@
|
|
|
1
|
+
import { click, focus, triggerEvent } from '@ember/test-helpers';
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
import { waitForObservers } from "./observers.js";
|
|
4
|
+
/** The longest a row's entrance is waited for, in milliseconds. */
|
|
5
|
+
const MAX_ENTRANCE = 1000;
|
|
6
|
+
/** How far each scroll key moves a viewport, as Chrome scrolls one. */
|
|
7
|
+
function keyScroll(viewport, key) {
|
|
8
|
+
const page = viewport.clientHeight * 0.875;
|
|
9
|
+
switch (key) {
|
|
10
|
+
case 'Home':
|
|
11
|
+
return -viewport.scrollTop;
|
|
12
|
+
case 'End':
|
|
13
|
+
return viewport.scrollHeight;
|
|
14
|
+
case 'PageUp':
|
|
15
|
+
return -page;
|
|
16
|
+
case 'PageDown':
|
|
17
|
+
case ' ':
|
|
18
|
+
return page;
|
|
19
|
+
case 'ArrowUp':
|
|
20
|
+
return -40;
|
|
21
|
+
case 'ArrowDown':
|
|
22
|
+
return 40;
|
|
23
|
+
default:
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Drives a `<MessageScroller>` (or the headless `MessageScrollerRoot`) from Joinery: where the
|
|
29
|
+
* transcript is scrolled to, which rows are in view, its scroll buttons, and scrolling it as a
|
|
30
|
+
* reader does, by wheel or by key, which a programmatic scroll doesn't:
|
|
31
|
+
*
|
|
32
|
+
* const chat = new MessageScrollerHarness('chat') // <s.Root @name="chat">
|
|
33
|
+
* assert.true(chat.isAtEnd)
|
|
34
|
+
* await chat.scrollBy(-200) // the reader scrolls up
|
|
35
|
+
* assert.true(chat.canScrollToEnd)
|
|
36
|
+
* await chat.clickButton() // "jump to latest"
|
|
37
|
+
* assert.strictEqual(chat.itemTop('turn-3'), 64)
|
|
38
|
+
*
|
|
39
|
+
* Its actions wait for the scroller to settle: its frames, a smooth scroll's end, and the
|
|
40
|
+
* observers' reports.
|
|
41
|
+
*/
|
|
42
|
+
export class MessageScrollerHarness extends Harness {
|
|
43
|
+
static component = 'message-scroller';
|
|
44
|
+
/** The viewport, the part that scrolls. */
|
|
45
|
+
get viewport() {
|
|
46
|
+
return this.part('viewport');
|
|
47
|
+
}
|
|
48
|
+
/** The content, around the rows. */
|
|
49
|
+
get content() {
|
|
50
|
+
return this.part('content');
|
|
51
|
+
}
|
|
52
|
+
/** The viewport's accessible name: `Messages` unless it was given another. */
|
|
53
|
+
get label() {
|
|
54
|
+
return this.viewport.getAttribute('aria-label') ?? '';
|
|
55
|
+
}
|
|
56
|
+
/** Every row, in order. */
|
|
57
|
+
get items() {
|
|
58
|
+
return this.parts('item');
|
|
59
|
+
}
|
|
60
|
+
/** The `@messageId` of each row that has one, in order. */
|
|
61
|
+
get messageIds() {
|
|
62
|
+
return this.values('item');
|
|
63
|
+
}
|
|
64
|
+
/** The row with this `@messageId`. Throws when there is none. */
|
|
65
|
+
item(messageId) {
|
|
66
|
+
return this.part('item', messageId);
|
|
67
|
+
}
|
|
68
|
+
/** The `@messageId` of each row marked `@scrollAnchor`, in order. */
|
|
69
|
+
get anchorIds() {
|
|
70
|
+
return this.items
|
|
71
|
+
.filter(item => item.getAttribute('data-scroll-anchor') === 'true')
|
|
72
|
+
.map(item => item.getAttribute('data-message-id'))
|
|
73
|
+
.filter((id) => id !== null);
|
|
74
|
+
}
|
|
75
|
+
/** How much the screen scales the viewport: on-screen lengths are this times CSS ones. */
|
|
76
|
+
get #scale() {
|
|
77
|
+
const viewport = this.viewport;
|
|
78
|
+
return viewport.offsetHeight
|
|
79
|
+
? viewport.getBoundingClientRect().height / viewport.offsetHeight
|
|
80
|
+
: 1;
|
|
81
|
+
}
|
|
82
|
+
/** How far the viewport is scrolled down, in pixels. */
|
|
83
|
+
get scrollTop() {
|
|
84
|
+
return this.viewport.scrollTop;
|
|
85
|
+
}
|
|
86
|
+
/** How far it can scroll down, in pixels. */
|
|
87
|
+
get maxScrollTop() {
|
|
88
|
+
const viewport = this.viewport;
|
|
89
|
+
return Math.max(0, viewport.scrollHeight - viewport.clientHeight);
|
|
90
|
+
}
|
|
91
|
+
/** Whether it is scrolled to the top, to within a pixel. */
|
|
92
|
+
get isAtStart() {
|
|
93
|
+
return this.scrollTop <= 1;
|
|
94
|
+
}
|
|
95
|
+
/** Whether it is scrolled to the bottom, to within a pixel. */
|
|
96
|
+
get isAtEnd() {
|
|
97
|
+
return this.scrollTop >= this.maxScrollTop - 1;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The edges it says it can scroll toward: its `data-scrollable`. `end` stays false while it
|
|
101
|
+
* follows the end, as its button does.
|
|
102
|
+
*/
|
|
103
|
+
get scrollable() {
|
|
104
|
+
const value = (this.element.getAttribute('data-scrollable') ?? '').split(/\s+/);
|
|
105
|
+
return { start: value.includes('start'), end: value.includes('end') };
|
|
106
|
+
}
|
|
107
|
+
/** Whether it says there is more above. */
|
|
108
|
+
get canScrollToStart() {
|
|
109
|
+
return this.scrollable.start;
|
|
110
|
+
}
|
|
111
|
+
/** Whether it says there is more below. */
|
|
112
|
+
get canScrollToEnd() {
|
|
113
|
+
return this.scrollable.end;
|
|
114
|
+
}
|
|
115
|
+
/** Whether the opening position is still to apply, and the viewport hidden till then. */
|
|
116
|
+
get isPendingScroll() {
|
|
117
|
+
return this.viewport.hasAttribute('data-pending-scroll');
|
|
118
|
+
}
|
|
119
|
+
/** Whether it is scrolling itself to the latest row (`data-autoscrolling`). */
|
|
120
|
+
get isAutoscrolling() {
|
|
121
|
+
return this.element.hasAttribute('data-autoscrolling');
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Where a row starts below the viewport's top edge, in CSS pixels: 0 at the top, negative
|
|
125
|
+
* above it.
|
|
126
|
+
*/
|
|
127
|
+
itemTop(messageId) {
|
|
128
|
+
const delta = this.item(messageId).getBoundingClientRect().top - this.viewport.getBoundingClientRect().top;
|
|
129
|
+
return delta / this.#scale;
|
|
130
|
+
}
|
|
131
|
+
/** Whether any of the row shows in the viewport. */
|
|
132
|
+
isItemVisible(messageId) {
|
|
133
|
+
const item = this.item(messageId).getBoundingClientRect();
|
|
134
|
+
const viewport = this.viewport.getBoundingClientRect();
|
|
135
|
+
return item.bottom > viewport.top + 1 && item.top < viewport.bottom - 1;
|
|
136
|
+
}
|
|
137
|
+
/** The `@messageId` of each row that shows in the viewport, in order. */
|
|
138
|
+
get visibleIds() {
|
|
139
|
+
return this.messageIds.filter(id => this.isItemVisible(id));
|
|
140
|
+
}
|
|
141
|
+
/** Its scroll button for that edge (`end` by default). Throws when there is none. */
|
|
142
|
+
button(direction = 'end') {
|
|
143
|
+
return this.part('button', direction);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Whether the button for that edge can be used: there is somewhere to go, so it is shown
|
|
147
|
+
* (`data-active`), and it is neither `inert` (nor inside something that is) nor out of the
|
|
148
|
+
* tab order, which is what a keyboard and assistive technology go by.
|
|
149
|
+
*/
|
|
150
|
+
isButtonActive(direction = 'end') {
|
|
151
|
+
const button = this.button(direction);
|
|
152
|
+
return (button.getAttribute('data-active') === 'true' &&
|
|
153
|
+
button.closest('[inert]') === null &&
|
|
154
|
+
button.getAttribute('tabindex') !== '-1');
|
|
155
|
+
}
|
|
156
|
+
/** Presses the button for that edge, as a reader would, and waits for the scroll to end. */
|
|
157
|
+
async clickButton(direction = 'end') {
|
|
158
|
+
await click(this.button(direction));
|
|
159
|
+
await this.settle();
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Scrolls the viewport to `top`, as a reader's wheel or scrollbar does: that lets go of
|
|
163
|
+
* following and of an anchored turn.
|
|
164
|
+
*/
|
|
165
|
+
async scrollTo(top) {
|
|
166
|
+
const viewport = this.viewport;
|
|
167
|
+
await triggerEvent(viewport, 'wheel', { deltaY: top - viewport.scrollTop });
|
|
168
|
+
viewport.scrollTo({ top, behavior: 'instant' });
|
|
169
|
+
await this.settle();
|
|
170
|
+
}
|
|
171
|
+
/** Scrolls the viewport by `delta` pixels (negative: up), as a reader's wheel does. */
|
|
172
|
+
async scrollBy(delta) {
|
|
173
|
+
await this.scrollTo(this.viewport.scrollTop + delta);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Presses a key in the viewport: a scroll key (`ArrowUp`, `ArrowDown`, `PageUp`,
|
|
177
|
+
* `PageDown`, `Home`, `End`, space) scrolls it as the browser would, and is the reader
|
|
178
|
+
* scrolling. A test can't send the browser's own scroll keys, so this moves it the same way.
|
|
179
|
+
*/
|
|
180
|
+
async pressKey(key) {
|
|
181
|
+
const viewport = this.viewport;
|
|
182
|
+
await triggerEvent(viewport, 'keydown', { key });
|
|
183
|
+
const delta = keyScroll(viewport, key);
|
|
184
|
+
if (delta)
|
|
185
|
+
viewport.scrollTo({ top: viewport.scrollTop + delta, behavior: 'instant' });
|
|
186
|
+
await this.settle();
|
|
187
|
+
}
|
|
188
|
+
/** Moves focus to the viewport, as tabbing to it would. */
|
|
189
|
+
async focus() {
|
|
190
|
+
await focus(this.viewport);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Waits for the scroller to settle: its frames, a smooth scroll, the observers' reports, and
|
|
194
|
+
* any entrance its rows play (a finite animation, such as a new message sliding up), which
|
|
195
|
+
* moves a row on screen while it runs.
|
|
196
|
+
*/
|
|
197
|
+
async settle() {
|
|
198
|
+
await waitForObservers();
|
|
199
|
+
// How long until the last finite animation inside it ends. Waited for by the clock, not
|
|
200
|
+
// `finished`: an animation in a row the browser skips (`content-visibility: auto`) doesn't
|
|
201
|
+
// advance until the row shows.
|
|
202
|
+
const remaining = this.element.getAnimations({ subtree: true }).map(animation => {
|
|
203
|
+
const timing = animation.effect?.getComputedTiming();
|
|
204
|
+
const end = Number(timing?.endTime ?? 0);
|
|
205
|
+
const now = Number(animation.currentTime ?? 0);
|
|
206
|
+
return Number.isFinite(end) ? end - now : 0;
|
|
207
|
+
});
|
|
208
|
+
const wait = Math.min(MAX_ENTRANCE, Math.max(0, ...remaining));
|
|
209
|
+
if (wait > 0) {
|
|
210
|
+
await new Promise(resolve => setTimeout(resolve, wait));
|
|
211
|
+
await waitForObservers();
|
|
212
|
+
}
|
|
213
|
+
await waitForObservers();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BubbleHarness } from './bubble.ts';
|
|
2
|
+
import { Harness } from './harness.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Drives a `<Message>` from `@ember-joinery/ember`: one row of a conversation. It reads the
|
|
5
|
+
* row's side and its header and footer, and reaches the bubbles in it:
|
|
6
|
+
*
|
|
7
|
+
* const reply = new MessageHarness('reply') // <Message @name="reply">
|
|
8
|
+
* assert.strictEqual(reply.align, 'end')
|
|
9
|
+
* assert.strictEqual(reply.footerText, 'Delivered')
|
|
10
|
+
* assert.strictEqual(reply.bubbles[0]!.text, "It's a one-line change.")
|
|
11
|
+
*
|
|
12
|
+
* Find what else is inside it, such as its avatar or the footer's buttons, with `find()`.
|
|
13
|
+
*/
|
|
14
|
+
export declare class MessageHarness extends Harness {
|
|
15
|
+
static component: string;
|
|
16
|
+
/** All the text it shows, whitespace collapsed. */
|
|
17
|
+
get text(): string;
|
|
18
|
+
/** Its `@align`: `start` or `end`. */
|
|
19
|
+
get align(): string | null;
|
|
20
|
+
/** The avatar's slot. Throws when it has none. */
|
|
21
|
+
get avatar(): HTMLElement;
|
|
22
|
+
/** Whether it has an avatar's slot, even an empty one that only keeps it in line. */
|
|
23
|
+
get hasAvatar(): boolean;
|
|
24
|
+
/** The content: the header, the bubbles and the footer. Throws when it has none. */
|
|
25
|
+
get content(): HTMLElement;
|
|
26
|
+
/** The header. Throws when it has none. */
|
|
27
|
+
get header(): HTMLElement;
|
|
28
|
+
/** The footer. Throws when it has none. */
|
|
29
|
+
get footer(): HTMLElement;
|
|
30
|
+
/** The header's text, such as the sender's name, or `''` without one. */
|
|
31
|
+
get headerText(): string;
|
|
32
|
+
/** The footer's text, such as a status, or `''` without one. */
|
|
33
|
+
get footerText(): string;
|
|
34
|
+
/** A harness for each bubble in it, in order. */
|
|
35
|
+
get bubbles(): BubbleHarness[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Drives a `<MessageGroup>` from `@ember-joinery/ember`: consecutive messages from one sender.
|
|
39
|
+
*
|
|
40
|
+
* const group = new MessageGroupHarness()
|
|
41
|
+
* assert.strictEqual(group.messages.length, 2)
|
|
42
|
+
*/
|
|
43
|
+
export declare class MessageGroupHarness extends Harness {
|
|
44
|
+
static component: string;
|
|
45
|
+
/** A harness for each message in the group, in order. */
|
|
46
|
+
get messages(): MessageHarness[];
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../src/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAMtC;;;;;;;;;;GAUG;AACH,qBAAa,cAAe,SAAQ,OAAO;IACzC,OAAgB,SAAS,SAAY;IAErC,mDAAmD;IACnD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,sCAAsC;IACtC,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAEzB;IAED,kDAAkD;IAClD,IAAI,MAAM,IAAI,WAAW,CAExB;IAED,qFAAqF;IACrF,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,oFAAoF;IACpF,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED,2CAA2C;IAC3C,IAAI,MAAM,IAAI,WAAW,CAExB;IAED,2CAA2C;IAC3C,IAAI,MAAM,IAAI,WAAW,CAExB;IAED,yEAAyE;IACzE,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,gEAAgE;IAChE,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,iDAAiD;IACjD,IAAI,OAAO,IAAI,aAAa,EAAE,CAE7B;CACF;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,OAAO;IAC9C,OAAgB,SAAS,SAAkB;IAE3C,yDAAyD;IACzD,IAAI,QAAQ,IAAI,cAAc,EAAE,CAE/B;CACF"}
|
package/dist/message.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { BubbleHarness } from "./bubble.js";
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
function text(element) {
|
|
4
|
+
return (element?.textContent ?? '').replace(/\s+/g, ' ').trim();
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Drives a `<Message>` from `@ember-joinery/ember`: one row of a conversation. It reads the
|
|
8
|
+
* row's side and its header and footer, and reaches the bubbles in it:
|
|
9
|
+
*
|
|
10
|
+
* const reply = new MessageHarness('reply') // <Message @name="reply">
|
|
11
|
+
* assert.strictEqual(reply.align, 'end')
|
|
12
|
+
* assert.strictEqual(reply.footerText, 'Delivered')
|
|
13
|
+
* assert.strictEqual(reply.bubbles[0]!.text, "It's a one-line change.")
|
|
14
|
+
*
|
|
15
|
+
* Find what else is inside it, such as its avatar or the footer's buttons, with `find()`.
|
|
16
|
+
*/
|
|
17
|
+
export class MessageHarness extends Harness {
|
|
18
|
+
static component = 'message';
|
|
19
|
+
/** All the text it shows, whitespace collapsed. */
|
|
20
|
+
get text() {
|
|
21
|
+
return text(this.element);
|
|
22
|
+
}
|
|
23
|
+
/** Its `@align`: `start` or `end`. */
|
|
24
|
+
get align() {
|
|
25
|
+
return this.element.getAttribute('data-align');
|
|
26
|
+
}
|
|
27
|
+
/** The avatar's slot. Throws when it has none. */
|
|
28
|
+
get avatar() {
|
|
29
|
+
return this.part('avatar');
|
|
30
|
+
}
|
|
31
|
+
/** Whether it has an avatar's slot, even an empty one that only keeps it in line. */
|
|
32
|
+
get hasAvatar() {
|
|
33
|
+
return this.queryPart('avatar') !== null;
|
|
34
|
+
}
|
|
35
|
+
/** The content: the header, the bubbles and the footer. Throws when it has none. */
|
|
36
|
+
get content() {
|
|
37
|
+
return this.part('content');
|
|
38
|
+
}
|
|
39
|
+
/** The header. Throws when it has none. */
|
|
40
|
+
get header() {
|
|
41
|
+
return this.part('header');
|
|
42
|
+
}
|
|
43
|
+
/** The footer. Throws when it has none. */
|
|
44
|
+
get footer() {
|
|
45
|
+
return this.part('footer');
|
|
46
|
+
}
|
|
47
|
+
/** The header's text, such as the sender's name, or `''` without one. */
|
|
48
|
+
get headerText() {
|
|
49
|
+
return text(this.queryPart('header'));
|
|
50
|
+
}
|
|
51
|
+
/** The footer's text, such as a status, or `''` without one. */
|
|
52
|
+
get footerText() {
|
|
53
|
+
return text(this.queryPart('footer'));
|
|
54
|
+
}
|
|
55
|
+
/** A harness for each bubble in it, in order. */
|
|
56
|
+
get bubbles() {
|
|
57
|
+
return this.findAll(BubbleHarness);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Drives a `<MessageGroup>` from `@ember-joinery/ember`: consecutive messages from one sender.
|
|
62
|
+
*
|
|
63
|
+
* const group = new MessageGroupHarness()
|
|
64
|
+
* assert.strictEqual(group.messages.length, 2)
|
|
65
|
+
*/
|
|
66
|
+
export class MessageGroupHarness extends Harness {
|
|
67
|
+
static component = 'message-group';
|
|
68
|
+
/** A harness for each message in the group, in order. */
|
|
69
|
+
get messages() {
|
|
70
|
+
return this.findAll(MessageHarness);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
type Control = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
3
|
+
/**
|
|
4
|
+
* Drives a `<NativeForm>` from `@ember-joinery/primitives/native-form`: fills in its fields by
|
|
5
|
+
* their `name`, as a user does, and submits it.
|
|
6
|
+
*
|
|
7
|
+
* const profile = new NativeFormHarness('profile') // <NativeForm @name="profile">
|
|
8
|
+
* await profile.fillIn('firstName', 'Ada')
|
|
9
|
+
* await profile.choose('universe', '616')
|
|
10
|
+
* await profile.submit()
|
|
11
|
+
*/
|
|
12
|
+
export declare class NativeFormHarness extends Harness {
|
|
13
|
+
static component: string;
|
|
14
|
+
/** The `<form>`. */
|
|
15
|
+
get form(): HTMLFormElement;
|
|
16
|
+
/** Its data as the browser would submit it: `FormData`'s entries, the last of each name. */
|
|
17
|
+
get entries(): Record<string, FormDataEntryValue>;
|
|
18
|
+
/** The controls named `name`. Throws when there is none. */
|
|
19
|
+
controls(name: string): Control[];
|
|
20
|
+
/** Fills in the text field named `name`. */
|
|
21
|
+
fillIn(name: string, text: string): Promise<void>;
|
|
22
|
+
/** Picks the radio named `name` whose value is `value`. */
|
|
23
|
+
choose(name: string, value: string): Promise<void>;
|
|
24
|
+
/** Clicks the checkbox named `name` (and, given one, whose value is `value`). */
|
|
25
|
+
toggle(name: string, value?: string): Promise<void>;
|
|
26
|
+
/** Selects `value` in the select named `name`. */
|
|
27
|
+
select(name: string, value: string | string[]): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Presses Enter in the field named `name`, and does what the browser then does, which a
|
|
30
|
+
* test's key events don't make it do (as with `tab()`): in a single-line field, unless the
|
|
31
|
+
* keydown was cancelled, it submits the form. That is a click on the form's default button
|
|
32
|
+
* (its first submit button), which does nothing while that button is disabled; without one,
|
|
33
|
+
* the form submits when that field is the only one Enter submits from. In a textarea, a
|
|
34
|
+
* select, a checkbox or a radio, Enter submits nothing.
|
|
35
|
+
*/
|
|
36
|
+
pressEnter(name: string): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Submits it, as a press on its submit button does: the browser checks its constraints
|
|
39
|
+
* first, and a form that fails them doesn't submit.
|
|
40
|
+
*/
|
|
41
|
+
submit(): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=native-form.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-form.d.ts","sourceRoot":"","sources":["../src/native-form.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC,KAAK,OAAO,GAAG,gBAAgB,GAAG,iBAAiB,GAAG,mBAAmB,CAAA;AAmCzE;;;;;;;;GAQG;AACH,qBAAa,iBAAkB,SAAQ,OAAO;IAC5C,OAAgB,SAAS,SAAgB;IAEzC,oBAAoB;IACpB,IAAI,IAAI,IAAI,eAAe,CAE1B;IAED,4FAA4F;IAC5F,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAEhD;IAED,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE;IASjC,4CAA4C;IACtC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvD,2DAA2D;IACrD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMxD,iFAAiF;IAC3E,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMzD,kDAAkD;IAC5C,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAInE;;;;;;;OAOG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAc7C;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAI9B"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { click, fillIn, focus, select, settled } from '@ember/test-helpers';
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
import { pressKey } from "./focus.js";
|
|
4
|
+
/**
|
|
5
|
+
* The input types in which Enter submits the form (HTML's "fields that block implicit
|
|
6
|
+
* submission"): the single-line text and number fields, not checkboxes, radios or buttons.
|
|
7
|
+
*/
|
|
8
|
+
const SUBMITS_ON_ENTER = new Set([
|
|
9
|
+
'text',
|
|
10
|
+
'search',
|
|
11
|
+
'url',
|
|
12
|
+
'tel',
|
|
13
|
+
'email',
|
|
14
|
+
'password',
|
|
15
|
+
'date',
|
|
16
|
+
'month',
|
|
17
|
+
'week',
|
|
18
|
+
'time',
|
|
19
|
+
'datetime-local',
|
|
20
|
+
'number',
|
|
21
|
+
]);
|
|
22
|
+
function submitsOnEnter(element) {
|
|
23
|
+
return element instanceof HTMLInputElement && SUBMITS_ON_ENTER.has(element.type);
|
|
24
|
+
}
|
|
25
|
+
/** A form's default button: its first submit button, as the browser picks it for Enter. */
|
|
26
|
+
function defaultButton(form) {
|
|
27
|
+
return [...form.elements].find((element) => (element instanceof HTMLButtonElement && element.type === 'submit') ||
|
|
28
|
+
(element instanceof HTMLInputElement &&
|
|
29
|
+
(element.type === 'submit' || element.type === 'image')));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Drives a `<NativeForm>` from `@ember-joinery/primitives/native-form`: fills in its fields by
|
|
33
|
+
* their `name`, as a user does, and submits it.
|
|
34
|
+
*
|
|
35
|
+
* const profile = new NativeFormHarness('profile') // <NativeForm @name="profile">
|
|
36
|
+
* await profile.fillIn('firstName', 'Ada')
|
|
37
|
+
* await profile.choose('universe', '616')
|
|
38
|
+
* await profile.submit()
|
|
39
|
+
*/
|
|
40
|
+
export class NativeFormHarness extends Harness {
|
|
41
|
+
static component = 'native-form';
|
|
42
|
+
/** The `<form>`. */
|
|
43
|
+
get form() {
|
|
44
|
+
return this.element;
|
|
45
|
+
}
|
|
46
|
+
/** Its data as the browser would submit it: `FormData`'s entries, the last of each name. */
|
|
47
|
+
get entries() {
|
|
48
|
+
return Object.fromEntries(new FormData(this.form));
|
|
49
|
+
}
|
|
50
|
+
/** The controls named `name`. Throws when there is none. */
|
|
51
|
+
controls(name) {
|
|
52
|
+
const found = [...this.form.elements].filter((element) => 'name' in element && element.name === name && element.tagName !== 'BUTTON');
|
|
53
|
+
if (!found.length)
|
|
54
|
+
throw new Error(`Joinery harness: ${this} has no control named "${name}"`);
|
|
55
|
+
return found;
|
|
56
|
+
}
|
|
57
|
+
/** Fills in the text field named `name`. */
|
|
58
|
+
async fillIn(name, text) {
|
|
59
|
+
await fillIn(this.controls(name)[0], text);
|
|
60
|
+
}
|
|
61
|
+
/** Picks the radio named `name` whose value is `value`. */
|
|
62
|
+
async choose(name, value) {
|
|
63
|
+
const radio = this.controls(name).find(control => control.value === value);
|
|
64
|
+
if (!radio)
|
|
65
|
+
throw new Error(`Joinery harness: ${this} has no "${name}" worth "${value}"`);
|
|
66
|
+
await click(radio);
|
|
67
|
+
}
|
|
68
|
+
/** Clicks the checkbox named `name` (and, given one, whose value is `value`). */
|
|
69
|
+
async toggle(name, value) {
|
|
70
|
+
const box = this.controls(name).find(control => value === undefined || control.value === value);
|
|
71
|
+
if (!box)
|
|
72
|
+
throw new Error(`Joinery harness: ${this} has no "${name}" worth "${value}"`);
|
|
73
|
+
await click(box);
|
|
74
|
+
}
|
|
75
|
+
/** Selects `value` in the select named `name`. */
|
|
76
|
+
async select(name, value) {
|
|
77
|
+
await select(this.controls(name)[0], value);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Presses Enter in the field named `name`, and does what the browser then does, which a
|
|
81
|
+
* test's key events don't make it do (as with `tab()`): in a single-line field, unless the
|
|
82
|
+
* keydown was cancelled, it submits the form. That is a click on the form's default button
|
|
83
|
+
* (its first submit button), which does nothing while that button is disabled; without one,
|
|
84
|
+
* the form submits when that field is the only one Enter submits from. In a textarea, a
|
|
85
|
+
* select, a checkbox or a radio, Enter submits nothing.
|
|
86
|
+
*/
|
|
87
|
+
async pressEnter(name) {
|
|
88
|
+
const control = this.controls(name)[0];
|
|
89
|
+
await focus(control);
|
|
90
|
+
const prevented = await pressKey('Enter');
|
|
91
|
+
if (prevented || !submitsOnEnter(control))
|
|
92
|
+
return;
|
|
93
|
+
const button = defaultButton(this.form);
|
|
94
|
+
if (button) {
|
|
95
|
+
if (!button.disabled)
|
|
96
|
+
await click(button);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const fields = [...this.form.elements].filter(submitsOnEnter);
|
|
100
|
+
if (fields.length === 1)
|
|
101
|
+
await this.submit();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Submits it, as a press on its submit button does: the browser checks its constraints
|
|
105
|
+
* first, and a form that fails them doesn't submit.
|
|
106
|
+
*/
|
|
107
|
+
async submit() {
|
|
108
|
+
this.form.requestSubmit();
|
|
109
|
+
await settled();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Drives a `<NativeSelect>` from `@ember-joinery/ember`: the browser's own `<select>`, so it
|
|
4
|
+
* chooses an option the way the browser's menu does (`input` and `change` events). State comes
|
|
5
|
+
* from the element and its ARIA.
|
|
6
|
+
*
|
|
7
|
+
* const status = new NativeSelectHarness('status') // <NativeSelect @name="status">
|
|
8
|
+
* await status.select('done')
|
|
9
|
+
* assert.strictEqual(status.value, 'done')
|
|
10
|
+
* assert.strictEqual(status.selectedText, 'Done')
|
|
11
|
+
*/
|
|
12
|
+
export declare class NativeSelectHarness extends Harness {
|
|
13
|
+
static component: string;
|
|
14
|
+
/** The `<select>` itself (its root is the wrapper around it). */
|
|
15
|
+
get control(): HTMLSelectElement;
|
|
16
|
+
/** The icon at its end. */
|
|
17
|
+
get icon(): SVGSVGElement;
|
|
18
|
+
/** The value of the option chosen now (`''` for none). */
|
|
19
|
+
get value(): string;
|
|
20
|
+
/** The text of the option chosen now, or `''` for none. */
|
|
21
|
+
get selectedText(): string;
|
|
22
|
+
/** Every option's value, in order. */
|
|
23
|
+
get options(): string[];
|
|
24
|
+
/** Every option's text, in order. */
|
|
25
|
+
get optionTexts(): string[];
|
|
26
|
+
/** Every group's `label`, in order. */
|
|
27
|
+
get groups(): string[];
|
|
28
|
+
/** The values of the options in the group with this `label`, in order. */
|
|
29
|
+
optionsIn(group: string): string[];
|
|
30
|
+
/** Whether the option with this value can't be chosen (it, or its group, is `disabled`). */
|
|
31
|
+
isOptionDisabled(value: string): boolean;
|
|
32
|
+
/** Its `@size`: `default` or `sm`. */
|
|
33
|
+
get size(): string | null;
|
|
34
|
+
/**
|
|
35
|
+
* Its accessible name, as assistive technology reads it: `aria-labelledby`'s text, else
|
|
36
|
+
* `aria-label`, else its `<label>`'s text, else `title`.
|
|
37
|
+
*/
|
|
38
|
+
get label(): string;
|
|
39
|
+
/** The text of what its `aria-describedby` names (a field's description and errors), or `''`. */
|
|
40
|
+
get description(): string;
|
|
41
|
+
/** Whether it is `disabled`. */
|
|
42
|
+
get isDisabled(): boolean;
|
|
43
|
+
/** Whether it is `required`. */
|
|
44
|
+
get isRequired(): boolean;
|
|
45
|
+
/** Whether it is marked invalid with `aria-invalid`. */
|
|
46
|
+
get isInvalid(): boolean;
|
|
47
|
+
/** Whether it has focus. */
|
|
48
|
+
get isFocused(): boolean;
|
|
49
|
+
/** Chooses the option with this value. Fails when the select is disabled, as a user can't. */
|
|
50
|
+
select(value: string): Promise<void>;
|
|
51
|
+
/** Moves focus to it, as tabbing to it would. Fails if it can't take focus. */
|
|
52
|
+
focus(): Promise<void>;
|
|
53
|
+
/** Moves focus away from it. */
|
|
54
|
+
blur(): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=native-select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-select.d.ts","sourceRoot":"","sources":["../src/native-select.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC;;;;;;;;;GASG;AACH,qBAAa,mBAAoB,SAAQ,OAAO;IAC9C,OAAgB,SAAS,SAAkB;IAE3C,iEAAiE;IACjE,IAAI,OAAO,IAAI,iBAAiB,CAE/B;IAED,2BAA2B;IAC3B,IAAI,IAAI,IAAI,aAAa,CAExB;IAED,0DAA0D;IAC1D,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,2DAA2D;IAC3D,IAAI,YAAY,IAAI,MAAM,CAGzB;IAED,sCAAsC;IACtC,IAAI,OAAO,IAAI,MAAM,EAAE,CAEtB;IAED,qCAAqC;IACrC,IAAI,WAAW,IAAI,MAAM,EAAE,CAE1B;IAED,uCAAuC;IACvC,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAED,0EAA0E;IAC1E,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;IAOlC,4FAA4F;IAC5F,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAMxC,sCAAsC;IACtC,IAAI,IAAI,IAAI,MAAM,GAAG,IAAI,CAExB;IAED;;;OAGG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,iGAAiG;IACjG,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,gCAAgC;IAChC,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,gCAAgC;IAChC,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,wDAAwD;IACxD,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,4BAA4B;IAC5B,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,8FAA8F;IACxF,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,+EAA+E;IACzE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,gCAAgC;IAC1B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5B"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { blur, focus, select } from '@ember/test-helpers';
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
import { controlDescription, controlLabel, isMarkedInvalid, textOf } from "./-private/control.js";
|
|
4
|
+
/**
|
|
5
|
+
* Drives a `<NativeSelect>` from `@ember-joinery/ember`: the browser's own `<select>`, so it
|
|
6
|
+
* chooses an option the way the browser's menu does (`input` and `change` events). State comes
|
|
7
|
+
* from the element and its ARIA.
|
|
8
|
+
*
|
|
9
|
+
* const status = new NativeSelectHarness('status') // <NativeSelect @name="status">
|
|
10
|
+
* await status.select('done')
|
|
11
|
+
* assert.strictEqual(status.value, 'done')
|
|
12
|
+
* assert.strictEqual(status.selectedText, 'Done')
|
|
13
|
+
*/
|
|
14
|
+
export class NativeSelectHarness extends Harness {
|
|
15
|
+
static component = 'native-select';
|
|
16
|
+
/** The `<select>` itself (its root is the wrapper around it). */
|
|
17
|
+
get control() {
|
|
18
|
+
return this.part('select');
|
|
19
|
+
}
|
|
20
|
+
/** The icon at its end. */
|
|
21
|
+
get icon() {
|
|
22
|
+
return this.part('icon');
|
|
23
|
+
}
|
|
24
|
+
/** The value of the option chosen now (`''` for none). */
|
|
25
|
+
get value() {
|
|
26
|
+
return this.control.value;
|
|
27
|
+
}
|
|
28
|
+
/** The text of the option chosen now, or `''` for none. */
|
|
29
|
+
get selectedText() {
|
|
30
|
+
const option = this.control.selectedOptions[0];
|
|
31
|
+
return option ? textOf(option) : '';
|
|
32
|
+
}
|
|
33
|
+
/** Every option's value, in order. */
|
|
34
|
+
get options() {
|
|
35
|
+
return [...this.control.options].map(option => option.value);
|
|
36
|
+
}
|
|
37
|
+
/** Every option's text, in order. */
|
|
38
|
+
get optionTexts() {
|
|
39
|
+
return [...this.control.options].map(textOf);
|
|
40
|
+
}
|
|
41
|
+
/** Every group's `label`, in order. */
|
|
42
|
+
get groups() {
|
|
43
|
+
return [...this.control.querySelectorAll('optgroup')].map(group => group.label);
|
|
44
|
+
}
|
|
45
|
+
/** The values of the options in the group with this `label`, in order. */
|
|
46
|
+
optionsIn(group) {
|
|
47
|
+
const found = [...this.control.querySelectorAll('optgroup')].find(candidate => candidate.label === group);
|
|
48
|
+
return found ? [...found.querySelectorAll('option')].map(option => option.value) : [];
|
|
49
|
+
}
|
|
50
|
+
/** Whether the option with this value can't be chosen (it, or its group, is `disabled`). */
|
|
51
|
+
isOptionDisabled(value) {
|
|
52
|
+
const option = [...this.control.options].find(candidate => candidate.value === value);
|
|
53
|
+
if (!option)
|
|
54
|
+
throw new Error(`Joinery harness: no option "${value}" in ${this}`);
|
|
55
|
+
return option.disabled || Boolean(option.closest('optgroup')?.disabled);
|
|
56
|
+
}
|
|
57
|
+
/** Its `@size`: `default` or `sm`. */
|
|
58
|
+
get size() {
|
|
59
|
+
return this.element.getAttribute('data-size');
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Its accessible name, as assistive technology reads it: `aria-labelledby`'s text, else
|
|
63
|
+
* `aria-label`, else its `<label>`'s text, else `title`.
|
|
64
|
+
*/
|
|
65
|
+
get label() {
|
|
66
|
+
return controlLabel(this.control);
|
|
67
|
+
}
|
|
68
|
+
/** The text of what its `aria-describedby` names (a field's description and errors), or `''`. */
|
|
69
|
+
get description() {
|
|
70
|
+
return controlDescription(this.control);
|
|
71
|
+
}
|
|
72
|
+
/** Whether it is `disabled`. */
|
|
73
|
+
get isDisabled() {
|
|
74
|
+
return this.control.disabled;
|
|
75
|
+
}
|
|
76
|
+
/** Whether it is `required`. */
|
|
77
|
+
get isRequired() {
|
|
78
|
+
return this.control.required;
|
|
79
|
+
}
|
|
80
|
+
/** Whether it is marked invalid with `aria-invalid`. */
|
|
81
|
+
get isInvalid() {
|
|
82
|
+
return isMarkedInvalid(this.control);
|
|
83
|
+
}
|
|
84
|
+
/** Whether it has focus. */
|
|
85
|
+
get isFocused() {
|
|
86
|
+
return this.control.ownerDocument.activeElement === this.control;
|
|
87
|
+
}
|
|
88
|
+
/** Chooses the option with this value. Fails when the select is disabled, as a user can't. */
|
|
89
|
+
async select(value) {
|
|
90
|
+
await select(this.control, value);
|
|
91
|
+
}
|
|
92
|
+
/** Moves focus to it, as tabbing to it would. Fails if it can't take focus. */
|
|
93
|
+
async focus() {
|
|
94
|
+
await focus(this.control);
|
|
95
|
+
}
|
|
96
|
+
/** Moves focus away from it. */
|
|
97
|
+
async blur() {
|
|
98
|
+
await blur(this.control);
|
|
99
|
+
}
|
|
100
|
+
}
|