@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.
Files changed (215) hide show
  1. package/README.md +3 -3
  2. package/dist/accessible-native.d.ts.map +1 -1
  3. package/dist/accessible-native.js.map +1 -1
  4. package/dist/act.d.ts +7 -1
  5. package/dist/act.d.ts.map +1 -1
  6. package/dist/act.js +54 -4
  7. package/dist/act.js.map +1 -1
  8. package/dist/bound-queries.d.ts +1 -1
  9. package/dist/bound-queries.d.ts.map +1 -1
  10. package/dist/bound-queries.js.map +1 -1
  11. package/dist/build-queries.d.ts +1 -1
  12. package/dist/build-queries.d.ts.map +1 -1
  13. package/dist/build-queries.js +1 -1
  14. package/dist/build-queries.js.map +1 -1
  15. package/dist/cleanup-registry.d.ts.map +1 -1
  16. package/dist/cleanup-registry.js +4 -1
  17. package/dist/cleanup-registry.js.map +1 -1
  18. package/dist/config.d.ts.map +1 -1
  19. package/dist/editable.d.ts.map +1 -1
  20. package/dist/errors.d.ts.map +1 -1
  21. package/dist/errors.js.map +1 -1
  22. package/dist/fire-event.d.ts.map +1 -1
  23. package/dist/fire-event.js +16 -4
  24. package/dist/fire-event.js.map +1 -1
  25. package/dist/frame-sync.d.ts.map +1 -1
  26. package/dist/frame-sync.js +1 -10
  27. package/dist/frame-sync.js.map +1 -1
  28. package/dist/harness-window.d.ts +8 -2
  29. package/dist/harness-window.d.ts.map +1 -1
  30. package/dist/harness-window.js +28 -5
  31. package/dist/harness-window.js.map +1 -1
  32. package/dist/index.d.ts +2 -2
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +1 -1
  35. package/dist/index.js.map +1 -1
  36. package/dist/internal.d.ts +5 -0
  37. package/dist/internal.d.ts.map +1 -1
  38. package/dist/internal.js +5 -0
  39. package/dist/internal.js.map +1 -1
  40. package/dist/matchers.d.ts +4 -1
  41. package/dist/matchers.d.ts.map +1 -1
  42. package/dist/matchers.js +29 -9
  43. package/dist/matchers.js.map +1 -1
  44. package/dist/normalize.d.ts +1 -1
  45. package/dist/normalize.d.ts.map +1 -1
  46. package/dist/normalize.js +1 -1
  47. package/dist/normalize.js.map +1 -1
  48. package/dist/pretty-widget.d.ts +4 -2
  49. package/dist/pretty-widget.d.ts.map +1 -1
  50. package/dist/pretty-widget.js +7 -5
  51. package/dist/pretty-widget.js.map +1 -1
  52. package/dist/production.d.ts.map +1 -1
  53. package/dist/queries.d.ts +2 -1
  54. package/dist/queries.d.ts.map +1 -1
  55. package/dist/queries.js +22 -11
  56. package/dist/queries.js.map +1 -1
  57. package/dist/register-test-hooks.js +8 -0
  58. package/dist/register-test-hooks.js.map +1 -1
  59. package/dist/render-hook.js.map +1 -1
  60. package/dist/render.d.ts +14 -6
  61. package/dist/render.d.ts.map +1 -1
  62. package/dist/render.js +46 -31
  63. package/dist/render.js.map +1 -1
  64. package/dist/role-helpers.d.ts.map +1 -1
  65. package/dist/role-helpers.js.map +1 -1
  66. package/dist/role-naming.d.ts.map +1 -1
  67. package/dist/screen.d.ts.map +1 -1
  68. package/dist/screenshot.d.ts.map +1 -1
  69. package/dist/screenshot.js.map +1 -1
  70. package/dist/suggestions.d.ts +1 -1
  71. package/dist/suggestions.d.ts.map +1 -1
  72. package/dist/suggestions.js +1 -1
  73. package/dist/suggestions.js.map +1 -1
  74. package/dist/timers.d.ts.map +1 -1
  75. package/dist/traversal.d.ts.map +1 -1
  76. package/dist/types.d.ts +10 -2
  77. package/dist/types.d.ts.map +1 -1
  78. package/dist/types.js.map +1 -1
  79. package/dist/usage-error.d.ts +9 -0
  80. package/dist/usage-error.d.ts.map +1 -0
  81. package/dist/usage-error.js +13 -0
  82. package/dist/usage-error.js.map +1 -0
  83. package/dist/user-event/adjustment.d.ts.map +1 -1
  84. package/dist/user-event/adjustment.js +6 -5
  85. package/dist/user-event/adjustment.js.map +1 -1
  86. package/dist/user-event/click.d.ts +15 -7
  87. package/dist/user-event/click.d.ts.map +1 -1
  88. package/dist/user-event/click.js +165 -44
  89. package/dist/user-event/click.js.map +1 -1
  90. package/dist/user-event/column-header-click.d.ts.map +1 -1
  91. package/dist/user-event/column-header-click.js +1 -1
  92. package/dist/user-event/column-header-click.js.map +1 -1
  93. package/dist/user-event/controller.d.ts +11 -3
  94. package/dist/user-event/controller.d.ts.map +1 -1
  95. package/dist/user-event/controller.js +26 -4
  96. package/dist/user-event/controller.js.map +1 -1
  97. package/dist/user-event/dispatch.d.ts +1 -1
  98. package/dist/user-event/dispatch.d.ts.map +1 -1
  99. package/dist/user-event/dispatch.js +9 -6
  100. package/dist/user-event/dispatch.js.map +1 -1
  101. package/dist/user-event/editable-label-click.d.ts +5 -0
  102. package/dist/user-event/editable-label-click.d.ts.map +1 -0
  103. package/dist/user-event/editable-label-click.js +12 -0
  104. package/dist/user-event/editable-label-click.js.map +1 -0
  105. package/dist/user-event/event-wrapper.d.ts +11 -1
  106. package/dist/user-event/event-wrapper.d.ts.map +1 -1
  107. package/dist/user-event/event-wrapper.js +66 -12
  108. package/dist/user-event/event-wrapper.js.map +1 -1
  109. package/dist/user-event/gesture.d.ts.map +1 -1
  110. package/dist/user-event/gesture.js +70 -29
  111. package/dist/user-event/gesture.js.map +1 -1
  112. package/dist/user-event/index.d.ts +55 -18
  113. package/dist/user-event/index.d.ts.map +1 -1
  114. package/dist/user-event/index.js +43 -9
  115. package/dist/user-event/index.js.map +1 -1
  116. package/dist/user-event/indexed-children.d.ts.map +1 -1
  117. package/dist/user-event/keyboard.d.ts +27 -2
  118. package/dist/user-event/keyboard.d.ts.map +1 -1
  119. package/dist/user-event/keyboard.js +291 -44
  120. package/dist/user-event/keyboard.js.map +1 -1
  121. package/dist/user-event/list-row-click.d.ts +2 -1
  122. package/dist/user-event/list-row-click.d.ts.map +1 -1
  123. package/dist/user-event/list-row-click.js +10 -6
  124. package/dist/user-event/list-row-click.js.map +1 -1
  125. package/dist/user-event/native-click.d.ts +2 -1
  126. package/dist/user-event/native-click.d.ts.map +1 -1
  127. package/dist/user-event/native-click.js +17 -5
  128. package/dist/user-event/native-click.js.map +1 -1
  129. package/dist/user-event/notebook-tab-click.d.ts.map +1 -1
  130. package/dist/user-event/notebook-tab-click.js +1 -1
  131. package/dist/user-event/notebook-tab-click.js.map +1 -1
  132. package/dist/user-event/pointer.d.ts +5 -3
  133. package/dist/user-event/pointer.d.ts.map +1 -1
  134. package/dist/user-event/pointer.js +72 -27
  135. package/dist/user-event/pointer.js.map +1 -1
  136. package/dist/user-event/selection.d.ts.map +1 -1
  137. package/dist/user-event/selection.js +46 -15
  138. package/dist/user-event/selection.js.map +1 -1
  139. package/dist/user-event/state.d.ts +2 -1
  140. package/dist/user-event/state.d.ts.map +1 -1
  141. package/dist/user-event/state.js +1 -1
  142. package/dist/user-event/state.js.map +1 -1
  143. package/dist/user-event/tab-view-click.d.ts +8 -0
  144. package/dist/user-event/tab-view-click.d.ts.map +1 -0
  145. package/dist/user-event/tab-view-click.js +37 -0
  146. package/dist/user-event/tab-view-click.js.map +1 -0
  147. package/dist/user-event/text.d.ts +3 -2
  148. package/dist/user-event/text.d.ts.map +1 -1
  149. package/dist/user-event/text.js +34 -14
  150. package/dist/user-event/text.js.map +1 -1
  151. package/dist/wait-for.d.ts.map +1 -1
  152. package/dist/wait-for.js.map +1 -1
  153. package/dist/widget-accessible-properties.d.ts +13 -3
  154. package/dist/widget-accessible-properties.d.ts.map +1 -1
  155. package/dist/widget-accessible-properties.js +59 -21
  156. package/dist/widget-accessible-properties.js.map +1 -1
  157. package/dist/widget-getters.d.ts.map +1 -1
  158. package/dist/widget-getters.js +0 -1
  159. package/dist/widget-getters.js.map +1 -1
  160. package/dist/widget-target.d.ts.map +1 -1
  161. package/dist/widget-target.js +2 -1
  162. package/dist/widget-target.js.map +1 -1
  163. package/dist/window-state.d.ts.map +1 -1
  164. package/dist/window-state.js +3 -1
  165. package/dist/window-state.js.map +1 -1
  166. package/dist/within.d.ts.map +1 -1
  167. package/dist/within.js.map +1 -1
  168. package/package.json +17 -19
  169. package/src/accessible-native.ts +2 -2
  170. package/src/act.ts +70 -6
  171. package/src/bound-queries.ts +1 -1
  172. package/src/build-queries.ts +52 -70
  173. package/src/cleanup-registry.ts +5 -1
  174. package/src/errors.ts +6 -6
  175. package/src/fire-event.ts +23 -9
  176. package/src/frame-sync.ts +1 -13
  177. package/src/harness-window.ts +37 -6
  178. package/src/index.ts +2 -12
  179. package/src/internal.ts +5 -0
  180. package/src/matchers.ts +70 -42
  181. package/src/normalize.ts +1 -4
  182. package/src/pretty-widget.ts +8 -5
  183. package/src/queries.ts +42 -21
  184. package/src/register-test-hooks.ts +11 -0
  185. package/src/render-hook.tsx +1 -1
  186. package/src/render.tsx +57 -36
  187. package/src/role-helpers.ts +1 -1
  188. package/src/screenshot.ts +3 -8
  189. package/src/suggestions.ts +1 -1
  190. package/src/types.ts +22 -17
  191. package/src/usage-error.ts +16 -0
  192. package/src/user-event/adjustment.ts +10 -7
  193. package/src/user-event/click.ts +221 -48
  194. package/src/user-event/column-header-click.ts +1 -1
  195. package/src/user-event/controller.ts +49 -4
  196. package/src/user-event/dispatch.ts +17 -7
  197. package/src/user-event/editable-label-click.ts +17 -0
  198. package/src/user-event/event-wrapper.ts +105 -14
  199. package/src/user-event/gesture.ts +105 -35
  200. package/src/user-event/index.ts +113 -57
  201. package/src/user-event/keyboard.ts +416 -52
  202. package/src/user-event/list-row-click.ts +12 -6
  203. package/src/user-event/native-click.ts +23 -6
  204. package/src/user-event/notebook-tab-click.ts +1 -1
  205. package/src/user-event/pointer.ts +101 -35
  206. package/src/user-event/selection.ts +72 -25
  207. package/src/user-event/state.ts +4 -2
  208. package/src/user-event/tab-view-click.ts +59 -0
  209. package/src/user-event/text.ts +42 -18
  210. package/src/wait-for.ts +1 -4
  211. package/src/widget-accessible-properties.ts +85 -26
  212. package/src/widget-getters.ts +1 -3
  213. package/src/widget-target.ts +2 -1
  214. package/src/window-state.ts +4 -3
  215. 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
- /** Asserts the widget and its ancestors are all visible, and that none of them is fully transparent. */
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("toBePressed", "pressed", getWidgetPressedState);
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
- `(role ${Gtk.AccessibleRole[widget.getAccessibleRole()]})\n${describeWidget(widget)}`,
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
- return stateResult(widget, "visible", isWidgetVisible(widget));
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/consistent-type-definitions, @typescript-eslint/no-unused-vars --
1003
- declaration merging requires an interface with vitest's exact type parameters */
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/consistent-type-definitions, @typescript-eslint/no-unused-vars */
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
 
@@ -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 openLine;
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
- "If you want to use the default trim and collapseWhitespace logic in your normalizer, " +
181
- "use \"getDefaultNormalizer({ trim, collapseWhitespace })\" and compose that into your normalizer",
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 nameQueryFamily<Args extends unknown[], Element extends Gtk.Accessible>(
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<Args, Element>,
307
- built: BuiltQueries<Args, Element>,
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 = widget.getAccessibleRole() === Gtk.AccessibleRole.LABEL ? null : getWidgetOwnLabel(widget);
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((widget): widget is Gtk.Widget & T =>
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();
@@ -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 = (options as { initialProps?: Props } | undefined)?.initialProps as Props;
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 { CaughtErrorInfo, Root, RootElement } from "@gtkx/react";
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
- "Platform state such as focus is only readable once that window is allocated and active.",
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
- const handleError = (error: unknown): void => {
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
- return {
180
- onUncaughtError: handleError,
181
- onCaughtError: (error: unknown, errorInfo: CaughtErrorInfo): void => {
182
- handleError(error);
183
- options?.onCaughtError?.(error, errorInfo);
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. Its initially focused editable
204
- * keeps its text unselected, with the caret at the end.
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 own activation; a caller-owned or rendered
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
- applyEnableAnimations(options?.areAnimationsEnabled === true);
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
- return options?.isReactStrictMode ? <StrictMode>{wrapped}</StrictMode> : wrapped;
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
- await flushRender(active, () => {
244
- root.render(wrap(element));
245
- });
246
- presentHarnessWindow(resolved.window);
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 and runs all registered cleanup callbacks,
279
- * resetting the screen and clipboard. Called automatically after each test.
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();
@@ -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, string | number>): Map<number, 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")