@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.
Files changed (182) hide show
  1. package/dist/act.d.ts +6 -6
  2. package/dist/act.d.ts.map +1 -1
  3. package/dist/act.js +34 -26
  4. package/dist/act.js.map +1 -1
  5. package/dist/bound-queries.d.ts +4 -3
  6. package/dist/bound-queries.d.ts.map +1 -1
  7. package/dist/bound-queries.js.map +1 -1
  8. package/dist/build-queries.d.ts +5 -5
  9. package/dist/build-queries.d.ts.map +1 -1
  10. package/dist/build-queries.js +21 -9
  11. package/dist/build-queries.js.map +1 -1
  12. package/dist/cleanup-registry.d.ts +4 -3
  13. package/dist/cleanup-registry.d.ts.map +1 -1
  14. package/dist/cleanup-registry.js +13 -3
  15. package/dist/cleanup-registry.js.map +1 -1
  16. package/dist/config.d.ts +5 -4
  17. package/dist/config.d.ts.map +1 -1
  18. package/dist/config.js +11 -9
  19. package/dist/config.js.map +1 -1
  20. package/dist/editable.d.ts +6 -5
  21. package/dist/editable.d.ts.map +1 -1
  22. package/dist/editable.js +7 -5
  23. package/dist/editable.js.map +1 -1
  24. package/dist/errors.d.ts +7 -6
  25. package/dist/errors.d.ts.map +1 -1
  26. package/dist/errors.js +64 -48
  27. package/dist/errors.js.map +1 -1
  28. package/dist/fire-event.d.ts +2 -1
  29. package/dist/fire-event.d.ts.map +1 -1
  30. package/dist/fire-event.js +2 -1
  31. package/dist/fire-event.js.map +1 -1
  32. package/dist/frame-sync.d.ts +2 -1
  33. package/dist/frame-sync.d.ts.map +1 -1
  34. package/dist/frame-sync.js +28 -21
  35. package/dist/frame-sync.js.map +1 -1
  36. package/dist/index.d.ts +2 -2
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +1 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/matchers.d.ts +38 -34
  41. package/dist/matchers.d.ts.map +1 -1
  42. package/dist/matchers.js +72 -58
  43. package/dist/matchers.js.map +1 -1
  44. package/dist/pretty-widget.d.ts +6 -4
  45. package/dist/pretty-widget.d.ts.map +1 -1
  46. package/dist/pretty-widget.js +64 -24
  47. package/dist/pretty-widget.js.map +1 -1
  48. package/dist/queries.d.ts +143 -86
  49. package/dist/queries.d.ts.map +1 -1
  50. package/dist/queries.js +231 -147
  51. package/dist/queries.js.map +1 -1
  52. package/dist/register-test-hooks.js +2 -1
  53. package/dist/register-test-hooks.js.map +1 -1
  54. package/dist/render-hook.d.ts +3 -2
  55. package/dist/render-hook.d.ts.map +1 -1
  56. package/dist/render-hook.js +2 -1
  57. package/dist/render-hook.js.map +1 -1
  58. package/dist/render.d.ts +3 -2
  59. package/dist/render.d.ts.map +1 -1
  60. package/dist/render.js +24 -18
  61. package/dist/render.js.map +1 -1
  62. package/dist/role-helpers.d.ts +6 -5
  63. package/dist/role-helpers.d.ts.map +1 -1
  64. package/dist/role-helpers.js +16 -12
  65. package/dist/role-helpers.js.map +1 -1
  66. package/dist/screen.d.ts +4 -3
  67. package/dist/screen.d.ts.map +1 -1
  68. package/dist/screen.js +13 -11
  69. package/dist/screen.js.map +1 -1
  70. package/dist/screenshot.d.ts +4 -3
  71. package/dist/screenshot.d.ts.map +1 -1
  72. package/dist/screenshot.js +43 -36
  73. package/dist/screenshot.js.map +1 -1
  74. package/dist/suggestions.d.ts +11 -6
  75. package/dist/suggestions.d.ts.map +1 -1
  76. package/dist/suggestions.js +10 -5
  77. package/dist/suggestions.js.map +1 -1
  78. package/dist/traversal.d.ts +7 -7
  79. package/dist/traversal.d.ts.map +1 -1
  80. package/dist/traversal.js +17 -11
  81. package/dist/traversal.js.map +1 -1
  82. package/dist/types.d.ts +39 -24
  83. package/dist/types.d.ts.map +1 -1
  84. package/dist/types.js.map +1 -1
  85. package/dist/user-event/adjustment.d.ts +5 -3
  86. package/dist/user-event/adjustment.d.ts.map +1 -1
  87. package/dist/user-event/adjustment.js +6 -4
  88. package/dist/user-event/adjustment.js.map +1 -1
  89. package/dist/user-event/click.d.ts +6 -5
  90. package/dist/user-event/click.d.ts.map +1 -1
  91. package/dist/user-event/click.js +29 -21
  92. package/dist/user-event/click.js.map +1 -1
  93. package/dist/user-event/controller.d.ts +6 -5
  94. package/dist/user-event/controller.d.ts.map +1 -1
  95. package/dist/user-event/controller.js +9 -6
  96. package/dist/user-event/controller.js.map +1 -1
  97. package/dist/user-event/dispatch.d.ts +3 -3
  98. package/dist/user-event/dispatch.d.ts.map +1 -1
  99. package/dist/user-event/dispatch.js +3 -2
  100. package/dist/user-event/dispatch.js.map +1 -1
  101. package/dist/user-event/event-wrapper.d.ts +2 -1
  102. package/dist/user-event/event-wrapper.d.ts.map +1 -1
  103. package/dist/user-event/event-wrapper.js +27 -16
  104. package/dist/user-event/event-wrapper.js.map +1 -1
  105. package/dist/user-event/gesture.d.ts +18 -14
  106. package/dist/user-event/gesture.d.ts.map +1 -1
  107. package/dist/user-event/gesture.js +70 -37
  108. package/dist/user-event/gesture.js.map +1 -1
  109. package/dist/user-event/index.d.ts +17 -10
  110. package/dist/user-event/index.d.ts.map +1 -1
  111. package/dist/user-event/index.js +7 -3
  112. package/dist/user-event/index.js.map +1 -1
  113. package/dist/user-event/keyboard.d.ts +4 -3
  114. package/dist/user-event/keyboard.d.ts.map +1 -1
  115. package/dist/user-event/keyboard.js +89 -58
  116. package/dist/user-event/keyboard.js.map +1 -1
  117. package/dist/user-event/pointer.d.ts +7 -3
  118. package/dist/user-event/pointer.d.ts.map +1 -1
  119. package/dist/user-event/pointer.js +4 -1
  120. package/dist/user-event/pointer.js.map +1 -1
  121. package/dist/user-event/selection.d.ts +3 -2
  122. package/dist/user-event/selection.d.ts.map +1 -1
  123. package/dist/user-event/selection.js +26 -27
  124. package/dist/user-event/selection.js.map +1 -1
  125. package/dist/user-event/state.d.ts +3 -2
  126. package/dist/user-event/state.d.ts.map +1 -1
  127. package/dist/user-event/state.js +2 -1
  128. package/dist/user-event/state.js.map +1 -1
  129. package/dist/user-event/text.d.ts +8 -7
  130. package/dist/user-event/text.d.ts.map +1 -1
  131. package/dist/user-event/text.js +39 -33
  132. package/dist/user-event/text.js.map +1 -1
  133. package/dist/wait-for.d.ts +5 -5
  134. package/dist/wait-for.d.ts.map +1 -1
  135. package/dist/wait-for.js +45 -30
  136. package/dist/wait-for.js.map +1 -1
  137. package/dist/widget-accessible-properties.d.ts +26 -25
  138. package/dist/widget-accessible-properties.d.ts.map +1 -1
  139. package/dist/widget-accessible-properties.js +106 -61
  140. package/dist/widget-accessible-properties.js.map +1 -1
  141. package/dist/within.d.ts +2 -1
  142. package/dist/within.d.ts.map +1 -1
  143. package/dist/within.js +2 -1
  144. package/dist/within.js.map +1 -1
  145. package/package.json +11 -9
  146. package/src/act.ts +44 -35
  147. package/src/bound-queries.ts +5 -4
  148. package/src/build-queries.ts +84 -43
  149. package/src/cleanup-registry.ts +18 -5
  150. package/src/config.ts +16 -12
  151. package/src/editable.ts +13 -6
  152. package/src/errors.ts +106 -45
  153. package/src/fire-event.ts +3 -1
  154. package/src/frame-sync.ts +38 -21
  155. package/src/index.ts +2 -1
  156. package/src/matchers.ts +158 -107
  157. package/src/pretty-widget.ts +114 -42
  158. package/src/queries.ts +422 -233
  159. package/src/register-test-hooks.ts +4 -1
  160. package/src/render-hook.tsx +10 -4
  161. package/src/render.tsx +58 -33
  162. package/src/role-helpers.ts +29 -16
  163. package/src/screen.ts +17 -12
  164. package/src/screenshot.ts +61 -38
  165. package/src/suggestions.ts +29 -10
  166. package/src/traversal.ts +35 -15
  167. package/src/types.ts +65 -32
  168. package/src/user-event/adjustment.ts +23 -10
  169. package/src/user-event/click.ts +49 -20
  170. package/src/user-event/controller.ts +21 -7
  171. package/src/user-event/dispatch.ts +4 -2
  172. package/src/user-event/event-wrapper.ts +42 -16
  173. package/src/user-event/gesture.ts +135 -50
  174. package/src/user-event/index.ts +19 -12
  175. package/src/user-event/keyboard.ts +147 -61
  176. package/src/user-event/pointer.ts +20 -8
  177. package/src/user-event/selection.ts +69 -32
  178. package/src/user-event/state.ts +4 -2
  179. package/src/user-event/text.ts +73 -38
  180. package/src/wait-for.ts +77 -36
  181. package/src/widget-accessible-properties.ts +218 -74
  182. 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
- * Builds the default text normalizer, which optionally trims surrounding whitespace and collapses runs of whitespace into single spaces.
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
- export const getDefaultNormalizer = ({ trim = true, collapseWhitespace = true, } = {}) => {
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
- 'use "getDefaultNormalizer({ trim, collapseWhitespace })" and compose that into your normalizer');
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 matchText = (actual, expected, widget, options) => {
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 exact = options?.exact ?? true;
52
- return exact
184
+ const isExact = options?.exact ?? true;
185
+ return isExact
53
186
  ? normalizedActual === normalizedExpected
54
187
  : normalizedActual.toLowerCase().includes(normalizedExpected.toLowerCase());
55
188
  };
56
- const matchAccessibleName = (widget, options) => {
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 matchText(text, options.name, widget, options);
194
+ return isTextMatch(text, options.name, widget, options);
61
195
  };
62
- const matchAccessibleValue = (widget, value, options) => {
196
+ const isNumericValueMatch = (expected, actual) => expected === undefined || actual === expected;
197
+ const hasMatchingAccessibleValue = (widget, value, options) => {
63
198
  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;
73
- };
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;
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 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;
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 matchByRoleOptions = (widget, options) => {
100
- if (!options)
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
- return matchAccessibleName(widget, options) && matchAccessibleStates(widget, options);
237
+ }
238
+ return hasMatchingAccessibleName(widget, options) && hasMatchingAccessibleStates(widget, options);
103
239
  };
104
- const nameQueryFamily = (suffix, queryAllBy, built) => {
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
- 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 })));
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 || !matchText(labelText, text, widget, options))
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 widget's own accessible label, or its labelled-by relation.
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
- export const queryAllByLabelText = (container, text, options) => {
302
+ function queryAllByLabelText(container, text, options) {
147
303
  const results = new Set();
148
304
  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);
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
- 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 })));
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
- 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 })));
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
- 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 })));
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
- 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;
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