@gtkx/testing 0.1.35 → 0.1.37

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/dist/index.d.ts CHANGED
@@ -2,7 +2,8 @@ export { fireEvent } from "./fire-event.js";
2
2
  export { findAllByLabelText, findAllByRole, findAllByTestId, findAllByText, findByLabelText, findByRole, findByTestId, findByText, } from "./queries.js";
3
3
  export { cleanup, render, teardown } from "./render.js";
4
4
  export { screen } from "./screen.js";
5
- export type { ByRoleOptions, RenderOptions, RenderResult, TextMatchOptions, WaitForOptions, } from "./types.js";
5
+ export type { BoundQueries, ByRoleOptions, RenderOptions, RenderResult, TextMatchOptions, WaitForOptions, } from "./types.js";
6
6
  export type { UserEventInstance, UserEventOptions } from "./user-event.js";
7
7
  export { userEvent } from "./user-event.js";
8
8
  export { waitFor, waitForElementToBeRemoved } from "./wait-for.js";
9
+ export { within } from "./within.js";
package/dist/index.js CHANGED
@@ -4,3 +4,4 @@ export { cleanup, render, teardown } from "./render.js";
4
4
  export { screen } from "./screen.js";
5
5
  export { userEvent } from "./user-event.js";
6
6
  export { waitFor, waitForElementToBeRemoved } from "./wait-for.js";
7
+ export { within } from "./within.js";
package/dist/queries.js CHANGED
@@ -1,4 +1,4 @@
1
- import { wrapPtr } from "@gtkx/ffi";
1
+ import { getObject } from "@gtkx/ffi";
2
2
  import { AccessibleRole, Button, CheckButton, Expander, Label, ToggleButton } from "@gtkx/ffi/gtk";
3
3
  import { findAll } from "./traversal.js";
4
4
  import { waitFor } from "./wait-for.js";
@@ -18,11 +18,11 @@ const matchText = (actual, expected, options) => {
18
18
  }
19
19
  return expected.test(normalizedActual);
20
20
  };
21
- const asButton = (widget) => wrapPtr(widget.ptr, Button);
22
- const asLabel = (widget) => wrapPtr(widget.ptr, Label);
23
- const asCheckButton = (widget) => wrapPtr(widget.ptr, CheckButton);
24
- const asToggleButton = (widget) => wrapPtr(widget.ptr, ToggleButton);
25
- const asExpander = (widget) => wrapPtr(widget.ptr, Expander);
21
+ const asButton = (widget) => getObject(widget.ptr, Button);
22
+ const asLabel = (widget) => getObject(widget.ptr, Label);
23
+ const asCheckButton = (widget) => getObject(widget.ptr, CheckButton);
24
+ const asToggleButton = (widget) => getObject(widget.ptr, ToggleButton);
25
+ const asExpander = (widget) => getObject(widget.ptr, Expander);
26
26
  const isInternalLabel = (widget) => {
27
27
  const accessible = widget;
28
28
  if (accessible.getAccessibleRole() !== AccessibleRole.LABEL)
package/dist/render.js CHANGED
@@ -4,6 +4,7 @@ import * as Gtk from "@gtkx/ffi/gtk";
4
4
  import { ApplicationWindow, reconciler } from "@gtkx/react";
5
5
  import * as queries from "./queries.js";
6
6
  import { setScreenRoot } from "./screen.js";
7
+ const ROOT_NODE_CONTAINER = Symbol.for("ROOT_NODE_CONTAINER");
7
8
  const APP_ID = "com.gtkx.testing";
8
9
  let container = null;
9
10
  const hasGetLabel = (widget) => typeof widget.getLabel === "function";
@@ -29,7 +30,7 @@ const ensureInitialized = () => {
29
30
  const app = start(APP_ID);
30
31
  if (!container) {
31
32
  const instance = reconciler.getInstance();
32
- container = instance.createContainer(app, 0, null, false, null, "", (error) => console.error("Test reconciler error:", error), () => { }, () => { }, () => { }, null);
33
+ container = instance.createContainer(ROOT_NODE_CONTAINER, 0, null, false, null, "", (error) => console.error("Test reconciler error:", error), () => { }, () => { }, () => { }, null);
33
34
  }
34
35
  return { app, container };
35
36
  };
package/dist/types.d.ts CHANGED
@@ -23,8 +23,7 @@ export interface RenderOptions {
23
23
  children: ReactNode;
24
24
  }>;
25
25
  }
26
- export interface RenderResult {
27
- container: Gtk.Application;
26
+ export interface BoundQueries {
28
27
  findByRole: (role: AccessibleRole, options?: ByRoleOptions) => Promise<Gtk.Widget>;
29
28
  findByLabelText: (text: string | RegExp, options?: TextMatchOptions) => Promise<Gtk.Widget>;
30
29
  findByText: (text: string | RegExp, options?: TextMatchOptions) => Promise<Gtk.Widget>;
@@ -33,6 +32,9 @@ export interface RenderResult {
33
32
  findAllByLabelText: (text: string | RegExp, options?: TextMatchOptions) => Promise<Gtk.Widget[]>;
34
33
  findAllByText: (text: string | RegExp, options?: TextMatchOptions) => Promise<Gtk.Widget[]>;
35
34
  findAllByTestId: (testId: string | RegExp, options?: TextMatchOptions) => Promise<Gtk.Widget[]>;
35
+ }
36
+ export interface RenderResult extends BoundQueries {
37
+ container: Gtk.Application;
36
38
  unmount: () => Promise<void>;
37
39
  rerender: (element: ReactNode) => Promise<void>;
38
40
  debug: () => void;
@@ -0,0 +1,3 @@
1
+ import type * as Gtk from "@gtkx/ffi/gtk";
2
+ import type { BoundQueries } from "./types.js";
3
+ export declare const within: (container: Gtk.Widget) => BoundQueries;
package/dist/within.js ADDED
@@ -0,0 +1,11 @@
1
+ import * as queries from "./queries.js";
2
+ export const within = (container) => ({
3
+ findByRole: (role, options) => queries.findByRole(container, role, options),
4
+ findByLabelText: (text, options) => queries.findByLabelText(container, text, options),
5
+ findByText: (text, options) => queries.findByText(container, text, options),
6
+ findByTestId: (testId, options) => queries.findByTestId(container, testId, options),
7
+ findAllByRole: (role, options) => queries.findAllByRole(container, role, options),
8
+ findAllByLabelText: (text, options) => queries.findAllByLabelText(container, text, options),
9
+ findAllByText: (text, options) => queries.findAllByText(container, text, options),
10
+ findAllByTestId: (testId, options) => queries.findAllByTestId(container, testId, options),
11
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtkx/testing",
3
- "version": "0.1.35",
3
+ "version": "0.1.37",
4
4
  "description": "Testing utilities for GTKX applications",
5
5
  "keywords": [
6
6
  "gtk",
@@ -32,9 +32,9 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@gtkx/ffi": "0.1.35",
36
- "@gtkx/react": "0.1.35",
37
- "@gtkx/native": "0.1.35"
35
+ "@gtkx/ffi": "0.1.37",
36
+ "@gtkx/react": "0.1.37",
37
+ "@gtkx/native": "0.1.37"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsc -b && cp ../../README.md .",