@gtkx/testing 0.7.0 → 0.9.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/dist/screen.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type * as Gtk from "@gtkx/ffi/gtk";
2
- import type { AccessibleRole } from "@gtkx/ffi/gtk";
3
2
  import type { ByRoleOptions, TextMatch, TextMatchOptions } from "./types.js";
4
3
  /**
5
4
  * Sets the root application for screen queries. Called internally by render().
@@ -12,11 +11,11 @@ export declare const setScreenRoot: (root: Gtk.Application | null) => void;
12
11
  * needing to destructure from render().
13
12
  */
14
13
  export declare const screen: {
15
- findByRole: (role: AccessibleRole, options?: ByRoleOptions) => Promise<Gtk.Widget>;
14
+ findByRole: (role: Gtk.AccessibleRole, options?: ByRoleOptions) => Promise<Gtk.Widget>;
16
15
  findByLabelText: (text: TextMatch, options?: TextMatchOptions) => Promise<Gtk.Widget>;
17
16
  findByText: (text: TextMatch, options?: TextMatchOptions) => Promise<Gtk.Widget>;
18
17
  findByTestId: (testId: TextMatch, options?: TextMatchOptions) => Promise<Gtk.Widget>;
19
- findAllByRole: (role: AccessibleRole, options?: ByRoleOptions) => Promise<Gtk.Widget[]>;
18
+ findAllByRole: (role: Gtk.AccessibleRole, options?: ByRoleOptions) => Promise<Gtk.Widget[]>;
20
19
  findAllByLabelText: (text: TextMatch, options?: TextMatchOptions) => Promise<Gtk.Widget[]>;
21
20
  findAllByText: (text: TextMatch, options?: TextMatchOptions) => Promise<Gtk.Widget[]>;
22
21
  findAllByTestId: (testId: TextMatch, options?: TextMatchOptions) => Promise<Gtk.Widget[]>;
package/dist/types.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type * as Gtk from "@gtkx/ffi/gtk";
2
- import type { AccessibleRole } from "@gtkx/ffi/gtk";
3
2
  import type { ComponentType, ReactNode } from "react";
4
3
  /**
5
4
  * A function that receives the text content and widget, returning true for a match.
@@ -86,7 +85,7 @@ export type RenderOptions = {
86
85
  */
87
86
  export type BoundQueries = {
88
87
  /** Find a single element by its accessible role. */
89
- findByRole: (role: AccessibleRole, options?: ByRoleOptions) => Promise<Gtk.Widget>;
88
+ findByRole: (role: Gtk.AccessibleRole, options?: ByRoleOptions) => Promise<Gtk.Widget>;
90
89
  /** Find a single element by its associated label text. */
91
90
  findByLabelText: (text: TextMatch, options?: TextMatchOptions) => Promise<Gtk.Widget>;
92
91
  /** Find a single element by its text content. */
@@ -94,7 +93,7 @@ export type BoundQueries = {
94
93
  /** Find a single element by its test ID. */
95
94
  findByTestId: (testId: TextMatch, options?: TextMatchOptions) => Promise<Gtk.Widget>;
96
95
  /** Find all elements matching an accessible role. */
97
- findAllByRole: (role: AccessibleRole, options?: ByRoleOptions) => Promise<Gtk.Widget[]>;
96
+ findAllByRole: (role: Gtk.AccessibleRole, options?: ByRoleOptions) => Promise<Gtk.Widget[]>;
98
97
  /** Find all elements with matching label text. */
99
98
  findAllByLabelText: (text: TextMatch, options?: TextMatchOptions) => Promise<Gtk.Widget[]>;
100
99
  /** Find all elements with matching text content. */
@@ -1,4 +1,4 @@
1
- import type * as Gtk from "@gtkx/ffi/gtk";
1
+ import * as Gtk from "@gtkx/ffi/gtk";
2
2
  /**
3
3
  * Options for the tab user event.
4
4
  */
@@ -1,28 +1,28 @@
1
1
  import { getInterface, getObject } from "@gtkx/ffi";
2
- import { Accessible, AccessibleRole, DirectionType, Editable, } from "@gtkx/ffi/gtk";
2
+ import * as Gtk from "@gtkx/ffi/gtk";
3
3
  import { fireEvent } from "./fire-event.js";
4
4
  import { tick } from "./timing.js";
5
5
  import { isEditable } from "./widget.js";
6
6
  const TOGGLEABLE_ROLES = new Set([
7
- AccessibleRole.CHECKBOX,
8
- AccessibleRole.RADIO,
9
- AccessibleRole.TOGGLE_BUTTON,
10
- AccessibleRole.SWITCH,
7
+ Gtk.AccessibleRole.CHECKBOX,
8
+ Gtk.AccessibleRole.RADIO,
9
+ Gtk.AccessibleRole.TOGGLE_BUTTON,
10
+ Gtk.AccessibleRole.SWITCH,
11
11
  ]);
12
12
  const isToggleable = (widget) => {
13
- const accessible = getInterface(widget.id, Accessible);
13
+ const accessible = getInterface(widget.id, Gtk.Accessible);
14
14
  if (!accessible)
15
15
  return false;
16
16
  return TOGGLEABLE_ROLES.has(accessible.getAccessibleRole());
17
17
  };
18
18
  const click = async (element) => {
19
19
  if (isToggleable(element)) {
20
- const role = getInterface(element.id, Accessible)?.getAccessibleRole();
21
- if (role === AccessibleRole.CHECKBOX || role === AccessibleRole.RADIO) {
20
+ const role = getInterface(element.id, Gtk.Accessible)?.getAccessibleRole();
21
+ if (role === Gtk.AccessibleRole.CHECKBOX || role === Gtk.AccessibleRole.RADIO) {
22
22
  const checkButton = element;
23
23
  checkButton.setActive(!checkButton.getActive());
24
24
  }
25
- else if (role === AccessibleRole.SWITCH) {
25
+ else if (role === Gtk.AccessibleRole.SWITCH) {
26
26
  const switchWidget = element;
27
27
  switchWidget.setActive(!switchWidget.getActive());
28
28
  }
@@ -50,7 +50,7 @@ const activate = async (element) => {
50
50
  await tick();
51
51
  };
52
52
  const tab = async (element, options) => {
53
- const direction = options?.shift ? DirectionType.TAB_BACKWARD : DirectionType.TAB_FORWARD;
53
+ const direction = options?.shift ? Gtk.DirectionType.TAB_BACKWARD : Gtk.DirectionType.TAB_FORWARD;
54
54
  const root = element.getRoot();
55
55
  if (root) {
56
56
  getObject(root.id).childFocus(direction);
@@ -61,7 +61,7 @@ const type = async (element, text) => {
61
61
  if (!isEditable(element)) {
62
62
  throw new Error("Cannot type into element: element is not editable (TEXT_BOX, SEARCH_BOX, or SPIN_BUTTON)");
63
63
  }
64
- const editable = getInterface(element.id, Editable);
64
+ const editable = getInterface(element.id, Gtk.Editable);
65
65
  if (!editable)
66
66
  return;
67
67
  const currentText = editable.getText();
@@ -72,12 +72,12 @@ const clear = async (element) => {
72
72
  if (!isEditable(element)) {
73
73
  throw new Error("Cannot clear element: element is not editable (TEXT_BOX, SEARCH_BOX, or SPIN_BUTTON)");
74
74
  }
75
- getInterface(element.id, Editable)?.setText("");
75
+ getInterface(element.id, Gtk.Editable)?.setText("");
76
76
  await tick();
77
77
  };
78
- const SELECTABLE_ROLES = new Set([AccessibleRole.COMBO_BOX, AccessibleRole.LIST]);
78
+ const SELECTABLE_ROLES = new Set([Gtk.AccessibleRole.COMBO_BOX, Gtk.AccessibleRole.LIST]);
79
79
  const isSelectable = (widget) => {
80
- const accessible = getInterface(widget.id, Accessible);
80
+ const accessible = getInterface(widget.id, Gtk.Accessible);
81
81
  if (!accessible)
82
82
  return false;
83
83
  return SELECTABLE_ROLES.has(accessible.getAccessibleRole());
@@ -86,9 +86,9 @@ const selectOptions = async (element, values) => {
86
86
  if (!isSelectable(element)) {
87
87
  throw new Error("Cannot select options: element is not a selectable widget (COMBO_BOX or LIST)");
88
88
  }
89
- const role = getInterface(element.id, Accessible)?.getAccessibleRole();
89
+ const role = getInterface(element.id, Gtk.Accessible)?.getAccessibleRole();
90
90
  const valueArray = Array.isArray(values) ? values : [values];
91
- if (role === AccessibleRole.COMBO_BOX) {
91
+ if (role === Gtk.AccessibleRole.COMBO_BOX) {
92
92
  if (valueArray.length > 1) {
93
93
  throw new Error("Cannot select multiple options on a ComboBox/DropDown");
94
94
  }
@@ -104,7 +104,7 @@ const selectOptions = async (element, values) => {
104
104
  element.setActive(value);
105
105
  }
106
106
  }
107
- else if (role === AccessibleRole.LIST) {
107
+ else if (role === Gtk.AccessibleRole.LIST) {
108
108
  const listBox = element;
109
109
  for (const value of valueArray) {
110
110
  if (typeof value !== "number") {
@@ -120,8 +120,8 @@ const selectOptions = async (element, values) => {
120
120
  await tick();
121
121
  };
122
122
  const deselectOptions = async (element, values) => {
123
- const role = getInterface(element.id, Accessible)?.getAccessibleRole();
124
- if (role !== AccessibleRole.LIST) {
123
+ const role = getInterface(element.id, Gtk.Accessible)?.getAccessibleRole();
124
+ if (role !== Gtk.AccessibleRole.LIST) {
125
125
  throw new Error("Cannot deselect options: only ListBox supports deselection");
126
126
  }
127
127
  const listBox = element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtkx/testing",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
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/native": "0.7.0",
36
- "@gtkx/ffi": "0.7.0",
37
- "@gtkx/react": "0.7.0"
35
+ "@gtkx/ffi": "0.9.0",
36
+ "@gtkx/native": "0.9.0",
37
+ "@gtkx/react": "0.9.0"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsc -b && cp ../../README.md .",