@gtkx/testing 0.21.0 → 1.0.0-rc.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/README.md +137 -34
- package/dist/act.d.ts +19 -0
- package/dist/act.d.ts.map +1 -0
- package/dist/act.js +48 -0
- package/dist/act.js.map +1 -0
- package/dist/bound-queries.d.ts +32 -0
- package/dist/bound-queries.d.ts.map +1 -0
- package/dist/bound-queries.js +2 -0
- package/dist/bound-queries.js.map +1 -0
- package/dist/build-queries.d.ts +16 -0
- package/dist/build-queries.d.ts.map +1 -0
- package/dist/build-queries.js +103 -0
- package/dist/build-queries.js.map +1 -0
- package/dist/cleanup-registry.d.ts +4 -0
- package/dist/cleanup-registry.d.ts.map +1 -0
- package/dist/cleanup-registry.js +11 -0
- package/dist/cleanup-registry.js.map +1 -0
- package/dist/config.d.ts +18 -51
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +9 -40
- package/dist/config.js.map +1 -1
- package/dist/editable.d.ts +7 -0
- package/dist/editable.d.ts.map +1 -0
- package/dist/editable.js +24 -0
- package/dist/editable.js.map +1 -0
- package/dist/errors.d.ts +29 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +119 -0
- package/dist/errors.js.map +1 -0
- package/dist/fire-event.d.ts +7 -25
- package/dist/fire-event.d.ts.map +1 -1
- package/dist/fire-event.js +9 -29
- package/dist/fire-event.js.map +1 -1
- package/dist/frame-sync.d.ts +3 -0
- package/dist/frame-sync.d.ts.map +1 -0
- package/dist/frame-sync.js +30 -0
- package/dist/frame-sync.js.map +1 -0
- package/dist/index.d.ts +16 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -6
- package/dist/index.js.map +1 -1
- package/dist/matchers.d.ts +55 -0
- package/dist/matchers.d.ts.map +1 -0
- package/dist/matchers.js +103 -0
- package/dist/matchers.js.map +1 -0
- package/dist/pretty-widget.d.ts +21 -25
- package/dist/pretty-widget.d.ts.map +1 -1
- package/dist/pretty-widget.js +69 -115
- package/dist/pretty-widget.js.map +1 -1
- package/dist/queries.d.ts +130 -177
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +212 -325
- package/dist/queries.js.map +1 -1
- package/dist/register-test-hooks.d.ts +2 -0
- package/dist/register-test-hooks.d.ts.map +1 -0
- package/dist/register-test-hooks.js +15 -0
- package/dist/register-test-hooks.js.map +1 -0
- package/dist/render-hook.d.ts +14 -35
- package/dist/render-hook.d.ts.map +1 -1
- package/dist/render-hook.js +8 -45
- package/dist/render-hook.js.map +1 -1
- package/dist/render.d.ts +11 -41
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +129 -118
- package/dist/render.js.map +1 -1
- package/dist/role-helpers.d.ts +16 -51
- package/dist/role-helpers.d.ts.map +1 -1
- package/dist/role-helpers.js +39 -58
- package/dist/role-helpers.js.map +1 -1
- package/dist/screen.d.ts +6 -63
- package/dist/screen.d.ts.map +1 -1
- package/dist/screen.js +21 -109
- package/dist/screen.js.map +1 -1
- package/dist/screenshot.d.ts +20 -23
- package/dist/screenshot.d.ts.map +1 -1
- package/dist/screenshot.js +89 -48
- package/dist/screenshot.js.map +1 -1
- package/dist/suggestions.d.ts +22 -0
- package/dist/suggestions.d.ts.map +1 -0
- package/dist/suggestions.js +56 -0
- package/dist/suggestions.js.map +1 -0
- package/dist/traversal.d.ts +10 -8
- package/dist/traversal.d.ts.map +1 -1
- package/dist/traversal.js +28 -13
- package/dist/traversal.js.map +1 -1
- package/dist/types.d.ts +103 -172
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/user-event/adjustment.d.ts +8 -0
- package/dist/user-event/adjustment.d.ts.map +1 -0
- package/dist/user-event/adjustment.js +33 -0
- package/dist/user-event/adjustment.js.map +1 -0
- package/dist/user-event/click.d.ts +7 -0
- package/dist/user-event/click.d.ts.map +1 -0
- package/dist/user-event/click.js +65 -0
- package/dist/user-event/click.js.map +1 -0
- package/dist/user-event/controller.d.ts +7 -0
- package/dist/user-event/controller.d.ts.map +1 -0
- package/dist/user-event/controller.js +28 -0
- package/dist/user-event/controller.js.map +1 -0
- package/dist/user-event/dispatch.d.ts +7 -0
- package/dist/user-event/dispatch.d.ts.map +1 -0
- package/dist/user-event/dispatch.js +10 -0
- package/dist/user-event/dispatch.js.map +1 -0
- package/dist/user-event/event-wrapper.d.ts +3 -0
- package/dist/user-event/event-wrapper.d.ts.map +1 -0
- package/dist/user-event/event-wrapper.js +48 -0
- package/dist/user-event/event-wrapper.js.map +1 -0
- package/dist/user-event/gesture.d.ts +31 -0
- package/dist/user-event/gesture.d.ts.map +1 -0
- package/dist/user-event/gesture.js +105 -0
- package/dist/user-event/gesture.js.map +1 -0
- package/dist/user-event/index.d.ts +44 -0
- package/dist/user-event/index.d.ts.map +1 -0
- package/dist/user-event/index.js +38 -0
- package/dist/user-event/index.js.map +1 -0
- package/dist/user-event/keyboard.d.ts +9 -0
- package/dist/user-event/keyboard.d.ts.map +1 -0
- package/dist/user-event/keyboard.js +173 -0
- package/dist/user-event/keyboard.js.map +1 -0
- package/dist/user-event/pointer.d.ts +6 -0
- package/dist/user-event/pointer.d.ts.map +1 -0
- package/dist/user-event/pointer.js +27 -0
- package/dist/user-event/pointer.js.map +1 -0
- package/dist/user-event/selection.d.ts +4 -0
- package/dist/user-event/selection.d.ts.map +1 -0
- package/dist/user-event/selection.js +106 -0
- package/dist/user-event/selection.js.map +1 -0
- package/dist/user-event/state.d.ts +6 -0
- package/dist/user-event/state.d.ts.map +1 -0
- package/dist/user-event/state.js +2 -0
- package/dist/user-event/state.js.map +1 -0
- package/dist/user-event/text.d.ts +17 -0
- package/dist/user-event/text.d.ts.map +1 -0
- package/dist/user-event/text.js +107 -0
- package/dist/user-event/text.js.map +1 -0
- package/dist/wait-for.d.ts +13 -33
- package/dist/wait-for.d.ts.map +1 -1
- package/dist/wait-for.js +62 -73
- package/dist/wait-for.js.map +1 -1
- package/dist/widget-accessible-properties.d.ts +33 -0
- package/dist/widget-accessible-properties.d.ts.map +1 -0
- package/dist/widget-accessible-properties.js +215 -0
- package/dist/widget-accessible-properties.js.map +1 -0
- package/dist/within.d.ts +9 -26
- package/dist/within.d.ts.map +1 -1
- package/dist/within.js +15 -25
- package/dist/within.js.map +1 -1
- package/package.json +21 -12
- package/src/act.ts +68 -0
- package/src/bound-queries.ts +36 -0
- package/src/build-queries.ts +185 -0
- package/src/cleanup-registry.ts +14 -0
- package/src/config.ts +28 -59
- package/src/editable.ts +30 -0
- package/src/errors.ts +130 -0
- package/src/fire-event.ts +11 -38
- package/src/frame-sync.ts +34 -0
- package/src/index.ts +56 -14
- package/src/matchers.ts +200 -0
- package/src/pretty-widget.ts +99 -138
- package/src/queries.ts +320 -420
- package/src/register-test-hooks.ts +16 -0
- package/src/render-hook.tsx +31 -44
- package/src/render.tsx +161 -149
- package/src/role-helpers.ts +47 -67
- package/src/screen.ts +21 -114
- package/src/screenshot.ts +104 -55
- package/src/suggestions.ts +87 -0
- package/src/traversal.ts +32 -18
- package/src/types.ts +115 -176
- package/src/user-event/adjustment.ts +49 -0
- package/src/user-event/click.ts +70 -0
- package/src/user-event/controller.ts +44 -0
- package/src/user-event/dispatch.ts +23 -0
- package/src/user-event/event-wrapper.ts +54 -0
- package/src/user-event/gesture.ts +154 -0
- package/src/user-event/index.ts +74 -0
- package/src/user-event/keyboard.ts +204 -0
- package/src/user-event/pointer.ts +34 -0
- package/src/user-event/selection.ts +122 -0
- package/src/user-event/state.ts +6 -0
- package/src/user-event/text.ts +137 -0
- package/src/wait-for.ts +79 -81
- package/src/widget-accessible-properties.ts +244 -0
- package/src/within.ts +26 -27
- package/dist/bind-queries.d.ts +0 -14
- package/dist/bind-queries.d.ts.map +0 -1
- package/dist/bind-queries.js +0 -29
- package/dist/bind-queries.js.map +0 -1
- package/dist/error-builder.d.ts +0 -28
- package/dist/error-builder.d.ts.map +0 -1
- package/dist/error-builder.js +0 -81
- package/dist/error-builder.js.map +0 -1
- package/dist/timing.d.ts +0 -18
- package/dist/timing.d.ts.map +0 -1
- package/dist/timing.js +0 -18
- package/dist/timing.js.map +0 -1
- package/dist/user-event.d.ts +0 -138
- package/dist/user-event.d.ts.map +0 -1
- package/dist/user-event.js +0 -411
- package/dist/user-event.js.map +0 -1
- package/dist/widget-text.d.ts +0 -69
- package/dist/widget-text.d.ts.map +0 -1
- package/dist/widget-text.js +0 -177
- package/dist/widget-text.js.map +0 -1
- package/dist/widget.d.ts +0 -3
- package/dist/widget.d.ts.map +0 -1
- package/dist/widget.js +0 -13
- package/dist/widget.js.map +0 -1
- package/src/bind-queries.ts +0 -52
- package/src/error-builder.ts +0 -102
- package/src/timing.ts +0 -17
- package/src/user-event.ts +0 -492
- package/src/widget-text.ts +0 -202
- package/src/widget.ts +0 -15
package/dist/config.js
CHANGED
|
@@ -1,60 +1,29 @@
|
|
|
1
1
|
const defaultGetElementError = (message, _container) => {
|
|
2
|
-
|
|
2
|
+
const error = new Error(message);
|
|
3
|
+
error.name = "GtkxElementError";
|
|
4
|
+
return error;
|
|
3
5
|
};
|
|
4
6
|
const defaultConfig = {
|
|
5
|
-
|
|
7
|
+
throwSuggestions: false,
|
|
6
8
|
getElementError: defaultGetElementError,
|
|
7
9
|
asyncUtilTimeout: 1000,
|
|
10
|
+
actionabilityTimeout: 500,
|
|
8
11
|
};
|
|
9
12
|
let currentConfig = { ...defaultConfig };
|
|
10
13
|
/**
|
|
11
|
-
* Returns the current testing
|
|
12
|
-
*
|
|
13
|
-
* @returns The current configuration object
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* import { getConfig } from "@gtkx/testing";
|
|
18
|
-
*
|
|
19
|
-
* const config = getConfig();
|
|
20
|
-
* console.log(config.showSuggestions);
|
|
21
|
-
* ```
|
|
14
|
+
* Returns the current global testing configuration.
|
|
22
15
|
*/
|
|
23
16
|
export const getConfig = () => {
|
|
24
17
|
return currentConfig;
|
|
25
18
|
};
|
|
26
19
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* Accepts either a partial configuration object or a function that receives
|
|
30
|
-
* the current configuration and returns updates.
|
|
31
|
-
*
|
|
32
|
-
* @param newConfig - Partial configuration or updater function
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```tsx
|
|
36
|
-
* import { configure } from "@gtkx/testing";
|
|
20
|
+
* Merges the given overrides into the global testing configuration.
|
|
37
21
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* // Use updater function
|
|
42
|
-
* configure((current) => ({
|
|
43
|
-
* showSuggestions: !current.showSuggestions,
|
|
44
|
-
* }));
|
|
45
|
-
* ```
|
|
22
|
+
* @param newConfig Either a partial config object or a function that receives
|
|
23
|
+
* the current config and returns the fields to override.
|
|
46
24
|
*/
|
|
47
25
|
export const configure = (newConfig) => {
|
|
48
26
|
const updates = typeof newConfig === "function" ? newConfig(currentConfig) : newConfig;
|
|
49
27
|
currentConfig = { ...currentConfig, ...updates };
|
|
50
28
|
};
|
|
51
|
-
/**
|
|
52
|
-
* Resets configuration to defaults.
|
|
53
|
-
* Primarily used for testing.
|
|
54
|
-
*
|
|
55
|
-
* @internal
|
|
56
|
-
*/
|
|
57
|
-
export const resetConfig = () => {
|
|
58
|
-
currentConfig = { ...defaultConfig };
|
|
59
|
-
};
|
|
60
29
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AA0BA,MAAM,sBAAsB,GAAG,CAAC,OAAe,EAAE,UAAsB,EAAS,EAAE;IAC9E,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IACjC,KAAK,CAAC,IAAI,GAAG,kBAAkB,CAAC;IAChC,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,aAAa,GAAW;IAC1B,gBAAgB,EAAE,KAAK;IACvB,eAAe,EAAE,sBAAsB;IACvC,gBAAgB,EAAE,IAAI;IACtB,oBAAoB,EAAE,GAAG;CAC5B,CAAC;AAEF,IAAI,aAAa,GAAW,EAAE,GAAG,aAAa,EAAE,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,GAAW,EAAE;IAClC,OAAO,aAAa,CAAC;AACzB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,SAAqC,EAAQ,EAAE;IACrE,MAAM,OAAO,GAAG,OAAO,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACvF,aAAa,GAAG,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,EAAE,CAAC;AACrD,CAAC,CAAC","sourcesContent":["import type { Container } from \"./traversal.js\";\n\n/**\n * Global configuration for the testing harness, controlling query behavior,\n * error formatting, and the timeouts used by async utilities and actionability\n * checks.\n */\nexport type Config = {\n throwSuggestions: boolean;\n\n /** Builds the error thrown when a query fails, given a message and optional container. */\n getElementError: (message: string, container?: Container) => Error;\n\n /** Default timeout in milliseconds for async utilities such as waitFor. */\n asyncUtilTimeout: number;\n\n /** Timeout in milliseconds for waiting on a widget to become actionable. */\n actionabilityTimeout: number;\n};\n\n/**\n * Function form of a configuration update: receives the current config and\n * returns the fields to override.\n */\nexport type ConfigFn = (existingConfig: Config) => Partial<Config>;\n\nconst defaultGetElementError = (message: string, _container?: Container): Error => {\n const error = new Error(message);\n error.name = \"GtkxElementError\";\n return error;\n};\n\nconst defaultConfig: Config = {\n throwSuggestions: false,\n getElementError: defaultGetElementError,\n asyncUtilTimeout: 1000,\n actionabilityTimeout: 500,\n};\n\nlet currentConfig: Config = { ...defaultConfig };\n\n/**\n * Returns the current global testing configuration.\n */\nexport const getConfig = (): Config => {\n return currentConfig;\n};\n\n/**\n * Merges the given overrides into the global testing configuration.\n *\n * @param newConfig Either a partial config object or a function that receives\n * the current config and returns the fields to override.\n */\nexport const configure = (newConfig: Partial<Config> | ConfigFn): void => {\n const updates = typeof newConfig === \"function\" ? newConfig(currentConfig) : newConfig;\n currentConfig = { ...currentConfig, ...updates };\n};\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
+
export type EditableTarget = Gtk.Editable | Gtk.TextView;
|
|
3
|
+
export declare const EDITABLE_ROLES: Set<Gtk.AccessibleRole>;
|
|
4
|
+
export declare const isEditable: (widget: unknown) => widget is EditableTarget;
|
|
5
|
+
export declare const getEditableDelegate: (widget: Gtk.Widget) => Gtk.Widget | null;
|
|
6
|
+
export declare const readEditableText: (widget: EditableTarget) => string;
|
|
7
|
+
//# sourceMappingURL=editable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editable.d.ts","sourceRoot":"","sources":["../src/editable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAEpC,MAAM,MAAM,cAAc,GAAG,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;AAEzD,eAAO,MAAM,cAAc,EAAE,GAAG,CAAC,GAAG,CAAC,cAAc,CAIjD,CAAC;AAEH,eAAO,MAAM,UAAU,WAAY,OAAO,KAAG,MAAM,IAAI,cACa,CAAC;AAErE,eAAO,MAAM,mBAAmB,WAAY,GAAG,CAAC,MAAM,KAAG,GAAG,CAAC,MAAM,GAAG,IAGrE,CAAC;AAQF,eAAO,MAAM,gBAAgB,WAAY,cAAc,KAAG,MAKzD,CAAC"}
|
package/dist/editable.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
+
export const EDITABLE_ROLES = new Set([
|
|
3
|
+
Gtk.AccessibleRole.TEXT_BOX,
|
|
4
|
+
Gtk.AccessibleRole.SEARCH_BOX,
|
|
5
|
+
Gtk.AccessibleRole.SPIN_BUTTON,
|
|
6
|
+
]);
|
|
7
|
+
export const isEditable = (widget) => widget instanceof Gtk.Editable || widget instanceof Gtk.TextView;
|
|
8
|
+
export const getEditableDelegate = (widget) => {
|
|
9
|
+
if (!(widget instanceof Gtk.Editable))
|
|
10
|
+
return null;
|
|
11
|
+
return widget.getDelegate();
|
|
12
|
+
};
|
|
13
|
+
const readTextViewBufferText = (widget) => {
|
|
14
|
+
const buffer = widget.getBuffer();
|
|
15
|
+
const [start, end] = buffer.getBounds();
|
|
16
|
+
return buffer.getText(start, end, true);
|
|
17
|
+
};
|
|
18
|
+
export const readEditableText = (widget) => {
|
|
19
|
+
if (widget instanceof Gtk.TextView) {
|
|
20
|
+
return readTextViewBufferText(widget);
|
|
21
|
+
}
|
|
22
|
+
return widget.getText();
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=editable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editable.js","sourceRoot":"","sources":["../src/editable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAIpC,MAAM,CAAC,MAAM,cAAc,GAA4B,IAAI,GAAG,CAAqB;IAC/E,GAAG,CAAC,cAAc,CAAC,QAAQ;IAC3B,GAAG,CAAC,cAAc,CAAC,UAAU;IAC7B,GAAG,CAAC,cAAc,CAAC,WAAW;CACjC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAe,EAA4B,EAAE,CACpE,MAAM,YAAY,GAAG,CAAC,QAAQ,IAAI,MAAM,YAAY,GAAG,CAAC,QAAQ,CAAC;AAErE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,MAAkB,EAAqB,EAAE;IACzE,IAAI,CAAC,CAAC,MAAM,YAAY,GAAG,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IACnD,OAAO,MAAM,CAAC,WAAW,EAAE,CAAC;AAChC,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,MAAoB,EAAU,EAAE;IAC5D,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAClC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IACxC,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAsB,EAAU,EAAE;IAC/D,IAAI,MAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,CAAC;QACjC,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC;AAC5B,CAAC,CAAC","sourcesContent":["import * as Gtk from \"@gtkx/gi/gtk\";\n\nexport type EditableTarget = Gtk.Editable | Gtk.TextView;\n\nexport const EDITABLE_ROLES: Set<Gtk.AccessibleRole> = new Set<Gtk.AccessibleRole>([\n Gtk.AccessibleRole.TEXT_BOX,\n Gtk.AccessibleRole.SEARCH_BOX,\n Gtk.AccessibleRole.SPIN_BUTTON,\n]);\n\nexport const isEditable = (widget: unknown): widget is EditableTarget =>\n widget instanceof Gtk.Editable || widget instanceof Gtk.TextView;\n\nexport const getEditableDelegate = (widget: Gtk.Widget): Gtk.Widget | null => {\n if (!(widget instanceof Gtk.Editable)) return null;\n return widget.getDelegate();\n};\n\nconst readTextViewBufferText = (widget: Gtk.TextView): string => {\n const buffer = widget.getBuffer();\n const [start, end] = buffer.getBounds();\n return buffer.getText(start, end, true);\n};\n\nexport const readEditableText = (widget: EditableTarget): string => {\n if (widget instanceof Gtk.TextView) {\n return readTextViewBufferText(widget);\n }\n return widget.getText();\n};\n"]}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
+
import type { Container } from "./traversal.js";
|
|
3
|
+
import type { ByRoleOptions, Matcher } from "./types.js";
|
|
4
|
+
export type QueryDescriptor = {
|
|
5
|
+
queryType: "role";
|
|
6
|
+
role: Gtk.AccessibleRole;
|
|
7
|
+
options?: ByRoleOptions | undefined;
|
|
8
|
+
} | {
|
|
9
|
+
queryType: "text";
|
|
10
|
+
text: Matcher;
|
|
11
|
+
} | {
|
|
12
|
+
queryType: "labelText";
|
|
13
|
+
text: Matcher;
|
|
14
|
+
} | {
|
|
15
|
+
queryType: "name";
|
|
16
|
+
name: Matcher;
|
|
17
|
+
} | {
|
|
18
|
+
queryType: "placeholderText";
|
|
19
|
+
text: Matcher;
|
|
20
|
+
} | {
|
|
21
|
+
queryType: "displayValue";
|
|
22
|
+
value: Matcher;
|
|
23
|
+
};
|
|
24
|
+
export declare const runWithExpensiveErrorDiagnosticsDisabled: <T>(callback: () => T) => T;
|
|
25
|
+
export declare const notFoundError: (container: Container, descriptor: QueryDescriptor) => Error;
|
|
26
|
+
export declare const multipleFoundError: (container: Container, descriptor: QueryDescriptor, matches: Gtk.Widget[]) => Error;
|
|
27
|
+
export declare const suggestionError: (suggestion: string, container: Container) => Error;
|
|
28
|
+
export declare const timeoutError: (timeout: number, lastError: Error | null) => Error;
|
|
29
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AAIzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAe,OAAO,EAAE,MAAM,YAAY,CAAC;AAoCtE,MAAM,MAAM,eAAe,GACrB;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,GAAG,CAAC,cAAc,CAAC;IAAC,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAA;CAAE,GACpF;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GACpC;IAAE,SAAS,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GACzC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GACpC;IAAE,SAAS,EAAE,iBAAiB,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC/C;IAAE,SAAS,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAqBpD,eAAO,MAAM,wCAAwC,GAAI,CAAC,YAAY,MAAM,CAAC,KAAG,CAQ/E,CAAC;AAUF,eAAO,MAAM,aAAa,cAAe,SAAS,cAAc,eAAe,KAAG,KASjF,CAAC;AAUF,eAAO,MAAM,kBAAkB,cAAe,SAAS,cAAc,eAAe,WAAW,GAAG,CAAC,MAAM,EAAE,KAAG,KAY7G,CAAC;AAEF,eAAO,MAAM,eAAe,eAAgB,MAAM,aAAa,SAAS,KAAG,KAI1E,CAAC;AAEF,eAAO,MAAM,YAAY,YAAa,MAAM,aAAa,KAAK,GAAG,IAAI,KAAG,KAIvE,CAAC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { getConfig } from "./config.js";
|
|
2
|
+
import { prettyWidget } from "./pretty-widget.js";
|
|
3
|
+
import { formatRole, prettyRoles } from "./role-helpers.js";
|
|
4
|
+
const formatTextMatcher = (text) => {
|
|
5
|
+
if (typeof text === "function") {
|
|
6
|
+
return "custom function";
|
|
7
|
+
}
|
|
8
|
+
if (text instanceof RegExp) {
|
|
9
|
+
return text.toString();
|
|
10
|
+
}
|
|
11
|
+
return `'${text}'`;
|
|
12
|
+
};
|
|
13
|
+
const formatByRoleValue = (value) => {
|
|
14
|
+
const parts = [];
|
|
15
|
+
if (value.now !== undefined)
|
|
16
|
+
parts.push(`now=${value.now}`);
|
|
17
|
+
if (value.min !== undefined)
|
|
18
|
+
parts.push(`min=${value.min}`);
|
|
19
|
+
if (value.max !== undefined)
|
|
20
|
+
parts.push(`max=${value.max}`);
|
|
21
|
+
if (value.text !== undefined)
|
|
22
|
+
parts.push(`text ${formatTextMatcher(value.text)}`);
|
|
23
|
+
return parts.join(", ");
|
|
24
|
+
};
|
|
25
|
+
const formatByRoleDescription = (role, options) => {
|
|
26
|
+
const parts = [`role '${formatRole(role).toUpperCase()}'`];
|
|
27
|
+
if (options?.name)
|
|
28
|
+
parts.push(`name ${formatTextMatcher(options.name)}`);
|
|
29
|
+
if (options?.checked !== undefined)
|
|
30
|
+
parts.push(`checked=${options.checked}`);
|
|
31
|
+
if (options?.pressed !== undefined)
|
|
32
|
+
parts.push(`pressed=${options.pressed}`);
|
|
33
|
+
if (options?.selected !== undefined)
|
|
34
|
+
parts.push(`selected=${options.selected}`);
|
|
35
|
+
if (options?.expanded !== undefined)
|
|
36
|
+
parts.push(`expanded=${options.expanded}`);
|
|
37
|
+
if (options?.level !== undefined)
|
|
38
|
+
parts.push(`level=${options.level}`);
|
|
39
|
+
if (options?.busy !== undefined)
|
|
40
|
+
parts.push(`busy=${options.busy}`);
|
|
41
|
+
if (options?.description)
|
|
42
|
+
parts.push(`description ${formatTextMatcher(options.description)}`);
|
|
43
|
+
if (options?.value)
|
|
44
|
+
parts.push(`value ${formatByRoleValue(options.value)}`);
|
|
45
|
+
if (options?.hidden !== undefined)
|
|
46
|
+
parts.push(`hidden=${options.hidden}`);
|
|
47
|
+
return parts.join(" and ");
|
|
48
|
+
};
|
|
49
|
+
const formatQueryDescription = (descriptor) => {
|
|
50
|
+
switch (descriptor.queryType) {
|
|
51
|
+
case "role":
|
|
52
|
+
return formatByRoleDescription(descriptor.role, descriptor.options);
|
|
53
|
+
case "text":
|
|
54
|
+
return `text ${formatTextMatcher(descriptor.text)}`;
|
|
55
|
+
case "labelText":
|
|
56
|
+
return `label text ${formatTextMatcher(descriptor.text)}`;
|
|
57
|
+
case "name":
|
|
58
|
+
return `name ${formatTextMatcher(descriptor.name)}`;
|
|
59
|
+
case "placeholderText":
|
|
60
|
+
return `placeholder text ${formatTextMatcher(descriptor.text)}`;
|
|
61
|
+
case "displayValue":
|
|
62
|
+
return `display value ${formatTextMatcher(descriptor.value)}`;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
let expensiveErrorDiagnosticsDisabled = false;
|
|
66
|
+
export const runWithExpensiveErrorDiagnosticsDisabled = (callback) => {
|
|
67
|
+
const previous = expensiveErrorDiagnosticsDisabled;
|
|
68
|
+
expensiveErrorDiagnosticsDisabled = true;
|
|
69
|
+
try {
|
|
70
|
+
return callback();
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
expensiveErrorDiagnosticsDisabled = previous;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const buildElementError = (container, headLines) => {
|
|
77
|
+
const config = getConfig();
|
|
78
|
+
const lines = expensiveErrorDiagnosticsDisabled
|
|
79
|
+
? headLines
|
|
80
|
+
: [...headLines, "", prettyWidget(container, { highlight: false })];
|
|
81
|
+
return config.getElementError(lines.join("\n"), container);
|
|
82
|
+
};
|
|
83
|
+
export const notFoundError = (container, descriptor) => {
|
|
84
|
+
const description = formatQueryDescription(descriptor);
|
|
85
|
+
const headLines = [`Unable to find an element with ${description}`];
|
|
86
|
+
if (!expensiveErrorDiagnosticsDisabled && descriptor.queryType === "role") {
|
|
87
|
+
headLines.push("", "Here are the accessible roles:", "", prettyRoles(container));
|
|
88
|
+
}
|
|
89
|
+
return buildElementError(container, headLines);
|
|
90
|
+
};
|
|
91
|
+
const allByVariantHint = (descriptor) => {
|
|
92
|
+
const variant = descriptor.queryType === "role" ? "getAllByRole" : "getAllBy*";
|
|
93
|
+
return ("(If this is intentional, use the *AllBy* variant of the query, " +
|
|
94
|
+
`e.g. queryAllBy*/getAllBy*/findAllBy*, such as ${variant}.)`);
|
|
95
|
+
};
|
|
96
|
+
export const multipleFoundError = (container, descriptor, matches) => {
|
|
97
|
+
const description = formatQueryDescription(descriptor);
|
|
98
|
+
const headLines = [
|
|
99
|
+
`Found ${matches.length} elements with ${description}, but expected only one`,
|
|
100
|
+
"",
|
|
101
|
+
allByVariantHint(descriptor),
|
|
102
|
+
];
|
|
103
|
+
if (!expensiveErrorDiagnosticsDisabled) {
|
|
104
|
+
const renderedMatches = matches.map((widget) => prettyWidget(widget, { highlight: false }));
|
|
105
|
+
headLines.push("", "Here are the matching elements:", "", ...renderedMatches);
|
|
106
|
+
}
|
|
107
|
+
return buildElementError(container, headLines);
|
|
108
|
+
};
|
|
109
|
+
export const suggestionError = (suggestion, container) => {
|
|
110
|
+
const config = getConfig();
|
|
111
|
+
const message = `A better query is available, try this:\n${suggestion}\n`;
|
|
112
|
+
return config.getElementError(message, container);
|
|
113
|
+
};
|
|
114
|
+
export const timeoutError = (timeout, lastError) => {
|
|
115
|
+
const baseMessage = `Timed out after ${timeout}ms`;
|
|
116
|
+
const message = lastError ? `${baseMessage}.\n\n${lastError.message}` : baseMessage;
|
|
117
|
+
return getConfig().getElementError(message);
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAI5D,MAAM,iBAAiB,GAAG,CAAC,IAAa,EAAU,EAAE;IAChD,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;QAC7B,OAAO,iBAAiB,CAAC;IAC7B,CA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;AACnD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,UAAkB,EAAE,SAAoB,EAAS,EAAE;IAC/E,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,OAAO,GAAG,2CAA2C,UAAU,IAAI,CAAC;IAC1E,OAAO,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACtD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,SAAuB,EAAS,EAAE;IAC5E,MAAM,WAAW,GAAG,mBAAmB,OAAO,IAAI,CAAC;IACnD,MAAM,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,WAAW,QAAQ,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC;IACpF,OAAO,SAAS,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;AAChD,CAAC,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport { getConfig } from \"./config.js\";\nimport { prettyWidget } from \"./pretty-widget.js\";\nimport { formatRole, prettyRoles } from \"./role-helpers.js\";\nimport type { Container } from \"./traversal.js\";\nimport type { ByRoleOptions, ByRoleValue, Matcher } from \"./types.js\";\n\nconst formatTextMatcher = (text: Matcher): string => {\n if (typeof text === \"function\") {\n return \"custom function\";\n }\n if (text instanceof RegExp) {\n return text.toString();\n }\n return `'${text}'`;\n};\n\nconst formatByRoleValue = (value: ByRoleValue): string => {\n const parts: string[] = [];\n if (value.now !== undefined) parts.push(`now=${value.now}`);\n if (value.min !== undefined) parts.push(`min=${value.min}`);\n if (value.max !== undefined) parts.push(`max=${value.max}`);\n if (value.text !== undefined) parts.push(`text ${formatTextMatcher(value.text)}`);\n return parts.join(\", \");\n};\n\nconst formatByRoleDescription = (role: Gtk.AccessibleRole, options?: ByRoleOptions): string => {\n const parts = [`role '${formatRole(role).toUpperCase()}'`];\n if (options?.name) parts.push(`name ${formatTextMatcher(options.name)}`);\n if (options?.checked !== undefined) parts.push(`checked=${options.checked}`);\n if (options?.pressed !== undefined) parts.push(`pressed=${options.pressed}`);\n if (options?.selected !== undefined) parts.push(`selected=${options.selected}`);\n if (options?.expanded !== undefined) parts.push(`expanded=${options.expanded}`);\n if (options?.level !== undefined) parts.push(`level=${options.level}`);\n if (options?.busy !== undefined) parts.push(`busy=${options.busy}`);\n if (options?.description) parts.push(`description ${formatTextMatcher(options.description)}`);\n if (options?.value) parts.push(`value ${formatByRoleValue(options.value)}`);\n if (options?.hidden !== undefined) parts.push(`hidden=${options.hidden}`);\n return parts.join(\" and \");\n};\n\nexport type QueryDescriptor =\n | { queryType: \"role\"; role: Gtk.AccessibleRole; options?: ByRoleOptions | undefined }\n | { queryType: \"text\"; text: Matcher }\n | { queryType: \"labelText\"; text: Matcher }\n | { queryType: \"name\"; name: Matcher }\n | { queryType: \"placeholderText\"; text: Matcher }\n | { queryType: \"displayValue\"; value: Matcher };\n\nconst formatQueryDescription = (descriptor: QueryDescriptor): string => {\n switch (descriptor.queryType) {\n case \"role\":\n return formatByRoleDescription(descriptor.role, descriptor.options);\n case \"text\":\n return `text ${formatTextMatcher(descriptor.text)}`;\n case \"labelText\":\n return `label text ${formatTextMatcher(descriptor.text)}`;\n case \"name\":\n return `name ${formatTextMatcher(descriptor.name)}`;\n case \"placeholderText\":\n return `placeholder text ${formatTextMatcher(descriptor.text)}`;\n case \"displayValue\":\n return `display value ${formatTextMatcher(descriptor.value)}`;\n }\n};\n\nlet expensiveErrorDiagnosticsDisabled = false;\n\nexport const runWithExpensiveErrorDiagnosticsDisabled = <T>(callback: () => T): T => {\n const previous = expensiveErrorDiagnosticsDisabled;\n expensiveErrorDiagnosticsDisabled = true;\n try {\n return callback();\n } finally {\n expensiveErrorDiagnosticsDisabled = previous;\n }\n};\n\nconst buildElementError = (container: Container, headLines: string[]): Error => {\n const config = getConfig();\n const lines = expensiveErrorDiagnosticsDisabled\n ? headLines\n : [...headLines, \"\", prettyWidget(container, { highlight: false })];\n return config.getElementError(lines.join(\"\\n\"), container);\n};\n\nexport const notFoundError = (container: Container, descriptor: QueryDescriptor): Error => {\n const description = formatQueryDescription(descriptor);\n const headLines = [`Unable to find an element with ${description}`];\n\n if (!expensiveErrorDiagnosticsDisabled && descriptor.queryType === \"role\") {\n headLines.push(\"\", \"Here are the accessible roles:\", \"\", prettyRoles(container));\n }\n\n return buildElementError(container, headLines);\n};\n\nconst allByVariantHint = (descriptor: QueryDescriptor): string => {\n const variant = descriptor.queryType === \"role\" ? \"getAllByRole\" : \"getAllBy*\";\n return (\n \"(If this is intentional, use the *AllBy* variant of the query, \" +\n `e.g. queryAllBy*/getAllBy*/findAllBy*, such as ${variant}.)`\n );\n};\n\nexport const multipleFoundError = (container: Container, descriptor: QueryDescriptor, matches: Gtk.Widget[]): Error => {\n const description = formatQueryDescription(descriptor);\n const headLines = [\n `Found ${matches.length} elements with ${description}, but expected only one`,\n \"\",\n allByVariantHint(descriptor),\n ];\n if (!expensiveErrorDiagnosticsDisabled) {\n const renderedMatches = matches.map((widget) => prettyWidget(widget, { highlight: false }));\n headLines.push(\"\", \"Here are the matching elements:\", \"\", ...renderedMatches);\n }\n return buildElementError(container, headLines);\n};\n\nexport const suggestionError = (suggestion: string, container: Container): Error => {\n const config = getConfig();\n const message = `A better query is available, try this:\\n${suggestion}\\n`;\n return config.getElementError(message, container);\n};\n\nexport const timeoutError = (timeout: number, lastError: Error | null): Error => {\n const baseMessage = `Timed out after ${timeout}ms`;\n const message = lastError ? `${baseMessage}.\\n\\n${lastError.message}` : baseMessage;\n return getConfig().getElementError(message);\n};\n"]}
|
package/dist/fire-event.d.ts
CHANGED
|
@@ -1,29 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type * as Gtk from "@gtkx/ffi/gtk";
|
|
1
|
+
import type * as GObject from "@gtkx/gi/gobject";
|
|
3
2
|
/**
|
|
4
|
-
* Emits a
|
|
3
|
+
* Emits a GObject signal on a widget or object inside React's act environment,
|
|
4
|
+
* so any resulting state updates are flushed before the promise resolves.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @param element - The widget or event controller to emit the signal on
|
|
10
|
-
* @param signalName - GTK signal name (e.g., "clicked", "activate", "drag-begin")
|
|
11
|
-
* @param args - Additional signal arguments as GValues
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```tsx
|
|
15
|
-
* import { fireEvent } from "@gtkx/testing";
|
|
16
|
-
* import { Value } from "@gtkx/ffi/gobject";
|
|
17
|
-
*
|
|
18
|
-
* // Emit signal on widget
|
|
19
|
-
* await fireEvent(widget, "clicked");
|
|
20
|
-
*
|
|
21
|
-
* // Emit signal on gesture controller
|
|
22
|
-
* const gesture = widget.observeControllers().getObject(0) as Gtk.GestureDrag;
|
|
23
|
-
* await fireEvent(gesture, "drag-begin", Value.newFromDouble(100), Value.newFromDouble(100));
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @see {@link userEvent} for high-level user interactions
|
|
6
|
+
* @param element The GObject instance to emit the signal on.
|
|
7
|
+
* @param signalName Name of the signal to emit.
|
|
8
|
+
* @param args Arguments passed to the signal handlers.
|
|
27
9
|
*/
|
|
28
|
-
export declare const fireEvent: (element:
|
|
10
|
+
export declare const fireEvent: (element: GObject.Object, signalName: string, ...args: unknown[]) => Promise<void>;
|
|
29
11
|
//# sourceMappingURL=fire-event.d.ts.map
|
package/dist/fire-event.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fire-event.d.ts","sourceRoot":"","sources":["../src/fire-event.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"fire-event.d.ts","sourceRoot":"","sources":["../src/fire-event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAGjD;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,YAAmB,OAAO,CAAC,MAAM,cAAc,MAAM,WAAW,OAAO,EAAE,KAAG,OAAO,CAAC,IAAI,CAI7G,CAAC"}
|
package/dist/fire-event.js
CHANGED
|
@@ -1,35 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { tick } from "./timing.js";
|
|
1
|
+
import { runInAct } from "./act.js";
|
|
3
2
|
/**
|
|
4
|
-
* Emits a
|
|
3
|
+
* Emits a GObject signal on a widget or object inside React's act environment,
|
|
4
|
+
* so any resulting state updates are flushed before the promise resolves.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @param element - The widget or event controller to emit the signal on
|
|
10
|
-
* @param signalName - GTK signal name (e.g., "clicked", "activate", "drag-begin")
|
|
11
|
-
* @param args - Additional signal arguments as GValues
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```tsx
|
|
15
|
-
* import { fireEvent } from "@gtkx/testing";
|
|
16
|
-
* import { Value } from "@gtkx/ffi/gobject";
|
|
17
|
-
*
|
|
18
|
-
* // Emit signal on widget
|
|
19
|
-
* await fireEvent(widget, "clicked");
|
|
20
|
-
*
|
|
21
|
-
* // Emit signal on gesture controller
|
|
22
|
-
* const gesture = widget.observeControllers().getObject(0) as Gtk.GestureDrag;
|
|
23
|
-
* await fireEvent(gesture, "drag-begin", Value.newFromDouble(100), Value.newFromDouble(100));
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @see {@link userEvent} for high-level user interactions
|
|
6
|
+
* @param element The GObject instance to emit the signal on.
|
|
7
|
+
* @param signalName Name of the signal to emit.
|
|
8
|
+
* @param args Arguments passed to the signal handlers.
|
|
27
9
|
*/
|
|
28
10
|
export const fireEvent = async (element, signalName, ...args) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
signalEmitv([instanceValue, ...args], signalId, 0);
|
|
33
|
-
await tick();
|
|
11
|
+
await runInAct(() => {
|
|
12
|
+
element.emit(signalName, ...args);
|
|
13
|
+
});
|
|
34
14
|
};
|
|
35
15
|
//# sourceMappingURL=fire-event.js.map
|
package/dist/fire-event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fire-event.js","sourceRoot":"","sources":["../src/fire-event.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fire-event.js","sourceRoot":"","sources":["../src/fire-event.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,OAAuB,EAAE,UAAkB,EAAE,GAAG,IAAe,EAAiB,EAAE;IAC9G,MAAM,QAAQ,CAAC,GAAG,EAAE;QAChB,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC","sourcesContent":["import type * as GObject from \"@gtkx/gi/gobject\";\nimport { runInAct } from \"./act.js\";\n\n/**\n * Emits a GObject signal on a widget or object inside React's act environment,\n * so any resulting state updates are flushed before the promise resolves.\n *\n * @param element The GObject instance to emit the signal on.\n * @param signalName Name of the signal to emit.\n * @param args Arguments passed to the signal handlers.\n */\nexport const fireEvent = async (element: GObject.Object, signalName: string, ...args: unknown[]): Promise<void> => {\n await runInAct(() => {\n element.emit(signalName, ...args);\n });\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-sync.d.ts","sourceRoot":"","sources":["../src/frame-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AAIzC,eAAO,MAAM,mBAAmB,WAAY,GAAG,CAAC,MAAM,GAAG,IAAI,YAAY,MAAM,IAAI,KAAG,IA6BrF,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const CLOCK_STALL_FALLBACK_MS = 500;
|
|
2
|
+
export const scheduleAfterLayout = (widget, callback) => {
|
|
3
|
+
let done = false;
|
|
4
|
+
let removeTick = null;
|
|
5
|
+
let fallback = null;
|
|
6
|
+
const finish = () => {
|
|
7
|
+
if (done)
|
|
8
|
+
return;
|
|
9
|
+
done = true;
|
|
10
|
+
if (fallback !== null)
|
|
11
|
+
clearTimeout(fallback);
|
|
12
|
+
removeTick?.();
|
|
13
|
+
removeTick = null;
|
|
14
|
+
fallback = null;
|
|
15
|
+
callback();
|
|
16
|
+
};
|
|
17
|
+
if (widget === null || widget.getFrameClock() === null || widget.getWidth() > 0) {
|
|
18
|
+
queueMicrotask(finish);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
fallback = setTimeout(finish, CLOCK_STALL_FALLBACK_MS);
|
|
22
|
+
const tickId = widget.addTickCallback(() => {
|
|
23
|
+
if (widget.getWidth() === 0)
|
|
24
|
+
return true;
|
|
25
|
+
finish();
|
|
26
|
+
return false;
|
|
27
|
+
});
|
|
28
|
+
removeTick = () => widget.removeTickCallback(tickId);
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=frame-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-sync.js","sourceRoot":"","sources":["../src/frame-sync.ts"],"names":[],"mappings":"AAEA,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,MAAyB,EAAE,QAAoB,EAAQ,EAAE;IACzF,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,IAAI,UAAU,GAAwB,IAAI,CAAC;IAC3C,IAAI,QAAQ,GAAyC,IAAI,CAAC;IAE1D,MAAM,MAAM,GAAG,GAAS,EAAE;QACtB,IAAI,IAAI;YAAE,OAAO;QACjB,IAAI,GAAG,IAAI,CAAC;QACZ,IAAI,QAAQ,KAAK,IAAI;YAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;QAC9C,UAAU,EAAE,EAAE,CAAC;QACf,UAAU,GAAG,IAAI,CAAC;QAClB,QAAQ,GAAG,IAAI,CAAC;QAChB,QAAQ,EAAE,CAAC;IACf,CAAC,CAAC;IAEF,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,aAAa,EAAE,KAAK,IAAI,IAAI,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,CAAC;QAC9E,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,OAAO;IACX,CAAC;IAED,QAAQ,GAAG,UAAU,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;IAEvD,MAAM,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE;QACvC,IAAI,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACzC,MAAM,EAAE,CAAC;QACT,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,UAAU,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;AACzD,CAAC,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\n\nconst CLOCK_STALL_FALLBACK_MS = 500;\n\nexport const scheduleAfterLayout = (widget: Gtk.Widget | null, callback: () => void): void => {\n let done = false;\n let removeTick: (() => void) | null = null;\n let fallback: ReturnType<typeof setTimeout> | null = null;\n\n const finish = (): void => {\n if (done) return;\n done = true;\n if (fallback !== null) clearTimeout(fallback);\n removeTick?.();\n removeTick = null;\n fallback = null;\n callback();\n };\n\n if (widget === null || widget.getFrameClock() === null || widget.getWidth() > 0) {\n queueMicrotask(finish);\n return;\n }\n\n fallback = setTimeout(finish, CLOCK_STALL_FALLBACK_MS);\n\n const tickId = widget.addTickCallback(() => {\n if (widget.getWidth() === 0) return true;\n finish();\n return false;\n });\n\n removeTick = () => widget.removeTickCallback(tickId);\n};\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import "./register-test-hooks.js";
|
|
2
|
+
export { act } from "./act.js";
|
|
3
|
+
export type { BoundQueries, RenderResult, Screen } from "./bound-queries.js";
|
|
4
|
+
export type { Config, ConfigFn } from "./config.js";
|
|
2
5
|
export { configure, getConfig } from "./config.js";
|
|
3
6
|
export { fireEvent } from "./fire-event.js";
|
|
7
|
+
export type { TextExpectation } from "./matchers.js";
|
|
8
|
+
export { matchers, registerMatchers } from "./matchers.js";
|
|
4
9
|
export type { PrettyWidgetOptions } from "./pretty-widget.js";
|
|
5
|
-
export { prettyWidget } from "./pretty-widget.js";
|
|
6
|
-
export { findAllByLabelText, findAllByName, findAllByRole, findAllByText, findByLabelText, findByName, findByRole, findByText, queryAllByLabelText, queryAllByName, queryAllByRole, queryAllByText, queryByLabelText, queryByName, queryByRole, queryByText, } from "./queries.js";
|
|
10
|
+
export { logWidget, prettyWidget } from "./pretty-widget.js";
|
|
11
|
+
export { findAllByDisplayValue, findAllByLabelText, findAllByName, findAllByPlaceholderText, findAllByRole, findAllByText, findByDisplayValue, findByLabelText, findByName, findByPlaceholderText, findByRole, findByText, getAllByDisplayValue, getAllByLabelText, getAllByName, getAllByPlaceholderText, getAllByRole, getAllByText, getByDisplayValue, getByLabelText, getByName, getByPlaceholderText, getByRole, getByText, getDefaultNormalizer, queryAllByDisplayValue, queryAllByLabelText, queryAllByName, queryAllByPlaceholderText, queryAllByRole, queryAllByText, queryByDisplayValue, queryByLabelText, queryByName, queryByPlaceholderText, queryByRole, queryByText, } from "./queries.js";
|
|
7
12
|
export { cleanup, render } from "./render.js";
|
|
8
13
|
export { renderHook } from "./render-hook.js";
|
|
9
|
-
export
|
|
10
|
-
export { getRoles, logRoles, prettyRoles } from "./role-helpers.js";
|
|
14
|
+
export { formatRole, getRoles, logRoles, prettyRoles } from "./role-helpers.js";
|
|
11
15
|
export { screen } from "./screen.js";
|
|
12
|
-
export
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
16
|
+
export { captureAndSaveScreenshot, logScreenshotPath, screenshot } from "./screenshot.js";
|
|
17
|
+
export type { Method, Suggestion, Variant } from "./suggestions.js";
|
|
18
|
+
export { getSuggestedQuery } from "./suggestions.js";
|
|
15
19
|
export type { Container } from "./traversal.js";
|
|
16
|
-
export type {
|
|
17
|
-
export type { PointerInput, TabOptions } from "./user-event.js";
|
|
18
|
-
export { userEvent } from "./user-event.js";
|
|
20
|
+
export type { ByRoleOptions, ByRoleValue, Matcher, MatcherFunction, MatcherOptions, NormalizerFn, NormalizerOptions, RenderHookOptions, RenderHookResult, RenderOptions, ScreenshotOptions, ScreenshotResult, WaitForOptions, WindowSelector, WrapperComponent, } from "./types.js";
|
|
21
|
+
export type { DragOffset, DragOptions, DropContent, DropOptions, PointerInput, TabOptions, TypeOptions, UserEvent, } from "./user-event/index.js";
|
|
22
|
+
export { userEvent } from "./user-event/index.js";
|
|
19
23
|
export { waitFor, waitForElementToBeRemoved } from "./wait-for.js";
|
|
24
|
+
export { getWidgetErrorMessage, getWidgetInvalidState, getWidgetNodeText, } from "./widget-accessible-properties.js";
|
|
20
25
|
export { within } from "./within.js";
|
|
21
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,0BAA0B,CAAC;AAElC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC7E,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CA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BAAkB,CAAC;AACrD,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EACR,aAAa,EACb,WAAW,EACX,OAAO,EACP,eAAe,EACf,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,gBAAgB,GACnB,MAAM,YAAY,CAAC;AACpB,YAAY,EACR,UAAU,EACV,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EACZ,UAAU,EACV,WAAW,EACX,SAAS,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EACH,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,GACpB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
import "./register-test-hooks.js";
|
|
2
|
+
export { act } from "./act.js";
|
|
1
3
|
export { configure, getConfig } from "./config.js";
|
|
2
4
|
export { fireEvent } from "./fire-event.js";
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
+
export { matchers, registerMatchers } from "./matchers.js";
|
|
6
|
+
export { logWidget, prettyWidget } from "./pretty-widget.js";
|
|
7
|
+
export { findAllByDisplayValue, findAllByLabelText, findAllByName, findAllByPlaceholderText, findAllByRole, findAllByText, findByDisplayValue, findByLabelText, findByName, findByPlaceholderText, findByRole, findByText, getAllByDisplayValue, getAllByLabelText, getAllByName, getAllByPlaceholderText, getAllByRole, getAllByText, getByDisplayValue, getByLabelText, getByName, getByPlaceholderText, getByRole, getByText, getDefaultNormalizer, queryAllByDisplayValue, queryAllByLabelText, queryAllByName, queryAllByPlaceholderText, queryAllByRole, queryAllByText, queryByDisplayValue, queryByLabelText, queryByName, queryByPlaceholderText, queryByRole, queryByText, } from "./queries.js";
|
|
5
8
|
export { cleanup, render } from "./render.js";
|
|
6
9
|
export { renderHook } from "./render-hook.js";
|
|
7
|
-
export { getRoles, logRoles, prettyRoles } from "./role-helpers.js";
|
|
10
|
+
export { formatRole, getRoles, logRoles, prettyRoles } from "./role-helpers.js";
|
|
8
11
|
export { screen } from "./screen.js";
|
|
9
|
-
export { screenshot } from "./screenshot.js";
|
|
10
|
-
export {
|
|
11
|
-
export { userEvent } from "./user-event.js";
|
|
12
|
+
export { captureAndSaveScreenshot, logScreenshotPath, screenshot } from "./screenshot.js";
|
|
13
|
+
export { getSuggestedQuery } from "./suggestions.js";
|
|
14
|
+
export { userEvent } from "./user-event/index.js";
|
|
12
15
|
export { waitFor, waitForElementToBeRemoved } from "./wait-for.js";
|
|
16
|
+
export { getWidgetErrorMessage, getWidgetInvalidState, getWidgetNodeText, } from "./widget-accessible-properties.js";
|
|
13
17
|
export { within } from "./within.js";
|
|
14
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,0BAA0B,CAAC;AAElC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAG/B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EACH,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,wBAAwB,EACxB,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,UAAU,EACV,UAAU,EACV,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,uBAAuB,EACvB,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,SAAS,EACT,oBAAoB,EACpB,SAAS,EACT,SAAS,EACT,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,yBAAyB,EACzB,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,sBAAsB,EACtB,WAAW,EACX,WAAW,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AA6BrD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EACH,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,GACpB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC","sourcesContent":["import \"./register-test-hooks.js\";\n\nexport { act } from \"./act.js\";\nexport type { BoundQueries, RenderResult, Screen } from \"./bound-queries.js\";\nexport type { Config, ConfigFn } from \"./config.js\";\nexport { configure, getConfig } from \"./config.js\";\nexport { fireEvent } from \"./fire-event.js\";\nexport type { TextExpectation } from \"./matchers.js\";\nexport { matchers, registerMatchers } from \"./matchers.js\";\nexport type { PrettyWidgetOptions } from \"./pretty-widget.js\";\nexport { logWidget, prettyWidget } from \"./pretty-widget.js\";\nexport {\n findAllByDisplayValue,\n findAllByLabelText,\n findAllByName,\n findAllByPlaceholderText,\n findAllByRole,\n findAllByText,\n findByDisplayValue,\n findByLabelText,\n findByName,\n findByPlaceholderText,\n findByRole,\n findByText,\n getAllByDisplayValue,\n getAllByLabelText,\n getAllByName,\n getAllByPlaceholderText,\n getAllByRole,\n getAllByText,\n getByDisplayValue,\n getByLabelText,\n getByName,\n getByPlaceholderText,\n getByRole,\n getByText,\n getDefaultNormalizer,\n queryAllByDisplayValue,\n queryAllByLabelText,\n queryAllByName,\n queryAllByPlaceholderText,\n queryAllByRole,\n queryAllByText,\n queryByDisplayValue,\n queryByLabelText,\n queryByName,\n queryByPlaceholderText,\n queryByRole,\n queryByText,\n} from \"./queries.js\";\nexport { cleanup, render } from \"./render.js\";\nexport { renderHook } from \"./render-hook.js\";\nexport { formatRole, getRoles, logRoles, prettyRoles } from \"./role-helpers.js\";\nexport { screen } from \"./screen.js\";\nexport { captureAndSaveScreenshot, logScreenshotPath, screenshot } from \"./screenshot.js\";\nexport type { Method, Suggestion, Variant } from \"./suggestions.js\";\nexport { getSuggestedQuery } from \"./suggestions.js\";\nexport type { Container } from \"./traversal.js\";\nexport type {\n ByRoleOptions,\n ByRoleValue,\n Matcher,\n MatcherFunction,\n MatcherOptions,\n NormalizerFn,\n NormalizerOptions,\n RenderHookOptions,\n RenderHookResult,\n RenderOptions,\n ScreenshotOptions,\n ScreenshotResult,\n WaitForOptions,\n WindowSelector,\n WrapperComponent,\n} from \"./types.js\";\nexport type {\n DragOffset,\n DragOptions,\n DropContent,\n DropOptions,\n PointerInput,\n TabOptions,\n TypeOptions,\n UserEvent,\n} from \"./user-event/index.js\";\nexport { userEvent } from \"./user-event/index.js\";\nexport { waitFor, waitForElementToBeRemoved } from \"./wait-for.js\";\nexport {\n getWidgetErrorMessage,\n getWidgetInvalidState,\n getWidgetNodeText,\n} from \"./widget-accessible-properties.js\";\nexport { within } from \"./within.js\";\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** The expected value for a text matcher: an exact string or a regular expression. */
|
|
2
|
+
export type TextExpectation = string | RegExp;
|
|
3
|
+
type MatcherResult = {
|
|
4
|
+
pass: boolean;
|
|
5
|
+
message: () => string;
|
|
6
|
+
};
|
|
7
|
+
interface MatcherContext {
|
|
8
|
+
isNot: boolean;
|
|
9
|
+
}
|
|
10
|
+
type TextMatcher = (this: MatcherContext, received: unknown, expected?: TextExpectation) => MatcherResult;
|
|
11
|
+
type StateMatcher = (this: MatcherContext, received: unknown) => MatcherResult;
|
|
12
|
+
type ValueMatcher = (this: MatcherContext, received: unknown, expected: number) => MatcherResult;
|
|
13
|
+
export declare const toHaveDisplayValue: TextMatcher;
|
|
14
|
+
export declare const toHaveTextContent: TextMatcher;
|
|
15
|
+
export declare const toHaveAccessibleName: TextMatcher;
|
|
16
|
+
export declare const toHavePlaceholderText: TextMatcher;
|
|
17
|
+
export declare const toBeChecked: StateMatcher;
|
|
18
|
+
export declare const toBePressed: StateMatcher;
|
|
19
|
+
export declare const toBeExpanded: StateMatcher;
|
|
20
|
+
export declare const toBeSelected: StateMatcher;
|
|
21
|
+
export declare const toHaveValue: ValueMatcher;
|
|
22
|
+
interface MatcherImplementations {
|
|
23
|
+
toHaveDisplayValue: TextMatcher;
|
|
24
|
+
toHaveTextContent: TextMatcher;
|
|
25
|
+
toHaveAccessibleName: TextMatcher;
|
|
26
|
+
toHavePlaceholderText: TextMatcher;
|
|
27
|
+
toBeChecked: StateMatcher;
|
|
28
|
+
toBePressed: StateMatcher;
|
|
29
|
+
toBeExpanded: StateMatcher;
|
|
30
|
+
toBeSelected: StateMatcher;
|
|
31
|
+
toHaveValue: ValueMatcher;
|
|
32
|
+
}
|
|
33
|
+
/** The widget assertion matchers keyed by name, suitable for passing to `expect.extend`. */
|
|
34
|
+
export declare const matchers: MatcherImplementations;
|
|
35
|
+
/** Registers the widget matchers on the global `expect`, when one is available. Safe to call more than once. */
|
|
36
|
+
export declare const registerMatchers: () => void;
|
|
37
|
+
interface WidgetMatchers<R = void> {
|
|
38
|
+
toHaveDisplayValue(expected?: TextExpectation): R;
|
|
39
|
+
toHaveTextContent(expected?: TextExpectation): R;
|
|
40
|
+
toHaveAccessibleName(expected?: TextExpectation): R;
|
|
41
|
+
toHavePlaceholderText(expected?: TextExpectation): R;
|
|
42
|
+
toBeChecked(): R;
|
|
43
|
+
toBePressed(): R;
|
|
44
|
+
toBeExpanded(): R;
|
|
45
|
+
toBeSelected(): R;
|
|
46
|
+
toHaveValue(expected: number): R;
|
|
47
|
+
}
|
|
48
|
+
declare module "@vitest/expect" {
|
|
49
|
+
interface Assertion<T = any> extends WidgetMatchers {
|
|
50
|
+
}
|
|
51
|
+
interface AsymmetricMatchersContaining extends WidgetMatchers {
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=matchers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchers.d.ts","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAcA,sFAAsF;AACtF,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC;AAE9C,KAAK,aAAa,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,MAAM,CAAA;CAAE,CAAC;AAE9D,UAAU,cAAc;IACpB,KAAK,EAAE,OAAO,CAAC;CAClB;AAED,KAAK,WAAW,GAAG,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,eAAe,KAAK,aAAa,CAAC;AAC1G,KAAK,YAAY,GAAG,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ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