@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,83 @@
|
|
|
1
|
+
import { click, focus } from '@ember/test-helpers';
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
import { isShowing } from "./-private/showing.js";
|
|
4
|
+
function text(element) {
|
|
5
|
+
return (element.textContent ?? '').replace(/\s+/g, ' ').trim();
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Drives a `<Collapsible>`, from `@ember-joinery/ember` or, headless, from
|
|
9
|
+
* `@ember-joinery/primitives/collapsible`. Its state is read from the trigger's
|
|
10
|
+
* `aria-expanded`, so every test also checks what assistive technology hears.
|
|
11
|
+
*
|
|
12
|
+
* const details = new CollapsibleHarness('order') // <Collapsible @name="order">
|
|
13
|
+
* await details.open()
|
|
14
|
+
* assert.true(details.isOpen)
|
|
15
|
+
* assert.strictEqual(details.text, '100 Market St, San Francisco')
|
|
16
|
+
*/
|
|
17
|
+
export class CollapsibleHarness extends Harness {
|
|
18
|
+
static component = 'collapsible';
|
|
19
|
+
/** The trigger: `c.Trigger`, or your own element with `{{c.trigger}}`. */
|
|
20
|
+
get trigger() {
|
|
21
|
+
return this.part('trigger');
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The content's element, which is there (`hidden`) while closed. `null` before it renders.
|
|
25
|
+
* Content that sits inside another component, as in a `FieldGroup` (upstream's settings
|
|
26
|
+
* panel), is that component's part as far as the tree goes, so it is found through the
|
|
27
|
+
* element the trigger's `aria-controls` names instead.
|
|
28
|
+
*/
|
|
29
|
+
get content() {
|
|
30
|
+
const own = this.queryPart('content');
|
|
31
|
+
if (own)
|
|
32
|
+
return own;
|
|
33
|
+
const id = this.queryPart('trigger')?.getAttribute('aria-controls');
|
|
34
|
+
const controlled = id ? this.element.ownerDocument.getElementById(id) : null;
|
|
35
|
+
return controlled?.getAttribute('data-test-jn-part') === 'content' ? controlled : null;
|
|
36
|
+
}
|
|
37
|
+
/** Whether it is open, from the trigger's `aria-expanded`. */
|
|
38
|
+
get isOpen() {
|
|
39
|
+
return this.trigger.getAttribute('aria-expanded') === 'true';
|
|
40
|
+
}
|
|
41
|
+
/** Whether its content shows: open, or still animating out. */
|
|
42
|
+
get isShown() {
|
|
43
|
+
return isShowing(this.content);
|
|
44
|
+
}
|
|
45
|
+
/** Whether the trigger can't open or close it. */
|
|
46
|
+
get isDisabled() {
|
|
47
|
+
const trigger = this.trigger;
|
|
48
|
+
return trigger.hasAttribute('disabled') || trigger.hasAttribute('data-disabled');
|
|
49
|
+
}
|
|
50
|
+
/** The trigger's text, whitespace collapsed. */
|
|
51
|
+
get label() {
|
|
52
|
+
const trigger = this.trigger;
|
|
53
|
+
return trigger.getAttribute('aria-label')?.trim() || text(trigger);
|
|
54
|
+
}
|
|
55
|
+
/** The content's text, whitespace collapsed: `''` while it is closed. */
|
|
56
|
+
get text() {
|
|
57
|
+
const content = this.content;
|
|
58
|
+
return content && !content.hidden ? text(content) : '';
|
|
59
|
+
}
|
|
60
|
+
/** Whether the trigger names the content in `aria-controls`, as the ARIA pattern asks. */
|
|
61
|
+
get controlsContent() {
|
|
62
|
+
const content = this.content;
|
|
63
|
+
return Boolean(content?.id) && this.trigger.getAttribute('aria-controls') === content.id;
|
|
64
|
+
}
|
|
65
|
+
/** Clicks the trigger, as a user does. */
|
|
66
|
+
async toggle() {
|
|
67
|
+
await click(this.trigger);
|
|
68
|
+
}
|
|
69
|
+
/** Opens it with the trigger, unless it is open. */
|
|
70
|
+
async open() {
|
|
71
|
+
if (!this.isOpen)
|
|
72
|
+
await this.toggle();
|
|
73
|
+
}
|
|
74
|
+
/** Closes it with the trigger, unless it is closed. */
|
|
75
|
+
async close() {
|
|
76
|
+
if (this.isOpen)
|
|
77
|
+
await this.toggle();
|
|
78
|
+
}
|
|
79
|
+
/** Moves focus to the trigger. */
|
|
80
|
+
async focus() {
|
|
81
|
+
await focus(this.trigger);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { TestHooks } from './test-hooks.ts';
|
|
2
|
+
/** A color scheme the system can prefer. */
|
|
3
|
+
export type SystemColorScheme = 'light' | 'dark';
|
|
4
|
+
export interface ColorSchemeEmulation {
|
|
5
|
+
/** What the emulated system prefers now. */
|
|
6
|
+
readonly system: SystemColorScheme;
|
|
7
|
+
/** Changes what the system prefers, as switching the OS to dark mode would: listeners hear it. */
|
|
8
|
+
setSystem(scheme: SystemColorScheme): void;
|
|
9
|
+
/**
|
|
10
|
+
* What another tab does when the user picks a scheme there: saves it and sends the `storage`
|
|
11
|
+
* event. `null` clears the saved choice.
|
|
12
|
+
*/
|
|
13
|
+
fromAnotherTab(preference: string | null): void;
|
|
14
|
+
/** The saved choice, or `null`. */
|
|
15
|
+
readonly stored: string | null;
|
|
16
|
+
}
|
|
17
|
+
export interface SetupColorSchemeOptions {
|
|
18
|
+
/** What the system prefers at the start of each test. Default `light`. */
|
|
19
|
+
system?: SystemColorScheme;
|
|
20
|
+
/** The storage key the app's `ColorScheme` uses. Default `joinery-color-scheme`. */
|
|
21
|
+
storageKey?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Isolates each test from the color scheme around it: what the machine running the tests
|
|
25
|
+
* prefers, and a choice an earlier test saved. Before each test it clears the saved choice and
|
|
26
|
+
* makes `matchMedia('(prefers-color-scheme: …)')` answer from an emulated system preference
|
|
27
|
+
* instead of the real one; after each, it puts both back.
|
|
28
|
+
*
|
|
29
|
+
* module('dark mode', function (hooks) {
|
|
30
|
+
* setupRenderingTest(hooks)
|
|
31
|
+
* const scheme = setupColorScheme(hooks, { system: 'light' })
|
|
32
|
+
*
|
|
33
|
+
* test('it follows the system', async function (assert) {
|
|
34
|
+
* await render(<template><ModeToggle /></template>)
|
|
35
|
+
* scheme.setSystem('dark')
|
|
36
|
+
* await settled()
|
|
37
|
+
* assert.dom(document.documentElement).hasClass('dark')
|
|
38
|
+
* })
|
|
39
|
+
* })
|
|
40
|
+
*
|
|
41
|
+
* The app's `ColorScheme` is per owner, so it starts fresh in each test without help.
|
|
42
|
+
*/
|
|
43
|
+
export declare function setupColorScheme(hooks: TestHooks, options?: SetupColorSchemeOptions): ColorSchemeEmulation;
|
|
44
|
+
//# sourceMappingURL=color-scheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-scheme.d.ts","sourceRoot":"","sources":["../src/color-scheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD,4CAA4C;AAC5C,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,MAAM,CAAA;AAEhD,MAAM,WAAW,oBAAoB;IACnC,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAA;IAClC,kGAAkG;IAClG,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAA;IAC1C;;;OAGG;IACH,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAA;IAC/C,mCAAmC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CAC/B;AAED,MAAM,WAAW,uBAAuB;IACtC,0EAA0E;IAC1E,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAC1B,oFAAoF;IACpF,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AA2CD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,EAChB,OAAO,GAAE,uBAA4B,GACpC,oBAAoB,CAgEtB"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/** `@ember-joinery/primitives/color-scheme`'s default key (`COLOR_SCHEME_STORAGE_KEY`). */
|
|
2
|
+
const DEFAULT_STORAGE_KEY = 'joinery-color-scheme';
|
|
3
|
+
const QUERY = /^\(\s*prefers-color-scheme\s*:\s*(light|dark|no-preference)\s*\)$/;
|
|
4
|
+
/** A `MediaQueryList` for a `prefers-color-scheme` query, answered by the emulation. */
|
|
5
|
+
class EmulatedMediaQueryList extends EventTarget {
|
|
6
|
+
media;
|
|
7
|
+
#value;
|
|
8
|
+
#system;
|
|
9
|
+
onchange = null;
|
|
10
|
+
#legacy = new Set();
|
|
11
|
+
constructor(media, value, system) {
|
|
12
|
+
super();
|
|
13
|
+
this.media = media;
|
|
14
|
+
this.#value = value;
|
|
15
|
+
this.#system = system;
|
|
16
|
+
}
|
|
17
|
+
get matches() {
|
|
18
|
+
return this.#system() === this.#value;
|
|
19
|
+
}
|
|
20
|
+
addListener(listener) {
|
|
21
|
+
if (listener)
|
|
22
|
+
this.#legacy.add(listener);
|
|
23
|
+
}
|
|
24
|
+
removeListener(listener) {
|
|
25
|
+
if (listener)
|
|
26
|
+
this.#legacy.delete(listener);
|
|
27
|
+
}
|
|
28
|
+
/** Tells listeners the answer changed. */
|
|
29
|
+
notify() {
|
|
30
|
+
const event = new MediaQueryListEvent('change', { matches: this.matches, media: this.media });
|
|
31
|
+
this.dispatchEvent(event);
|
|
32
|
+
this.onchange?.call(this, event);
|
|
33
|
+
for (const listener of this.#legacy)
|
|
34
|
+
listener(event);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Isolates each test from the color scheme around it: what the machine running the tests
|
|
39
|
+
* prefers, and a choice an earlier test saved. Before each test it clears the saved choice and
|
|
40
|
+
* makes `matchMedia('(prefers-color-scheme: …)')` answer from an emulated system preference
|
|
41
|
+
* instead of the real one; after each, it puts both back.
|
|
42
|
+
*
|
|
43
|
+
* module('dark mode', function (hooks) {
|
|
44
|
+
* setupRenderingTest(hooks)
|
|
45
|
+
* const scheme = setupColorScheme(hooks, { system: 'light' })
|
|
46
|
+
*
|
|
47
|
+
* test('it follows the system', async function (assert) {
|
|
48
|
+
* await render(<template><ModeToggle /></template>)
|
|
49
|
+
* scheme.setSystem('dark')
|
|
50
|
+
* await settled()
|
|
51
|
+
* assert.dom(document.documentElement).hasClass('dark')
|
|
52
|
+
* })
|
|
53
|
+
* })
|
|
54
|
+
*
|
|
55
|
+
* The app's `ColorScheme` is per owner, so it starts fresh in each test without help.
|
|
56
|
+
*/
|
|
57
|
+
export function setupColorScheme(hooks, options = {}) {
|
|
58
|
+
const storageKey = options.storageKey ?? DEFAULT_STORAGE_KEY;
|
|
59
|
+
let system = options.system ?? 'light';
|
|
60
|
+
let lists = new Map();
|
|
61
|
+
let original;
|
|
62
|
+
const clear = () => {
|
|
63
|
+
try {
|
|
64
|
+
localStorage.removeItem(storageKey);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// storage is off; there is nothing saved
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
hooks.beforeEach(() => {
|
|
71
|
+
system = options.system ?? 'light';
|
|
72
|
+
lists = new Map();
|
|
73
|
+
clear();
|
|
74
|
+
const real = window.matchMedia;
|
|
75
|
+
original = real;
|
|
76
|
+
window.matchMedia = (query) => {
|
|
77
|
+
const match = QUERY.exec(query.trim());
|
|
78
|
+
if (!match)
|
|
79
|
+
return real.call(window, query);
|
|
80
|
+
let list = lists.get(query);
|
|
81
|
+
if (!list)
|
|
82
|
+
lists.set(query, (list = new EmulatedMediaQueryList(query, match[1], () => system)));
|
|
83
|
+
return list;
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
hooks.afterEach(() => {
|
|
87
|
+
if (original)
|
|
88
|
+
window.matchMedia = original;
|
|
89
|
+
original = undefined;
|
|
90
|
+
clear();
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
get system() {
|
|
94
|
+
return system;
|
|
95
|
+
},
|
|
96
|
+
setSystem(scheme) {
|
|
97
|
+
if (scheme === system)
|
|
98
|
+
return;
|
|
99
|
+
const before = new Map([...lists].map(([query, list]) => [query, list.matches]));
|
|
100
|
+
system = scheme;
|
|
101
|
+
for (const [query, list] of lists)
|
|
102
|
+
if (before.get(query) !== list.matches)
|
|
103
|
+
list.notify();
|
|
104
|
+
},
|
|
105
|
+
fromAnotherTab(preference) {
|
|
106
|
+
const oldValue = localStorage.getItem(storageKey);
|
|
107
|
+
if (preference === null)
|
|
108
|
+
localStorage.removeItem(storageKey);
|
|
109
|
+
else
|
|
110
|
+
localStorage.setItem(storageKey, preference);
|
|
111
|
+
window.dispatchEvent(new StorageEvent('storage', {
|
|
112
|
+
key: storageKey,
|
|
113
|
+
oldValue,
|
|
114
|
+
newValue: preference,
|
|
115
|
+
storageArea: localStorage,
|
|
116
|
+
url: location.href,
|
|
117
|
+
}));
|
|
118
|
+
},
|
|
119
|
+
get stored() {
|
|
120
|
+
return localStorage.getItem(storageKey);
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Drives a `<Combobox>` from `@ember-joinery/ember` or `@ember-joinery/primitives/combobox`: an
|
|
4
|
+
* input that filters a list of items. It reads the state from the input's ARIA and the items'
|
|
5
|
+
* (`aria-expanded`, `aria-activedescendant`, `aria-selected`), and acts as a user does: typing
|
|
6
|
+
* (with real `input` events, so the list filters and opens as it does for a person), the arrow
|
|
7
|
+
* keys, presses on items, chips and buttons.
|
|
8
|
+
*
|
|
9
|
+
* const framework = new ComboboxHarness('framework') // <Combobox @name="framework">
|
|
10
|
+
* await framework.type('sv')
|
|
11
|
+
* assert.deepEqual(framework.items, ['SvelteKit'])
|
|
12
|
+
* await framework.pressKey('ArrowDown')
|
|
13
|
+
* await framework.pressKey('Enter')
|
|
14
|
+
* assert.strictEqual(framework.inputValue, 'SvelteKit')
|
|
15
|
+
*
|
|
16
|
+
* Items are named by their label (`data-test-jn-value`). While the list is closed its items
|
|
17
|
+
* aren't in the page: read them after `open()` or `type()`.
|
|
18
|
+
*/
|
|
19
|
+
export declare class ComboboxHarness extends Harness {
|
|
20
|
+
#private;
|
|
21
|
+
static component: string;
|
|
22
|
+
/** The text input, or `null` while it is inside the closed popup. */
|
|
23
|
+
get input(): HTMLInputElement | null;
|
|
24
|
+
/** The button that opens and closes the list, or `null` without one. */
|
|
25
|
+
get trigger(): HTMLElement | null;
|
|
26
|
+
/** The clear button, or `null` while there's nothing to clear. */
|
|
27
|
+
get clearButton(): HTMLElement | null;
|
|
28
|
+
/** The popup, or `null` while it is closed. */
|
|
29
|
+
get content(): HTMLElement | null;
|
|
30
|
+
/** The `listbox`, or `null` while it is closed. */
|
|
31
|
+
get list(): HTMLElement | null;
|
|
32
|
+
/** Whether the list is open (`aria-expanded`). */
|
|
33
|
+
get isOpen(): boolean;
|
|
34
|
+
/** Whether the popup is showing in the browser's top layer. */
|
|
35
|
+
get isShown(): boolean;
|
|
36
|
+
/** The side the popup was placed on, after any flip (`data-side`). */
|
|
37
|
+
get side(): string | null;
|
|
38
|
+
/** The input's text. */
|
|
39
|
+
get inputValue(): string;
|
|
40
|
+
/** The input's accessible name: its label, `aria-label` or placeholder. */
|
|
41
|
+
get label(): string;
|
|
42
|
+
/** The text of what the input's `aria-describedby` names, or `''`. */
|
|
43
|
+
get description(): string;
|
|
44
|
+
/** The input's placeholder. */
|
|
45
|
+
get placeholder(): string;
|
|
46
|
+
/** Whether it is disabled. */
|
|
47
|
+
get isDisabled(): boolean;
|
|
48
|
+
/** Whether the input is marked invalid with `aria-invalid`. */
|
|
49
|
+
get isInvalid(): boolean;
|
|
50
|
+
/** Whether it is marked required (`aria-required`). */
|
|
51
|
+
get isRequired(): boolean;
|
|
52
|
+
/** Whether the input has focus. */
|
|
53
|
+
get isFocused(): boolean;
|
|
54
|
+
/** The items' elements, in order (while open). */
|
|
55
|
+
get itemElements(): HTMLElement[];
|
|
56
|
+
/** Every item's label (its `data-test-jn-value`), in order (while open). */
|
|
57
|
+
get items(): string[];
|
|
58
|
+
/** Every item's text, in order (while open). */
|
|
59
|
+
get itemTexts(): string[];
|
|
60
|
+
/** The item with this label. Throws when there is none. */
|
|
61
|
+
item(label: string): HTMLElement;
|
|
62
|
+
/** The label of the highlighted item (the input's `aria-activedescendant`), or `null`. */
|
|
63
|
+
get highlighted(): string | null;
|
|
64
|
+
/** Whether the item with this label is chosen (`aria-selected`). */
|
|
65
|
+
isItemSelected(label: string): boolean;
|
|
66
|
+
/** Whether the item with this label can't be chosen (`aria-disabled`). */
|
|
67
|
+
isItemDisabled(label: string): boolean;
|
|
68
|
+
/** Each group's label, in order (while open). */
|
|
69
|
+
get groups(): string[];
|
|
70
|
+
/** Whether nothing matches the query (the popup's `data-empty`). */
|
|
71
|
+
get isEmpty(): boolean;
|
|
72
|
+
/** What the Empty part says now (only while nothing matches), or `''`. */
|
|
73
|
+
get emptyText(): string;
|
|
74
|
+
/** The chips' labels, in order: the chosen items of a multiple combobox. */
|
|
75
|
+
get chips(): string[];
|
|
76
|
+
/** The chip with this label. */
|
|
77
|
+
chip(label: string): HTMLElement;
|
|
78
|
+
/** The values a form would get, from the hidden inputs (with `@formName`). */
|
|
79
|
+
get formValues(): string[];
|
|
80
|
+
/** Opens the list with a press on the input (or the trigger, when the input is in the popup). */
|
|
81
|
+
open(): Promise<void>;
|
|
82
|
+
/** Closes the list with Escape, unless it is closed. */
|
|
83
|
+
close(): Promise<void>;
|
|
84
|
+
/** A press on the trigger: it opens or closes the list. */
|
|
85
|
+
pressTrigger(): Promise<void>;
|
|
86
|
+
/** A press on the clear button. */
|
|
87
|
+
clear(): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Types `text` at the end of the input, a character at a time, as a person does: each makes
|
|
90
|
+
* an `input` event with `inputType: 'insertText'`, which filters and opens the list.
|
|
91
|
+
*/
|
|
92
|
+
type(text: string): Promise<void>;
|
|
93
|
+
/** Deletes the input's last `count` characters, as Backspace does. */
|
|
94
|
+
deleteBackward(count?: number): Promise<void>;
|
|
95
|
+
/** Replaces the input's text, as autofill or a paste does (which doesn't open the list). */
|
|
96
|
+
fill(text: string): Promise<void>;
|
|
97
|
+
/** Chooses the item with this label: opens the list unless open, then presses the item. */
|
|
98
|
+
select(label: string): Promise<void>;
|
|
99
|
+
/** Presses the item with this label (the list must be open). */
|
|
100
|
+
pressItem(label: string): Promise<void>;
|
|
101
|
+
/** Removes the chip with this label, with a press on its remove button. */
|
|
102
|
+
removeChip(label: string): Promise<void>;
|
|
103
|
+
/** Presses a key where focus is: the arrows, Enter, Escape, Backspace, Home or End. */
|
|
104
|
+
pressKey(key: string): Promise<void>;
|
|
105
|
+
/** Presses Escape where focus is. */
|
|
106
|
+
pressEscape(): Promise<void>;
|
|
107
|
+
/** A press outside the combobox and its popup. */
|
|
108
|
+
pressOutside(): Promise<void>;
|
|
109
|
+
/** Moves focus to the input. */
|
|
110
|
+
focus(): Promise<void>;
|
|
111
|
+
/** Moves focus away from the input. */
|
|
112
|
+
blur(): Promise<void>;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=combobox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combobox.d.ts","sourceRoot":"","sources":["../src/combobox.ts"],"names":[],"mappings":"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"}
|
package/dist/combobox.js
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { blur, focus, settled, triggerEvent } from '@ember/test-helpers';
|
|
2
|
+
import { Harness } from "./harness.js";
|
|
3
|
+
import { pressKey } from "./focus.js";
|
|
4
|
+
import { pressEscape, pressOutside, press } from "./layers.js";
|
|
5
|
+
import { shownInTopLayer, text } from "./-private/overlay.js";
|
|
6
|
+
import { controlDescription, controlLabel, isMarkedInvalid } from "./-private/control.js";
|
|
7
|
+
/** Dispatches an `input` event the way typing makes one, with its `inputType`. */
|
|
8
|
+
function inputEvent(input, inputType, data) {
|
|
9
|
+
input.dispatchEvent(new InputEvent('input', { bubbles: true, inputType, data }));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A press on a button that keeps focus where it is (its `mousedown` is prevented), as the
|
|
13
|
+
* trigger, the clear button and a chip's remove button do: `click()` would focus it.
|
|
14
|
+
*/
|
|
15
|
+
async function pressInPlace(element) {
|
|
16
|
+
await triggerEvent(element, 'pointerdown', { pointerType: 'mouse', button: 0 });
|
|
17
|
+
await triggerEvent(element, 'mousedown', { button: 0 });
|
|
18
|
+
await triggerEvent(element, 'pointerup', { pointerType: 'mouse', button: 0 });
|
|
19
|
+
await triggerEvent(element, 'mouseup', { button: 0 });
|
|
20
|
+
await triggerEvent(element, 'click', { button: 0 });
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Drives a `<Combobox>` from `@ember-joinery/ember` or `@ember-joinery/primitives/combobox`: an
|
|
24
|
+
* input that filters a list of items. It reads the state from the input's ARIA and the items'
|
|
25
|
+
* (`aria-expanded`, `aria-activedescendant`, `aria-selected`), and acts as a user does: typing
|
|
26
|
+
* (with real `input` events, so the list filters and opens as it does for a person), the arrow
|
|
27
|
+
* keys, presses on items, chips and buttons.
|
|
28
|
+
*
|
|
29
|
+
* const framework = new ComboboxHarness('framework') // <Combobox @name="framework">
|
|
30
|
+
* await framework.type('sv')
|
|
31
|
+
* assert.deepEqual(framework.items, ['SvelteKit'])
|
|
32
|
+
* await framework.pressKey('ArrowDown')
|
|
33
|
+
* await framework.pressKey('Enter')
|
|
34
|
+
* assert.strictEqual(framework.inputValue, 'SvelteKit')
|
|
35
|
+
*
|
|
36
|
+
* Items are named by their label (`data-test-jn-value`). While the list is closed its items
|
|
37
|
+
* aren't in the page: read them after `open()` or `type()`.
|
|
38
|
+
*/
|
|
39
|
+
export class ComboboxHarness extends Harness {
|
|
40
|
+
static component = 'combobox';
|
|
41
|
+
/** The text input, or `null` while it is inside the closed popup. */
|
|
42
|
+
get input() {
|
|
43
|
+
return this.queryPart('input');
|
|
44
|
+
}
|
|
45
|
+
#input() {
|
|
46
|
+
const input = this.input;
|
|
47
|
+
if (!input)
|
|
48
|
+
throw new Error(`Joinery harness: ${this} has no input showing`);
|
|
49
|
+
return input;
|
|
50
|
+
}
|
|
51
|
+
/** The button that opens and closes the list, or `null` without one. */
|
|
52
|
+
get trigger() {
|
|
53
|
+
return this.queryPart('trigger');
|
|
54
|
+
}
|
|
55
|
+
/** The clear button, or `null` while there's nothing to clear. */
|
|
56
|
+
get clearButton() {
|
|
57
|
+
return this.queryPart('clear');
|
|
58
|
+
}
|
|
59
|
+
/** The popup, or `null` while it is closed. */
|
|
60
|
+
get content() {
|
|
61
|
+
return this.queryPart('content');
|
|
62
|
+
}
|
|
63
|
+
/** The `listbox`, or `null` while it is closed. */
|
|
64
|
+
get list() {
|
|
65
|
+
return this.queryPart('list');
|
|
66
|
+
}
|
|
67
|
+
/** The element whose `aria-expanded` says whether it's open: the input, or the trigger when the input is in the popup. */
|
|
68
|
+
get #combobox() {
|
|
69
|
+
const trigger = this.trigger;
|
|
70
|
+
if (trigger?.getAttribute('role') === 'combobox')
|
|
71
|
+
return trigger;
|
|
72
|
+
return this.input ?? trigger;
|
|
73
|
+
}
|
|
74
|
+
/** Whether the list is open (`aria-expanded`). */
|
|
75
|
+
get isOpen() {
|
|
76
|
+
return this.#combobox.getAttribute('aria-expanded') === 'true';
|
|
77
|
+
}
|
|
78
|
+
/** Whether the popup is showing in the browser's top layer. */
|
|
79
|
+
get isShown() {
|
|
80
|
+
return shownInTopLayer(this.content);
|
|
81
|
+
}
|
|
82
|
+
/** The side the popup was placed on, after any flip (`data-side`). */
|
|
83
|
+
get side() {
|
|
84
|
+
return this.content?.getAttribute('data-side') ?? null;
|
|
85
|
+
}
|
|
86
|
+
/** The input's text. */
|
|
87
|
+
get inputValue() {
|
|
88
|
+
return this.input?.value ?? '';
|
|
89
|
+
}
|
|
90
|
+
/** The input's accessible name: its label, `aria-label` or placeholder. */
|
|
91
|
+
get label() {
|
|
92
|
+
const input = this.input;
|
|
93
|
+
return input ? controlLabel(input) : '';
|
|
94
|
+
}
|
|
95
|
+
/** The text of what the input's `aria-describedby` names, or `''`. */
|
|
96
|
+
get description() {
|
|
97
|
+
const input = this.input;
|
|
98
|
+
return input ? controlDescription(input) : '';
|
|
99
|
+
}
|
|
100
|
+
/** The input's placeholder. */
|
|
101
|
+
get placeholder() {
|
|
102
|
+
return this.input?.placeholder ?? '';
|
|
103
|
+
}
|
|
104
|
+
/** Whether it is disabled. */
|
|
105
|
+
get isDisabled() {
|
|
106
|
+
return this.input?.disabled ?? this.trigger?.hasAttribute('disabled') ?? false;
|
|
107
|
+
}
|
|
108
|
+
/** Whether the input is marked invalid with `aria-invalid`. */
|
|
109
|
+
get isInvalid() {
|
|
110
|
+
const input = this.input;
|
|
111
|
+
return input ? isMarkedInvalid(input) : false;
|
|
112
|
+
}
|
|
113
|
+
/** Whether it is marked required (`aria-required`). */
|
|
114
|
+
get isRequired() {
|
|
115
|
+
return this.#combobox.getAttribute('aria-required') === 'true';
|
|
116
|
+
}
|
|
117
|
+
/** Whether the input has focus. */
|
|
118
|
+
get isFocused() {
|
|
119
|
+
return document.activeElement === this.input;
|
|
120
|
+
}
|
|
121
|
+
/** The items' elements, in order (while open). */
|
|
122
|
+
get itemElements() {
|
|
123
|
+
return this.parts('item');
|
|
124
|
+
}
|
|
125
|
+
/** Every item's label (its `data-test-jn-value`), in order (while open). */
|
|
126
|
+
get items() {
|
|
127
|
+
return this.values('item');
|
|
128
|
+
}
|
|
129
|
+
/** Every item's text, in order (while open). */
|
|
130
|
+
get itemTexts() {
|
|
131
|
+
return this.itemElements.map(item => text(item));
|
|
132
|
+
}
|
|
133
|
+
/** The item with this label. Throws when there is none. */
|
|
134
|
+
item(label) {
|
|
135
|
+
return this.part('item', label);
|
|
136
|
+
}
|
|
137
|
+
/** The label of the highlighted item (the input's `aria-activedescendant`), or `null`. */
|
|
138
|
+
get highlighted() {
|
|
139
|
+
const id = (this.input ?? this.#combobox).getAttribute('aria-activedescendant');
|
|
140
|
+
const item = id ? document.getElementById(id) : null;
|
|
141
|
+
return item?.getAttribute('data-test-jn-value') ?? null;
|
|
142
|
+
}
|
|
143
|
+
/** Whether the item with this label is chosen (`aria-selected`). */
|
|
144
|
+
isItemSelected(label) {
|
|
145
|
+
return this.item(label).getAttribute('aria-selected') === 'true';
|
|
146
|
+
}
|
|
147
|
+
/** Whether the item with this label can't be chosen (`aria-disabled`). */
|
|
148
|
+
isItemDisabled(label) {
|
|
149
|
+
return this.item(label).getAttribute('aria-disabled') === 'true';
|
|
150
|
+
}
|
|
151
|
+
/** Each group's label, in order (while open). */
|
|
152
|
+
get groups() {
|
|
153
|
+
return this.parts('group').map(group => {
|
|
154
|
+
const id = group.getAttribute('aria-labelledby');
|
|
155
|
+
return id ? text(document.getElementById(id)) : '';
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/** Whether nothing matches the query (the popup's `data-empty`). */
|
|
159
|
+
get isEmpty() {
|
|
160
|
+
return this.content?.hasAttribute('data-empty') ?? false;
|
|
161
|
+
}
|
|
162
|
+
/** What the Empty part says now (only while nothing matches), or `''`. */
|
|
163
|
+
get emptyText() {
|
|
164
|
+
return text(this.queryPart('empty'));
|
|
165
|
+
}
|
|
166
|
+
/** The chips' labels, in order: the chosen items of a multiple combobox. */
|
|
167
|
+
get chips() {
|
|
168
|
+
return this.values('chip');
|
|
169
|
+
}
|
|
170
|
+
/** The chip with this label. */
|
|
171
|
+
chip(label) {
|
|
172
|
+
return this.part('chip', label);
|
|
173
|
+
}
|
|
174
|
+
/** The values a form would get, from the hidden inputs (with `@formName`). */
|
|
175
|
+
get formValues() {
|
|
176
|
+
return this.parts('form-value').map(input => input.value);
|
|
177
|
+
}
|
|
178
|
+
/** Opens the list with a press on the input (or the trigger, when the input is in the popup). */
|
|
179
|
+
async open() {
|
|
180
|
+
if (this.isOpen)
|
|
181
|
+
return;
|
|
182
|
+
const input = this.input;
|
|
183
|
+
if (input) {
|
|
184
|
+
await focus(input);
|
|
185
|
+
await triggerEvent(input, 'mousedown', { button: 0 });
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
await this.pressTrigger();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/** Closes the list with Escape, unless it is closed. */
|
|
192
|
+
async close() {
|
|
193
|
+
if (this.isOpen)
|
|
194
|
+
await pressEscape();
|
|
195
|
+
}
|
|
196
|
+
/** A press on the trigger: it opens or closes the list. */
|
|
197
|
+
async pressTrigger() {
|
|
198
|
+
const trigger = this.trigger;
|
|
199
|
+
if (!trigger)
|
|
200
|
+
throw new Error(`Joinery harness: ${this} has no trigger`);
|
|
201
|
+
// A trigger beside the input keeps focus in the input; one that opens a popup with the
|
|
202
|
+
// input inside takes focus, as a button does.
|
|
203
|
+
if (trigger.getAttribute('role') === 'combobox') {
|
|
204
|
+
// The press focuses it before the popup opens and moves focus inside.
|
|
205
|
+
await focus(trigger);
|
|
206
|
+
await triggerEvent(trigger, 'mousedown', { button: 0 });
|
|
207
|
+
await triggerEvent(trigger, 'mouseup', { button: 0 });
|
|
208
|
+
await triggerEvent(trigger, 'click', { button: 0 });
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
await pressInPlace(trigger);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/** A press on the clear button. */
|
|
215
|
+
async clear() {
|
|
216
|
+
const button = this.clearButton;
|
|
217
|
+
if (!button)
|
|
218
|
+
throw new Error(`Joinery harness: ${this} has nothing to clear`);
|
|
219
|
+
await pressInPlace(button);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Types `text` at the end of the input, a character at a time, as a person does: each makes
|
|
223
|
+
* an `input` event with `inputType: 'insertText'`, which filters and opens the list.
|
|
224
|
+
*/
|
|
225
|
+
async type(text) {
|
|
226
|
+
const input = this.#input();
|
|
227
|
+
if (document.activeElement !== input)
|
|
228
|
+
await focus(input);
|
|
229
|
+
for (const character of text) {
|
|
230
|
+
await triggerEvent(input, 'keydown', { key: character });
|
|
231
|
+
input.value += character;
|
|
232
|
+
inputEvent(input, 'insertText', character);
|
|
233
|
+
await settled();
|
|
234
|
+
await triggerEvent(input, 'keyup', { key: character });
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/** Deletes the input's last `count` characters, as Backspace does. */
|
|
238
|
+
async deleteBackward(count = 1) {
|
|
239
|
+
const input = this.#input();
|
|
240
|
+
if (document.activeElement !== input)
|
|
241
|
+
await focus(input);
|
|
242
|
+
for (let i = 0; i < count && input.value; i += 1) {
|
|
243
|
+
input.value = input.value.slice(0, -1);
|
|
244
|
+
inputEvent(input, 'deleteContentBackward', null);
|
|
245
|
+
await settled();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/** Replaces the input's text, as autofill or a paste does (which doesn't open the list). */
|
|
249
|
+
async fill(text) {
|
|
250
|
+
const input = this.#input();
|
|
251
|
+
if (document.activeElement !== input)
|
|
252
|
+
await focus(input);
|
|
253
|
+
input.value = text;
|
|
254
|
+
inputEvent(input, 'insertReplacementText', text);
|
|
255
|
+
await settled();
|
|
256
|
+
}
|
|
257
|
+
/** Chooses the item with this label: opens the list unless open, then presses the item. */
|
|
258
|
+
async select(label) {
|
|
259
|
+
await this.open();
|
|
260
|
+
await press(this.item(label));
|
|
261
|
+
}
|
|
262
|
+
/** Presses the item with this label (the list must be open). */
|
|
263
|
+
async pressItem(label) {
|
|
264
|
+
await press(this.item(label));
|
|
265
|
+
}
|
|
266
|
+
/** Removes the chip with this label, with a press on its remove button. */
|
|
267
|
+
async removeChip(label) {
|
|
268
|
+
const remove = this.chip(label).querySelector('[data-test-jn-part="chip-remove"]');
|
|
269
|
+
if (!remove)
|
|
270
|
+
throw new Error(`Joinery harness: chip "${label}" in ${this} has no remove button`);
|
|
271
|
+
await pressInPlace(remove);
|
|
272
|
+
}
|
|
273
|
+
/** Presses a key where focus is: the arrows, Enter, Escape, Backspace, Home or End. */
|
|
274
|
+
async pressKey(key) {
|
|
275
|
+
await pressKey(key);
|
|
276
|
+
}
|
|
277
|
+
/** Presses Escape where focus is. */
|
|
278
|
+
async pressEscape() {
|
|
279
|
+
await pressEscape();
|
|
280
|
+
}
|
|
281
|
+
/** A press outside the combobox and its popup. */
|
|
282
|
+
async pressOutside() {
|
|
283
|
+
await pressOutside();
|
|
284
|
+
}
|
|
285
|
+
/** Moves focus to the input. */
|
|
286
|
+
async focus() {
|
|
287
|
+
await focus(this.#input());
|
|
288
|
+
}
|
|
289
|
+
/** Moves focus away from the input. */
|
|
290
|
+
async blur() {
|
|
291
|
+
await blur(this.#input());
|
|
292
|
+
}
|
|
293
|
+
}
|