@gtkx/testing 0.13.2 → 0.14.0

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 CHANGED
@@ -1,18 +1,18 @@
1
1
  <p align="center">
2
- <img src="https://raw.githubusercontent.com/eugeniodepalo/gtkx/main/logo.svg" alt="GTKX" width="60" height="60">
2
+ <img src="https://raw.githubusercontent.com/eugeniodepalo/gtkx/main/logo.svg" alt="GTKX" width="60" height="60">
3
3
  </p>
4
4
 
5
5
  <h1 align="center">GTKX</h1>
6
6
 
7
7
  <p align="center">
8
- <strong>Build native GTK4 desktop applications with React and TypeScript.</strong>
8
+ <strong>Build native GTK4 desktop applications with React and TypeScript.</strong>
9
9
  </p>
10
10
 
11
11
  <p align="center">
12
- <a href="https://www.npmjs.com/package/@gtkx/react"><img src="https://img.shields.io/npm/v/@gtkx/react.svg" alt="npm version"></a>
13
- <a href="https://github.com/eugeniodepalo/gtkx/actions"><img src="https://img.shields.io/github/actions/workflow/status/eugeniodepalo/gtkx/ci.yml" alt="CI"></a>
14
- <a href="https://github.com/eugeniodepalo/gtkx/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MPL--2.0-blue.svg" alt="License"></a>
15
- <a href="https://github.com/eugeniodepalo/gtkx/discussions"><img src="https://img.shields.io/badge/discussions-GitHub-blue" alt="GitHub Discussions"></a>
12
+ <a href="https://www.npmjs.com/package/@gtkx/react"><img src="https://img.shields.io/npm/v/@gtkx/react.svg" alt="npm version"></a>
13
+ <a href="https://github.com/eugeniodepalo/gtkx/actions"><img src="https://img.shields.io/github/actions/workflow/status/eugeniodepalo/gtkx/ci.yml" alt="CI"></a>
14
+ <a href="https://github.com/eugeniodepalo/gtkx/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MPL--2.0-blue.svg" alt="License"></a>
15
+ <a href="https://github.com/eugeniodepalo/gtkx/discussions"><img src="https://img.shields.io/badge/discussions-GitHub-blue" alt="GitHub Discussions"></a>
16
16
  </p>
17
17
 
18
18
  ---
@@ -80,10 +80,11 @@ render(<App />, "com.example.counter");
80
80
 
81
81
  Explore complete applications in the [`examples/`](./examples) directory:
82
82
 
83
+ - **[browser](./examples/browser)** — Simple browser using WebKitWebView
83
84
  - **[gtk-demo](./examples/gtk-demo)** — Full replica of the official GTK demo app
84
85
  - **[hello-world](./examples/hello-world)** — Minimal application showing a counter
85
86
  - **[todo](./examples/todo)** — Full-featured todo application with Adwaita styling and testing
86
- - **[x-showcase](./examples/x-showcase)** — Showcase of all x.* virtual components
87
+ - **[x-showcase](./examples/x-showcase)** — Showcase of all x.\* virtual components
87
88
  - **[deploying](./examples/deploying)** — Example of packaging and distributing a GTKX app
88
89
 
89
90
  ## Documentation
@@ -1,23 +1,27 @@
1
1
  import type * as Gtk from "@gtkx/ffi/gtk";
2
2
  import type { Arg } from "@gtkx/native";
3
3
  /**
4
- * Emits a GTK signal on a widget.
4
+ * Emits a GTK signal on a widget or event controller.
5
5
  *
6
6
  * Low-level utility for triggering signals directly. Prefer {@link userEvent}
7
7
  * for common interactions like clicking and typing.
8
8
  *
9
- * @param element - The widget to emit the signal on
10
- * @param signalName - GTK signal name (e.g., "clicked", "activate")
9
+ * @param element - The widget or event controller to emit the signal on
10
+ * @param signalName - GTK signal name (e.g., "clicked", "activate", "drag-begin")
11
11
  * @param args - Additional signal arguments
12
12
  *
13
13
  * @example
14
14
  * ```tsx
15
15
  * import { fireEvent } from "@gtkx/testing";
16
16
  *
17
- * // Emit custom signal
18
- * await fireEvent(widget, "my-custom-signal");
17
+ * // Emit signal on widget
18
+ * await fireEvent(widget, "clicked");
19
+ *
20
+ * // Emit signal on gesture controller
21
+ * const gesture = widget.observeControllers().getObject(0) as Gtk.GestureDrag;
22
+ * await fireEvent(gesture, "drag-begin", { type: { type: "float", size: 64 }, value: 100 }, { type: { type: "float", size: 64 }, value: 100 });
19
23
  * ```
20
24
  *
21
25
  * @see {@link userEvent} for high-level user interactions
22
26
  */
23
- export declare const fireEvent: (element: Gtk.Widget, signalName: string, ...args: Arg[]) => Promise<void>;
27
+ export declare const fireEvent: (element: Gtk.Widget | Gtk.EventController, signalName: string, ...args: Arg[]) => Promise<void>;
@@ -1,21 +1,25 @@
1
1
  import { call } from "@gtkx/native";
2
2
  import { tick } from "./timing.js";
3
3
  /**
4
- * Emits a GTK signal on a widget.
4
+ * Emits a GTK signal on a widget or event controller.
5
5
  *
6
6
  * Low-level utility for triggering signals directly. Prefer {@link userEvent}
7
7
  * for common interactions like clicking and typing.
8
8
  *
9
- * @param element - The widget to emit the signal on
10
- * @param signalName - GTK signal name (e.g., "clicked", "activate")
9
+ * @param element - The widget or event controller to emit the signal on
10
+ * @param signalName - GTK signal name (e.g., "clicked", "activate", "drag-begin")
11
11
  * @param args - Additional signal arguments
12
12
  *
13
13
  * @example
14
14
  * ```tsx
15
15
  * import { fireEvent } from "@gtkx/testing";
16
16
  *
17
- * // Emit custom signal
18
- * await fireEvent(widget, "my-custom-signal");
17
+ * // Emit signal on widget
18
+ * await fireEvent(widget, "clicked");
19
+ *
20
+ * // Emit signal on gesture controller
21
+ * const gesture = widget.observeControllers().getObject(0) as Gtk.GestureDrag;
22
+ * await fireEvent(gesture, "drag-begin", { type: { type: "float", size: 64 }, value: 100 }, { type: { type: "float", size: 64 }, value: 100 });
19
23
  * ```
20
24
  *
21
25
  * @see {@link userEvent} for high-level user interactions
package/dist/render.d.ts CHANGED
@@ -15,9 +15,9 @@ import type { RenderOptions, RenderResult } from "./types.js";
15
15
  * import { render, screen } from "@gtkx/testing";
16
16
  *
17
17
  * test("button click", async () => {
18
- * await render(<MyButton />);
19
- * const button = await screen.findByRole(Gtk.AccessibleRole.BUTTON);
20
- * await userEvent.click(button);
18
+ * await render(<MyButton />);
19
+ * const button = await screen.findByRole(Gtk.AccessibleRole.BUTTON);
20
+ * await userEvent.click(button);
21
21
  * });
22
22
  * ```
23
23
  *
@@ -36,12 +36,12 @@ export declare const render: (element: ReactNode, options?: RenderOptions) => Pr
36
36
  * import { render, cleanup } from "@gtkx/testing";
37
37
  *
38
38
  * afterEach(async () => {
39
- * await cleanup();
39
+ * await cleanup();
40
40
  * });
41
41
  *
42
42
  * test("my test", async () => {
43
- * await render(<MyComponent />);
44
- * // ...
43
+ * await render(<MyComponent />);
44
+ * // ...
45
45
  * });
46
46
  * ```
47
47
  */
package/dist/render.js CHANGED
@@ -55,9 +55,9 @@ const wrapElement = (element, wrapper = true) => {
55
55
  * import { render, screen } from "@gtkx/testing";
56
56
  *
57
57
  * test("button click", async () => {
58
- * await render(<MyButton />);
59
- * const button = await screen.findByRole(Gtk.AccessibleRole.BUTTON);
60
- * await userEvent.click(button);
58
+ * await render(<MyButton />);
59
+ * const button = await screen.findByRole(Gtk.AccessibleRole.BUTTON);
60
+ * await userEvent.click(button);
61
61
  * });
62
62
  * ```
63
63
  *
@@ -96,12 +96,12 @@ export const render = async (element, options) => {
96
96
  * import { render, cleanup } from "@gtkx/testing";
97
97
  *
98
98
  * afterEach(async () => {
99
- * await cleanup();
99
+ * await cleanup();
100
100
  * });
101
101
  *
102
102
  * test("my test", async () => {
103
- * await render(<MyComponent />);
104
- * // ...
103
+ * await render(<MyComponent />);
104
+ * // ...
105
105
  * });
106
106
  * ```
107
107
  */
@@ -1,7 +1,7 @@
1
1
  import { getNativeObject } from "@gtkx/ffi";
2
2
  import * as Gdk from "@gtkx/ffi/gdk";
3
3
  import * as Gtk from "@gtkx/ffi/gtk";
4
- import { call } from "@gtkx/native";
4
+ import { call, createRef } from "@gtkx/native";
5
5
  import { fireEvent } from "./fire-event.js";
6
6
  import { tick } from "./timing.js";
7
7
  import { isEditable } from "./widget.js";
@@ -166,6 +166,7 @@ const getOrCreateController = (element, controllerType) => {
166
166
  element.addController(controller);
167
167
  return controller;
168
168
  };
169
+ const SIGNALS_WITH_RETURN_VALUE = new Set(["key-pressed", "key-released"]);
169
170
  const emitSignal = (target, signalName, ...args) => {
170
171
  const signalArgs = args.map((arg) => {
171
172
  if (arg.type === "float") {
@@ -173,11 +174,19 @@ const emitSignal = (target, signalName, ...args) => {
173
174
  }
174
175
  return { type: { type: "int", size: 32, unsigned: true }, value: arg.value };
175
176
  });
176
- call("libgobject-2.0.so.0", "g_signal_emit_by_name", [
177
+ const ffiArgs = [
177
178
  { type: { type: "gobject", ownership: "borrowed" }, value: target.handle },
178
179
  { type: { type: "string", ownership: "borrowed" }, value: signalName },
179
180
  ...signalArgs,
180
- ], { type: "undefined" });
181
+ ];
182
+ if (SIGNALS_WITH_RETURN_VALUE.has(signalName)) {
183
+ const returnRef = createRef(0);
184
+ ffiArgs.push({
185
+ type: { type: "ref", innerType: { type: "int", size: 32, unsigned: false } },
186
+ value: returnRef,
187
+ });
188
+ }
189
+ call("libgobject-2.0.so.0", "g_signal_emit_by_name", ffiArgs, { type: "undefined" });
181
190
  };
182
191
  const hover = async (element) => {
183
192
  const controller = getOrCreateController(element, Gtk.EventControllerMotion);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtkx/testing",
3
- "version": "0.13.2",
3
+ "version": "0.14.0",
4
4
  "description": "Testing utilities for GTKX applications",
5
5
  "keywords": [
6
6
  "gtkx",
@@ -36,14 +36,14 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@gtkx/ffi": "0.13.2",
40
- "@gtkx/react": "0.13.2",
41
- "@gtkx/native": "0.13.2"
39
+ "@gtkx/ffi": "0.14.0",
40
+ "@gtkx/native": "0.14.0",
41
+ "@gtkx/react": "0.14.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/react-reconciler": "^0.32.3",
45
45
  "react-reconciler": "^0.33.0",
46
- "@gtkx/vitest": "0.13.2"
46
+ "@gtkx/vitest": "0.14.0"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "tsc -b && cp ../../README.md .",