@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.
Files changed (216) hide show
  1. package/README.md +137 -34
  2. package/dist/act.d.ts +19 -0
  3. package/dist/act.d.ts.map +1 -0
  4. package/dist/act.js +48 -0
  5. package/dist/act.js.map +1 -0
  6. package/dist/bound-queries.d.ts +32 -0
  7. package/dist/bound-queries.d.ts.map +1 -0
  8. package/dist/bound-queries.js +2 -0
  9. package/dist/bound-queries.js.map +1 -0
  10. package/dist/build-queries.d.ts +16 -0
  11. package/dist/build-queries.d.ts.map +1 -0
  12. package/dist/build-queries.js +103 -0
  13. package/dist/build-queries.js.map +1 -0
  14. package/dist/cleanup-registry.d.ts +4 -0
  15. package/dist/cleanup-registry.d.ts.map +1 -0
  16. package/dist/cleanup-registry.js +11 -0
  17. package/dist/cleanup-registry.js.map +1 -0
  18. package/dist/config.d.ts +18 -51
  19. package/dist/config.d.ts.map +1 -1
  20. package/dist/config.js +9 -40
  21. package/dist/config.js.map +1 -1
  22. package/dist/editable.d.ts +7 -0
  23. package/dist/editable.d.ts.map +1 -0
  24. package/dist/editable.js +24 -0
  25. package/dist/editable.js.map +1 -0
  26. package/dist/errors.d.ts +29 -0
  27. package/dist/errors.d.ts.map +1 -0
  28. package/dist/errors.js +119 -0
  29. package/dist/errors.js.map +1 -0
  30. package/dist/fire-event.d.ts +7 -25
  31. package/dist/fire-event.d.ts.map +1 -1
  32. package/dist/fire-event.js +9 -29
  33. package/dist/fire-event.js.map +1 -1
  34. package/dist/frame-sync.d.ts +3 -0
  35. package/dist/frame-sync.d.ts.map +1 -0
  36. package/dist/frame-sync.js +30 -0
  37. package/dist/frame-sync.js.map +1 -0
  38. package/dist/index.d.ts +16 -11
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +10 -6
  41. package/dist/index.js.map +1 -1
  42. package/dist/matchers.d.ts +55 -0
  43. package/dist/matchers.d.ts.map +1 -0
  44. package/dist/matchers.js +103 -0
  45. package/dist/matchers.js.map +1 -0
  46. package/dist/pretty-widget.d.ts +21 -25
  47. package/dist/pretty-widget.d.ts.map +1 -1
  48. package/dist/pretty-widget.js +69 -115
  49. package/dist/pretty-widget.js.map +1 -1
  50. package/dist/queries.d.ts +130 -177
  51. package/dist/queries.d.ts.map +1 -1
  52. package/dist/queries.js +212 -325
  53. package/dist/queries.js.map +1 -1
  54. package/dist/register-test-hooks.d.ts +2 -0
  55. package/dist/register-test-hooks.d.ts.map +1 -0
  56. package/dist/register-test-hooks.js +15 -0
  57. package/dist/register-test-hooks.js.map +1 -0
  58. package/dist/render-hook.d.ts +14 -35
  59. package/dist/render-hook.d.ts.map +1 -1
  60. package/dist/render-hook.js +8 -45
  61. package/dist/render-hook.js.map +1 -1
  62. package/dist/render.d.ts +11 -41
  63. package/dist/render.d.ts.map +1 -1
  64. package/dist/render.js +129 -118
  65. package/dist/render.js.map +1 -1
  66. package/dist/role-helpers.d.ts +16 -51
  67. package/dist/role-helpers.d.ts.map +1 -1
  68. package/dist/role-helpers.js +39 -58
  69. package/dist/role-helpers.js.map +1 -1
  70. package/dist/screen.d.ts +6 -63
  71. package/dist/screen.d.ts.map +1 -1
  72. package/dist/screen.js +21 -109
  73. package/dist/screen.js.map +1 -1
  74. package/dist/screenshot.d.ts +20 -23
  75. package/dist/screenshot.d.ts.map +1 -1
  76. package/dist/screenshot.js +89 -48
  77. package/dist/screenshot.js.map +1 -1
  78. package/dist/suggestions.d.ts +22 -0
  79. package/dist/suggestions.d.ts.map +1 -0
  80. package/dist/suggestions.js +56 -0
  81. package/dist/suggestions.js.map +1 -0
  82. package/dist/traversal.d.ts +10 -8
  83. package/dist/traversal.d.ts.map +1 -1
  84. package/dist/traversal.js +28 -13
  85. package/dist/traversal.js.map +1 -1
  86. package/dist/types.d.ts +103 -172
  87. package/dist/types.d.ts.map +1 -1
  88. package/dist/types.js.map +1 -1
  89. package/dist/user-event/adjustment.d.ts +8 -0
  90. package/dist/user-event/adjustment.d.ts.map +1 -0
  91. package/dist/user-event/adjustment.js +33 -0
  92. package/dist/user-event/adjustment.js.map +1 -0
  93. package/dist/user-event/click.d.ts +7 -0
  94. package/dist/user-event/click.d.ts.map +1 -0
  95. package/dist/user-event/click.js +65 -0
  96. package/dist/user-event/click.js.map +1 -0
  97. package/dist/user-event/controller.d.ts +7 -0
  98. package/dist/user-event/controller.d.ts.map +1 -0
  99. package/dist/user-event/controller.js +28 -0
  100. package/dist/user-event/controller.js.map +1 -0
  101. package/dist/user-event/dispatch.d.ts +7 -0
  102. package/dist/user-event/dispatch.d.ts.map +1 -0
  103. package/dist/user-event/dispatch.js +10 -0
  104. package/dist/user-event/dispatch.js.map +1 -0
  105. package/dist/user-event/event-wrapper.d.ts +3 -0
  106. package/dist/user-event/event-wrapper.d.ts.map +1 -0
  107. package/dist/user-event/event-wrapper.js +48 -0
  108. package/dist/user-event/event-wrapper.js.map +1 -0
  109. package/dist/user-event/gesture.d.ts +31 -0
  110. package/dist/user-event/gesture.d.ts.map +1 -0
  111. package/dist/user-event/gesture.js +105 -0
  112. package/dist/user-event/gesture.js.map +1 -0
  113. package/dist/user-event/index.d.ts +44 -0
  114. package/dist/user-event/index.d.ts.map +1 -0
  115. package/dist/user-event/index.js +38 -0
  116. package/dist/user-event/index.js.map +1 -0
  117. package/dist/user-event/keyboard.d.ts +9 -0
  118. package/dist/user-event/keyboard.d.ts.map +1 -0
  119. package/dist/user-event/keyboard.js +173 -0
  120. package/dist/user-event/keyboard.js.map +1 -0
  121. package/dist/user-event/pointer.d.ts +6 -0
  122. package/dist/user-event/pointer.d.ts.map +1 -0
  123. package/dist/user-event/pointer.js +27 -0
  124. package/dist/user-event/pointer.js.map +1 -0
  125. package/dist/user-event/selection.d.ts +4 -0
  126. package/dist/user-event/selection.d.ts.map +1 -0
  127. package/dist/user-event/selection.js +106 -0
  128. package/dist/user-event/selection.js.map +1 -0
  129. package/dist/user-event/state.d.ts +6 -0
  130. package/dist/user-event/state.d.ts.map +1 -0
  131. package/dist/user-event/state.js +2 -0
  132. package/dist/user-event/state.js.map +1 -0
  133. package/dist/user-event/text.d.ts +17 -0
  134. package/dist/user-event/text.d.ts.map +1 -0
  135. package/dist/user-event/text.js +107 -0
  136. package/dist/user-event/text.js.map +1 -0
  137. package/dist/wait-for.d.ts +13 -33
  138. package/dist/wait-for.d.ts.map +1 -1
  139. package/dist/wait-for.js +62 -73
  140. package/dist/wait-for.js.map +1 -1
  141. package/dist/widget-accessible-properties.d.ts +33 -0
  142. package/dist/widget-accessible-properties.d.ts.map +1 -0
  143. package/dist/widget-accessible-properties.js +215 -0
  144. package/dist/widget-accessible-properties.js.map +1 -0
  145. package/dist/within.d.ts +9 -26
  146. package/dist/within.d.ts.map +1 -1
  147. package/dist/within.js +15 -25
  148. package/dist/within.js.map +1 -1
  149. package/package.json +21 -12
  150. package/src/act.ts +68 -0
  151. package/src/bound-queries.ts +36 -0
  152. package/src/build-queries.ts +185 -0
  153. package/src/cleanup-registry.ts +14 -0
  154. package/src/config.ts +28 -59
  155. package/src/editable.ts +30 -0
  156. package/src/errors.ts +130 -0
  157. package/src/fire-event.ts +11 -38
  158. package/src/frame-sync.ts +34 -0
  159. package/src/index.ts +56 -14
  160. package/src/matchers.ts +200 -0
  161. package/src/pretty-widget.ts +99 -138
  162. package/src/queries.ts +320 -420
  163. package/src/register-test-hooks.ts +16 -0
  164. package/src/render-hook.tsx +31 -44
  165. package/src/render.tsx +161 -149
  166. package/src/role-helpers.ts +47 -67
  167. package/src/screen.ts +21 -114
  168. package/src/screenshot.ts +104 -55
  169. package/src/suggestions.ts +87 -0
  170. package/src/traversal.ts +32 -18
  171. package/src/types.ts +115 -176
  172. package/src/user-event/adjustment.ts +49 -0
  173. package/src/user-event/click.ts +70 -0
  174. package/src/user-event/controller.ts +44 -0
  175. package/src/user-event/dispatch.ts +23 -0
  176. package/src/user-event/event-wrapper.ts +54 -0
  177. package/src/user-event/gesture.ts +154 -0
  178. package/src/user-event/index.ts +74 -0
  179. package/src/user-event/keyboard.ts +204 -0
  180. package/src/user-event/pointer.ts +34 -0
  181. package/src/user-event/selection.ts +122 -0
  182. package/src/user-event/state.ts +6 -0
  183. package/src/user-event/text.ts +137 -0
  184. package/src/wait-for.ts +79 -81
  185. package/src/widget-accessible-properties.ts +244 -0
  186. package/src/within.ts +26 -27
  187. package/dist/bind-queries.d.ts +0 -14
  188. package/dist/bind-queries.d.ts.map +0 -1
  189. package/dist/bind-queries.js +0 -29
  190. package/dist/bind-queries.js.map +0 -1
  191. package/dist/error-builder.d.ts +0 -28
  192. package/dist/error-builder.d.ts.map +0 -1
  193. package/dist/error-builder.js +0 -81
  194. package/dist/error-builder.js.map +0 -1
  195. package/dist/timing.d.ts +0 -18
  196. package/dist/timing.d.ts.map +0 -1
  197. package/dist/timing.js +0 -18
  198. package/dist/timing.js.map +0 -1
  199. package/dist/user-event.d.ts +0 -138
  200. package/dist/user-event.d.ts.map +0 -1
  201. package/dist/user-event.js +0 -411
  202. package/dist/user-event.js.map +0 -1
  203. package/dist/widget-text.d.ts +0 -69
  204. package/dist/widget-text.d.ts.map +0 -1
  205. package/dist/widget-text.js +0 -177
  206. package/dist/widget-text.js.map +0 -1
  207. package/dist/widget.d.ts +0 -3
  208. package/dist/widget.d.ts.map +0 -1
  209. package/dist/widget.js +0 -13
  210. package/dist/widget.js.map +0 -1
  211. package/src/bind-queries.ts +0 -52
  212. package/src/error-builder.ts +0 -102
  213. package/src/timing.ts +0 -17
  214. package/src/user-event.ts +0 -492
  215. package/src/widget-text.ts +0 -202
  216. package/src/widget.ts +0 -15
package/dist/queries.js CHANGED
@@ -1,25 +1,37 @@
1
- import * as Gtk from "@gtkx/ffi/gtk";
2
- import { buildMultipleFoundError, buildNotFoundError } from "./error-builder.js";
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 { waitFor } from "./wait-for.js";
5
- import { getWidgetAccessibleName, getWidgetCheckedState, getWidgetExpandedState, getWidgetName, getWidgetPressedState, getWidgetSelectedState, getWidgetText, } from "./widget-text.js";
6
- const buildNormalizer = (options) => {
7
- if (options?.normalizer) {
8
- return options.normalizer;
9
- }
10
- const trim = options?.trim ?? true;
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.replace(/\s+/g, " ");
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 matchByRoleOptions = (widget, options) => {
45
- if (!options)
56
+ const matchAccessibleName = (widget, options) => {
57
+ if (options.name === undefined)
46
58
  return true;
47
- if (options.name !== undefined) {
48
- const text = getWidgetAccessibleName(widget);
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
- * Finds all elements matching a role without throwing.
76
- *
77
- * @param container - The container to search within
78
- * @param role - The GTK accessible role to match
79
- * @param options - Query options including name and state filters
80
- * @returns Array of matching widgets (empty if none found)
81
- */
82
- export const queryAllByRole = (container, role, options) => {
83
- return findAll(container, (node) => {
84
- if (node.getAccessibleRole() !== role)
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
- * Finds all elements that are labelled by a GtkLabel whose text matches.
107
- *
108
- * Uses GtkLabel's mnemonic widget association to find form elements
109
- * by their label text. Only returns widgets that are properly labelled
110
- * via GtkLabel's mnemonic-widget property.
111
- *
112
- * @param container - The container to search within
113
- * @param text - Label text to match (string, RegExp, or custom matcher)
114
- * @param options - Query options including normalization
115
- * @returns Array of labelled widgets (empty if none found)
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
- * Finds a single element matching label text without throwing.
136
- *
137
- * @param container - The container to search within
138
- * @param text - Text to match (string, RegExp, or custom matcher)
139
- * @param options - Query options including normalization
140
- * @returns The matching widget or null if not found
141
- * @throws Error if multiple elements match
142
- */
143
- export const queryByLabelText = (container, text, options) => {
144
- const matches = queryAllByLabelText(container, text, options);
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
- * Finds all elements matching text content without throwing.
152
- *
153
- * @param container - The container to search within
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
- * Finds a single element matching text content without throwing.
165
- *
166
- * @param container - The container to search within
167
- * @param text - Text to match (string, RegExp, or custom matcher)
168
- * @param options - Query options including normalization
169
- * @returns The matching widget or null if not found
170
- * @throws Error if multiple elements match
171
- */
172
- export const queryByText = (container, text, options) => {
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 all elements matching a widget name without throwing.
181
- *
182
- * @param container - The container to search within
183
- * @param name - Widget name to match (string, RegExp, or custom matcher)
184
- * @param options - Query options including normalization
185
- * @returns Array of matching widgets (empty if none found)
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 queryAllByName = (container, name, options) => {
188
- return findAll(container, (node) => {
189
- const widgetName = getWidgetName(node);
190
- return matchText(widgetName, name, node, options);
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 single element matching a widget name without throwing.
195
- *
196
- * @param container - The container to search within
197
- * @param name - Widget name to match (string, RegExp, or custom matcher)
198
- * @param options - Query options including normalization
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 queryByName = (container, name, options) => {
203
- const matches = queryAllByName(container, name, options);
204
- if (matches.length > 1) {
205
- throw buildMultipleFoundError(container, "name", { name, options }, matches.length);
206
- }
207
- return matches[0] ?? null;
208
- };
209
- const getAllByRole = (container, role, options) => {
210
- const matches = queryAllByRole(container, role, options);
211
- if (matches.length === 0) {
212
- throw buildNotFoundError(container, "role", { role, options });
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 matches[0];
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 a single element by accessible role.
267
- *
268
- * Waits for the element to appear, throwing if not found within timeout.
269
- *
270
- * @param container - The container to search within
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 findByRole = async (container, role, options) => waitFor(() => getByRole(container, role, options), {
281
- timeout: options?.timeout,
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 a single element that is labelled by a GtkLabel whose text matches.
296
- *
297
- * Waits for the element to appear, throwing if not found within timeout.
298
- * Uses GtkLabel's mnemonic widget association to find form elements.
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 findByLabelText = async (container, text, options) => waitFor(() => getByLabelText(container, text, options), {
311
- timeout: options?.timeout,
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 all elements matching label or text content.
315
- *
316
- * @param container - The container to search within
317
- * @param text - Text to match (string, RegExp, or custom matcher)
318
- * @param options - Query options including normalization and timeout
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 findAllByLabelText = async (container, text, options) => waitFor(() => getAllByLabelText(container, text, options), {
322
- timeout: options?.timeout,
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 a single element by visible text content.
326
- *
327
- * Similar to {@link findByLabelText} but focuses on directly visible text.
328
- *
329
- * @param container - The container to search within
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 findByText = async (container, text, options) => waitFor(() => getByText(container, text, options), {
335
- timeout: options?.timeout,
336
- });
337
- /**
338
- * Finds all elements matching visible text content.
339
- *
340
- * @param container - The container to search within
341
- * @param text - Text to match (string, RegExp, or custom matcher)
342
- * @param options - Query options including normalization and timeout
343
- * @returns Promise resolving to array of matching widgets
344
- */
345
- export const findAllByText = async (container, text, options) => waitFor(() => getAllByText(container, text, options), {
346
- timeout: options?.timeout,
347
- });
348
- /**
349
- * Finds a single element by widget name.
350
- *
351
- * Uses the widget's `name` property (gtk_widget_get_name).
352
- * Set via the `name` prop on GTKX components.
353
- *
354
- * @param container - The container to search within
355
- * @param name - Widget name to match (string, RegExp, or custom matcher)
356
- * @param options - Query options including normalization and timeout
357
- * @returns Promise resolving to the matching widget
358
- *
359
- * @example
360
- * ```tsx
361
- * // In component: <GtkButton name="submit-btn" />
362
- * const button = await findByName(container, "submit-btn");
363
- * ```
364
- */
365
- export const findByName = async (container, name, options) => waitFor(() => getByName(container, name, options), {
366
- timeout: options?.timeout,
367
- });
368
- /**
369
- * Finds all elements matching a widget name pattern.
370
- *
371
- * @param container - The container to search within
372
- * @param name - Widget name to match (string, RegExp, or custom matcher)
373
- * @param options - Query options including normalization and timeout
374
- * @returns Promise resolving to array of matching widgets
375
- */
376
- export const findAllByName = async (container, name, options) => waitFor(() => getAllByName(container, name, options), {
377
- timeout: options?.timeout,
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