@gtkx/testing 2.0.0-beta.11 → 2.0.0-beta.13
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 +3 -3
- package/dist/accessible-native.d.ts.map +1 -1
- package/dist/accessible-native.js.map +1 -1
- package/dist/act.d.ts +7 -1
- package/dist/act.d.ts.map +1 -1
- package/dist/act.js +54 -4
- package/dist/act.js.map +1 -1
- package/dist/bound-queries.d.ts +1 -1
- package/dist/bound-queries.d.ts.map +1 -1
- package/dist/bound-queries.js.map +1 -1
- package/dist/build-queries.d.ts +1 -1
- package/dist/build-queries.d.ts.map +1 -1
- package/dist/build-queries.js +1 -1
- package/dist/build-queries.js.map +1 -1
- package/dist/cleanup-registry.d.ts.map +1 -1
- package/dist/cleanup-registry.js +4 -1
- package/dist/cleanup-registry.js.map +1 -1
- package/dist/config.d.ts.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 +16 -4
- 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 +8 -2
- package/dist/harness-window.d.ts.map +1 -1
- package/dist/harness-window.js +28 -5
- package/dist/harness-window.js.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/internal.d.ts +5 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +5 -0
- package/dist/internal.js.map +1 -1
- package/dist/matchers.d.ts +4 -1
- package/dist/matchers.d.ts.map +1 -1
- package/dist/matchers.js +29 -9
- 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 +4 -2
- package/dist/pretty-widget.d.ts.map +1 -1
- package/dist/pretty-widget.js +7 -5
- package/dist/pretty-widget.js.map +1 -1
- package/dist/production.d.ts.map +1 -1
- package/dist/queries.d.ts +2 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +22 -11
- package/dist/queries.js.map +1 -1
- package/dist/register-test-hooks.js +8 -0
- package/dist/register-test-hooks.js.map +1 -1
- package/dist/render-hook.js.map +1 -1
- package/dist/render.d.ts +14 -6
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +46 -31
- package/dist/render.js.map +1 -1
- package/dist/role-helpers.d.ts.map +1 -1
- package/dist/role-helpers.js.map +1 -1
- package/dist/role-naming.d.ts.map +1 -1
- package/dist/screen.d.ts.map +1 -1
- package/dist/screenshot.d.ts.map +1 -1
- 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 +1 -1
- package/dist/suggestions.js.map +1 -1
- package/dist/timers.d.ts.map +1 -1
- package/dist/traversal.d.ts.map +1 -1
- package/dist/types.d.ts +10 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/usage-error.d.ts +9 -0
- package/dist/usage-error.d.ts.map +1 -0
- package/dist/usage-error.js +13 -0
- package/dist/usage-error.js.map +1 -0
- package/dist/user-event/adjustment.d.ts.map +1 -1
- package/dist/user-event/adjustment.js +6 -5
- package/dist/user-event/adjustment.js.map +1 -1
- package/dist/user-event/click.d.ts +15 -7
- package/dist/user-event/click.d.ts.map +1 -1
- package/dist/user-event/click.js +165 -44
- 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 +11 -3
- package/dist/user-event/controller.d.ts.map +1 -1
- package/dist/user-event/controller.js +26 -4
- package/dist/user-event/controller.js.map +1 -1
- package/dist/user-event/dispatch.d.ts +1 -1
- package/dist/user-event/dispatch.d.ts.map +1 -1
- package/dist/user-event/dispatch.js +9 -6
- package/dist/user-event/dispatch.js.map +1 -1
- package/dist/user-event/editable-label-click.d.ts +5 -0
- package/dist/user-event/editable-label-click.d.ts.map +1 -0
- package/dist/user-event/editable-label-click.js +12 -0
- package/dist/user-event/editable-label-click.js.map +1 -0
- package/dist/user-event/event-wrapper.d.ts +11 -1
- package/dist/user-event/event-wrapper.d.ts.map +1 -1
- package/dist/user-event/event-wrapper.js +66 -12
- package/dist/user-event/event-wrapper.js.map +1 -1
- package/dist/user-event/gesture.d.ts.map +1 -1
- package/dist/user-event/gesture.js +70 -29
- package/dist/user-event/gesture.js.map +1 -1
- package/dist/user-event/index.d.ts +55 -18
- package/dist/user-event/index.d.ts.map +1 -1
- package/dist/user-event/index.js +43 -9
- 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 +27 -2
- package/dist/user-event/keyboard.d.ts.map +1 -1
- package/dist/user-event/keyboard.js +291 -44
- package/dist/user-event/keyboard.js.map +1 -1
- package/dist/user-event/list-row-click.d.ts +2 -1
- package/dist/user-event/list-row-click.d.ts.map +1 -1
- package/dist/user-event/list-row-click.js +10 -6
- package/dist/user-event/list-row-click.js.map +1 -1
- package/dist/user-event/native-click.d.ts +2 -1
- package/dist/user-event/native-click.d.ts.map +1 -1
- package/dist/user-event/native-click.js +17 -5
- 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 +5 -3
- package/dist/user-event/pointer.d.ts.map +1 -1
- package/dist/user-event/pointer.js +72 -27
- package/dist/user-event/pointer.js.map +1 -1
- package/dist/user-event/selection.d.ts.map +1 -1
- package/dist/user-event/selection.js +46 -15
- package/dist/user-event/selection.js.map +1 -1
- package/dist/user-event/state.d.ts +2 -1
- package/dist/user-event/state.d.ts.map +1 -1
- package/dist/user-event/state.js +1 -1
- package/dist/user-event/state.js.map +1 -1
- package/dist/user-event/tab-view-click.d.ts +8 -0
- package/dist/user-event/tab-view-click.d.ts.map +1 -0
- package/dist/user-event/tab-view-click.js +37 -0
- package/dist/user-event/tab-view-click.js.map +1 -0
- package/dist/user-event/text.d.ts +3 -2
- package/dist/user-event/text.d.ts.map +1 -1
- package/dist/user-event/text.js +34 -14
- package/dist/user-event/text.js.map +1 -1
- package/dist/wait-for.d.ts.map +1 -1
- package/dist/wait-for.js.map +1 -1
- package/dist/widget-accessible-properties.d.ts +13 -3
- package/dist/widget-accessible-properties.d.ts.map +1 -1
- package/dist/widget-accessible-properties.js +59 -21
- 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/widget-target.js +2 -1
- package/dist/widget-target.js.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 +17 -19
- package/src/accessible-native.ts +2 -2
- package/src/act.ts +70 -6
- package/src/bound-queries.ts +1 -1
- package/src/build-queries.ts +52 -70
- package/src/cleanup-registry.ts +5 -1
- package/src/errors.ts +6 -6
- package/src/fire-event.ts +23 -9
- package/src/frame-sync.ts +1 -13
- package/src/harness-window.ts +37 -6
- package/src/index.ts +2 -12
- package/src/internal.ts +5 -0
- package/src/matchers.ts +70 -42
- package/src/normalize.ts +1 -4
- package/src/pretty-widget.ts +8 -5
- package/src/queries.ts +42 -21
- package/src/register-test-hooks.ts +11 -0
- package/src/render-hook.tsx +1 -1
- package/src/render.tsx +57 -36
- package/src/role-helpers.ts +1 -1
- package/src/screenshot.ts +3 -8
- package/src/suggestions.ts +1 -1
- package/src/types.ts +22 -17
- package/src/usage-error.ts +16 -0
- package/src/user-event/adjustment.ts +10 -7
- package/src/user-event/click.ts +221 -48
- package/src/user-event/column-header-click.ts +1 -1
- package/src/user-event/controller.ts +49 -4
- package/src/user-event/dispatch.ts +17 -7
- package/src/user-event/editable-label-click.ts +17 -0
- package/src/user-event/event-wrapper.ts +105 -14
- package/src/user-event/gesture.ts +105 -35
- package/src/user-event/index.ts +113 -57
- package/src/user-event/keyboard.ts +416 -52
- package/src/user-event/list-row-click.ts +12 -6
- package/src/user-event/native-click.ts +23 -6
- package/src/user-event/notebook-tab-click.ts +1 -1
- package/src/user-event/pointer.ts +101 -35
- package/src/user-event/selection.ts +72 -25
- package/src/user-event/state.ts +4 -2
- package/src/user-event/tab-view-click.ts +59 -0
- package/src/user-event/text.ts +42 -18
- package/src/wait-for.ts +1 -4
- package/src/widget-accessible-properties.ts +85 -26
- package/src/widget-getters.ts +1 -3
- package/src/widget-target.ts +2 -1
- package/src/window-state.ts +4 -3
- package/src/within.ts +2 -2
package/src/matchers.ts
CHANGED
|
@@ -22,6 +22,7 @@ import { formatRole } from "./role-helpers.js";
|
|
|
22
22
|
import { type Container, descendants } from "./traversal.js";
|
|
23
23
|
import {
|
|
24
24
|
type CheckedState,
|
|
25
|
+
findHiddenCause,
|
|
25
26
|
getWidgetAccessibleName,
|
|
26
27
|
getWidgetCheckedState,
|
|
27
28
|
getWidgetDescribedByText,
|
|
@@ -37,7 +38,6 @@ import {
|
|
|
37
38
|
hasDisplayValue,
|
|
38
39
|
isWidgetDisabled,
|
|
39
40
|
isWidgetValueMatch,
|
|
40
|
-
isWidgetVisible,
|
|
41
41
|
} from "./widget-accessible-properties.js";
|
|
42
42
|
import { getTypeTag } from "./widget-getters.js";
|
|
43
43
|
import { isWindowActivated } from "./window-state.js";
|
|
@@ -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 = (
|
|
@@ -167,7 +167,10 @@ type MatcherImplementations = {
|
|
|
167
167
|
toBeDisabled: StateMatcher;
|
|
168
168
|
/** Asserts the widget and all of its ancestors are sensitive. */
|
|
169
169
|
toBeEnabled: StateMatcher;
|
|
170
|
-
/**
|
|
170
|
+
/**
|
|
171
|
+
* Asserts the widget and its ancestors are all visible and shown by their containers, as a collapsed
|
|
172
|
+
* revealer or an inactive stack page does not show its child, and that none of them is fully transparent.
|
|
173
|
+
*/
|
|
171
174
|
toBeVisible: StateMatcher;
|
|
172
175
|
/** Asserts the widget's root is a window that is still in the toplevel list. */
|
|
173
176
|
toBeRooted: StateMatcher;
|
|
@@ -260,7 +263,12 @@ const toHaveAccessibleErrorMessage: TextMatcher = textMatcher(
|
|
|
260
263
|
);
|
|
261
264
|
|
|
262
265
|
const toHaveSelection: TextMatcher = textMatcher("toHaveSelection", getWidgetSelection, "exact");
|
|
263
|
-
const toBePressed: StateMatcher = booleanStateMatcher(
|
|
266
|
+
const toBePressed: StateMatcher = booleanStateMatcher(
|
|
267
|
+
"toBePressed",
|
|
268
|
+
"pressed",
|
|
269
|
+
getWidgetPressedState,
|
|
270
|
+
checkedInsteadHint,
|
|
271
|
+
);
|
|
264
272
|
const toBeRequired: StateMatcher = booleanStateMatcher("toBeRequired", "required", getWidgetRequiredState);
|
|
265
273
|
|
|
266
274
|
const toContainAnyByRole: ContainmentMatcher<RoleQueryArgs> = containmentMatcher(
|
|
@@ -650,34 +658,39 @@ function readTextContent(widget: Gtk.Widget, options?: TextContentOptions): stri
|
|
|
650
658
|
return text === null ? null : normalizeTextContent(text, options);
|
|
651
659
|
}
|
|
652
660
|
|
|
653
|
-
function toHaveTextContent(
|
|
654
|
-
received: unknown,
|
|
655
|
-
expected?: TextExpectation,
|
|
656
|
-
options?: TextContentOptions,
|
|
657
|
-
): MatcherResult {
|
|
661
|
+
function toHaveTextContent(received: unknown, expected?: TextExpectation, options?: TextContentOptions): MatcherResult {
|
|
658
662
|
const read = (widget: Gtk.Widget): string | null => readTextContent(widget, options);
|
|
659
663
|
|
|
660
664
|
return textMatcher("toHaveTextContent", read, "substring")(received, expected);
|
|
661
665
|
}
|
|
662
666
|
|
|
663
|
-
function notApplicable(matcherName: string, stateName: string, widget: Gtk.Widget): Error {
|
|
667
|
+
function notApplicable(matcherName: string, stateName: string, widget: Gtk.Widget, hint = ""): Error {
|
|
664
668
|
return new Error(
|
|
665
669
|
`${matcherName}: widget does not expose a ${stateName} ` +
|
|
666
|
-
|
|
670
|
+
`(role ${Gtk.AccessibleRole[widget.getAccessibleRole()]})${hint}\n${describeWidget(widget)}`,
|
|
667
671
|
);
|
|
668
672
|
}
|
|
669
673
|
|
|
674
|
+
function pressedInsteadHint(widget: Gtk.Widget): string {
|
|
675
|
+
return getWidgetPressedState(widget) === null ? "" : "; it exposes a pressed state instead; use toBePressed";
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
function checkedInsteadHint(widget: Gtk.Widget): string {
|
|
679
|
+
return getWidgetCheckedState(widget) === null ? "" : "; it exposes a checked state instead; use toBeChecked";
|
|
680
|
+
}
|
|
681
|
+
|
|
670
682
|
function booleanStateMatcher(
|
|
671
683
|
matcherName: string,
|
|
672
684
|
stateName: string,
|
|
673
685
|
read: (widget: Gtk.Widget) => boolean | null,
|
|
686
|
+
hint: (widget: Gtk.Widget) => string = () => "",
|
|
674
687
|
): StateMatcher {
|
|
675
688
|
return (received: unknown): MatcherResult => {
|
|
676
689
|
const widget = asWidget(received, matcherName);
|
|
677
690
|
const state = read(widget);
|
|
678
691
|
|
|
679
692
|
if (state === null) {
|
|
680
|
-
throw notApplicable(matcherName, `${stateName} state`, widget);
|
|
693
|
+
throw notApplicable(matcherName, `${stateName} state`, widget, hint(widget));
|
|
681
694
|
}
|
|
682
695
|
|
|
683
696
|
return stateResult(widget, stateName, state);
|
|
@@ -775,7 +788,7 @@ function toBePartiallyPressed(received: unknown): MatcherResult {
|
|
|
775
788
|
const state = readAccessibleState(widget, Gtk.AccessibleState.PRESSED);
|
|
776
789
|
|
|
777
790
|
if (state === null) {
|
|
778
|
-
throw notApplicable("toBePartiallyPressed", "pressed state", widget);
|
|
791
|
+
throw notApplicable("toBePartiallyPressed", "pressed state", widget, checkedInsteadHint(widget));
|
|
779
792
|
}
|
|
780
793
|
|
|
781
794
|
return stateResult(widget, "partially pressed", state === MIXED_TRISTATE);
|
|
@@ -799,7 +812,7 @@ function readCheckedState(widget: Gtk.Widget, matcherName: string): CheckedState
|
|
|
799
812
|
const state = getWidgetCheckedState(widget);
|
|
800
813
|
|
|
801
814
|
if (state === null) {
|
|
802
|
-
throw notApplicable(matcherName, "checked state", widget);
|
|
815
|
+
throw notApplicable(matcherName, "checked state", widget, pressedInsteadHint(widget));
|
|
803
816
|
}
|
|
804
817
|
|
|
805
818
|
return state;
|
|
@@ -865,10 +878,27 @@ function toBeEnabled(received: unknown): MatcherResult {
|
|
|
865
878
|
return stateResult(widget, "enabled", !isWidgetDisabled(widget));
|
|
866
879
|
}
|
|
867
880
|
|
|
881
|
+
const HIDDEN_REASONS = {
|
|
882
|
+
hidden: "is hidden",
|
|
883
|
+
unshown: "is not shown by its parent",
|
|
884
|
+
transparent: "has opacity 0",
|
|
885
|
+
} as const;
|
|
886
|
+
|
|
868
887
|
function toBeVisible(received: unknown): MatcherResult {
|
|
869
888
|
const widget = asWidget(received, "toBeVisible");
|
|
889
|
+
const hidden = findHiddenCause(widget);
|
|
890
|
+
|
|
891
|
+
if (!hidden) {
|
|
892
|
+
return stateResult(widget, "visible", true);
|
|
893
|
+
}
|
|
870
894
|
|
|
871
|
-
|
|
895
|
+
const subject = hidden.widget === widget ? "it" : `its ancestor ${describeWidget(hidden.widget)}`;
|
|
896
|
+
const reason = HIDDEN_REASONS[hidden.cause];
|
|
897
|
+
|
|
898
|
+
return {
|
|
899
|
+
pass: false,
|
|
900
|
+
message: () => `expected widget to be visible, but ${subject} ${reason}\n${describeWidget(widget)}`,
|
|
901
|
+
};
|
|
872
902
|
}
|
|
873
903
|
|
|
874
904
|
function toBeRooted(received: unknown): MatcherResult {
|
|
@@ -999,8 +1029,8 @@ const registerMatchers = (): void => {
|
|
|
999
1029
|
};
|
|
1000
1030
|
|
|
1001
1031
|
declare module "vitest" {
|
|
1002
|
-
/* eslint-disable @typescript-eslint/
|
|
1003
|
-
declaration merging requires
|
|
1032
|
+
/* eslint-disable @typescript-eslint/no-unused-vars --
|
|
1033
|
+
declaration merging requires vitest's exact type parameters */
|
|
1004
1034
|
interface Matchers<R extends void | Promise<void> = void | Promise<void>, T = unknown> {
|
|
1005
1035
|
toHaveDisplayValue(expected?: TextExpectation): R;
|
|
1006
1036
|
toHaveTextContent(expected?: TextExpectation, options?: TextContentOptions): R;
|
|
@@ -1008,12 +1038,10 @@ declare module "vitest" {
|
|
|
1008
1038
|
toHaveAccessibleDescription(expected?: TextExpectation): R;
|
|
1009
1039
|
toHaveAccessibleErrorMessage(expected?: TextExpectation): R;
|
|
1010
1040
|
toHaveSelection(expected?: TextExpectation): R;
|
|
1011
|
-
/* eslint-disable-next-line unicorn/consistent-boolean-name -- expected is the jest-dom matcher argument name */
|
|
1012
1041
|
toHaveAccessibleState(state: BooleanAccessibleState, expected?: boolean): R;
|
|
1013
1042
|
toHaveAccessibleState(state: TristateAccessibleState, expected?: Gtk.AccessibleTristate): R;
|
|
1014
1043
|
toHaveAccessibleState(state: Gtk.AccessibleState.INVALID, expected?: Gtk.AccessibleInvalidState): R;
|
|
1015
1044
|
toHaveAccessibleProperty(property: StringAccessibleProperty, expected?: string): R;
|
|
1016
|
-
/* eslint-disable-next-line unicorn/consistent-boolean-name -- expected is the jest-dom matcher argument name */
|
|
1017
1045
|
toHaveAccessibleProperty(property: BooleanAccessibleProperty, expected?: boolean): R;
|
|
1018
1046
|
toHaveAccessibleProperty(property: NumberAccessibleProperty, expected?: number): R;
|
|
1019
1047
|
toHaveAccessibleProperty(
|
|
@@ -1053,7 +1081,7 @@ declare module "vitest" {
|
|
|
1053
1081
|
toHaveClass(...args: (ClassExpectation | { exact: boolean })[]): R;
|
|
1054
1082
|
toHaveObjectProperty(name: string, expected?: unknown): R;
|
|
1055
1083
|
}
|
|
1056
|
-
/* eslint-enable @typescript-eslint/
|
|
1084
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
1057
1085
|
}
|
|
1058
1086
|
|
|
1059
1087
|
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
|
@@ -195,15 +195,15 @@ const formatWidget = (widget: Gtk.Widget, indentation: string, depth: number, ct
|
|
|
195
195
|
const { config } = ctx;
|
|
196
196
|
const tag = getTypeTag(widget);
|
|
197
197
|
const attrs = formatAttrs(buildAttrs(widget, ctx.getId), config.colors);
|
|
198
|
-
const openTag = `${paint(config.colors.tag, "<" + tag)}${attrs}${paint(config.colors.tag, ">")}`;
|
|
199
|
-
const closeTag = paint(config.colors.tag, `</${tag}>`);
|
|
200
198
|
const text = printableText(widget);
|
|
201
|
-
const openLine = `${indentation}${openTag}${config.spacingOuter}`;
|
|
202
199
|
|
|
203
200
|
if (!text && !widget.getFirstChild()) {
|
|
204
|
-
return
|
|
201
|
+
return `${indentation}${paint(config.colors.tag, "<" + tag)}${attrs}${paint(config.colors.tag, " />")}${config.spacingOuter}`;
|
|
205
202
|
}
|
|
206
203
|
|
|
204
|
+
const openTag = `${paint(config.colors.tag, "<" + tag)}${attrs}${paint(config.colors.tag, ">")}`;
|
|
205
|
+
const closeTag = paint(config.colors.tag, `</${tag}>`);
|
|
206
|
+
const openLine = `${indentation}${openTag}${config.spacingOuter}`;
|
|
207
207
|
const textLine = text ? `${indentation}${config.indent}${text}${config.spacingOuter}` : "";
|
|
208
208
|
const body = isPasswordWidget(widget) ? "" : formatBody(widget, indentation, depth, ctx);
|
|
209
209
|
|
|
@@ -216,6 +216,9 @@ const createWidgetPlugin = (options: PrettyWidgetOptions): NewPlugin => ({
|
|
|
216
216
|
formatWidget(widget, indentation, 0, { getId: options.getId, config, maxDepth: options.maxDepth }),
|
|
217
217
|
});
|
|
218
218
|
|
|
219
|
+
/** Prints widgets in snapshots as their widget tree, in the format of {@link prettyWidget}. */
|
|
220
|
+
const widgetSnapshotSerializer: NewPlugin = createWidgetPlugin({});
|
|
221
|
+
|
|
219
222
|
const resolveMaxLength = (options: PrettyWidgetOptions): number => {
|
|
220
223
|
const envLimit = process.env.DEBUG_PRINT_LIMIT ? Number(process.env.DEBUG_PRINT_LIMIT) : DEFAULT_MAX_LENGTH;
|
|
221
224
|
|
|
@@ -275,4 +278,4 @@ const logWidget = (container: Container | Container[], options?: PrettyWidgetOpt
|
|
|
275
278
|
}
|
|
276
279
|
};
|
|
277
280
|
|
|
278
|
-
export { logWidget, prettyWidget, type PrettyWidgetOptions };
|
|
281
|
+
export { logWidget, prettyWidget, widgetSnapshotSerializer, type PrettyWidgetOptions };
|
package/src/queries.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 type {
|
|
3
4
|
ByRoleOptions,
|
|
@@ -6,6 +7,7 @@ import type {
|
|
|
6
7
|
MatcherOptions,
|
|
7
8
|
NormalizerFn,
|
|
8
9
|
QueryFamilies,
|
|
10
|
+
WaitForOptions,
|
|
9
11
|
} from "./types.js";
|
|
10
12
|
import { buildQueries, type BuiltQueries, type QueryAllBy } from "./build-queries.js";
|
|
11
13
|
import { multipleFoundError, notFoundError } from "./errors.js";
|
|
@@ -177,8 +179,8 @@ const buildNormalizer = (options?: MatcherOptions): NormalizerFn => {
|
|
|
177
179
|
if (trim !== undefined || collapseWhitespace !== undefined) {
|
|
178
180
|
throw new Error(
|
|
179
181
|
"trim and collapseWhitespace are not supported with a normalizer. " +
|
|
180
|
-
|
|
181
|
-
|
|
182
|
+
"If you want to use the default trim and collapseWhitespace logic in your normalizer, " +
|
|
183
|
+
'use "getDefaultNormalizer({ trim, collapseWhitespace })" and compose that into your normalizer',
|
|
182
184
|
);
|
|
183
185
|
}
|
|
184
186
|
|
|
@@ -284,27 +286,45 @@ const hasMatchingAccessibleStates = (widget: Gtk.Widget, options: ByRoleOptions)
|
|
|
284
286
|
hasMatchingDescriptionState(widget, options) &&
|
|
285
287
|
hasMatchingValueState(widget, options);
|
|
286
288
|
|
|
289
|
+
const isDialogContentShown = (widget: Gtk.Widget): boolean => {
|
|
290
|
+
if (!(widget instanceof Adw.Dialog)) {
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const child = widget.getChild();
|
|
295
|
+
|
|
296
|
+
return child === null || child.getMapped();
|
|
297
|
+
};
|
|
298
|
+
|
|
287
299
|
const isMatchingWidgetType = <T extends Gtk.Accessible>(
|
|
288
300
|
widget: Gtk.Widget,
|
|
289
301
|
options?: MatcherOptions<T>,
|
|
290
|
-
): widget is Gtk.Widget & T =>
|
|
291
|
-
options?.as === undefined || widget instanceof options.as;
|
|
302
|
+
): widget is Gtk.Widget & T => options?.as === undefined || widget instanceof options.as;
|
|
292
303
|
|
|
293
304
|
const hasMatchingAccessibleOptions = (widget: Gtk.Widget, options?: ByRoleOptions): boolean => {
|
|
294
305
|
if (!options) {
|
|
295
306
|
return true;
|
|
296
307
|
}
|
|
297
308
|
|
|
298
|
-
return (
|
|
299
|
-
hasMatchingAccessibleName(widget, options) &&
|
|
300
|
-
hasMatchingAccessibleStates(widget, options)
|
|
301
|
-
);
|
|
309
|
+
return hasMatchingAccessibleName(widget, options) && hasMatchingAccessibleStates(widget, options);
|
|
302
310
|
};
|
|
303
311
|
|
|
304
|
-
function
|
|
312
|
+
function withWaitForOptions<Expected, Result>(
|
|
313
|
+
find: (container: Container, expected: Expected, options?: MatcherOptions<Gtk.Widget>) => Promise<Result>,
|
|
314
|
+
) {
|
|
315
|
+
return (
|
|
316
|
+
container: Container,
|
|
317
|
+
expected: Expected,
|
|
318
|
+
options?: MatcherOptions<Gtk.Widget>,
|
|
319
|
+
waitForOptions?: WaitForOptions,
|
|
320
|
+
): Promise<Result> =>
|
|
321
|
+
find(container, expected, waitForOptions === undefined ? options : { ...options, ...waitForOptions });
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function nameQueryFamily<Expected, Element extends Gtk.Accessible>(
|
|
305
325
|
suffix: string,
|
|
306
|
-
queryAllBy: QueryAllBy<
|
|
307
|
-
built: BuiltQueries<
|
|
326
|
+
queryAllBy: QueryAllBy<[expected: Expected, options?: MatcherOptions<Gtk.Widget>], Element>,
|
|
327
|
+
built: BuiltQueries<[expected: Expected, options?: MatcherOptions<Gtk.Widget>], Element>,
|
|
308
328
|
): Record<string, unknown> {
|
|
309
329
|
const [queryBy, getAllBy, getBy, findAllBy, findBy] = built;
|
|
310
330
|
|
|
@@ -313,15 +333,16 @@ function nameQueryFamily<Args extends unknown[], Element extends Gtk.Accessible>
|
|
|
313
333
|
[`queryAllBy${suffix}`]: queryAllBy,
|
|
314
334
|
[`getBy${suffix}`]: getBy,
|
|
315
335
|
[`getAllBy${suffix}`]: getAllBy,
|
|
316
|
-
[`findBy${suffix}`]: findBy,
|
|
317
|
-
[`findAllBy${suffix}`]: findAllBy,
|
|
336
|
+
[`findBy${suffix}`]: withWaitForOptions(findBy),
|
|
337
|
+
[`findAllBy${suffix}`]: withWaitForOptions(findAllBy),
|
|
318
338
|
};
|
|
319
339
|
}
|
|
320
340
|
|
|
321
341
|
/**
|
|
322
342
|
* Finds every widget under the container whose accessible role matches `role` and that satisfies the given options.
|
|
323
343
|
* Widgets that are not mapped are never matched, and widgets excluded from the accessibility tree are
|
|
324
|
-
* skipped unless `options.hidden` is set.
|
|
344
|
+
* skipped unless `options.hidden` is set. An Adwaita dialog matches once its content is shown, which
|
|
345
|
+
* libadwaita does a frame after the dialog opens.
|
|
325
346
|
* @param container Widget subtree to search.
|
|
326
347
|
* @param role Accessible role to match.
|
|
327
348
|
* @param options Additional accessible name, state, and value constraints.
|
|
@@ -335,7 +356,7 @@ function queryAllByRole<T extends Gtk.Accessible = Gtk.Widget>(
|
|
|
335
356
|
const isInaccessible = buildInaccessibilityCheck();
|
|
336
357
|
|
|
337
358
|
const matches = findAll(container, (widget) => {
|
|
338
|
-
if (widget.getAccessibleRole() !== role) {
|
|
359
|
+
if (widget.getAccessibleRole() !== role || !isDialogContentShown(widget)) {
|
|
339
360
|
return false;
|
|
340
361
|
}
|
|
341
362
|
|
|
@@ -372,9 +393,10 @@ const collectMnemonicMatch = (
|
|
|
372
393
|
};
|
|
373
394
|
|
|
374
395
|
const labellingText = (widget: Gtk.Widget): string | null => {
|
|
375
|
-
const ownLabel =
|
|
396
|
+
const ownLabel = getWidgetOwnLabel(widget);
|
|
397
|
+
const isOwnText = widget.getAccessibleRole() === Gtk.AccessibleRole.LABEL && ownLabel === namingLabelText(widget);
|
|
376
398
|
|
|
377
|
-
return ownLabel ?? getWidgetExternalLabelText(widget);
|
|
399
|
+
return (isOwnText ? null : ownLabel) ?? getWidgetExternalLabelText(widget);
|
|
378
400
|
};
|
|
379
401
|
|
|
380
402
|
const collectLabelMatches = (
|
|
@@ -416,8 +438,8 @@ function queryAllByLabelText<T extends Gtk.Accessible = Gtk.Widget>(
|
|
|
416
438
|
collectLabelMatches(results, widget, text, options);
|
|
417
439
|
}
|
|
418
440
|
|
|
419
|
-
return [...results].filter(
|
|
420
|
-
widgets.has(widget) && isMatchingWidgetType(widget, options),
|
|
441
|
+
return [...results].filter(
|
|
442
|
+
(widget): widget is Gtk.Widget & T => widgets.has(widget) && isMatchingWidgetType(widget, options),
|
|
421
443
|
);
|
|
422
444
|
}
|
|
423
445
|
|
|
@@ -499,8 +521,7 @@ function queryAllByDisplayValue<T extends Gtk.Accessible = Gtk.Widget>(
|
|
|
499
521
|
const matches = findAll(
|
|
500
522
|
container,
|
|
501
523
|
(widget) =>
|
|
502
|
-
isMatchingWidgetType(widget, options) &&
|
|
503
|
-
isTextMatch(getWidgetDisplayValue(widget), value, widget, options),
|
|
524
|
+
isMatchingWidgetType(widget, options) && isTextMatch(getWidgetDisplayValue(widget), value, widget, options),
|
|
504
525
|
);
|
|
505
526
|
|
|
506
527
|
return matches.filter((widget): widget is Gtk.Widget & T => isMatchingWidgetType(widget, options));
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { quit } from "@gtkx/runtime";
|
|
2
2
|
import { getIsReactActEnvironment, setIsReactActEnvironment } from "./act.js";
|
|
3
3
|
import { registerMatchers } from "./matchers.js";
|
|
4
|
+
import { widgetSnapshotSerializer } from "./pretty-widget.js";
|
|
4
5
|
import { cleanup } from "./render.js";
|
|
5
6
|
|
|
6
7
|
type RunnerHook = "beforeAll" | "afterEach" | "afterAll";
|
|
8
|
+
type SnapshotExpect = { addSnapshotSerializer: (serializer: typeof widgetSnapshotSerializer) => void };
|
|
7
9
|
|
|
8
10
|
const callRunnerHook = (name: RunnerHook, callback: () => unknown): void => {
|
|
9
11
|
const hook: unknown = Reflect.get(globalThis, name);
|
|
@@ -26,11 +28,20 @@ const registerActEnvironment = (): void => {
|
|
|
26
28
|
});
|
|
27
29
|
};
|
|
28
30
|
|
|
31
|
+
const registerSnapshotSerializer = (): void => {
|
|
32
|
+
const expect: unknown = Reflect.get(globalThis, "expect");
|
|
33
|
+
|
|
34
|
+
if (expect && typeof (expect as SnapshotExpect).addSnapshotSerializer === "function") {
|
|
35
|
+
(expect as SnapshotExpect).addSnapshotSerializer(widgetSnapshotSerializer);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
29
39
|
const registerTestRuntimeHooks = (): void => {
|
|
30
40
|
registerActEnvironment();
|
|
31
41
|
callRunnerHook("afterEach", cleanup);
|
|
32
42
|
callRunnerHook("afterAll", quit);
|
|
33
43
|
registerMatchers();
|
|
44
|
+
registerSnapshotSerializer();
|
|
34
45
|
};
|
|
35
46
|
|
|
36
47
|
registerTestRuntimeHooks();
|
package/src/render-hook.tsx
CHANGED
|
@@ -32,7 +32,7 @@ async function renderHook<Result, Props>(
|
|
|
32
32
|
callback: (props: Props) => Result,
|
|
33
33
|
options?: RenderHookOptions<Props>,
|
|
34
34
|
): Promise<RenderHookResult<Result, Props>> {
|
|
35
|
-
const initialProps =
|
|
35
|
+
const initialProps = options?.initialProps as Props;
|
|
36
36
|
const resultRef: { current: Result | undefined } = { current: undefined };
|
|
37
37
|
let currentProps: Props = initialProps;
|
|
38
38
|
|
package/src/render.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Root, RootElement } from "@gtkx/react";
|
|
2
|
+
import * as Gio from "@gtkx/gi/gio";
|
|
2
3
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
3
4
|
import { createRoot } from "@gtkx/react";
|
|
4
|
-
import { isRootElement, settleAccessible } from "@gtkx/react/internal";
|
|
5
|
+
import { isRootElement, ParentWindowContext, settleAccessible } from "@gtkx/react/internal";
|
|
5
6
|
import { type ErrorInfo, type ReactNode, StrictMode } from "react";
|
|
6
7
|
import type { RenderResult } from "./bound-queries.js";
|
|
7
8
|
import type { QueryMap, RenderOptions, ScreenshotOptions } from "./types.js";
|
|
@@ -9,13 +10,13 @@ import { runInAct, runWithActEnvironment } from "./act.js";
|
|
|
9
10
|
import { addToCleanupQueue, runCleanup, runCleanupCallbacks } from "./cleanup-registry.js";
|
|
10
11
|
import { getConfig } from "./config.js";
|
|
11
12
|
import { scheduleWhenWindowReady } from "./frame-sync.js";
|
|
12
|
-
import { createHarnessWindow, presentHarnessWindow } from "./harness-window.js";
|
|
13
|
+
import { createHarnessWindow, presentHarnessTransients, presentHarnessWindow } from "./harness-window.js";
|
|
13
14
|
import { logWidget, type PrettyWidgetOptions } from "./pretty-widget.js";
|
|
14
15
|
import { logRoles } from "./role-helpers.js";
|
|
15
16
|
import { clearScreen, setScreen } from "./screen.js";
|
|
16
17
|
import { captureScreen } from "./screenshot.js";
|
|
17
18
|
import { type Container, roots, TOPLEVELS } from "./traversal.js";
|
|
18
|
-
import { resetClipboard } from "./user-event/index.js";
|
|
19
|
+
import { resetClipboard, resetUserEventState } from "./user-event/index.js";
|
|
19
20
|
import { requireWidget } from "./widget-target.js";
|
|
20
21
|
import { findPresentedWindowFailure, findRenderedWindowFailure, mappedToplevels } from "./window-state.js";
|
|
21
22
|
import { within } from "./within.js";
|
|
@@ -24,6 +25,7 @@ type ActiveRender = {
|
|
|
24
25
|
root: Root;
|
|
25
26
|
window: Gtk.Window | null;
|
|
26
27
|
errors: RenderErrorState;
|
|
28
|
+
application: Gio.Application | null;
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
type ResolvedContainer = {
|
|
@@ -61,7 +63,7 @@ const settleWindow = async (
|
|
|
61
63
|
if (failure !== null) {
|
|
62
64
|
throw new Error(
|
|
63
65
|
`${action} timed out after ${String(timeout)}ms waiting for the window it rendered into: ${failure}. ` +
|
|
64
|
-
|
|
66
|
+
"Platform state such as focus is only readable once that window is allocated and active.",
|
|
65
67
|
);
|
|
66
68
|
}
|
|
67
69
|
};
|
|
@@ -90,6 +92,7 @@ const disposeActiveRender = async (active: ActiveRender): Promise<void> => {
|
|
|
90
92
|
await flushRender(active, active.root.unmount);
|
|
91
93
|
} finally {
|
|
92
94
|
active.window?.destroy();
|
|
95
|
+
active.application?.quit();
|
|
93
96
|
}
|
|
94
97
|
};
|
|
95
98
|
|
|
@@ -171,28 +174,22 @@ const settleRender = async (
|
|
|
171
174
|
await settleWindow(settleTarget(resolved, container), findFailure, action);
|
|
172
175
|
};
|
|
173
176
|
|
|
174
|
-
const renderErrorHandlers = <Q extends QueryMap>(errors: RenderErrorState, options: RenderOptions<Q> | undefined) => {
|
|
175
|
-
|
|
177
|
+
const renderErrorHandlers = <Q extends QueryMap>(errors: RenderErrorState, options: RenderOptions<Q> | undefined) => ({
|
|
178
|
+
onUncaughtError: (error: unknown): void => {
|
|
176
179
|
errors.lastError = error instanceof Error ? error : new Error(String(error));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
onRecoverableError: (error: unknown, errorInfo: ErrorInfo): void => {
|
|
186
|
-
options?.onRecoverableError?.(error, errorInfo);
|
|
187
|
-
},
|
|
188
|
-
};
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
const applyEnableAnimations = (areAnimationsEnabled: boolean): void => {
|
|
180
|
+
},
|
|
181
|
+
onCaughtError: options?.onCaughtError,
|
|
182
|
+
onRecoverableError: (error: unknown, errorInfo: ErrorInfo): void => {
|
|
183
|
+
options?.onRecoverableError?.(error, errorInfo);
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const applyDisplaySettings = (areAnimationsEnabled: boolean): void => {
|
|
192
188
|
const settings = Gtk.Settings.getDefault();
|
|
193
189
|
|
|
194
190
|
if (settings) {
|
|
195
191
|
settings.gtkEnableAnimations = areAnimationsEnabled;
|
|
192
|
+
settings.gtkCursorBlink = false;
|
|
196
193
|
}
|
|
197
194
|
};
|
|
198
195
|
|
|
@@ -200,27 +197,34 @@ const applyEnableAnimations = (areAnimationsEnabled: boolean): void => {
|
|
|
200
197
|
* Renders React into native widgets and returns queries, debug helpers, and lifecycle controls.
|
|
201
198
|
*
|
|
202
199
|
* @remarks
|
|
203
|
-
* Without a container, creates and presents a harness window
|
|
204
|
-
*
|
|
200
|
+
* Without a container, creates and presents a harness window, which the tree sees as its parent
|
|
201
|
+
* window. Windows the tree opens over it, such as an Adwaita dialog rendered on its own, are shown
|
|
202
|
+
* again after it, so the topmost one is active as in a running application. Initially focused
|
|
203
|
+
* editables keep their text unselected, with the caret at the end. Carets do not blink, so a focused
|
|
204
|
+
* editable does not keep the display redrawing and GLib idle callbacks still run.
|
|
205
205
|
*
|
|
206
206
|
* Waits for layout and activation before resolving, so focus and other platform state can be
|
|
207
|
-
* read immediately. A new harness waits for its
|
|
207
|
+
* read immediately. A new harness waits for its topmost window's activation; a caller-owned or rendered
|
|
208
208
|
* window waits for application activation, since only presentation can claim it. A container
|
|
209
209
|
* that is not shown requires no activation wait.
|
|
210
210
|
*
|
|
211
211
|
* Widgets outside all toplevels or inside a hidden window cannot receive pointer or keyboard
|
|
212
212
|
* input. `userEvent` rejects after `actionabilityTimeout`; use `fireEvent` to drive them directly.
|
|
213
213
|
*
|
|
214
|
+
* Errors an error boundary catches go to `onCaughtError` and do not fail the test. An error no boundary
|
|
215
|
+
* catches rejects this render, or the next rerender, unmount or cleanup, with that error.
|
|
216
|
+
*
|
|
214
217
|
* @param element React element to render.
|
|
215
218
|
* @param options Container, wrapper, custom queries, and render settings.
|
|
216
219
|
* @returns Bound queries, debug helpers, and rerender/unmount controls.
|
|
217
|
-
* @throws If a shown window is not laid out and activated within `windowActivationTimeout
|
|
220
|
+
* @throws If a shown window is not laid out and activated within `windowActivationTimeout`, or the tree
|
|
221
|
+
* throws an error no boundary catches.
|
|
218
222
|
*/
|
|
219
223
|
const render = async <Q extends QueryMap = Record<never, never>>(
|
|
220
224
|
element: ReactNode,
|
|
221
225
|
options?: RenderOptions<Q>,
|
|
222
226
|
): Promise<RenderResult<Q>> => {
|
|
223
|
-
|
|
227
|
+
applyDisplaySettings(options?.areAnimationsEnabled === true);
|
|
224
228
|
const baseElement: Container = options?.baseElement ?? TOPLEVELS;
|
|
225
229
|
const Wrapper = options?.wrapper;
|
|
226
230
|
const resolved = resolveContainer(options?.container);
|
|
@@ -228,23 +232,39 @@ const render = async <Q extends QueryMap = Record<never, never>>(
|
|
|
228
232
|
const errors: RenderErrorState = { lastError: null };
|
|
229
233
|
const root = createRoot(resolved.containerInfo, renderErrorHandlers(errors, options));
|
|
230
234
|
|
|
231
|
-
const active: ActiveRender = { root, window: resolved.window, errors };
|
|
235
|
+
const active: ActiveRender = { root, window: resolved.window, errors, application: null };
|
|
232
236
|
activeRenders.add(active);
|
|
233
237
|
addToCleanupQueue(disposeAllActiveRenders);
|
|
234
238
|
addToCleanupQueue(clearScreen);
|
|
235
239
|
addToCleanupQueue(resetClipboard);
|
|
240
|
+
addToCleanupQueue(resetUserEventState);
|
|
236
241
|
|
|
237
242
|
const wrap = (node: ReactNode): ReactNode => {
|
|
238
243
|
const wrapped = Wrapper ? <Wrapper>{node}</Wrapper> : node;
|
|
239
|
-
|
|
240
|
-
|
|
244
|
+
const hosted =
|
|
245
|
+
resolved.window === null ? (
|
|
246
|
+
wrapped
|
|
247
|
+
) : (
|
|
248
|
+
<ParentWindowContext.Provider value={resolved.window}>{wrapped}</ParentWindowContext.Provider>
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
return options?.isReactStrictMode ? <StrictMode>{hosted}</StrictMode> : hosted;
|
|
241
252
|
};
|
|
242
253
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
254
|
+
const previousApplication = Gio.Application.getDefault();
|
|
255
|
+
|
|
256
|
+
try {
|
|
257
|
+
await flushRender(active, () => {
|
|
258
|
+
root.render(wrap(element));
|
|
259
|
+
});
|
|
260
|
+
} finally {
|
|
261
|
+
const application = Gio.Application.getDefault();
|
|
262
|
+
active.application = application === previousApplication ? null : application;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const transients = presentHarnessWindow(resolved.window);
|
|
247
266
|
await settleRender(resolved, options?.container, "render");
|
|
267
|
+
await settleWindow(realizedWindow(presentHarnessTransients(transients)), findPresentedWindowFailure, "render");
|
|
248
268
|
const container = resolveResultContainer(resolved, options?.container, baseElement);
|
|
249
269
|
|
|
250
270
|
const result: RenderResult<Q> = {
|
|
@@ -275,8 +295,9 @@ const render = async <Q extends QueryMap = Record<never, never>>(
|
|
|
275
295
|
};
|
|
276
296
|
|
|
277
297
|
/**
|
|
278
|
-
* Unmounts every active render
|
|
279
|
-
* resetting the screen
|
|
298
|
+
* Unmounts every active render, quits the applications those renders started, and runs all
|
|
299
|
+
* registered cleanup callbacks, resetting the screen, the clipboard and the input the default `userEvent` still holds.
|
|
300
|
+
* Called automatically after each test.
|
|
280
301
|
*/
|
|
281
302
|
const cleanup = async (): Promise<void> => {
|
|
282
303
|
await runCleanup();
|
package/src/role-helpers.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { requireWidget } from "./widget-target.js";
|
|
|
7
7
|
|
|
8
8
|
const ROLE_NAMES_BY_VALUE = enumNamesByValue(Gtk.AccessibleRole);
|
|
9
9
|
|
|
10
|
-
function enumNamesByValue(enumObject: Record<string,
|
|
10
|
+
function enumNamesByValue(enumObject: Readonly<Record<string, unknown>>): Map<number, string> {
|
|
11
11
|
return new Map<number, string>(
|
|
12
12
|
Object.entries(enumObject)
|
|
13
13
|
.filter((entry): entry is [string, number] => typeof entry[1] === "number")
|