@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/queries.js
CHANGED
|
@@ -1,25 +1,37 @@
|
|
|
1
|
-
import * as Gtk from "@gtkx/
|
|
2
|
-
import {
|
|
1
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
+
import { buildQueries } from "./build-queries.js";
|
|
3
|
+
import { multipleFoundError, notFoundError } from "./errors.js";
|
|
3
4
|
import { findAll, traverse } from "./traversal.js";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const collapseWhitespace = options?.collapseWhitespace ?? true;
|
|
5
|
+
import { getWidgetAccessibleName, getWidgetBusyState, getWidgetCheckedState, getWidgetDescription, getWidgetDisplayValue, getWidgetExpandedState, getWidgetLabelledByText, getWidgetLabelText, getWidgetLevel, getWidgetName, getWidgetOwnLabel, getWidgetPlaceholderText, getWidgetPressedState, getWidgetSelectedState, getWidgetValue, isInaccessible, } from "./widget-accessible-properties.js";
|
|
6
|
+
/**
|
|
7
|
+
* Builds the default text normalizer, which optionally trims surrounding whitespace and collapses runs of whitespace into single spaces.
|
|
8
|
+
* @param options Toggles for trimming and whitespace collapsing.
|
|
9
|
+
* @returns A function that normalizes a string for comparison against a matcher.
|
|
10
|
+
*/
|
|
11
|
+
export const getDefaultNormalizer = ({ trim = true, collapseWhitespace = true, } = {}) => {
|
|
12
12
|
return (text) => {
|
|
13
13
|
let result = text;
|
|
14
14
|
if (trim) {
|
|
15
15
|
result = result.trim();
|
|
16
16
|
}
|
|
17
17
|
if (collapseWhitespace) {
|
|
18
|
-
result = result.
|
|
18
|
+
result = result.replaceAll(/\s+/g, " ");
|
|
19
19
|
}
|
|
20
20
|
return result;
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
|
+
const buildNormalizer = (options) => {
|
|
24
|
+
const { normalizer, trim, collapseWhitespace } = options ?? {};
|
|
25
|
+
if (!normalizer) {
|
|
26
|
+
return getDefaultNormalizer({ trim, collapseWhitespace });
|
|
27
|
+
}
|
|
28
|
+
if (trim !== undefined || collapseWhitespace !== undefined) {
|
|
29
|
+
throw new Error("trim and collapseWhitespace are not supported with a normalizer. " +
|
|
30
|
+
"If you want to use the default trim and collapseWhitespace logic in your normalizer, " +
|
|
31
|
+
'use "getDefaultNormalizer({ trim, collapseWhitespace })" and compose that into your normalizer');
|
|
32
|
+
}
|
|
33
|
+
return normalizer;
|
|
34
|
+
};
|
|
23
35
|
const normalizeText = (text, options) => {
|
|
24
36
|
const normalizer = buildNormalizer(options);
|
|
25
37
|
return normalizer(text);
|
|
@@ -35,345 +47,220 @@ const matchText = (actual, expected, widget, options) => {
|
|
|
35
47
|
expected.lastIndex = 0;
|
|
36
48
|
return expected.test(normalizedActual);
|
|
37
49
|
}
|
|
38
|
-
const normalizedExpected = normalizeText(expected, options);
|
|
50
|
+
const normalizedExpected = normalizeText(String(expected), options);
|
|
39
51
|
const exact = options?.exact ?? true;
|
|
40
52
|
return exact
|
|
41
53
|
? normalizedActual === normalizedExpected
|
|
42
54
|
: normalizedActual.toLowerCase().includes(normalizedExpected.toLowerCase());
|
|
43
55
|
};
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
56
|
+
const matchAccessibleName = (widget, options) => {
|
|
57
|
+
if (options.name === undefined)
|
|
46
58
|
return true;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (!matchText(text, options.name, widget, options))
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
if (options.checked !== undefined) {
|
|
53
|
-
const checked = getWidgetCheckedState(widget);
|
|
54
|
-
if (checked !== options.checked)
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
if (options.pressed !== undefined) {
|
|
58
|
-
const pressed = getWidgetPressedState(widget);
|
|
59
|
-
if (pressed !== options.pressed)
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
if (options.expanded !== undefined) {
|
|
63
|
-
const expanded = getWidgetExpandedState(widget);
|
|
64
|
-
if (expanded !== options.expanded)
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
if (options.selected !== undefined) {
|
|
68
|
-
const selected = getWidgetSelectedState(widget);
|
|
69
|
-
if (selected !== options.selected)
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
return true;
|
|
59
|
+
const text = getWidgetAccessibleName(widget);
|
|
60
|
+
return matchText(text, options.name, widget, options);
|
|
73
61
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return false;
|
|
86
|
-
return matchByRoleOptions(node, options);
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Finds a single element matching a role without throwing.
|
|
91
|
-
*
|
|
92
|
-
* @param container - The container to search within
|
|
93
|
-
* @param role - The GTK accessible role to match
|
|
94
|
-
* @param options - Query options including name and state filters
|
|
95
|
-
* @returns The matching widget or null if not found
|
|
96
|
-
* @throws Error if multiple elements match
|
|
97
|
-
*/
|
|
98
|
-
export const queryByRole = (container, role, options) => {
|
|
99
|
-
const matches = queryAllByRole(container, role, options);
|
|
100
|
-
if (matches.length > 1) {
|
|
101
|
-
throw buildMultipleFoundError(container, "role", { role, options }, matches.length);
|
|
102
|
-
}
|
|
103
|
-
return matches[0] ?? null;
|
|
62
|
+
const matchAccessibleValue = (widget, value, options) => {
|
|
63
|
+
const actual = getWidgetValue(widget);
|
|
64
|
+
if (value.now !== undefined && actual.now !== value.now)
|
|
65
|
+
return false;
|
|
66
|
+
if (value.min !== undefined && actual.min !== value.min)
|
|
67
|
+
return false;
|
|
68
|
+
if (value.max !== undefined && actual.max !== value.max)
|
|
69
|
+
return false;
|
|
70
|
+
if (value.text !== undefined && !matchText(actual.text, value.text, widget, options))
|
|
71
|
+
return false;
|
|
72
|
+
return true;
|
|
104
73
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
export const queryAllByLabelText = (container, text, options) => {
|
|
118
|
-
const results = [];
|
|
119
|
-
for (const node of traverse(container)) {
|
|
120
|
-
if (!(node instanceof Gtk.Label))
|
|
121
|
-
continue;
|
|
122
|
-
const labelText = node.getLabel();
|
|
123
|
-
if (!labelText)
|
|
124
|
-
continue;
|
|
125
|
-
if (!matchText(labelText, text, node, options))
|
|
126
|
-
continue;
|
|
127
|
-
const target = node.getMnemonicWidget();
|
|
128
|
-
if (target) {
|
|
129
|
-
results.push(target);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return results;
|
|
74
|
+
const matchBooleanStates = (widget, options) => {
|
|
75
|
+
if (options.checked !== undefined && getWidgetCheckedState(widget) !== options.checked)
|
|
76
|
+
return false;
|
|
77
|
+
if (options.pressed !== undefined && getWidgetPressedState(widget) !== options.pressed)
|
|
78
|
+
return false;
|
|
79
|
+
if (options.expanded !== undefined && getWidgetExpandedState(widget) !== options.expanded)
|
|
80
|
+
return false;
|
|
81
|
+
if (options.selected !== undefined && getWidgetSelectedState(widget) !== options.selected)
|
|
82
|
+
return false;
|
|
83
|
+
if (options.busy !== undefined && (getWidgetBusyState(widget) ?? false) !== options.busy)
|
|
84
|
+
return false;
|
|
85
|
+
return true;
|
|
133
86
|
};
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if (matches.length > 1) {
|
|
146
|
-
throw buildMultipleFoundError(container, "labelText", { text, options }, matches.length);
|
|
147
|
-
}
|
|
148
|
-
return matches[0] ?? null;
|
|
87
|
+
const matchAccessibleStates = (widget, options) => {
|
|
88
|
+
if (!matchBooleanStates(widget, options))
|
|
89
|
+
return false;
|
|
90
|
+
if (options.level !== undefined && getWidgetLevel(widget) !== options.level)
|
|
91
|
+
return false;
|
|
92
|
+
if (options.description !== undefined &&
|
|
93
|
+
!matchText(getWidgetDescription(widget), options.description, widget, options))
|
|
94
|
+
return false;
|
|
95
|
+
if (options.value !== undefined && !matchAccessibleValue(widget, options.value, options))
|
|
96
|
+
return false;
|
|
97
|
+
return true;
|
|
149
98
|
};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
* @param text - Text to match (string, RegExp, or custom matcher)
|
|
155
|
-
* @param options - Query options including normalization
|
|
156
|
-
* @returns Array of matching widgets (empty if none found)
|
|
157
|
-
*/
|
|
158
|
-
export const queryAllByText = (container, text, options) => {
|
|
159
|
-
return findAll(container, (node) => {
|
|
160
|
-
return matchText(getWidgetText(node), text, node, options);
|
|
161
|
-
});
|
|
99
|
+
const matchByRoleOptions = (widget, options) => {
|
|
100
|
+
if (!options)
|
|
101
|
+
return true;
|
|
102
|
+
return matchAccessibleName(widget, options) && matchAccessibleStates(widget, options);
|
|
162
103
|
};
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const matches = queryAllByText(container, text, options);
|
|
174
|
-
if (matches.length > 1) {
|
|
175
|
-
throw buildMultipleFoundError(container, "text", { text, options }, matches.length);
|
|
176
|
-
}
|
|
177
|
-
return matches[0] ?? null;
|
|
104
|
+
const nameQueryFamily = (suffix, queryAllBy, built) => {
|
|
105
|
+
const family = {
|
|
106
|
+
[`queryBy${suffix}`]: built.queryBy,
|
|
107
|
+
[`queryAllBy${suffix}`]: queryAllBy,
|
|
108
|
+
[`getBy${suffix}`]: built.getBy,
|
|
109
|
+
[`getAllBy${suffix}`]: built.getAllBy,
|
|
110
|
+
[`findBy${suffix}`]: built.findBy,
|
|
111
|
+
[`findAllBy${suffix}`]: built.findAllBy,
|
|
112
|
+
};
|
|
113
|
+
return family;
|
|
178
114
|
};
|
|
179
115
|
/**
|
|
180
|
-
* Finds
|
|
181
|
-
*
|
|
182
|
-
* @param container
|
|
183
|
-
* @param
|
|
184
|
-
* @param options
|
|
185
|
-
* @returns
|
|
116
|
+
* Finds every widget under the container whose accessible role matches `role` and that satisfies the given options.
|
|
117
|
+
* Widgets excluded from the accessibility tree are skipped unless `options.hidden` is set.
|
|
118
|
+
* @param container Widget subtree to search.
|
|
119
|
+
* @param role Accessible role to match.
|
|
120
|
+
* @param options Additional accessible name, state, and value constraints.
|
|
121
|
+
* @returns Every matching widget, or an empty array when none match.
|
|
186
122
|
*/
|
|
187
|
-
export const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
123
|
+
export const queryAllByRole = (container, role, options) => findAll(container, (widget) => {
|
|
124
|
+
if (widget.getAccessibleRole() !== role)
|
|
125
|
+
return false;
|
|
126
|
+
if (!options?.hidden && isInaccessible(widget))
|
|
127
|
+
return false;
|
|
128
|
+
return matchByRoleOptions(widget, options);
|
|
129
|
+
});
|
|
130
|
+
const roleQueries = nameQueryFamily("Role", queryAllByRole, buildQueries("Role", queryAllByRole, (container, matches, role, options) => multipleFoundError(container, { queryType: "role", role, options }, matches), (container, role, options) => notFoundError(container, { queryType: "role", role, options })));
|
|
131
|
+
const collectMnemonicMatch = (widget, text, options) => {
|
|
132
|
+
if (!(widget instanceof Gtk.Label))
|
|
133
|
+
return null;
|
|
134
|
+
const labelText = widget.getLabel();
|
|
135
|
+
if (!labelText || !matchText(labelText, text, widget, options))
|
|
136
|
+
return null;
|
|
137
|
+
return widget.getMnemonicWidget();
|
|
192
138
|
};
|
|
193
139
|
/**
|
|
194
|
-
* Finds a
|
|
195
|
-
*
|
|
196
|
-
* @param
|
|
197
|
-
* @param
|
|
198
|
-
* @
|
|
199
|
-
* @returns The matching widget or null if not found
|
|
200
|
-
* @throws Error if multiple elements match
|
|
140
|
+
* Finds every widget associated with a label whose text matches: a Gtk.Label mnemonic target, the widget's own accessible label, or its labelled-by relation.
|
|
141
|
+
* @param container Widget subtree to search.
|
|
142
|
+
* @param text Matcher for the label text.
|
|
143
|
+
* @param options Text matching options.
|
|
144
|
+
* @returns Every matching widget, or an empty array when none match.
|
|
201
145
|
*/
|
|
202
|
-
export const
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
return matches;
|
|
215
|
-
};
|
|
216
|
-
const getByRole = (container, role, options) => {
|
|
217
|
-
const matches = getAllByRole(container, role, options);
|
|
218
|
-
if (matches.length > 1) {
|
|
219
|
-
throw buildMultipleFoundError(container, "role", { role, options }, matches.length);
|
|
220
|
-
}
|
|
221
|
-
return matches[0];
|
|
222
|
-
};
|
|
223
|
-
const getAllByLabelText = (container, text, options) => {
|
|
224
|
-
const matches = queryAllByLabelText(container, text, options);
|
|
225
|
-
if (matches.length === 0) {
|
|
226
|
-
throw buildNotFoundError(container, "labelText", { text, options });
|
|
227
|
-
}
|
|
228
|
-
return matches;
|
|
229
|
-
};
|
|
230
|
-
const getByLabelText = (container, text, options) => {
|
|
231
|
-
const matches = getAllByLabelText(container, text, options);
|
|
232
|
-
if (matches.length > 1) {
|
|
233
|
-
throw buildMultipleFoundError(container, "labelText", { text, options }, matches.length);
|
|
234
|
-
}
|
|
235
|
-
return matches[0];
|
|
236
|
-
};
|
|
237
|
-
const getAllByText = (container, text, options) => {
|
|
238
|
-
const matches = queryAllByText(container, text, options);
|
|
239
|
-
if (matches.length === 0) {
|
|
240
|
-
throw buildNotFoundError(container, "text", { text, options });
|
|
241
|
-
}
|
|
242
|
-
return matches;
|
|
243
|
-
};
|
|
244
|
-
const getByText = (container, text, options) => {
|
|
245
|
-
const matches = getAllByText(container, text, options);
|
|
246
|
-
if (matches.length > 1) {
|
|
247
|
-
throw buildMultipleFoundError(container, "text", { text, options }, matches.length);
|
|
248
|
-
}
|
|
249
|
-
return matches[0];
|
|
250
|
-
};
|
|
251
|
-
const getAllByName = (container, name, options) => {
|
|
252
|
-
const matches = queryAllByName(container, name, options);
|
|
253
|
-
if (matches.length === 0) {
|
|
254
|
-
throw buildNotFoundError(container, "name", { name, options });
|
|
255
|
-
}
|
|
256
|
-
return matches;
|
|
257
|
-
};
|
|
258
|
-
const getByName = (container, name, options) => {
|
|
259
|
-
const matches = getAllByName(container, name, options);
|
|
260
|
-
if (matches.length > 1) {
|
|
261
|
-
throw buildMultipleFoundError(container, "name", { name, options }, matches.length);
|
|
146
|
+
export const queryAllByLabelText = (container, text, options) => {
|
|
147
|
+
const results = new Set();
|
|
148
|
+
for (const widget of traverse(container)) {
|
|
149
|
+
const mnemonicTarget = collectMnemonicMatch(widget, text, options);
|
|
150
|
+
if (mnemonicTarget)
|
|
151
|
+
results.add(mnemonicTarget);
|
|
152
|
+
const ownLabel = getWidgetOwnLabel(widget);
|
|
153
|
+
if (ownLabel !== null && matchText(ownLabel, text, widget, options))
|
|
154
|
+
results.add(widget);
|
|
155
|
+
const labelledByText = getWidgetLabelledByText(widget);
|
|
156
|
+
if (labelledByText !== null && matchText(labelledByText, text, widget, options))
|
|
157
|
+
results.add(widget);
|
|
262
158
|
}
|
|
263
|
-
return
|
|
159
|
+
return [...results];
|
|
264
160
|
};
|
|
161
|
+
const labelTextQueries = nameQueryFamily("LabelText", queryAllByLabelText, buildQueries("LabelText", queryAllByLabelText, (container, matches, text) => multipleFoundError(container, { queryType: "labelText", text }, matches), (container, text) => notFoundError(container, { queryType: "labelText", text })));
|
|
265
162
|
/**
|
|
266
|
-
* Finds
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* @
|
|
271
|
-
* @param role - The GTK accessible role to match
|
|
272
|
-
* @param options - Query options including name, state filters, and timeout
|
|
273
|
-
* @returns Promise resolving to the matching widget
|
|
274
|
-
*
|
|
275
|
-
* @example
|
|
276
|
-
* ```tsx
|
|
277
|
-
* const button = await findByRole(container, Gtk.AccessibleRole.BUTTON, { name: "Submit" });
|
|
278
|
-
* ```
|
|
163
|
+
* Finds every widget whose rendered text content matches.
|
|
164
|
+
* @param container Widget subtree to search.
|
|
165
|
+
* @param text Matcher for the widget text.
|
|
166
|
+
* @param options Text matching options.
|
|
167
|
+
* @returns Every matching widget, or an empty array when none match.
|
|
279
168
|
*/
|
|
280
|
-
export const
|
|
281
|
-
|
|
282
|
-
});
|
|
283
|
-
/**
|
|
284
|
-
* Finds all elements matching an accessible role.
|
|
285
|
-
*
|
|
286
|
-
* @param container - The container to search within
|
|
287
|
-
* @param role - The GTK accessible role to match
|
|
288
|
-
* @param options - Query options including name, state filters, and timeout
|
|
289
|
-
* @returns Promise resolving to array of matching widgets
|
|
290
|
-
*/
|
|
291
|
-
export const findAllByRole = async (container, role, options) => waitFor(() => getAllByRole(container, role, options), {
|
|
292
|
-
timeout: options?.timeout,
|
|
293
|
-
});
|
|
169
|
+
export const queryAllByText = (container, text, options) => findAll(container, (widget) => matchText(getWidgetLabelText(widget), text, widget, options));
|
|
170
|
+
const textQueries = nameQueryFamily("Text", queryAllByText, buildQueries("Text", queryAllByText, (container, matches, text) => multipleFoundError(container, { queryType: "text", text }, matches), (container, text) => notFoundError(container, { queryType: "text", text })));
|
|
294
171
|
/**
|
|
295
|
-
* Finds
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
* @param container - The container to search within
|
|
301
|
-
* @param text - Label text to match (string, RegExp, or custom matcher)
|
|
302
|
-
* @param options - Query options including normalization and timeout
|
|
303
|
-
* @returns Promise resolving to the labelled widget
|
|
304
|
-
*
|
|
305
|
-
* @example
|
|
306
|
-
* ```tsx
|
|
307
|
-
* const input = await findByLabelText(container, "Username");
|
|
308
|
-
* ```
|
|
172
|
+
* Finds every widget whose widget name matches.
|
|
173
|
+
* @param container Widget subtree to search.
|
|
174
|
+
* @param name Matcher for the widget name.
|
|
175
|
+
* @param options Text matching options.
|
|
176
|
+
* @returns Every matching widget, or an empty array when none match.
|
|
309
177
|
*/
|
|
310
|
-
export const
|
|
311
|
-
|
|
312
|
-
});
|
|
178
|
+
export const queryAllByName = (container, name, options) => findAll(container, (widget) => matchText(getWidgetName(widget), name, widget, options));
|
|
179
|
+
const nameQueries = nameQueryFamily("Name", queryAllByName, buildQueries("Name", queryAllByName, (container, matches, name) => multipleFoundError(container, { queryType: "name", name }, matches), (container, name) => notFoundError(container, { queryType: "name", name })));
|
|
313
180
|
/**
|
|
314
|
-
* Finds
|
|
315
|
-
*
|
|
316
|
-
* @param
|
|
317
|
-
* @param
|
|
318
|
-
* @
|
|
319
|
-
* @returns Promise resolving to array of matching widgets
|
|
181
|
+
* Finds every widget whose placeholder text matches.
|
|
182
|
+
* @param container Widget subtree to search.
|
|
183
|
+
* @param text Matcher for the placeholder text.
|
|
184
|
+
* @param options Text matching options.
|
|
185
|
+
* @returns Every matching widget, or an empty array when none match.
|
|
320
186
|
*/
|
|
321
|
-
export const
|
|
322
|
-
|
|
323
|
-
});
|
|
187
|
+
export const queryAllByPlaceholderText = (container, text, options) => findAll(container, (widget) => matchText(getWidgetPlaceholderText(widget), text, widget, options));
|
|
188
|
+
const placeholderTextQueries = nameQueryFamily("PlaceholderText", queryAllByPlaceholderText, buildQueries("PlaceholderText", queryAllByPlaceholderText, (container, matches, text) => multipleFoundError(container, { queryType: "placeholderText", text }, matches), (container, text) => notFoundError(container, { queryType: "placeholderText", text })));
|
|
324
189
|
/**
|
|
325
|
-
* Finds
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
* @
|
|
330
|
-
* @param text - Text to match (string, RegExp, or custom matcher)
|
|
331
|
-
* @param options - Query options including normalization and timeout
|
|
332
|
-
* @returns Promise resolving to the matching widget
|
|
190
|
+
* Finds every widget whose current display value matches.
|
|
191
|
+
* @param container Widget subtree to search.
|
|
192
|
+
* @param value Matcher for the display value.
|
|
193
|
+
* @param options Text matching options.
|
|
194
|
+
* @returns Every matching widget, or an empty array when none match.
|
|
333
195
|
*/
|
|
334
|
-
export const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
*/
|
|
345
|
-
export const
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
*/
|
|
365
|
-
export const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
196
|
+
export const queryAllByDisplayValue = (container, value, options) => findAll(container, (widget) => matchText(getWidgetDisplayValue(widget), value, widget, options));
|
|
197
|
+
const displayValueQueries = nameQueryFamily("DisplayValue", queryAllByDisplayValue, buildQueries("DisplayValue", queryAllByDisplayValue, (container, matches, value) => multipleFoundError(container, { queryType: "displayValue", value }, matches), (container, value) => notFoundError(container, { queryType: "displayValue", value })));
|
|
198
|
+
export const builtinQueries = {
|
|
199
|
+
...roleQueries,
|
|
200
|
+
...labelTextQueries,
|
|
201
|
+
...textQueries,
|
|
202
|
+
...nameQueries,
|
|
203
|
+
...placeholderTextQueries,
|
|
204
|
+
...displayValueQueries,
|
|
205
|
+
};
|
|
206
|
+
/** Returns the single widget with a matching accessible role and options, or null when none match. Throws when more than one matches. */
|
|
207
|
+
export const queryByRole = roleQueries.queryByRole;
|
|
208
|
+
/** Returns every widget with a matching accessible role and options. Throws when none match. */
|
|
209
|
+
export const getAllByRole = roleQueries.getAllByRole;
|
|
210
|
+
/** Returns the single widget with a matching accessible role and options. Throws when none or more than one matches. */
|
|
211
|
+
export const getByRole = roleQueries.getByRole;
|
|
212
|
+
/** Waits for and returns every widget with a matching accessible role and options, retrying until at least one appears or the timeout elapses. */
|
|
213
|
+
export const findAllByRole = roleQueries.findAllByRole;
|
|
214
|
+
/** Waits for and returns the single widget with a matching accessible role and options, retrying until it appears or the timeout elapses. Rejects when none or more than one matches. */
|
|
215
|
+
export const findByRole = roleQueries.findByRole;
|
|
216
|
+
/** Returns the single widget with matching associated label text, or null when none match. Throws when more than one matches. */
|
|
217
|
+
export const queryByLabelText = labelTextQueries.queryByLabelText;
|
|
218
|
+
/** Returns every widget with matching associated label text. Throws when none match. */
|
|
219
|
+
export const getAllByLabelText = labelTextQueries.getAllByLabelText;
|
|
220
|
+
/** Returns the single widget with matching associated label text. Throws when none or more than one matches. */
|
|
221
|
+
export const getByLabelText = labelTextQueries.getByLabelText;
|
|
222
|
+
/** Waits for and returns every widget with matching associated label text, retrying until at least one appears or the timeout elapses. */
|
|
223
|
+
export const findAllByLabelText = labelTextQueries.findAllByLabelText;
|
|
224
|
+
/** Waits for and returns the single widget with matching associated label text, retrying until it appears or the timeout elapses. Rejects when none or more than one matches. */
|
|
225
|
+
export const findByLabelText = labelTextQueries.findByLabelText;
|
|
226
|
+
/** Returns the single widget with matching rendered text content, or null when none match. Throws when more than one matches. */
|
|
227
|
+
export const queryByText = textQueries.queryByText;
|
|
228
|
+
/** Returns every widget with matching rendered text content. Throws when none match. */
|
|
229
|
+
export const getAllByText = textQueries.getAllByText;
|
|
230
|
+
/** Returns the single widget with matching rendered text content. Throws when none or more than one matches. */
|
|
231
|
+
export const getByText = textQueries.getByText;
|
|
232
|
+
/** Waits for and returns every widget with matching rendered text content, retrying until at least one appears or the timeout elapses. */
|
|
233
|
+
export const findAllByText = textQueries.findAllByText;
|
|
234
|
+
/** Waits for and returns the single widget with matching rendered text content, retrying until it appears or the timeout elapses. Rejects when none or more than one matches. */
|
|
235
|
+
export const findByText = textQueries.findByText;
|
|
236
|
+
/** Returns the single widget with a matching widget name, or null when none match. Throws when more than one matches. */
|
|
237
|
+
export const queryByName = nameQueries.queryByName;
|
|
238
|
+
/** Returns every widget with a matching widget name. Throws when none match. */
|
|
239
|
+
export const getAllByName = nameQueries.getAllByName;
|
|
240
|
+
/** Returns the single widget with a matching widget name. Throws when none or more than one matches. */
|
|
241
|
+
export const getByName = nameQueries.getByName;
|
|
242
|
+
/** Waits for and returns every widget with a matching widget name, retrying until at least one appears or the timeout elapses. */
|
|
243
|
+
export const findAllByName = nameQueries.findAllByName;
|
|
244
|
+
/** Waits for and returns the single widget with a matching widget name, retrying until it appears or the timeout elapses. Rejects when none or more than one matches. */
|
|
245
|
+
export const findByName = nameQueries.findByName;
|
|
246
|
+
/** Returns the single widget with matching placeholder text, or null when none match. Throws when more than one matches. */
|
|
247
|
+
export const queryByPlaceholderText = placeholderTextQueries.queryByPlaceholderText;
|
|
248
|
+
/** Returns every widget with matching placeholder text. Throws when none match. */
|
|
249
|
+
export const getAllByPlaceholderText = placeholderTextQueries.getAllByPlaceholderText;
|
|
250
|
+
/** Returns the single widget with matching placeholder text. Throws when none or more than one matches. */
|
|
251
|
+
export const getByPlaceholderText = placeholderTextQueries.getByPlaceholderText;
|
|
252
|
+
/** Waits for and returns every widget with matching placeholder text, retrying until at least one appears or the timeout elapses. */
|
|
253
|
+
export const findAllByPlaceholderText = placeholderTextQueries.findAllByPlaceholderText;
|
|
254
|
+
/** Waits for and returns the single widget with matching placeholder text, retrying until it appears or the timeout elapses. Rejects when none or more than one matches. */
|
|
255
|
+
export const findByPlaceholderText = placeholderTextQueries.findByPlaceholderText;
|
|
256
|
+
/** Returns the single widget with a matching display value, or null when none match. Throws when more than one matches. */
|
|
257
|
+
export const queryByDisplayValue = displayValueQueries.queryByDisplayValue;
|
|
258
|
+
/** Returns every widget with a matching display value. Throws when none match. */
|
|
259
|
+
export const getAllByDisplayValue = displayValueQueries.getAllByDisplayValue;
|
|
260
|
+
/** Returns the single widget with a matching display value. Throws when none or more than one matches. */
|
|
261
|
+
export const getByDisplayValue = displayValueQueries.getByDisplayValue;
|
|
262
|
+
/** Waits for and returns every widget with a matching display value, retrying until at least one appears or the timeout elapses. */
|
|
263
|
+
export const findAllByDisplayValue = displayValueQueries.findAllByDisplayValue;
|
|
264
|
+
/** Waits for and returns the single widget with a matching display value, retrying until it appears or the timeout elapses. Rejects when none or more than one matches. */
|
|
265
|
+
export const findByDisplayValue = displayValueQueries.findByDisplayValue;
|
|
379
266
|
//# sourceMappingURL=queries.js.map
|