@gtkx/testing 1.0.0-rc.1 → 1.0.0-rc.2
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/dist/act.d.ts +6 -6
- package/dist/act.d.ts.map +1 -1
- package/dist/act.js +34 -26
- package/dist/act.js.map +1 -1
- package/dist/bound-queries.d.ts +4 -3
- package/dist/bound-queries.d.ts.map +1 -1
- package/dist/bound-queries.js.map +1 -1
- package/dist/build-queries.d.ts +5 -5
- package/dist/build-queries.d.ts.map +1 -1
- package/dist/build-queries.js +21 -9
- package/dist/build-queries.js.map +1 -1
- package/dist/cleanup-registry.d.ts +4 -3
- package/dist/cleanup-registry.d.ts.map +1 -1
- package/dist/cleanup-registry.js +13 -3
- package/dist/cleanup-registry.js.map +1 -1
- package/dist/config.d.ts +5 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +11 -9
- package/dist/config.js.map +1 -1
- package/dist/editable.d.ts +6 -5
- package/dist/editable.d.ts.map +1 -1
- package/dist/editable.js +7 -5
- package/dist/editable.js.map +1 -1
- package/dist/errors.d.ts +7 -6
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +64 -48
- package/dist/errors.js.map +1 -1
- package/dist/fire-event.d.ts +2 -1
- package/dist/fire-event.d.ts.map +1 -1
- package/dist/fire-event.js +2 -1
- package/dist/fire-event.js.map +1 -1
- package/dist/frame-sync.d.ts +2 -1
- package/dist/frame-sync.d.ts.map +1 -1
- package/dist/frame-sync.js +28 -21
- package/dist/frame-sync.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/matchers.d.ts +38 -34
- package/dist/matchers.d.ts.map +1 -1
- package/dist/matchers.js +72 -58
- package/dist/matchers.js.map +1 -1
- package/dist/pretty-widget.d.ts +6 -4
- package/dist/pretty-widget.d.ts.map +1 -1
- package/dist/pretty-widget.js +64 -24
- package/dist/pretty-widget.js.map +1 -1
- package/dist/queries.d.ts +143 -86
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +231 -147
- package/dist/queries.js.map +1 -1
- package/dist/register-test-hooks.js +2 -1
- package/dist/register-test-hooks.js.map +1 -1
- package/dist/render-hook.d.ts +3 -2
- package/dist/render-hook.d.ts.map +1 -1
- package/dist/render-hook.js +2 -1
- package/dist/render-hook.js.map +1 -1
- package/dist/render.d.ts +3 -2
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +24 -18
- package/dist/render.js.map +1 -1
- package/dist/role-helpers.d.ts +6 -5
- package/dist/role-helpers.d.ts.map +1 -1
- package/dist/role-helpers.js +16 -12
- package/dist/role-helpers.js.map +1 -1
- package/dist/screen.d.ts +4 -3
- package/dist/screen.d.ts.map +1 -1
- package/dist/screen.js +13 -11
- package/dist/screen.js.map +1 -1
- package/dist/screenshot.d.ts +4 -3
- package/dist/screenshot.d.ts.map +1 -1
- package/dist/screenshot.js +43 -36
- package/dist/screenshot.js.map +1 -1
- package/dist/suggestions.d.ts +11 -6
- package/dist/suggestions.d.ts.map +1 -1
- package/dist/suggestions.js +10 -5
- package/dist/suggestions.js.map +1 -1
- package/dist/traversal.d.ts +7 -7
- package/dist/traversal.d.ts.map +1 -1
- package/dist/traversal.js +17 -11
- package/dist/traversal.js.map +1 -1
- package/dist/types.d.ts +39 -24
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/user-event/adjustment.d.ts +5 -3
- package/dist/user-event/adjustment.d.ts.map +1 -1
- package/dist/user-event/adjustment.js +6 -4
- package/dist/user-event/adjustment.js.map +1 -1
- package/dist/user-event/click.d.ts +6 -5
- package/dist/user-event/click.d.ts.map +1 -1
- package/dist/user-event/click.js +29 -21
- package/dist/user-event/click.js.map +1 -1
- package/dist/user-event/controller.d.ts +6 -5
- package/dist/user-event/controller.d.ts.map +1 -1
- package/dist/user-event/controller.js +9 -6
- package/dist/user-event/controller.js.map +1 -1
- package/dist/user-event/dispatch.d.ts +3 -3
- package/dist/user-event/dispatch.d.ts.map +1 -1
- package/dist/user-event/dispatch.js +3 -2
- package/dist/user-event/dispatch.js.map +1 -1
- package/dist/user-event/event-wrapper.d.ts +2 -1
- package/dist/user-event/event-wrapper.d.ts.map +1 -1
- package/dist/user-event/event-wrapper.js +27 -16
- package/dist/user-event/event-wrapper.js.map +1 -1
- package/dist/user-event/gesture.d.ts +18 -14
- package/dist/user-event/gesture.d.ts.map +1 -1
- package/dist/user-event/gesture.js +70 -37
- package/dist/user-event/gesture.js.map +1 -1
- package/dist/user-event/index.d.ts +17 -10
- package/dist/user-event/index.d.ts.map +1 -1
- package/dist/user-event/index.js +7 -3
- package/dist/user-event/index.js.map +1 -1
- package/dist/user-event/keyboard.d.ts +4 -3
- package/dist/user-event/keyboard.d.ts.map +1 -1
- package/dist/user-event/keyboard.js +89 -58
- package/dist/user-event/keyboard.js.map +1 -1
- package/dist/user-event/pointer.d.ts +7 -3
- package/dist/user-event/pointer.d.ts.map +1 -1
- package/dist/user-event/pointer.js +4 -1
- package/dist/user-event/pointer.js.map +1 -1
- package/dist/user-event/selection.d.ts +3 -2
- package/dist/user-event/selection.d.ts.map +1 -1
- package/dist/user-event/selection.js +26 -27
- package/dist/user-event/selection.js.map +1 -1
- package/dist/user-event/state.d.ts +3 -2
- package/dist/user-event/state.d.ts.map +1 -1
- package/dist/user-event/state.js +2 -1
- package/dist/user-event/state.js.map +1 -1
- package/dist/user-event/text.d.ts +8 -7
- package/dist/user-event/text.d.ts.map +1 -1
- package/dist/user-event/text.js +39 -33
- package/dist/user-event/text.js.map +1 -1
- package/dist/wait-for.d.ts +5 -5
- package/dist/wait-for.d.ts.map +1 -1
- package/dist/wait-for.js +45 -30
- package/dist/wait-for.js.map +1 -1
- package/dist/widget-accessible-properties.d.ts +26 -25
- package/dist/widget-accessible-properties.d.ts.map +1 -1
- package/dist/widget-accessible-properties.js +106 -61
- package/dist/widget-accessible-properties.js.map +1 -1
- package/dist/within.d.ts +2 -1
- package/dist/within.d.ts.map +1 -1
- package/dist/within.js +2 -1
- package/dist/within.js.map +1 -1
- package/package.json +11 -9
- package/src/act.ts +44 -35
- package/src/bound-queries.ts +5 -4
- package/src/build-queries.ts +84 -43
- package/src/cleanup-registry.ts +18 -5
- package/src/config.ts +16 -12
- package/src/editable.ts +13 -6
- package/src/errors.ts +106 -45
- package/src/fire-event.ts +3 -1
- package/src/frame-sync.ts +38 -21
- package/src/index.ts +2 -1
- package/src/matchers.ts +158 -107
- package/src/pretty-widget.ts +114 -42
- package/src/queries.ts +422 -233
- package/src/register-test-hooks.ts +4 -1
- package/src/render-hook.tsx +10 -4
- package/src/render.tsx +58 -33
- package/src/role-helpers.ts +29 -16
- package/src/screen.ts +17 -12
- package/src/screenshot.ts +61 -38
- package/src/suggestions.ts +29 -10
- package/src/traversal.ts +35 -15
- package/src/types.ts +65 -32
- package/src/user-event/adjustment.ts +23 -10
- package/src/user-event/click.ts +49 -20
- package/src/user-event/controller.ts +21 -7
- package/src/user-event/dispatch.ts +4 -2
- package/src/user-event/event-wrapper.ts +42 -16
- package/src/user-event/gesture.ts +135 -50
- package/src/user-event/index.ts +19 -12
- package/src/user-event/keyboard.ts +147 -61
- package/src/user-event/pointer.ts +20 -8
- package/src/user-event/selection.ts +69 -32
- package/src/user-event/state.ts +4 -2
- package/src/user-event/text.ts +73 -38
- package/src/wait-for.ts +77 -36
- package/src/widget-accessible-properties.ts +218 -74
- package/src/within.ts +7 -4
package/dist/queries.js
CHANGED
|
@@ -3,12 +3,144 @@ import { buildQueries } from "./build-queries.js";
|
|
|
3
3
|
import { multipleFoundError, notFoundError } from "./errors.js";
|
|
4
4
|
import { findAll, traverse } from "./traversal.js";
|
|
5
5
|
import { getWidgetAccessibleName, getWidgetBusyState, getWidgetCheckedState, getWidgetDescription, getWidgetDisplayValue, getWidgetExpandedState, getWidgetLabelledByText, getWidgetLabelText, getWidgetLevel, getWidgetName, getWidgetOwnLabel, getWidgetPlaceholderText, getWidgetPressedState, getWidgetSelectedState, getWidgetValue, isInaccessible, } from "./widget-accessible-properties.js";
|
|
6
|
+
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 })));
|
|
7
|
+
const labelTextQueries = nameQueryFamily("LabelText", queryAllByLabelText, buildQueries("LabelText", queryAllByLabelText, (container, matches, text) => multipleFoundError(container, { queryType: "labelText", text }, matches), (container, text) => notFoundError(container, { queryType: "labelText", text })));
|
|
8
|
+
const textQueries = nameQueryFamily("Text", queryAllByText, buildQueries("Text", queryAllByText, (container, matches, text) => multipleFoundError(container, { queryType: "text", text }, matches), (container, text) => notFoundError(container, { queryType: "text", text })));
|
|
9
|
+
const nameQueries = nameQueryFamily("Name", queryAllByName, buildQueries("Name", queryAllByName, (container, matches, name) => multipleFoundError(container, { queryType: "name", name }, matches), (container, name) => notFoundError(container, { queryType: "name", name })));
|
|
10
|
+
const placeholderTextQueries = nameQueryFamily("PlaceholderText", queryAllByPlaceholderText, buildQueries("PlaceholderText", queryAllByPlaceholderText, (container, matches, text) => multipleFoundError(container, { queryType: "placeholderText", text }, matches), (container, text) => notFoundError(container, { queryType: "placeholderText", text })));
|
|
11
|
+
const displayValueQueries = nameQueryFamily("DisplayValue", queryAllByDisplayValue, buildQueries("DisplayValue", queryAllByDisplayValue, (container, matches, value) => multipleFoundError(container, { queryType: "displayValue", value }, matches), (container, value) => notFoundError(container, { queryType: "displayValue", value })));
|
|
12
|
+
const builtinQueries = {
|
|
13
|
+
...roleQueries,
|
|
14
|
+
...labelTextQueries,
|
|
15
|
+
...textQueries,
|
|
16
|
+
...nameQueries,
|
|
17
|
+
...placeholderTextQueries,
|
|
18
|
+
...displayValueQueries,
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Returns the single widget with a matching accessible role and options, or null when none match.
|
|
22
|
+
* Throws when more than one matches.
|
|
23
|
+
*/
|
|
24
|
+
const queryByRole = roleQueries.queryByRole;
|
|
25
|
+
/** Returns every widget with a matching accessible role and options. Throws when none match. */
|
|
26
|
+
const getAllByRole = roleQueries.getAllByRole;
|
|
6
27
|
/**
|
|
7
|
-
*
|
|
28
|
+
* Returns the single widget with a matching accessible role and options.
|
|
29
|
+
* Throws when none or more than one matches.
|
|
30
|
+
*/
|
|
31
|
+
const getByRole = roleQueries.getByRole;
|
|
32
|
+
/**
|
|
33
|
+
* Waits for and returns every widget with a matching accessible role and options, retrying until at
|
|
34
|
+
* least one appears or the timeout elapses.
|
|
35
|
+
*/
|
|
36
|
+
const findAllByRole = roleQueries.findAllByRole;
|
|
37
|
+
/**
|
|
38
|
+
* Waits for and returns the single widget with a matching accessible role and options, retrying
|
|
39
|
+
* until it appears or the timeout elapses. Rejects when none or more than one matches.
|
|
40
|
+
*/
|
|
41
|
+
const findByRole = roleQueries.findByRole;
|
|
42
|
+
/**
|
|
43
|
+
* Returns the single widget with matching associated label text, or null when none match.
|
|
44
|
+
* Throws when more than one matches.
|
|
45
|
+
*/
|
|
46
|
+
const queryByLabelText = labelTextQueries.queryByLabelText;
|
|
47
|
+
/** Returns every widget with matching associated label text. Throws when none match. */
|
|
48
|
+
const getAllByLabelText = labelTextQueries.getAllByLabelText;
|
|
49
|
+
/** Returns the single widget with matching associated label text. Throws when none or more than one matches. */
|
|
50
|
+
const getByLabelText = labelTextQueries.getByLabelText;
|
|
51
|
+
/**
|
|
52
|
+
* Waits for and returns every widget with matching associated label text, retrying until at least
|
|
53
|
+
* one appears or the timeout elapses.
|
|
54
|
+
*/
|
|
55
|
+
const findAllByLabelText = labelTextQueries.findAllByLabelText;
|
|
56
|
+
/**
|
|
57
|
+
* Waits for and returns the single widget with matching associated label text, retrying until it
|
|
58
|
+
* appears or the timeout elapses. Rejects when none or more than one matches.
|
|
59
|
+
*/
|
|
60
|
+
const findByLabelText = labelTextQueries.findByLabelText;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the single widget with matching rendered text content, or null when none match.
|
|
63
|
+
* Throws when more than one matches.
|
|
64
|
+
*/
|
|
65
|
+
const queryByText = textQueries.queryByText;
|
|
66
|
+
/** Returns every widget with matching rendered text content. Throws when none match. */
|
|
67
|
+
const getAllByText = textQueries.getAllByText;
|
|
68
|
+
/** Returns the single widget with matching rendered text content. Throws when none or more than one matches. */
|
|
69
|
+
const getByText = textQueries.getByText;
|
|
70
|
+
/**
|
|
71
|
+
* Waits for and returns every widget with matching rendered text content, retrying until at least
|
|
72
|
+
* one appears or the timeout elapses.
|
|
73
|
+
*/
|
|
74
|
+
const findAllByText = textQueries.findAllByText;
|
|
75
|
+
/**
|
|
76
|
+
* Waits for and returns the single widget with matching rendered text content, retrying until it
|
|
77
|
+
* appears or the timeout elapses. Rejects when none or more than one matches.
|
|
78
|
+
*/
|
|
79
|
+
const findByText = textQueries.findByText;
|
|
80
|
+
/**
|
|
81
|
+
* Returns the single widget with a matching widget name, or null when none match.
|
|
82
|
+
* Throws when more than one matches.
|
|
83
|
+
*/
|
|
84
|
+
const queryByName = nameQueries.queryByName;
|
|
85
|
+
/** Returns every widget with a matching widget name. Throws when none match. */
|
|
86
|
+
const getAllByName = nameQueries.getAllByName;
|
|
87
|
+
/** Returns the single widget with a matching widget name. Throws when none or more than one matches. */
|
|
88
|
+
const getByName = nameQueries.getByName;
|
|
89
|
+
/**
|
|
90
|
+
* Waits for and returns every widget with a matching widget name, retrying until at least one
|
|
91
|
+
* appears or the timeout elapses.
|
|
92
|
+
*/
|
|
93
|
+
const findAllByName = nameQueries.findAllByName;
|
|
94
|
+
/**
|
|
95
|
+
* Waits for and returns the single widget with a matching widget name, retrying until it appears or
|
|
96
|
+
* the timeout elapses. Rejects when none or more than one matches.
|
|
97
|
+
*/
|
|
98
|
+
const findByName = nameQueries.findByName;
|
|
99
|
+
/**
|
|
100
|
+
* Returns the single widget with matching placeholder text, or null when none match.
|
|
101
|
+
* Throws when more than one matches.
|
|
102
|
+
*/
|
|
103
|
+
const queryByPlaceholderText = placeholderTextQueries.queryByPlaceholderText;
|
|
104
|
+
/** Returns every widget with matching placeholder text. Throws when none match. */
|
|
105
|
+
const getAllByPlaceholderText = placeholderTextQueries.getAllByPlaceholderText;
|
|
106
|
+
/** Returns the single widget with matching placeholder text. Throws when none or more than one matches. */
|
|
107
|
+
const getByPlaceholderText = placeholderTextQueries.getByPlaceholderText;
|
|
108
|
+
/**
|
|
109
|
+
* Waits for and returns every widget with matching placeholder text, retrying until at least one
|
|
110
|
+
* appears or the timeout elapses.
|
|
111
|
+
*/
|
|
112
|
+
const findAllByPlaceholderText = placeholderTextQueries.findAllByPlaceholderText;
|
|
113
|
+
/**
|
|
114
|
+
* Waits for and returns the single widget with matching placeholder text, retrying until it appears
|
|
115
|
+
* or the timeout elapses. Rejects when none or more than one matches.
|
|
116
|
+
*/
|
|
117
|
+
const findByPlaceholderText = placeholderTextQueries.findByPlaceholderText;
|
|
118
|
+
/**
|
|
119
|
+
* Returns the single widget with a matching display value, or null when none match.
|
|
120
|
+
* Throws when more than one matches.
|
|
121
|
+
*/
|
|
122
|
+
const queryByDisplayValue = displayValueQueries.queryByDisplayValue;
|
|
123
|
+
/** Returns every widget with a matching display value. Throws when none match. */
|
|
124
|
+
const getAllByDisplayValue = displayValueQueries.getAllByDisplayValue;
|
|
125
|
+
/** Returns the single widget with a matching display value. Throws when none or more than one matches. */
|
|
126
|
+
const getByDisplayValue = displayValueQueries.getByDisplayValue;
|
|
127
|
+
/**
|
|
128
|
+
* Waits for and returns every widget with a matching display value, retrying until at least one
|
|
129
|
+
* appears or the timeout elapses.
|
|
130
|
+
*/
|
|
131
|
+
const findAllByDisplayValue = displayValueQueries.findAllByDisplayValue;
|
|
132
|
+
/**
|
|
133
|
+
* Waits for and returns the single widget with a matching display value, retrying until it appears
|
|
134
|
+
* or the timeout elapses. Rejects when none or more than one matches.
|
|
135
|
+
*/
|
|
136
|
+
const findByDisplayValue = displayValueQueries.findByDisplayValue;
|
|
137
|
+
/**
|
|
138
|
+
* Builds the default text normalizer, which optionally trims surrounding whitespace and collapses
|
|
139
|
+
* runs of whitespace into single spaces.
|
|
8
140
|
* @param options Toggles for trimming and whitespace collapsing.
|
|
9
141
|
* @returns A function that normalizes a string for comparison against a matcher.
|
|
10
142
|
*/
|
|
11
|
-
|
|
143
|
+
const getDefaultNormalizer = ({ trim = true, collapseWhitespace = true, } = {}) => {
|
|
12
144
|
return (text) => {
|
|
13
145
|
let result = text;
|
|
14
146
|
if (trim) {
|
|
@@ -28,7 +160,7 @@ const buildNormalizer = (options) => {
|
|
|
28
160
|
if (trim !== undefined || collapseWhitespace !== undefined) {
|
|
29
161
|
throw new Error("trim and collapseWhitespace are not supported with a normalizer. " +
|
|
30
162
|
"If you want to use the default trim and collapseWhitespace logic in your normalizer, " +
|
|
31
|
-
|
|
163
|
+
"use \"getDefaultNormalizer({ trim, collapseWhitespace })\" and compose that into your normalizer");
|
|
32
164
|
}
|
|
33
165
|
return normalizer;
|
|
34
166
|
};
|
|
@@ -36,9 +168,10 @@ const normalizeText = (text, options) => {
|
|
|
36
168
|
const normalizer = buildNormalizer(options);
|
|
37
169
|
return normalizer(text);
|
|
38
170
|
};
|
|
39
|
-
const
|
|
40
|
-
if (actual === null)
|
|
171
|
+
const isTextMatch = (actual, expected, widget, options) => {
|
|
172
|
+
if (actual === null) {
|
|
41
173
|
return false;
|
|
174
|
+
}
|
|
42
175
|
const normalizedActual = normalizeText(actual, options);
|
|
43
176
|
if (typeof expected === "function") {
|
|
44
177
|
return expected(normalizedActual, widget);
|
|
@@ -48,60 +181,63 @@ const matchText = (actual, expected, widget, options) => {
|
|
|
48
181
|
return expected.test(normalizedActual);
|
|
49
182
|
}
|
|
50
183
|
const normalizedExpected = normalizeText(String(expected), options);
|
|
51
|
-
const
|
|
52
|
-
return
|
|
184
|
+
const isExact = options?.exact ?? true;
|
|
185
|
+
return isExact
|
|
53
186
|
? normalizedActual === normalizedExpected
|
|
54
187
|
: normalizedActual.toLowerCase().includes(normalizedExpected.toLowerCase());
|
|
55
188
|
};
|
|
56
|
-
const
|
|
57
|
-
if (options.name === undefined)
|
|
189
|
+
const hasMatchingAccessibleName = (widget, options) => {
|
|
190
|
+
if (options.name === undefined) {
|
|
58
191
|
return true;
|
|
192
|
+
}
|
|
59
193
|
const text = getWidgetAccessibleName(widget);
|
|
60
|
-
return
|
|
194
|
+
return isTextMatch(text, options.name, widget, options);
|
|
61
195
|
};
|
|
62
|
-
const
|
|
196
|
+
const isNumericValueMatch = (expected, actual) => expected === undefined || actual === expected;
|
|
197
|
+
const hasMatchingAccessibleValue = (widget, value, options) => {
|
|
63
198
|
const actual = getWidgetValue(widget);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
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;
|
|
199
|
+
const numericChecks = [
|
|
200
|
+
[value.now, actual.now],
|
|
201
|
+
[value.min, actual.min],
|
|
202
|
+
[value.max, actual.max],
|
|
203
|
+
];
|
|
204
|
+
for (const [expected, current] of numericChecks) {
|
|
205
|
+
if (!isNumericValueMatch(expected, current)) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return value.text === undefined || isTextMatch(actual.text, value.text, widget, options);
|
|
86
210
|
};
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
211
|
+
const hasMatchingBooleanStates = (widget, options) => {
|
|
212
|
+
const stateChecks = [
|
|
213
|
+
[options.checked, () => getWidgetCheckedState(widget)],
|
|
214
|
+
[options.pressed, () => getWidgetPressedState(widget)],
|
|
215
|
+
[options.expanded, () => getWidgetExpandedState(widget)],
|
|
216
|
+
[options.selected, () => getWidgetSelectedState(widget)],
|
|
217
|
+
[options.busy, () => getWidgetBusyState(widget) ?? false],
|
|
218
|
+
];
|
|
219
|
+
for (const [expected, getActual] of stateChecks) {
|
|
220
|
+
if (expected !== undefined && getActual() !== expected) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
97
224
|
return true;
|
|
98
225
|
};
|
|
99
|
-
const
|
|
100
|
-
|
|
226
|
+
const hasMatchingLevelState = (widget, options) => options.level === undefined || getWidgetLevel(widget) === options.level;
|
|
227
|
+
const hasMatchingDescriptionState = (widget, options) => options.description === undefined ||
|
|
228
|
+
isTextMatch(getWidgetDescription(widget), options.description, widget, options);
|
|
229
|
+
const hasMatchingValueState = (widget, options) => options.value === undefined || hasMatchingAccessibleValue(widget, options.value, options);
|
|
230
|
+
const hasMatchingAccessibleStates = (widget, options) => hasMatchingBooleanStates(widget, options) &&
|
|
231
|
+
hasMatchingLevelState(widget, options) &&
|
|
232
|
+
hasMatchingDescriptionState(widget, options) &&
|
|
233
|
+
hasMatchingValueState(widget, options);
|
|
234
|
+
const hasMatchingByRoleOptions = (widget, options) => {
|
|
235
|
+
if (!options) {
|
|
101
236
|
return true;
|
|
102
|
-
|
|
237
|
+
}
|
|
238
|
+
return hasMatchingAccessibleName(widget, options) && hasMatchingAccessibleStates(widget, options);
|
|
103
239
|
};
|
|
104
|
-
|
|
240
|
+
function nameQueryFamily(suffix, queryAllBy, built) {
|
|
105
241
|
const family = {
|
|
106
242
|
[`queryBy${suffix}`]: built.queryBy,
|
|
107
243
|
[`queryAllBy${suffix}`]: queryAllBy,
|
|
@@ -111,7 +247,7 @@ const nameQueryFamily = (suffix, queryAllBy, built) => {
|
|
|
111
247
|
[`findAllBy${suffix}`]: built.findAllBy,
|
|
112
248
|
};
|
|
113
249
|
return family;
|
|
114
|
-
}
|
|
250
|
+
}
|
|
115
251
|
/**
|
|
116
252
|
* Finds every widget under the container whose accessible role matches `role` and that satisfies the given options.
|
|
117
253
|
* Widgets excluded from the accessibility tree are skipped unless `options.hidden` is set.
|
|
@@ -120,45 +256,56 @@ const nameQueryFamily = (suffix, queryAllBy, built) => {
|
|
|
120
256
|
* @param options Additional accessible name, state, and value constraints.
|
|
121
257
|
* @returns Every matching widget, or an empty array when none match.
|
|
122
258
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
259
|
+
function queryAllByRole(container, role, options) {
|
|
260
|
+
return findAll(container, (widget) => {
|
|
261
|
+
if (widget.getAccessibleRole() !== role) {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
if (!options?.hidden && isInaccessible(widget)) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
return hasMatchingByRoleOptions(widget, options);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
131
270
|
const collectMnemonicMatch = (widget, text, options) => {
|
|
132
|
-
if (!(widget instanceof Gtk.Label))
|
|
271
|
+
if (!(widget instanceof Gtk.Label)) {
|
|
133
272
|
return null;
|
|
273
|
+
}
|
|
134
274
|
const labelText = widget.getLabel();
|
|
135
|
-
if (!labelText || !
|
|
275
|
+
if (!labelText || !isTextMatch(labelText, text, widget, options)) {
|
|
136
276
|
return null;
|
|
277
|
+
}
|
|
137
278
|
return widget.getMnemonicWidget();
|
|
138
279
|
};
|
|
280
|
+
const collectLabelMatches = (results, widget, text, options) => {
|
|
281
|
+
const mnemonicTarget = collectMnemonicMatch(widget, text, options);
|
|
282
|
+
if (mnemonicTarget) {
|
|
283
|
+
results.add(mnemonicTarget);
|
|
284
|
+
}
|
|
285
|
+
const ownLabel = getWidgetOwnLabel(widget);
|
|
286
|
+
if (ownLabel !== null && isTextMatch(ownLabel, text, widget, options)) {
|
|
287
|
+
results.add(widget);
|
|
288
|
+
}
|
|
289
|
+
const labelledByText = getWidgetLabelledByText(widget);
|
|
290
|
+
if (labelledByText !== null && isTextMatch(labelledByText, text, widget, options)) {
|
|
291
|
+
results.add(widget);
|
|
292
|
+
}
|
|
293
|
+
};
|
|
139
294
|
/**
|
|
140
|
-
* Finds every widget associated with a label whose text matches: a Gtk.Label mnemonic target, the
|
|
295
|
+
* Finds every widget associated with a label whose text matches: a Gtk.Label mnemonic target, the
|
|
296
|
+
* widget's own accessible label, or its labelled-by relation.
|
|
141
297
|
* @param container Widget subtree to search.
|
|
142
298
|
* @param text Matcher for the label text.
|
|
143
299
|
* @param options Text matching options.
|
|
144
300
|
* @returns Every matching widget, or an empty array when none match.
|
|
145
301
|
*/
|
|
146
|
-
|
|
302
|
+
function queryAllByLabelText(container, text, options) {
|
|
147
303
|
const results = new Set();
|
|
148
304
|
for (const widget of traverse(container)) {
|
|
149
|
-
|
|
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);
|
|
305
|
+
collectLabelMatches(results, widget, text, options);
|
|
158
306
|
}
|
|
159
307
|
return [...results];
|
|
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 })));
|
|
308
|
+
}
|
|
162
309
|
/**
|
|
163
310
|
* Finds every widget whose rendered text content matches.
|
|
164
311
|
* @param container Widget subtree to search.
|
|
@@ -166,8 +313,9 @@ const labelTextQueries = nameQueryFamily("LabelText", queryAllByLabelText, build
|
|
|
166
313
|
* @param options Text matching options.
|
|
167
314
|
* @returns Every matching widget, or an empty array when none match.
|
|
168
315
|
*/
|
|
169
|
-
|
|
170
|
-
|
|
316
|
+
function queryAllByText(container, text, options) {
|
|
317
|
+
return findAll(container, (widget) => isTextMatch(getWidgetLabelText(widget), text, widget, options));
|
|
318
|
+
}
|
|
171
319
|
/**
|
|
172
320
|
* Finds every widget whose widget name matches.
|
|
173
321
|
* @param container Widget subtree to search.
|
|
@@ -175,8 +323,9 @@ const textQueries = nameQueryFamily("Text", queryAllByText, buildQueries("Text",
|
|
|
175
323
|
* @param options Text matching options.
|
|
176
324
|
* @returns Every matching widget, or an empty array when none match.
|
|
177
325
|
*/
|
|
178
|
-
|
|
179
|
-
|
|
326
|
+
function queryAllByName(container, name, options) {
|
|
327
|
+
return findAll(container, (widget) => isTextMatch(getWidgetName(widget), name, widget, options));
|
|
328
|
+
}
|
|
180
329
|
/**
|
|
181
330
|
* Finds every widget whose placeholder text matches.
|
|
182
331
|
* @param container Widget subtree to search.
|
|
@@ -184,8 +333,9 @@ const nameQueries = nameQueryFamily("Name", queryAllByName, buildQueries("Name",
|
|
|
184
333
|
* @param options Text matching options.
|
|
185
334
|
* @returns Every matching widget, or an empty array when none match.
|
|
186
335
|
*/
|
|
187
|
-
|
|
188
|
-
|
|
336
|
+
function queryAllByPlaceholderText(container, text, options) {
|
|
337
|
+
return findAll(container, (widget) => isTextMatch(getWidgetPlaceholderText(widget), text, widget, options));
|
|
338
|
+
}
|
|
189
339
|
/**
|
|
190
340
|
* Finds every widget whose current display value matches.
|
|
191
341
|
* @param container Widget subtree to search.
|
|
@@ -193,74 +343,8 @@ const placeholderTextQueries = nameQueryFamily("PlaceholderText", queryAllByPlac
|
|
|
193
343
|
* @param options Text matching options.
|
|
194
344
|
* @returns Every matching widget, or an empty array when none match.
|
|
195
345
|
*/
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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;
|
|
346
|
+
function queryAllByDisplayValue(container, value, options) {
|
|
347
|
+
return findAll(container, (widget) => isTextMatch(getWidgetDisplayValue(widget), value, widget, options));
|
|
348
|
+
}
|
|
349
|
+
export { builtinQueries, queryByRole, getAllByRole, getByRole, findAllByRole, findByRole, queryByLabelText, getAllByLabelText, getByLabelText, findAllByLabelText, findByLabelText, queryByText, getAllByText, getByText, findAllByText, findByText, queryByName, getAllByName, getByName, findAllByName, findByName, queryByPlaceholderText, getAllByPlaceholderText, getByPlaceholderText, findAllByPlaceholderText, findByPlaceholderText, queryByDisplayValue, getAllByDisplayValue, getByDisplayValue, findAllByDisplayValue, findByDisplayValue, getDefaultNormalizer, queryAllByRole, queryAllByLabelText, queryAllByText, queryAllByName, queryAllByPlaceholderText, queryAllByDisplayValue, };
|
|
266
350
|
//# sourceMappingURL=queries.js.map
|