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