@gtkx/testing 0.8.0 → 0.9.1
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/queries.js +9 -9
- package/dist/render.js +3 -3
- package/dist/user-event.js +8 -8
- package/dist/widget.js +3 -3
- package/package.json +5 -5
package/dist/queries.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getObject } from "@gtkx/ffi";
|
|
2
2
|
import * as Gtk from "@gtkx/ffi/gtk";
|
|
3
3
|
import { findAll } from "./traversal.js";
|
|
4
4
|
import { waitFor } from "./wait-for.js";
|
|
@@ -50,13 +50,13 @@ const ROLES_WITH_INTERNAL_LABELS = new Set([
|
|
|
50
50
|
Gtk.AccessibleRole.LINK,
|
|
51
51
|
]);
|
|
52
52
|
const isInternalLabel = (widget) => {
|
|
53
|
-
const accessible =
|
|
53
|
+
const accessible = getObject(widget.id, Gtk.Accessible);
|
|
54
54
|
if (!accessible || accessible.getAccessibleRole() !== Gtk.AccessibleRole.LABEL)
|
|
55
55
|
return false;
|
|
56
56
|
const parent = widget.getParent();
|
|
57
57
|
if (!parent)
|
|
58
58
|
return false;
|
|
59
|
-
const parentAccessible =
|
|
59
|
+
const parentAccessible = getObject(parent.id, Gtk.Accessible);
|
|
60
60
|
if (!parentAccessible)
|
|
61
61
|
return false;
|
|
62
62
|
return ROLES_WITH_INTERNAL_LABELS.has(parentAccessible.getAccessibleRole());
|
|
@@ -70,7 +70,7 @@ const collectChildLabels = (widget) => {
|
|
|
70
70
|
const labels = [];
|
|
71
71
|
let child = widget.getFirstChild();
|
|
72
72
|
while (child) {
|
|
73
|
-
const childAccessible =
|
|
73
|
+
const childAccessible = getObject(child.id, Gtk.Accessible);
|
|
74
74
|
if (childAccessible?.getAccessibleRole() === Gtk.AccessibleRole.LABEL) {
|
|
75
75
|
const labelText = getLabelText(child);
|
|
76
76
|
if (labelText)
|
|
@@ -84,7 +84,7 @@ const collectChildLabels = (widget) => {
|
|
|
84
84
|
const getWidgetText = (widget) => {
|
|
85
85
|
if (isInternalLabel(widget))
|
|
86
86
|
return null;
|
|
87
|
-
const role =
|
|
87
|
+
const role = getObject(widget.id, Gtk.Accessible)?.getAccessibleRole();
|
|
88
88
|
if (role === undefined)
|
|
89
89
|
return null;
|
|
90
90
|
switch (role) {
|
|
@@ -109,7 +109,7 @@ const getWidgetText = (widget) => {
|
|
|
109
109
|
case Gtk.AccessibleRole.TEXT_BOX:
|
|
110
110
|
case Gtk.AccessibleRole.SEARCH_BOX:
|
|
111
111
|
case Gtk.AccessibleRole.SPIN_BUTTON:
|
|
112
|
-
return
|
|
112
|
+
return getObject(widget.id, Gtk.Editable)?.getText() ?? null;
|
|
113
113
|
case Gtk.AccessibleRole.GROUP:
|
|
114
114
|
return widget.getLabel?.() ?? null;
|
|
115
115
|
case Gtk.AccessibleRole.WINDOW:
|
|
@@ -135,7 +135,7 @@ const getWidgetTestId = (widget) => {
|
|
|
135
135
|
return widget.getName();
|
|
136
136
|
};
|
|
137
137
|
const getWidgetCheckedState = (widget) => {
|
|
138
|
-
const accessible =
|
|
138
|
+
const accessible = getObject(widget.id, Gtk.Accessible);
|
|
139
139
|
if (!accessible)
|
|
140
140
|
return undefined;
|
|
141
141
|
const role = accessible.getAccessibleRole();
|
|
@@ -152,7 +152,7 @@ const getWidgetCheckedState = (widget) => {
|
|
|
152
152
|
}
|
|
153
153
|
};
|
|
154
154
|
const getWidgetExpandedState = (widget) => {
|
|
155
|
-
const accessible =
|
|
155
|
+
const accessible = getObject(widget.id, Gtk.Accessible);
|
|
156
156
|
if (!accessible)
|
|
157
157
|
return undefined;
|
|
158
158
|
const role = accessible.getAccessibleRole();
|
|
@@ -203,7 +203,7 @@ const formatByRoleError = (role, options) => {
|
|
|
203
203
|
};
|
|
204
204
|
const getAllByRole = (container, role, options) => {
|
|
205
205
|
const matches = findAll(container, (node) => {
|
|
206
|
-
const accessible =
|
|
206
|
+
const accessible = getObject(node.id, Gtk.Accessible);
|
|
207
207
|
if (!accessible || accessible.getAccessibleRole() !== role)
|
|
208
208
|
return false;
|
|
209
209
|
return matchByRoleOptions(node, options);
|
package/dist/render.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { getCurrentApp,
|
|
2
|
+
import { getCurrentApp, getObject, start, stop } from "@gtkx/ffi";
|
|
3
3
|
import * as Gtk from "@gtkx/ffi/gtk";
|
|
4
4
|
import { ApplicationWindow, ROOT_NODE_CONTAINER, reconciler } from "@gtkx/react";
|
|
5
5
|
import * as queries from "./queries.js";
|
|
@@ -11,7 +11,7 @@ let container = null;
|
|
|
11
11
|
const getWidgetLabel = (widget) => {
|
|
12
12
|
if (!hasLabel(widget))
|
|
13
13
|
return null;
|
|
14
|
-
const accessible =
|
|
14
|
+
const accessible = getObject(widget.id, Gtk.Accessible);
|
|
15
15
|
if (!accessible)
|
|
16
16
|
return null;
|
|
17
17
|
const role = accessible.getAccessibleRole();
|
|
@@ -22,7 +22,7 @@ const getWidgetLabel = (widget) => {
|
|
|
22
22
|
};
|
|
23
23
|
const printWidgetTree = (root, indent = 0) => {
|
|
24
24
|
const prefix = " ".repeat(indent);
|
|
25
|
-
const accessibleRole =
|
|
25
|
+
const accessibleRole = getObject(root.id, Gtk.Accessible)?.getAccessibleRole();
|
|
26
26
|
const role = accessibleRole !== undefined ? (Gtk.AccessibleRole[accessibleRole] ?? "UNKNOWN") : "UNKNOWN";
|
|
27
27
|
const labelText = getWidgetLabel(root);
|
|
28
28
|
const label = labelText ? ` label="${labelText}"` : "";
|
package/dist/user-event.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getObject } from "@gtkx/ffi";
|
|
2
2
|
import * as Gtk from "@gtkx/ffi/gtk";
|
|
3
3
|
import { fireEvent } from "./fire-event.js";
|
|
4
4
|
import { tick } from "./timing.js";
|
|
@@ -10,14 +10,14 @@ const TOGGLEABLE_ROLES = new Set([
|
|
|
10
10
|
Gtk.AccessibleRole.SWITCH,
|
|
11
11
|
]);
|
|
12
12
|
const isToggleable = (widget) => {
|
|
13
|
-
const accessible =
|
|
13
|
+
const accessible = getObject(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 =
|
|
20
|
+
const role = getObject(element.id, Gtk.Accessible)?.getAccessibleRole();
|
|
21
21
|
if (role === Gtk.AccessibleRole.CHECKBOX || role === Gtk.AccessibleRole.RADIO) {
|
|
22
22
|
const checkButton = element;
|
|
23
23
|
checkButton.setActive(!checkButton.getActive());
|
|
@@ -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 =
|
|
64
|
+
const editable = getObject(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
|
-
|
|
75
|
+
getObject(element.id, Gtk.Editable)?.setText("");
|
|
76
76
|
await tick();
|
|
77
77
|
};
|
|
78
78
|
const SELECTABLE_ROLES = new Set([Gtk.AccessibleRole.COMBO_BOX, Gtk.AccessibleRole.LIST]);
|
|
79
79
|
const isSelectable = (widget) => {
|
|
80
|
-
const accessible =
|
|
80
|
+
const accessible = getObject(widget.id, Gtk.Accessible);
|
|
81
81
|
if (!accessible)
|
|
82
82
|
return false;
|
|
83
83
|
return SELECTABLE_ROLES.has(accessible.getAccessibleRole());
|
|
@@ -86,7 +86,7 @@ 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 =
|
|
89
|
+
const role = getObject(element.id, Gtk.Accessible)?.getAccessibleRole();
|
|
90
90
|
const valueArray = Array.isArray(values) ? values : [values];
|
|
91
91
|
if (role === Gtk.AccessibleRole.COMBO_BOX) {
|
|
92
92
|
if (valueArray.length > 1) {
|
|
@@ -120,7 +120,7 @@ const selectOptions = async (element, values) => {
|
|
|
120
120
|
await tick();
|
|
121
121
|
};
|
|
122
122
|
const deselectOptions = async (element, values) => {
|
|
123
|
-
const role =
|
|
123
|
+
const role = getObject(element.id, Gtk.Accessible)?.getAccessibleRole();
|
|
124
124
|
if (role !== Gtk.AccessibleRole.LIST) {
|
|
125
125
|
throw new Error("Cannot deselect options: only ListBox supports deselection");
|
|
126
126
|
}
|
package/dist/widget.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getObject } from "@gtkx/ffi";
|
|
2
2
|
import * as Gtk from "@gtkx/ffi/gtk";
|
|
3
3
|
const EDITABLE_ROLES = new Set([
|
|
4
4
|
Gtk.AccessibleRole.TEXT_BOX,
|
|
@@ -9,7 +9,7 @@ const EDITABLE_ROLES = new Set([
|
|
|
9
9
|
* Checks if a widget has an editable accessible role (text box, search box, or spin button).
|
|
10
10
|
*/
|
|
11
11
|
export const isEditable = (widget) => {
|
|
12
|
-
const accessible =
|
|
12
|
+
const accessible = getObject(widget.id, Gtk.Accessible);
|
|
13
13
|
if (!accessible)
|
|
14
14
|
return false;
|
|
15
15
|
return EDITABLE_ROLES.has(accessible.getAccessibleRole());
|
|
@@ -28,7 +28,7 @@ const LABEL_ROLES = new Set([
|
|
|
28
28
|
* Checks if a widget has an accessible role that supports labels.
|
|
29
29
|
*/
|
|
30
30
|
export const hasLabel = (widget) => {
|
|
31
|
-
const accessible =
|
|
31
|
+
const accessible = getObject(widget.id, Gtk.Accessible);
|
|
32
32
|
if (!accessible)
|
|
33
33
|
return false;
|
|
34
34
|
return LABEL_ROLES.has(accessible.getAccessibleRole());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/testing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Testing utilities for GTKX applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gtk",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@gtkx/ffi": "0.
|
|
36
|
-
"@gtkx/native": "0.
|
|
37
|
-
"@gtkx/react": "0.
|
|
35
|
+
"@gtkx/ffi": "0.9.1",
|
|
36
|
+
"@gtkx/native": "0.9.1",
|
|
37
|
+
"@gtkx/react": "0.9.1"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsc -b && cp ../../README.md .",
|
|
41
|
-
"test": "
|
|
41
|
+
"test": "../../scripts/run-tests.sh"
|
|
42
42
|
}
|
|
43
43
|
}
|