@gtkx/testing 2.0.0-beta.10 → 2.0.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -168
- package/dist/accessible-native.d.ts +1 -1
- package/dist/accessible-native.d.ts.map +1 -1
- package/dist/accessible-native.js +2 -2
- package/dist/accessible-native.js.map +1 -1
- package/dist/act.d.ts.map +1 -1
- package/dist/build-queries.d.ts +7 -8
- package/dist/build-queries.d.ts.map +1 -1
- package/dist/build-queries.js +25 -24
- package/dist/build-queries.js.map +1 -1
- package/dist/cleanup-registry.d.ts +2 -1
- package/dist/cleanup-registry.d.ts.map +1 -1
- package/dist/cleanup-registry.js +11 -4
- package/dist/cleanup-registry.js.map +1 -1
- package/dist/config.d.ts +3 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/editable.d.ts.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/fire-event.d.ts.map +1 -1
- package/dist/fire-event.js +5 -2
- package/dist/fire-event.js.map +1 -1
- package/dist/frame-sync.d.ts.map +1 -1
- package/dist/frame-sync.js +1 -10
- package/dist/frame-sync.js.map +1 -1
- package/dist/harness-window.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/matchers.d.ts +4 -6
- package/dist/matchers.d.ts.map +1 -1
- package/dist/matchers.js +2 -2
- package/dist/matchers.js.map +1 -1
- package/dist/normalize.d.ts +1 -1
- package/dist/normalize.d.ts.map +1 -1
- package/dist/normalize.js +1 -1
- package/dist/normalize.js.map +1 -1
- package/dist/pretty-widget.d.ts.map +1 -1
- package/dist/pretty-widget.js +13 -2
- package/dist/pretty-widget.js.map +1 -1
- package/dist/production.d.ts.map +1 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +6 -7
- package/dist/queries.js.map +1 -1
- package/dist/render-hook.js +3 -3
- package/dist/render-hook.js.map +1 -1
- package/dist/render.d.ts +17 -17
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +62 -62
- package/dist/render.js.map +1 -1
- package/dist/role-helpers.d.ts.map +1 -1
- package/dist/role-naming.d.ts +2 -1
- package/dist/role-naming.d.ts.map +1 -1
- package/dist/role-naming.js +2 -1
- package/dist/role-naming.js.map +1 -1
- package/dist/screen.d.ts.map +1 -1
- package/dist/screenshot.d.ts +10 -11
- package/dist/screenshot.d.ts.map +1 -1
- package/dist/screenshot.js +10 -11
- package/dist/screenshot.js.map +1 -1
- package/dist/suggestions.d.ts +1 -1
- package/dist/suggestions.d.ts.map +1 -1
- package/dist/suggestions.js +3 -3
- package/dist/suggestions.js.map +1 -1
- package/dist/timers.d.ts.map +1 -1
- package/dist/traversal.d.ts +4 -3
- package/dist/traversal.d.ts.map +1 -1
- package/dist/traversal.js +11 -4
- package/dist/traversal.js.map +1 -1
- package/dist/types.d.ts +3 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/user-event/adjustment.d.ts.map +1 -1
- package/dist/user-event/adjustment.js.map +1 -1
- package/dist/user-event/click.d.ts.map +1 -1
- package/dist/user-event/click.js +0 -1
- package/dist/user-event/click.js.map +1 -1
- package/dist/user-event/column-header-click.d.ts.map +1 -1
- package/dist/user-event/column-header-click.js +1 -1
- package/dist/user-event/column-header-click.js.map +1 -1
- package/dist/user-event/controller.d.ts +1 -1
- package/dist/user-event/controller.d.ts.map +1 -1
- package/dist/user-event/controller.js +3 -3
- package/dist/user-event/controller.js.map +1 -1
- package/dist/user-event/dispatch.d.ts.map +1 -1
- package/dist/user-event/event-wrapper.d.ts.map +1 -1
- package/dist/user-event/event-wrapper.js.map +1 -1
- package/dist/user-event/gesture.d.ts +1 -1
- package/dist/user-event/gesture.d.ts.map +1 -1
- package/dist/user-event/gesture.js +104 -29
- package/dist/user-event/gesture.js.map +1 -1
- package/dist/user-event/index.d.ts.map +1 -1
- package/dist/user-event/index.js +1 -1
- package/dist/user-event/index.js.map +1 -1
- package/dist/user-event/indexed-children.d.ts.map +1 -1
- package/dist/user-event/keyboard.d.ts.map +1 -1
- package/dist/user-event/keyboard.js +43 -16
- package/dist/user-event/keyboard.js.map +1 -1
- package/dist/user-event/list-row-click.d.ts.map +1 -1
- package/dist/user-event/list-row-click.js +1 -1
- package/dist/user-event/list-row-click.js.map +1 -1
- package/dist/user-event/native-click.d.ts.map +1 -1
- package/dist/user-event/native-click.js +1 -3
- package/dist/user-event/native-click.js.map +1 -1
- package/dist/user-event/notebook-tab-click.d.ts.map +1 -1
- package/dist/user-event/notebook-tab-click.js +1 -1
- package/dist/user-event/notebook-tab-click.js.map +1 -1
- package/dist/user-event/pointer.d.ts.map +1 -1
- package/dist/user-event/selection.d.ts.map +1 -1
- package/dist/user-event/selection.js +1 -6
- package/dist/user-event/selection.js.map +1 -1
- package/dist/user-event/text.d.ts.map +1 -1
- package/dist/user-event/text.js +31 -27
- package/dist/user-event/text.js.map +1 -1
- package/dist/wait-for.d.ts.map +1 -1
- package/dist/wait-for.js +28 -21
- package/dist/wait-for.js.map +1 -1
- package/dist/widget-accessible-properties.d.ts +1 -1
- package/dist/widget-accessible-properties.d.ts.map +1 -1
- package/dist/widget-accessible-properties.js +64 -28
- package/dist/widget-accessible-properties.js.map +1 -1
- package/dist/widget-getters.d.ts.map +1 -1
- package/dist/widget-getters.js +0 -1
- package/dist/widget-getters.js.map +1 -1
- package/dist/widget-target.d.ts.map +1 -1
- package/dist/window-state.d.ts.map +1 -1
- package/dist/window-state.js +3 -1
- package/dist/window-state.js.map +1 -1
- package/dist/within.d.ts.map +1 -1
- package/dist/within.js.map +1 -1
- package/package.json +16 -23
- package/src/accessible-native.ts +5 -5
- package/src/build-queries.ts +71 -88
- package/src/cleanup-registry.ts +11 -5
- package/src/config.ts +3 -4
- package/src/errors.ts +6 -6
- package/src/fire-event.ts +6 -7
- package/src/frame-sync.ts +1 -13
- package/src/index.ts +2 -12
- package/src/matchers.ts +34 -42
- package/src/normalize.ts +1 -4
- package/src/pretty-widget.ts +17 -2
- package/src/queries.ts +11 -20
- package/src/render-hook.tsx +4 -4
- package/src/render.tsx +67 -80
- package/src/role-naming.ts +2 -1
- package/src/screenshot.ts +13 -19
- package/src/suggestions.ts +3 -3
- package/src/traversal.ts +16 -6
- package/src/types.ts +14 -20
- package/src/user-event/adjustment.ts +1 -3
- package/src/user-event/click.ts +2 -9
- package/src/user-event/column-header-click.ts +1 -1
- package/src/user-event/controller.ts +3 -3
- package/src/user-event/event-wrapper.ts +1 -1
- package/src/user-event/gesture.ts +146 -37
- package/src/user-event/index.ts +10 -22
- package/src/user-event/keyboard.ts +61 -19
- package/src/user-event/list-row-click.ts +1 -1
- package/src/user-event/native-click.ts +1 -3
- package/src/user-event/notebook-tab-click.ts +1 -1
- package/src/user-event/selection.ts +4 -20
- package/src/user-event/text.ts +37 -36
- package/src/wait-for.ts +38 -34
- package/src/widget-accessible-properties.ts +80 -36
- package/src/widget-getters.ts +1 -3
- package/src/window-state.ts +4 -3
- package/src/within.ts +2 -2
package/src/build-queries.ts
CHANGED
|
@@ -12,19 +12,13 @@ import { requireWidget } from "./widget-target.js";
|
|
|
12
12
|
* family's own matcher arguments. Its name determines the family name, so `queryAllByTestId` builds
|
|
13
13
|
* a `TestId` family.
|
|
14
14
|
*/
|
|
15
|
-
type QueryAllBy<
|
|
16
|
-
Args extends unknown[],
|
|
17
|
-
Element extends Gtk.Accessible = Gtk.Accessible,
|
|
18
|
-
> = (
|
|
15
|
+
type QueryAllBy<Args extends unknown[], Element extends Gtk.Accessible = Gtk.Accessible> = (
|
|
19
16
|
container: Container,
|
|
20
17
|
...args: Args
|
|
21
18
|
) => Element[];
|
|
22
19
|
|
|
23
20
|
/** Builds the error thrown when a single-match query finds more than one widget. */
|
|
24
|
-
type MultipleErrorBuilder<
|
|
25
|
-
Args extends unknown[],
|
|
26
|
-
Element extends Gtk.Accessible = Gtk.Accessible,
|
|
27
|
-
> = (
|
|
21
|
+
type MultipleErrorBuilder<Args extends unknown[], Element extends Gtk.Accessible = Gtk.Accessible> = (
|
|
28
22
|
container: Container,
|
|
29
23
|
matches: Element[],
|
|
30
24
|
...args: Args
|
|
@@ -34,10 +28,7 @@ type MultipleErrorBuilder<
|
|
|
34
28
|
type MissingErrorBuilder<Args extends unknown[]> = (container: Container, ...args: Args) => Error;
|
|
35
29
|
|
|
36
30
|
/** The variants derived from one `queryAllBy` function, in the order DOM Testing Library returns them. */
|
|
37
|
-
type BuiltQueries<
|
|
38
|
-
Args extends unknown[],
|
|
39
|
-
Element extends Gtk.Accessible = Gtk.Accessible,
|
|
40
|
-
> = [
|
|
31
|
+
type BuiltQueries<Args extends unknown[], Element extends Gtk.Accessible = Gtk.Accessible> = [
|
|
41
32
|
queryBy: (container: Container, ...args: Args) => Element | null,
|
|
42
33
|
getAllBy: QueryAllBy<Args, Element>,
|
|
43
34
|
getBy: (container: Container, ...args: Args) => Element,
|
|
@@ -66,21 +57,27 @@ const getQueryFamily = (queryAllBy: { name: string }): string => queryAllBy.name
|
|
|
66
57
|
|
|
67
58
|
const maybeThrowSuggestion = (options: {
|
|
68
59
|
container: Container;
|
|
69
|
-
|
|
60
|
+
matches: readonly object[];
|
|
70
61
|
queryName: string;
|
|
71
62
|
variant: Variant;
|
|
72
63
|
shouldSuggest: boolean | undefined;
|
|
73
64
|
}): void => {
|
|
74
|
-
const { container,
|
|
65
|
+
const { container, matches, queryName, variant, shouldSuggest } = options;
|
|
75
66
|
|
|
76
67
|
if (!(shouldSuggest ?? getConfig().throwSuggestions)) {
|
|
77
68
|
return;
|
|
78
69
|
}
|
|
79
70
|
|
|
80
|
-
const
|
|
71
|
+
const suggestions = matches.map((match) => getSuggestedQuery(requireWidget(match), variant));
|
|
72
|
+
const [suggestion] = suggestions;
|
|
81
73
|
|
|
82
|
-
if (suggestion
|
|
83
|
-
|
|
74
|
+
if (!suggestion || suggestion.queryName === queryName) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const suggestedQuery = suggestion.toString();
|
|
78
|
+
|
|
79
|
+
if (suggestions.every((candidate) => candidate?.toString() === suggestedQuery)) {
|
|
80
|
+
throw suggestionError(suggestedQuery, container);
|
|
84
81
|
}
|
|
85
82
|
};
|
|
86
83
|
|
|
@@ -121,30 +118,30 @@ const singleFrom =
|
|
|
121
118
|
allQuery: QueryAllBy<Args, Element>,
|
|
122
119
|
getMultipleError: MultipleErrorBuilder<Args, Element>,
|
|
123
120
|
): SingleQuery<Args, Element> =>
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
(container, ...args) => {
|
|
122
|
+
const matches = allQuery(container, ...args);
|
|
126
123
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
if (matches.length > 1) {
|
|
125
|
+
throw getMultipleError(container, matches, ...args);
|
|
126
|
+
}
|
|
130
127
|
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
return matches[0] ?? null;
|
|
129
|
+
};
|
|
133
130
|
|
|
134
131
|
const allOrThrow =
|
|
135
132
|
<Args extends unknown[], Element extends Gtk.Accessible>(
|
|
136
133
|
allQuery: QueryAllBy<Args, Element>,
|
|
137
134
|
getMissingError: MissingErrorBuilder<Args>,
|
|
138
135
|
): QueryAllBy<Args, Element> =>
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
(container, ...args) => {
|
|
137
|
+
const matches = allQuery(container, ...args);
|
|
141
138
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
139
|
+
if (matches.length === 0) {
|
|
140
|
+
throw getMissingError(container, ...args);
|
|
141
|
+
}
|
|
145
142
|
|
|
146
|
-
|
|
147
|
-
|
|
143
|
+
return matches;
|
|
144
|
+
};
|
|
148
145
|
|
|
149
146
|
const wrapSingleWithSuggestion =
|
|
150
147
|
<Args extends unknown[], Element extends Gtk.Accessible>(
|
|
@@ -152,21 +149,21 @@ const wrapSingleWithSuggestion =
|
|
|
152
149
|
queryName: string,
|
|
153
150
|
variant: Variant,
|
|
154
151
|
): SingleQuery<Args, Element> =>
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
152
|
+
(container, ...args) => {
|
|
153
|
+
const match = query(container, ...args);
|
|
154
|
+
|
|
155
|
+
if (match) {
|
|
156
|
+
maybeThrowSuggestion({
|
|
157
|
+
container,
|
|
158
|
+
matches: [match],
|
|
159
|
+
queryName,
|
|
160
|
+
variant,
|
|
161
|
+
shouldSuggest: extractShouldSuggest(args),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return match;
|
|
166
|
+
};
|
|
170
167
|
|
|
171
168
|
const wrapAllWithSuggestion =
|
|
172
169
|
<Args extends unknown[], Element extends Gtk.Accessible>(
|
|
@@ -174,52 +171,44 @@ const wrapAllWithSuggestion =
|
|
|
174
171
|
queryName: string,
|
|
175
172
|
variant: Variant,
|
|
176
173
|
): QueryAllBy<Args, Element> =>
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return matches;
|
|
192
|
-
};
|
|
174
|
+
(container, ...args) => {
|
|
175
|
+
const matches = query(container, ...args);
|
|
176
|
+
maybeThrowSuggestion({
|
|
177
|
+
container,
|
|
178
|
+
matches,
|
|
179
|
+
queryName,
|
|
180
|
+
variant,
|
|
181
|
+
shouldSuggest: extractShouldSuggest(args),
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
return matches;
|
|
185
|
+
};
|
|
193
186
|
|
|
194
187
|
const requireSingle =
|
|
195
188
|
<Args extends unknown[], Element extends Gtk.Accessible>(
|
|
196
189
|
query: SingleQuery<Args, Element>,
|
|
197
190
|
getMissingError: MissingErrorBuilder<Args>,
|
|
198
191
|
) =>
|
|
199
|
-
|
|
200
|
-
|
|
192
|
+
(container: Container, ...args: Args): Element => {
|
|
193
|
+
const match = query(container, ...args);
|
|
201
194
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
195
|
+
if (match === null) {
|
|
196
|
+
throw getMissingError(container, ...args);
|
|
197
|
+
}
|
|
205
198
|
|
|
206
|
-
|
|
207
|
-
|
|
199
|
+
return match;
|
|
200
|
+
};
|
|
208
201
|
|
|
209
202
|
/**
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
* name used when suggesting a better query comes from `queryAllBy.name`.
|
|
203
|
+
* Builds a query family from `queryAllBy`, following DOM Testing Library's `buildQueries`.
|
|
204
|
+
* Query suggestions use `queryAllBy.name` as the family name.
|
|
213
205
|
*
|
|
214
|
-
* @param queryAllBy Finds
|
|
215
|
-
* @param getMultipleError Builds
|
|
216
|
-
* @param getMissingError Builds
|
|
217
|
-
* @returns
|
|
206
|
+
* @param queryAllBy Finds all matching widgets.
|
|
207
|
+
* @param getMultipleError Builds errors for single-match queries finding multiple widgets.
|
|
208
|
+
* @param getMissingError Builds errors for required queries finding no widgets.
|
|
209
|
+
* @returns `[queryBy, getAllBy, getBy, findAllBy, findBy]`.
|
|
218
210
|
*/
|
|
219
|
-
const buildQueries = <
|
|
220
|
-
Args extends unknown[],
|
|
221
|
-
Element extends Gtk.Accessible = Gtk.Accessible,
|
|
222
|
-
>(
|
|
211
|
+
const buildQueries = <Args extends unknown[], Element extends Gtk.Accessible = Gtk.Accessible>(
|
|
223
212
|
queryAllBy: QueryAllBy<Args, Element>,
|
|
224
213
|
getMultipleError: MultipleErrorBuilder<Args, Element>,
|
|
225
214
|
getMissingError: MissingErrorBuilder<Args>,
|
|
@@ -241,7 +230,7 @@ const buildQueries = <
|
|
|
241
230
|
|
|
242
231
|
maybeThrowSuggestion({
|
|
243
232
|
container,
|
|
244
|
-
match,
|
|
233
|
+
matches: [match],
|
|
245
234
|
queryName,
|
|
246
235
|
variant: "get",
|
|
247
236
|
shouldSuggest: extractShouldSuggest(args),
|
|
@@ -265,10 +254,4 @@ const buildQueries = <
|
|
|
265
254
|
return [queryByWithSuggestion, getAllByWithSuggestion, getByWithSuggestion, findAllBy, findBy];
|
|
266
255
|
};
|
|
267
256
|
|
|
268
|
-
export {
|
|
269
|
-
buildQueries,
|
|
270
|
-
type BuiltQueries,
|
|
271
|
-
type MissingErrorBuilder,
|
|
272
|
-
type MultipleErrorBuilder,
|
|
273
|
-
type QueryAllBy,
|
|
274
|
-
};
|
|
257
|
+
export { buildQueries, type BuiltQueries, type MissingErrorBuilder, type MultipleErrorBuilder, type QueryAllBy };
|
package/src/cleanup-registry.ts
CHANGED
|
@@ -6,10 +6,10 @@ const addToCleanupQueue = (fn: CleanupFunction): void => {
|
|
|
6
6
|
cleanupQueue.add(fn);
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const runCleanupCallbacks = async (callbacks: Iterable<CleanupFunction>): Promise<void> => {
|
|
10
10
|
const failures: unknown[] = [];
|
|
11
11
|
|
|
12
|
-
for (const fn of
|
|
12
|
+
for (const fn of callbacks) {
|
|
13
13
|
try {
|
|
14
14
|
await fn();
|
|
15
15
|
} catch (error) {
|
|
@@ -17,11 +17,17 @@ const runCleanup = async (): Promise<void> => {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
cleanupQueue.clear();
|
|
21
|
-
|
|
22
20
|
if (failures.length > 0) {
|
|
23
21
|
throw new AggregateError(failures, "Cleanup failed");
|
|
24
22
|
}
|
|
25
23
|
};
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
const runCleanup = async (): Promise<void> => {
|
|
26
|
+
try {
|
|
27
|
+
await runCleanupCallbacks(cleanupQueue);
|
|
28
|
+
} finally {
|
|
29
|
+
cleanupQueue.clear();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { addToCleanupQueue, runCleanup, runCleanupCallbacks };
|
package/src/config.ts
CHANGED
|
@@ -19,10 +19,9 @@ type Config = {
|
|
|
19
19
|
actionabilityTimeout: number;
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* how long a window that never activates takes to report, and costs nothing when one does.
|
|
22
|
+
* Maximum milliseconds `render` waits for window layout and activation. Activation needs a
|
|
23
|
+
* compositor round trip, so this is longer than {@link Config.actionabilityTimeout}. Rendering
|
|
24
|
+
* resolves as soon as activation succeeds, without waiting out the timeout.
|
|
26
25
|
*/
|
|
27
26
|
windowActivationTimeout: number;
|
|
28
27
|
};
|
package/src/errors.ts
CHANGED
|
@@ -6,12 +6,12 @@ import { prettyWidget } from "./pretty-widget.js";
|
|
|
6
6
|
import { formatRole, prettyRoles } from "./role-helpers.js";
|
|
7
7
|
|
|
8
8
|
type QueryDescriptor =
|
|
9
|
-
| { queryType: "role"; role: Gtk.AccessibleRole; options?: ByRoleOptions | undefined }
|
|
10
|
-
{ queryType: "text"; text: Matcher }
|
|
11
|
-
{ queryType: "labelText"; text: Matcher }
|
|
12
|
-
{ queryType: "name"; name: Matcher }
|
|
13
|
-
{ queryType: "placeholderText"; text: Matcher }
|
|
14
|
-
{ queryType: "displayValue"; value: Matcher };
|
|
9
|
+
| { queryType: "role"; role: Gtk.AccessibleRole; options?: ByRoleOptions | undefined }
|
|
10
|
+
| { queryType: "text"; text: Matcher }
|
|
11
|
+
| { queryType: "labelText"; text: Matcher }
|
|
12
|
+
| { queryType: "name"; name: Matcher }
|
|
13
|
+
| { queryType: "placeholderText"; text: Matcher }
|
|
14
|
+
| { queryType: "displayValue"; value: Matcher };
|
|
15
15
|
|
|
16
16
|
const roleOptionFormatters: ((options: ByRoleOptions) => string | null)[] = [
|
|
17
17
|
(o) => (o.name ? `name ${formatTextMatcher(o.name)}` : null),
|
package/src/fire-event.ts
CHANGED
|
@@ -50,8 +50,11 @@ const dispatchEvent = async (event: WidgetEvent): Promise<void> => {
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
const isWidgetEvent = (value: object): value is WidgetEvent =>
|
|
53
|
-
"target" in value &&
|
|
54
|
-
|
|
53
|
+
"target" in value &&
|
|
54
|
+
"signalName" in value &&
|
|
55
|
+
"args" in value &&
|
|
56
|
+
typeof value.signalName === "string" &&
|
|
57
|
+
Array.isArray(value.args);
|
|
55
58
|
|
|
56
59
|
/**
|
|
57
60
|
* Emits a recorded signal emission inside React's act environment, so any resulting state updates are
|
|
@@ -68,11 +71,7 @@ function fireEvent(event: WidgetEvent): Promise<void>;
|
|
|
68
71
|
* @param signalName Name of the signal to emit.
|
|
69
72
|
* @param args Arguments passed to the signal handlers.
|
|
70
73
|
*/
|
|
71
|
-
function fireEvent(
|
|
72
|
-
target: Pick<GObject.Object, "__type__">,
|
|
73
|
-
signalName: string,
|
|
74
|
-
...args: unknown[]
|
|
75
|
-
): Promise<void>;
|
|
74
|
+
function fireEvent(target: Pick<GObject.Object, "__type__">, signalName: string, ...args: unknown[]): Promise<void>;
|
|
76
75
|
|
|
77
76
|
function fireEvent(
|
|
78
77
|
eventOrTarget: WidgetEvent | Pick<GObject.Object, "__type__">,
|
package/src/frame-sync.ts
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
2
|
import * as GLib from "@gtkx/gi/glib";
|
|
3
|
+
import { once } from "@gtkx/utils";
|
|
3
4
|
import { cancelTimeout, scheduleTimeout } from "./timers.js";
|
|
4
5
|
|
|
5
6
|
const CLOCK_STALL_FALLBACK_MS = 500;
|
|
6
7
|
|
|
7
|
-
const once = (callback: () => void): (() => void) => {
|
|
8
|
-
let isCalled = false;
|
|
9
|
-
|
|
10
|
-
return () => {
|
|
11
|
-
if (isCalled) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
isCalled = true;
|
|
16
|
-
callback();
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
|
|
20
8
|
const hasFrameClock = (widget: Gtk.Widget | null): widget is Gtk.Widget => widget?.getFrameClock() != null;
|
|
21
9
|
|
|
22
10
|
const runUntilReady = (widget: Gtk.Widget, isReady: () => boolean, timeout: number, finish: () => void): void => {
|
package/src/index.ts
CHANGED
|
@@ -2,12 +2,7 @@ import "./register-test-hooks.js";
|
|
|
2
2
|
|
|
3
3
|
export { act } from "./act.js";
|
|
4
4
|
export type { BoundQueries, RenderResult, Screen } from "./bound-queries.js";
|
|
5
|
-
export type {
|
|
6
|
-
BuiltQueries,
|
|
7
|
-
MissingErrorBuilder,
|
|
8
|
-
MultipleErrorBuilder,
|
|
9
|
-
QueryAllBy,
|
|
10
|
-
} from "./build-queries.js";
|
|
5
|
+
export type { BuiltQueries, MissingErrorBuilder, MultipleErrorBuilder, QueryAllBy } from "./build-queries.js";
|
|
11
6
|
export { buildQueries } from "./build-queries.js";
|
|
12
7
|
export type { Config, ConfigFn } from "./config.js";
|
|
13
8
|
export { configure, getConfig } from "./config.js";
|
|
@@ -86,12 +81,7 @@ export type {
|
|
|
86
81
|
WrapperComponent,
|
|
87
82
|
} from "./types.js";
|
|
88
83
|
export type { ControllerConstructor } from "./user-event/controller.js";
|
|
89
|
-
export {
|
|
90
|
-
getAllControllers,
|
|
91
|
-
getController,
|
|
92
|
-
queryAllControllers,
|
|
93
|
-
queryController,
|
|
94
|
-
} from "./user-event/controller.js";
|
|
84
|
+
export { getAllControllers, getController, queryAllControllers, queryController } from "./user-event/controller.js";
|
|
95
85
|
export type {
|
|
96
86
|
DragOffset,
|
|
97
87
|
DragOptions,
|
package/src/matchers.ts
CHANGED
|
@@ -80,37 +80,37 @@ type ClassArguments = { expected: ClassExpectation[]; isExact: boolean };
|
|
|
80
80
|
type QueryAll<Args extends unknown[]> = (container: Container, ...args: Args) => object[];
|
|
81
81
|
|
|
82
82
|
type BooleanAccessibleState =
|
|
83
|
-
Gtk.AccessibleState.BUSY
|
|
84
|
-
Gtk.AccessibleState.DISABLED
|
|
85
|
-
Gtk.AccessibleState.EXPANDED
|
|
86
|
-
Gtk.AccessibleState.HIDDEN
|
|
87
|
-
Gtk.AccessibleState.SELECTED
|
|
88
|
-
Gtk.AccessibleState.VISITED;
|
|
83
|
+
| Gtk.AccessibleState.BUSY
|
|
84
|
+
| Gtk.AccessibleState.DISABLED
|
|
85
|
+
| Gtk.AccessibleState.EXPANDED
|
|
86
|
+
| Gtk.AccessibleState.HIDDEN
|
|
87
|
+
| Gtk.AccessibleState.SELECTED
|
|
88
|
+
| Gtk.AccessibleState.VISITED;
|
|
89
89
|
|
|
90
90
|
type TristateAccessibleState = Gtk.AccessibleState.CHECKED | Gtk.AccessibleState.PRESSED;
|
|
91
91
|
|
|
92
92
|
type StringAccessibleProperty =
|
|
93
|
-
Gtk.AccessibleProperty.DESCRIPTION
|
|
94
|
-
Gtk.AccessibleProperty.HELP_TEXT
|
|
95
|
-
Gtk.AccessibleProperty.KEY_SHORTCUTS
|
|
96
|
-
Gtk.AccessibleProperty.LABEL
|
|
97
|
-
Gtk.AccessibleProperty.PLACEHOLDER
|
|
98
|
-
Gtk.AccessibleProperty.ROLE_DESCRIPTION
|
|
99
|
-
Gtk.AccessibleProperty.VALUE_TEXT;
|
|
93
|
+
| Gtk.AccessibleProperty.DESCRIPTION
|
|
94
|
+
| Gtk.AccessibleProperty.HELP_TEXT
|
|
95
|
+
| Gtk.AccessibleProperty.KEY_SHORTCUTS
|
|
96
|
+
| Gtk.AccessibleProperty.LABEL
|
|
97
|
+
| Gtk.AccessibleProperty.PLACEHOLDER
|
|
98
|
+
| Gtk.AccessibleProperty.ROLE_DESCRIPTION
|
|
99
|
+
| Gtk.AccessibleProperty.VALUE_TEXT;
|
|
100
100
|
|
|
101
101
|
type BooleanAccessibleProperty =
|
|
102
|
-
Gtk.AccessibleProperty.HAS_POPUP
|
|
103
|
-
Gtk.AccessibleProperty.MODAL
|
|
104
|
-
Gtk.AccessibleProperty.MULTI_LINE
|
|
105
|
-
Gtk.AccessibleProperty.MULTI_SELECTABLE
|
|
106
|
-
Gtk.AccessibleProperty.READ_ONLY
|
|
107
|
-
Gtk.AccessibleProperty.REQUIRED;
|
|
102
|
+
| Gtk.AccessibleProperty.HAS_POPUP
|
|
103
|
+
| Gtk.AccessibleProperty.MODAL
|
|
104
|
+
| Gtk.AccessibleProperty.MULTI_LINE
|
|
105
|
+
| Gtk.AccessibleProperty.MULTI_SELECTABLE
|
|
106
|
+
| Gtk.AccessibleProperty.READ_ONLY
|
|
107
|
+
| Gtk.AccessibleProperty.REQUIRED;
|
|
108
108
|
|
|
109
109
|
type NumberAccessibleProperty =
|
|
110
|
-
Gtk.AccessibleProperty.LEVEL
|
|
111
|
-
Gtk.AccessibleProperty.VALUE_MAX
|
|
112
|
-
Gtk.AccessibleProperty.VALUE_MIN
|
|
113
|
-
Gtk.AccessibleProperty.VALUE_NOW;
|
|
110
|
+
| Gtk.AccessibleProperty.LEVEL
|
|
111
|
+
| Gtk.AccessibleProperty.VALUE_MAX
|
|
112
|
+
| Gtk.AccessibleProperty.VALUE_MIN
|
|
113
|
+
| Gtk.AccessibleProperty.VALUE_NOW;
|
|
114
114
|
|
|
115
115
|
/** A text matcher that also takes normalization options for the text it reads. */
|
|
116
116
|
type TextContentMatcher = (
|
|
@@ -184,12 +184,10 @@ type MatcherImplementations = {
|
|
|
184
184
|
/**
|
|
185
185
|
* Asserts a widget's numeric value, or its display value when a string is given.
|
|
186
186
|
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* the same tree, where the maximum of a paged widget such as a scrollbar is the last value it can
|
|
192
|
-
* reach, its adjustment's upper bound less one page.
|
|
187
|
+
* Numeric values come from GTK's accessibility tree, which ignores updates smaller than 0.001.
|
|
188
|
+
* Comparisons use that tolerance, matching `ByRole`'s `value` option and
|
|
189
|
+
* `toHaveAccessibleProperty`. For paged widgets such as scrollbars, the accessible maximum is
|
|
190
|
+
* the adjustment's upper bound minus its page size.
|
|
193
191
|
*/
|
|
194
192
|
toHaveValue: (received: unknown, expected?: number | string) => MatcherResult;
|
|
195
193
|
/** Asserts the widget's accessible role. */
|
|
@@ -541,7 +539,7 @@ const isEqualValue = (context: MatcherContext, actual: unknown, expected: unknow
|
|
|
541
539
|
};
|
|
542
540
|
|
|
543
541
|
const isClassMatch = (actual: string[], expected: ClassExpectation): boolean =>
|
|
544
|
-
|
|
542
|
+
actual.some((name) => isTextMatch(name, expected, "exact"));
|
|
545
543
|
|
|
546
544
|
const isWidgetRooted = (widget: Gtk.Widget): boolean => {
|
|
547
545
|
const root = widget.getRoot();
|
|
@@ -652,11 +650,7 @@ function readTextContent(widget: Gtk.Widget, options?: TextContentOptions): stri
|
|
|
652
650
|
return text === null ? null : normalizeTextContent(text, options);
|
|
653
651
|
}
|
|
654
652
|
|
|
655
|
-
function toHaveTextContent(
|
|
656
|
-
received: unknown,
|
|
657
|
-
expected?: TextExpectation,
|
|
658
|
-
options?: TextContentOptions,
|
|
659
|
-
): MatcherResult {
|
|
653
|
+
function toHaveTextContent(received: unknown, expected?: TextExpectation, options?: TextContentOptions): MatcherResult {
|
|
660
654
|
const read = (widget: Gtk.Widget): string | null => readTextContent(widget, options);
|
|
661
655
|
|
|
662
656
|
return textMatcher("toHaveTextContent", read, "substring")(received, expected);
|
|
@@ -665,7 +659,7 @@ function toHaveTextContent(
|
|
|
665
659
|
function notApplicable(matcherName: string, stateName: string, widget: Gtk.Widget): Error {
|
|
666
660
|
return new Error(
|
|
667
661
|
`${matcherName}: widget does not expose a ${stateName} ` +
|
|
668
|
-
|
|
662
|
+
`(role ${Gtk.AccessibleRole[widget.getAccessibleRole()]})\n${describeWidget(widget)}`,
|
|
669
663
|
);
|
|
670
664
|
}
|
|
671
665
|
|
|
@@ -886,7 +880,7 @@ function toBeRooted(received: unknown): MatcherResult {
|
|
|
886
880
|
function toBeEmptyWidget(received: unknown): MatcherResult {
|
|
887
881
|
const widget = asWidget(received, "toBeEmptyWidget");
|
|
888
882
|
|
|
889
|
-
return stateResult(widget, "empty", widget.getFirstChild() === null && getWidgetLabelText(widget)
|
|
883
|
+
return stateResult(widget, "empty", widget.getFirstChild() === null && !getWidgetLabelText(widget));
|
|
890
884
|
}
|
|
891
885
|
|
|
892
886
|
function toBeInvalid(received: unknown): MatcherResult {
|
|
@@ -1001,8 +995,8 @@ const registerMatchers = (): void => {
|
|
|
1001
995
|
};
|
|
1002
996
|
|
|
1003
997
|
declare module "vitest" {
|
|
1004
|
-
/* eslint-disable @typescript-eslint/
|
|
1005
|
-
declaration merging requires
|
|
998
|
+
/* eslint-disable @typescript-eslint/no-unused-vars --
|
|
999
|
+
declaration merging requires vitest's exact type parameters */
|
|
1006
1000
|
interface Matchers<R extends void | Promise<void> = void | Promise<void>, T = unknown> {
|
|
1007
1001
|
toHaveDisplayValue(expected?: TextExpectation): R;
|
|
1008
1002
|
toHaveTextContent(expected?: TextExpectation, options?: TextContentOptions): R;
|
|
@@ -1010,12 +1004,10 @@ declare module "vitest" {
|
|
|
1010
1004
|
toHaveAccessibleDescription(expected?: TextExpectation): R;
|
|
1011
1005
|
toHaveAccessibleErrorMessage(expected?: TextExpectation): R;
|
|
1012
1006
|
toHaveSelection(expected?: TextExpectation): R;
|
|
1013
|
-
/* eslint-disable-next-line unicorn/consistent-boolean-name -- expected is the jest-dom matcher argument name */
|
|
1014
1007
|
toHaveAccessibleState(state: BooleanAccessibleState, expected?: boolean): R;
|
|
1015
1008
|
toHaveAccessibleState(state: TristateAccessibleState, expected?: Gtk.AccessibleTristate): R;
|
|
1016
1009
|
toHaveAccessibleState(state: Gtk.AccessibleState.INVALID, expected?: Gtk.AccessibleInvalidState): R;
|
|
1017
1010
|
toHaveAccessibleProperty(property: StringAccessibleProperty, expected?: string): R;
|
|
1018
|
-
/* eslint-disable-next-line unicorn/consistent-boolean-name -- expected is the jest-dom matcher argument name */
|
|
1019
1011
|
toHaveAccessibleProperty(property: BooleanAccessibleProperty, expected?: boolean): R;
|
|
1020
1012
|
toHaveAccessibleProperty(property: NumberAccessibleProperty, expected?: number): R;
|
|
1021
1013
|
toHaveAccessibleProperty(
|
|
@@ -1055,7 +1047,7 @@ declare module "vitest" {
|
|
|
1055
1047
|
toHaveClass(...args: (ClassExpectation | { exact: boolean })[]): R;
|
|
1056
1048
|
toHaveObjectProperty(name: string, expected?: unknown): R;
|
|
1057
1049
|
}
|
|
1058
|
-
/* eslint-enable @typescript-eslint/
|
|
1050
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
1059
1051
|
}
|
|
1060
1052
|
|
|
1061
1053
|
export { matchers, registerMatchers, type ClassExpectation, type TextContentOptions, type TextExpectation };
|
package/src/normalize.ts
CHANGED
|
@@ -6,10 +6,7 @@ import type { NormalizerFn, NormalizerOptions } from "./types.js";
|
|
|
6
6
|
* @param options Toggles for trimming and whitespace collapsing.
|
|
7
7
|
* @returns A function that normalizes a string for comparison against a matcher.
|
|
8
8
|
*/
|
|
9
|
-
const getDefaultNormalizer = ({
|
|
10
|
-
trim = true,
|
|
11
|
-
collapseWhitespace = true,
|
|
12
|
-
}: NormalizerOptions = {}): NormalizerFn => {
|
|
9
|
+
const getDefaultNormalizer = ({ trim = true, collapseWhitespace = true }: NormalizerOptions = {}): NormalizerFn => {
|
|
13
10
|
return (text: string): string => {
|
|
14
11
|
let result = text;
|
|
15
12
|
|
package/src/pretty-widget.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as Adw from "@gtkx/gi/adw";
|
|
1
2
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
2
3
|
import { sortStringsBy } from "@gtkx/utils";
|
|
3
4
|
import { type Config, format, type NewPlugin, type PrettyFormatOptions } from "@vitest/pretty-format";
|
|
@@ -176,13 +177,27 @@ const formatBody = (widget: Gtk.Widget, indentation: string, depth: number, ctx:
|
|
|
176
177
|
return formatCollapsedChildrenLine(widget, indentation, ctx.config, collapseReason);
|
|
177
178
|
};
|
|
178
179
|
|
|
180
|
+
const isPasswordWidget = (widget: Gtk.Widget): boolean =>
|
|
181
|
+
widget instanceof Gtk.PasswordEntry ||
|
|
182
|
+
widget instanceof Adw.PasswordEntryRow ||
|
|
183
|
+
(widget instanceof Gtk.Entry && !widget.getVisibility()) ||
|
|
184
|
+
(widget instanceof Gtk.Text && !widget.getVisibility());
|
|
185
|
+
|
|
186
|
+
const printableText = (widget: Gtk.Widget): string | null => {
|
|
187
|
+
if (widget instanceof Adw.PasswordEntryRow) {
|
|
188
|
+
return widget.getTitle() || null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return isPasswordWidget(widget) ? null : getWidgetText(widget);
|
|
192
|
+
};
|
|
193
|
+
|
|
179
194
|
const formatWidget = (widget: Gtk.Widget, indentation: string, depth: number, ctx: FormatContext): string => {
|
|
180
195
|
const { config } = ctx;
|
|
181
196
|
const tag = getTypeTag(widget);
|
|
182
197
|
const attrs = formatAttrs(buildAttrs(widget, ctx.getId), config.colors);
|
|
183
198
|
const openTag = `${paint(config.colors.tag, "<" + tag)}${attrs}${paint(config.colors.tag, ">")}`;
|
|
184
199
|
const closeTag = paint(config.colors.tag, `</${tag}>`);
|
|
185
|
-
const text =
|
|
200
|
+
const text = printableText(widget);
|
|
186
201
|
const openLine = `${indentation}${openTag}${config.spacingOuter}`;
|
|
187
202
|
|
|
188
203
|
if (!text && !widget.getFirstChild()) {
|
|
@@ -190,7 +205,7 @@ const formatWidget = (widget: Gtk.Widget, indentation: string, depth: number, ct
|
|
|
190
205
|
}
|
|
191
206
|
|
|
192
207
|
const textLine = text ? `${indentation}${config.indent}${text}${config.spacingOuter}` : "";
|
|
193
|
-
const body = formatBody(widget, indentation, depth, ctx);
|
|
208
|
+
const body = isPasswordWidget(widget) ? "" : formatBody(widget, indentation, depth, ctx);
|
|
194
209
|
|
|
195
210
|
return `${openLine}${textLine}${body}${indentation}${closeTag}${config.spacingOuter}`;
|
|
196
211
|
};
|