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