@yuneta/gobj-ui 7.32.9 → 7.32.11
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 +94 -2
- package/dist/gobj-ui.cjs.js +1057 -360
- package/dist/gobj-ui.es.js +1046 -361
- package/index.js +18 -0
- package/package.json +1 -1
- package/src/c_yui_json.js +157 -2
- package/src/c_yui_node.js +47 -9
- package/src/c_yui_preferences.js +282 -0
- package/src/c_yui_shell.js +57 -1
- package/src/i18n_key_functions.js +6 -0
- package/src/json_level_stepper.wiring.test.js +186 -0
- package/src/preferences.wiring.test.js +159 -0
- package/src/yui_preferences.js +331 -0
package/src/c_yui_shell.js
CHANGED
|
@@ -49,8 +49,12 @@ import {
|
|
|
49
49
|
gobj_short_name,
|
|
50
50
|
gobj_is_destroying,
|
|
51
51
|
gobj_post_event,
|
|
52
|
+
kw_get_local_storage_value,
|
|
53
|
+
kw_set_local_storage_value,
|
|
52
54
|
} from "@yuneta/gobj-js";
|
|
53
55
|
|
|
56
|
+
import {NAV_MODES, is_nav_mode} from "./node_tree_model.js";
|
|
57
|
+
|
|
54
58
|
import {
|
|
55
59
|
BULMA_BP_ORDER,
|
|
56
60
|
breakpoints_from_expr,
|
|
@@ -4359,7 +4363,7 @@ function yui_shell_set_submenu(shell_gobj, parent_item_id, items)
|
|
|
4359
4363
|
* EV_ICONS_CHANGED). So they reach only the subscribers that
|
|
4360
4364
|
* declare them. Every other event of the shell goes out as before.
|
|
4361
4365
|
***************************************************************/
|
|
4362
|
-
const OPTIONAL_EVENTS = new Set(["EV_CONNECTION_STATE", "EV_ICONS_CHANGED"]);
|
|
4366
|
+
const OPTIONAL_EVENTS = new Set(["EV_CONNECTION_STATE", "EV_ICONS_CHANGED", "EV_NAV_MODE_CHANGED"]);
|
|
4363
4367
|
|
|
4364
4368
|
function mt_publication_pre_filter(gobj, subs, event, kw)
|
|
4365
4369
|
{
|
|
@@ -4446,6 +4450,15 @@ function create_gclass(gclass_name)
|
|
|
4446
4450
|
* icon cell of a table -- has to decide again. Delivered only to
|
|
4447
4451
|
* the subscribers that declare it: see
|
|
4448
4452
|
* mt_publication_pre_filter(). */
|
|
4453
|
+
/* The reader chose another way in for the trees of nodes
|
|
4454
|
+
* (yui_shell_set_nav_mode, the Navigation row of Preferences).
|
|
4455
|
+
* Every C_YUI_NODE root that has no mode of its own follows it.
|
|
4456
|
+
* Delivered only to the subscribers that declare it: see
|
|
4457
|
+
* mt_publication_pre_filter(). */
|
|
4458
|
+
["EV_NAV_MODE_CHANGED", event_flag_t.EVF_OUTPUT_EVENT
|
|
4459
|
+
|event_flag_t.EVF_PUBLIC_EVENT
|
|
4460
|
+
|event_flag_t.EVF_NO_WARN_SUBS],
|
|
4461
|
+
|
|
4449
4462
|
["EV_ICONS_CHANGED", event_flag_t.EVF_OUTPUT_EVENT
|
|
4450
4463
|
|event_flag_t.EVF_PUBLIC_EVENT
|
|
4451
4464
|
|event_flag_t.EVF_NO_WARN_SUBS],
|
|
@@ -5159,6 +5172,47 @@ function yui_shell_language_changed(shell_gobj)
|
|
|
5159
5172
|
gobj_publish_event(shell_gobj, "EV_LANGUAGE_CHANGED", {});
|
|
5160
5173
|
}
|
|
5161
5174
|
|
|
5175
|
+
/************************************************************
|
|
5176
|
+
* How the trees of nodes show the way in: the reader's choice
|
|
5177
|
+
* for the whole app, one of NAV_MODES (C_YUI_NODE):
|
|
5178
|
+
*
|
|
5179
|
+
* "stack" a strip of tabs per level, stacked (the default)
|
|
5180
|
+
* "back" one "back to parent" link
|
|
5181
|
+
* "path" a breadcrumb
|
|
5182
|
+
*
|
|
5183
|
+
* Kept in this browser (localStorage), like the theme and the
|
|
5184
|
+
* language. Every C_YUI_NODE root that has no `nav_mode` of its
|
|
5185
|
+
* own reads it, and follows a change: yui_shell_set_nav_mode()
|
|
5186
|
+
* publishes EV_NAV_MODE_CHANGED. Up to gobj-ui 7.32.10 each app
|
|
5187
|
+
* kept its own (gui_agent one for the app, yunovatios one per
|
|
5188
|
+
* tree) and handed it to its trees.
|
|
5189
|
+
************************************************************/
|
|
5190
|
+
const NAV_MODE_KEY = "yui_nav_mode";
|
|
5191
|
+
|
|
5192
|
+
function yui_shell_nav_mode(shell_gobj)
|
|
5193
|
+
{
|
|
5194
|
+
let mode = kw_get_local_storage_value(NAV_MODE_KEY, NAV_MODES[0], false);
|
|
5195
|
+
return is_nav_mode(mode) ? mode : NAV_MODES[0];
|
|
5196
|
+
}
|
|
5197
|
+
|
|
5198
|
+
function yui_shell_set_nav_mode(shell_gobj, mode)
|
|
5199
|
+
{
|
|
5200
|
+
if(!shell_gobj || !is_gobj(shell_gobj)) {
|
|
5201
|
+
log_error(`yui_shell_set_nav_mode(): no shell`);
|
|
5202
|
+
return -1;
|
|
5203
|
+
}
|
|
5204
|
+
if(!is_nav_mode(mode)) {
|
|
5205
|
+
log_error(`yui_shell_set_nav_mode(): unknown nav_mode '${mode}' — ` +
|
|
5206
|
+
`expected one of ${NAV_MODES.join("|")}`);
|
|
5207
|
+
return -1;
|
|
5208
|
+
}
|
|
5209
|
+
if(kw_set_local_storage_value(NAV_MODE_KEY, mode) < 0) {
|
|
5210
|
+
return -1; // Error already logged
|
|
5211
|
+
}
|
|
5212
|
+
gobj_publish_event(shell_gobj, "EV_NAV_MODE_CHANGED", {nav_mode: mode});
|
|
5213
|
+
return 0;
|
|
5214
|
+
}
|
|
5215
|
+
|
|
5162
5216
|
/************************************************************
|
|
5163
5217
|
* The user icons changed (lib_icons.js: yui_icons_set_user,
|
|
5164
5218
|
* yui_icons_put_user, yui_icons_remove_user): PUBLISH it, so
|
|
@@ -5415,6 +5469,8 @@ export {
|
|
|
5415
5469
|
yui_shell_set_translator,
|
|
5416
5470
|
yui_shell_translate,
|
|
5417
5471
|
yui_shell_language_changed,
|
|
5472
|
+
yui_shell_nav_mode,
|
|
5473
|
+
yui_shell_set_nav_mode,
|
|
5418
5474
|
yui_shell_icons_changed,
|
|
5419
5475
|
yui_shell_set_connection_state,
|
|
5420
5476
|
yui_shell_set_toolbar_item_icon,
|
|
@@ -313,4 +313,10 @@ export const I18N_KEY_FUNCTIONS = Object.freeze([
|
|
|
313
313
|
{module: "c_yui_shell.js", name: "announce_badge", exported: false, keys: ["1"]},
|
|
314
314
|
/* shell_route_map.js -- a node of the route map */
|
|
315
315
|
{module: "shell_route_map.js", name: "render_node", exported: false, keys: ["0.label"]},
|
|
316
|
+
/* yui_preferences.js -- the parts of a Preferences page an app
|
|
317
|
+
* uses for its own fields: the label of a field, the options of a
|
|
318
|
+
* segment (an option with a `text` and no `key` is data: a
|
|
319
|
+
* language named in its own words) */
|
|
320
|
+
{module: "yui_preferences.js", name: "yui_pref_field", exported: true, keys: ["0"]},
|
|
321
|
+
{module: "yui_preferences.js", name: "yui_pref_segment", exported: true, keys: ["2[].key"]},
|
|
316
322
|
]);
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* json_level_stepper.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* The tree of C_YUI_JSON opens and folds one LEVEL at a time
|
|
5
|
+
* (EV_EXPAND_LEVEL / EV_COLLAPSE_LEVEL), beside the pair that does
|
|
6
|
+
* it all at once (EV_EXPAND_ALL / EV_COLLAPSE_ALL):
|
|
7
|
+
*
|
|
8
|
+
* - `+` opens every loaded container of the shallowest level
|
|
9
|
+
* that still has one closed;
|
|
10
|
+
* - `-` folds the deepest level open in sight, and everything
|
|
11
|
+
* under it.
|
|
12
|
+
*
|
|
13
|
+
* Asked for on the json popup of a treedb cell: from a closed
|
|
14
|
+
* document, one press shows the fields of each entry with their
|
|
15
|
+
* own containers still closed.
|
|
16
|
+
*
|
|
17
|
+
* Driven through the real gclass on a document double.
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) 2026, ArtGins.
|
|
20
|
+
* All Rights Reserved.
|
|
21
|
+
***********************************************************************/
|
|
22
|
+
import {test, expect, beforeAll, beforeEach} from "vitest";
|
|
23
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
24
|
+
|
|
25
|
+
install_dom_double();
|
|
26
|
+
|
|
27
|
+
if(!globalThis.ResizeObserver) {
|
|
28
|
+
globalThis.ResizeObserver = class {
|
|
29
|
+
observe() {
|
|
30
|
+
}
|
|
31
|
+
unobserve() {
|
|
32
|
+
}
|
|
33
|
+
disconnect() {
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const {
|
|
39
|
+
SDATA_END, gclass_create, gobj_start_up, gobj_create_yuno, gobj_create,
|
|
40
|
+
gobj_create_pure_child, gobj_start, gobj_read_attr, gobj_send_event,
|
|
41
|
+
set_log_callback,
|
|
42
|
+
} = await import("@yuneta/gobj-js");
|
|
43
|
+
const {register_c_yui_json} = await import("./c_yui_json.js");
|
|
44
|
+
|
|
45
|
+
const logged = [];
|
|
46
|
+
let yuno = null;
|
|
47
|
+
let seq = 0;
|
|
48
|
+
|
|
49
|
+
/* The shape of a template_settings cell: entries of fields, some of
|
|
50
|
+
* them containers in turn. */
|
|
51
|
+
const DOC = {
|
|
52
|
+
template_version: {type: "integer", default: 1, flag: ["persistent", "writable"]},
|
|
53
|
+
top_measures: {type: "array", default: ["temperature"], flag: ["persistent", "writable", "enum"]},
|
|
54
|
+
coordinates: {type: "dict", default: {geometry: {type: "Point", coordinates: [0, 0]}}},
|
|
55
|
+
note: "a leaf at the top",
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
beforeAll(async () => {
|
|
59
|
+
const i18next = (await import("i18next")).default;
|
|
60
|
+
await i18next.init({lng: "en", resources: {}});
|
|
61
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
62
|
+
set_log_callback((level, msg) => {
|
|
63
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
64
|
+
});
|
|
65
|
+
gclass_create("C_TEST_LEVEL_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
66
|
+
gclass_create(
|
|
67
|
+
"C_TEST_LEVEL_APP",
|
|
68
|
+
[["EV_EXPAND_PATH", 0]],
|
|
69
|
+
[["ST_IDLE", [["EV_EXPAND_PATH", () => 0, null]]]],
|
|
70
|
+
{}, 0, [SDATA_END()], {}, 0, 0, 0, 0
|
|
71
|
+
);
|
|
72
|
+
register_c_yui_json();
|
|
73
|
+
yuno = gobj_create_yuno("level_yuno", "C_TEST_LEVEL_HOST", {});
|
|
74
|
+
gobj_start(yuno);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
beforeEach(() => {
|
|
78
|
+
logged.length = 0;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
function new_viewer(doc)
|
|
82
|
+
{
|
|
83
|
+
const app = gobj_create_pure_child(`level_app_${++seq}`, "C_TEST_LEVEL_APP", {}, yuno);
|
|
84
|
+
gobj_start(app);
|
|
85
|
+
const viewer = gobj_create(`level_json_${seq}`, "C_YUI_JSON", {view_mode: "tree"}, app);
|
|
86
|
+
gobj_start(viewer);
|
|
87
|
+
gobj_send_event(viewer, "EV_SET_JSON", {json: doc}, app);
|
|
88
|
+
return viewer;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* The keys of the container rows on screen that are open */
|
|
92
|
+
function open_keys(viewer)
|
|
93
|
+
{
|
|
94
|
+
const $c = gobj_read_attr(viewer, "$container");
|
|
95
|
+
return Array.from($c.querySelectorAll(".JSON_CONTAINER"))
|
|
96
|
+
.filter(($r) => $r.querySelector(".JSON_TOGGLE").classList.contains("is-open"))
|
|
97
|
+
.map(($r) => $r.querySelector(".JSON_KEY").textContent);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* How many rows the tree shows */
|
|
101
|
+
function row_count(viewer)
|
|
102
|
+
{
|
|
103
|
+
return gobj_read_attr(viewer, "$container").querySelectorAll(".JSON_ROW").length;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function step(viewer, event)
|
|
107
|
+
{
|
|
108
|
+
gobj_send_event(viewer, event, {}, viewer);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function errors()
|
|
112
|
+
{
|
|
113
|
+
return logged.filter((l) => l.level === "error").map((l) => l.msg);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
test("`+` opens one level at a time, `-` folds the deepest one", () => {
|
|
117
|
+
const v = new_viewer(DOC);
|
|
118
|
+
expect(open_keys(v)).toEqual([]);
|
|
119
|
+
expect(row_count(v)).toBe(4);
|
|
120
|
+
|
|
121
|
+
step(v, "EV_EXPAND_LEVEL");
|
|
122
|
+
expect(open_keys(v)).toEqual(["template_version", "top_measures", "coordinates"]);
|
|
123
|
+
|
|
124
|
+
step(v, "EV_EXPAND_LEVEL");
|
|
125
|
+
expect(open_keys(v)).toEqual(["template_version", "flag", "top_measures", "default", "flag",
|
|
126
|
+
"coordinates", "default"]);
|
|
127
|
+
|
|
128
|
+
step(v, "EV_EXPAND_LEVEL");
|
|
129
|
+
expect(open_keys(v)).toContain("geometry");
|
|
130
|
+
|
|
131
|
+
step(v, "EV_COLLAPSE_LEVEL");
|
|
132
|
+
expect(open_keys(v)).toEqual(["template_version", "flag", "top_measures", "default", "flag",
|
|
133
|
+
"coordinates", "default"]);
|
|
134
|
+
|
|
135
|
+
step(v, "EV_COLLAPSE_LEVEL");
|
|
136
|
+
step(v, "EV_COLLAPSE_LEVEL");
|
|
137
|
+
expect(open_keys(v)).toEqual([]);
|
|
138
|
+
expect(row_count(v)).toBe(4);
|
|
139
|
+
expect(errors()).toEqual([]);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("`+` opens the shallowest level that still has a container closed", () => {
|
|
143
|
+
const v = new_viewer(DOC);
|
|
144
|
+
/* The reader opened one branch by hand, two levels deep. */
|
|
145
|
+
gobj_send_event(v, "EV_TOGGLE_NODE", {path: "coordinates"}, v);
|
|
146
|
+
expect(open_keys(v)).toEqual(["coordinates"]);
|
|
147
|
+
|
|
148
|
+
step(v, "EV_EXPAND_LEVEL");
|
|
149
|
+
expect(open_keys(v)).toEqual(["template_version", "top_measures", "coordinates"]);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("`-` folds what is in sight, not a branch hidden under a closed one", () => {
|
|
153
|
+
const v = new_viewer(DOC);
|
|
154
|
+
step(v, "EV_EXPAND_LEVEL");
|
|
155
|
+
step(v, "EV_EXPAND_LEVEL");
|
|
156
|
+
/* Close `coordinates` by hand: its open `default` is out of sight. */
|
|
157
|
+
gobj_send_event(v, "EV_TOGGLE_NODE", {path: "coordinates"}, v);
|
|
158
|
+
|
|
159
|
+
step(v, "EV_COLLAPSE_LEVEL");
|
|
160
|
+
expect(open_keys(v)).toEqual(["template_version", "top_measures"]);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("a step with nothing to step does nothing, and says no error", () => {
|
|
164
|
+
const v = new_viewer({a: 1, b: "x"});
|
|
165
|
+
step(v, "EV_EXPAND_LEVEL");
|
|
166
|
+
step(v, "EV_COLLAPSE_LEVEL");
|
|
167
|
+
expect(row_count(v)).toBe(2);
|
|
168
|
+
expect(errors()).toEqual([]);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test("the stepper is a tree control: it hides with the tree", () => {
|
|
172
|
+
const v = new_viewer(DOC);
|
|
173
|
+
const $c = gobj_read_attr(v, "$container");
|
|
174
|
+
const $minus = $c.querySelector(".EV_COLLAPSE_LEVEL");
|
|
175
|
+
const $plus = $c.querySelector(".EV_EXPAND_LEVEL");
|
|
176
|
+
expect($minus.querySelector("i.yi-square-minus")).not.toBe(null);
|
|
177
|
+
expect($plus.querySelector("i.yi-square-plus")).not.toBe(null);
|
|
178
|
+
expect($minus.getAttribute("aria-label")).toBe("collapse one level");
|
|
179
|
+
expect($plus.getAttribute("data-i18n-aria-label")).toBe("expand one level");
|
|
180
|
+
|
|
181
|
+
gobj_send_event(v, "EV_SET_VIEW_MODE", {mode: "text"}, v);
|
|
182
|
+
expect($minus.classList.contains("is-hidden")).toBe(true);
|
|
183
|
+
expect($plus.classList.contains("is-hidden")).toBe(true);
|
|
184
|
+
gobj_send_event(v, "EV_SET_VIEW_MODE", {mode: "tree"}, v);
|
|
185
|
+
expect($plus.classList.contains("is-hidden")).toBe(false);
|
|
186
|
+
});
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* preferences.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* The Preferences page every app shows (C_YUI_PREFERENCES and the
|
|
5
|
+
* parts of yui_preferences.js):
|
|
6
|
+
*
|
|
7
|
+
* - three rows: theme, language, navigation, each marking the
|
|
8
|
+
* current choice;
|
|
9
|
+
* - a press applies through what the app registered
|
|
10
|
+
* (yui_preferences_setup), and the page marks the new choice;
|
|
11
|
+
* - the navigation is the shell's (yui_shell_nav_mode): a
|
|
12
|
+
* C_YUI_NODE tree with no mode of its own follows it, one with
|
|
13
|
+
* its own keeps it;
|
|
14
|
+
* - a language is shown and named in its own words, with `lang`;
|
|
15
|
+
* - the boxes the app adds come after the three rows.
|
|
16
|
+
*
|
|
17
|
+
* Driven through the real gclasses on a document double.
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) 2026, ArtGins.
|
|
20
|
+
* All Rights Reserved.
|
|
21
|
+
***********************************************************************/
|
|
22
|
+
import {test, expect, beforeAll, beforeEach} from "vitest";
|
|
23
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
24
|
+
|
|
25
|
+
install_dom_double();
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
SDATA_END, gclass_create,
|
|
29
|
+
gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_pure_child,
|
|
30
|
+
gobj_start, gobj_send_event, gobj_read_attr,
|
|
31
|
+
set_log_callback,
|
|
32
|
+
} = await import("@yuneta/gobj-js");
|
|
33
|
+
const {register_c_yui_shell, yui_shell_nav_mode} = await import("./c_yui_shell.js");
|
|
34
|
+
const {register_c_yui_nav} = await import("./c_yui_nav.js");
|
|
35
|
+
const {register_c_yui_node, yui_node_nav_mode} = await import("./c_yui_node.js");
|
|
36
|
+
const {register_c_yui_preferences} = await import("./c_yui_preferences.js");
|
|
37
|
+
const {yui_preferences_setup} = await import("./yui_preferences.js");
|
|
38
|
+
|
|
39
|
+
const logged = [];
|
|
40
|
+
const applied = [];
|
|
41
|
+
const state = {theme: "light", language: "en"};
|
|
42
|
+
let yuno = null;
|
|
43
|
+
let seq = 0;
|
|
44
|
+
|
|
45
|
+
beforeAll(async () => {
|
|
46
|
+
const i18next = (await import("i18next")).default;
|
|
47
|
+
await i18next.init({lng: "en", resources: {}});
|
|
48
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
49
|
+
set_log_callback((level, msg) => {
|
|
50
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
51
|
+
});
|
|
52
|
+
gclass_create("C_TEST_PREF_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
53
|
+
register_c_yui_shell();
|
|
54
|
+
register_c_yui_nav();
|
|
55
|
+
register_c_yui_node();
|
|
56
|
+
register_c_yui_preferences();
|
|
57
|
+
yuno = gobj_create_yuno("pref_yuno", "C_TEST_PREF_HOST", {});
|
|
58
|
+
gobj_start(yuno);
|
|
59
|
+
|
|
60
|
+
yui_preferences_setup({
|
|
61
|
+
current_theme: () => state.theme,
|
|
62
|
+
set_theme: (v) => { state.theme = v; applied.push(["theme", v]); },
|
|
63
|
+
languages: [{value: "en", text: "English"}, {value: "es", text: "Español"}],
|
|
64
|
+
current_language: () => state.language,
|
|
65
|
+
set_language: (v) => { state.language = v; applied.push(["language", v]); },
|
|
66
|
+
sections: () => [["div", {class: "APP_BOX box"}, "the app's own"]],
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
logged.length = 0;
|
|
72
|
+
applied.length = 0;
|
|
73
|
+
window.localStorage.removeItem("yui_nav_mode");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
/* The errors of the page, without the routing of a shell that has no
|
|
77
|
+
* routes: it starts on "/home" and has no target for it. */
|
|
78
|
+
function errors()
|
|
79
|
+
{
|
|
80
|
+
return logged.filter((l) => l.level === "error").map((l) => l.msg)
|
|
81
|
+
.filter((m) => !m.includes("no target for route"));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function new_page()
|
|
85
|
+
{
|
|
86
|
+
const n = ++seq;
|
|
87
|
+
const shell = gobj_create(`pref_shell_${n}`, "C_YUI_SHELL",
|
|
88
|
+
{config: {shell: {}}, default_route: "/home"}, yuno);
|
|
89
|
+
gobj_start(shell);
|
|
90
|
+
const page = gobj_create(`pref_page_${n}`, "C_YUI_PREFERENCES", {}, shell);
|
|
91
|
+
gobj_start(page);
|
|
92
|
+
return {shell, page, $c: gobj_read_attr(page, "$container")};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* The value of the marked option of a row */
|
|
96
|
+
function marked($c, row)
|
|
97
|
+
{
|
|
98
|
+
const $on = $c.querySelector(`.${row} .PREF_SEGMENT_ITEM.is-selected`);
|
|
99
|
+
return $on ? $on.querySelector(".PREF_SEGMENT_TEXT").textContent : null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
test("three rows, each marking the current choice, then the app's boxes", () => {
|
|
103
|
+
const {$c} = new_page();
|
|
104
|
+
expect($c.querySelector(".PREF_TITLE")).not.toBe(null);
|
|
105
|
+
expect($c.querySelectorAll(".PREF_APPEARANCE .PREF_FIELD").length).toBe(3);
|
|
106
|
+
expect(marked($c, "PREF_THEME")).toBe("light theme");
|
|
107
|
+
expect(marked($c, "PREF_LANGUAGE")).toBe("English");
|
|
108
|
+
expect(marked($c, "PREF_NAVIGATION")).toBe("stacked strips");
|
|
109
|
+
expect($c.querySelector(".APP_BOX")).not.toBe(null);
|
|
110
|
+
expect(errors()).toEqual([]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("a language is shown and named in its own words, with its lang", () => {
|
|
114
|
+
const {$c} = new_page();
|
|
115
|
+
const $es = $c.querySelectorAll(".PREF_LANGUAGE .PREF_SEGMENT_ITEM")[1];
|
|
116
|
+
expect($es.getAttribute("aria-label")).toBe("Español");
|
|
117
|
+
expect($es.getAttribute("lang")).toBe("es");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("a press applies through the app and the page marks it", () => {
|
|
121
|
+
const {page, $c} = new_page();
|
|
122
|
+
gobj_send_event(page, "EV_SET_THEME", {value: "dark"}, page);
|
|
123
|
+
gobj_send_event(page, "EV_SET_LANGUAGE", {value: "es"}, page);
|
|
124
|
+
expect(applied).toEqual([["theme", "dark"], ["language", "es"]]);
|
|
125
|
+
expect(marked($c, "PREF_THEME")).toBe("dark theme");
|
|
126
|
+
expect(marked($c, "PREF_LANGUAGE")).toBe("Español");
|
|
127
|
+
state.theme = "light";
|
|
128
|
+
state.language = "en";
|
|
129
|
+
expect(errors()).toEqual([]);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("the navigation is the shell's, and a tree with no mode of its own follows it", () => {
|
|
133
|
+
const {shell, page, $c} = new_page();
|
|
134
|
+
const follows = gobj_create_pure_child(`pref_tree_a_${seq}`, "C_YUI_NODE", {
|
|
135
|
+
node_id: "a", base_route: "/a", children: [{id: "x", label: "X"}]
|
|
136
|
+
}, shell);
|
|
137
|
+
gobj_start(follows);
|
|
138
|
+
const pinned = gobj_create_pure_child(`pref_tree_b_${seq}`, "C_YUI_NODE", {
|
|
139
|
+
node_id: "b", base_route: "/b", nav_mode: "back", children: [{id: "y", label: "Y"}]
|
|
140
|
+
}, shell);
|
|
141
|
+
gobj_start(pinned);
|
|
142
|
+
|
|
143
|
+
gobj_send_event(page, "EV_SET_NAV_MODE", {value: "path"}, page);
|
|
144
|
+
expect(yui_shell_nav_mode(shell)).toBe("path");
|
|
145
|
+
expect(marked($c, "PREF_NAVIGATION")).toBe("breadcrumb");
|
|
146
|
+
expect(yui_node_nav_mode(follows)).toBe("path");
|
|
147
|
+
expect(yui_node_nav_mode(pinned)).toBe("back");
|
|
148
|
+
|
|
149
|
+
gobj_send_event(page, "EV_SET_NAV_MODE", {value: "stack"}, page);
|
|
150
|
+
expect(yui_node_nav_mode(follows)).toBe("stack");
|
|
151
|
+
expect(errors()).toEqual([]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("an unknown navigation mode is refused, and said", () => {
|
|
155
|
+
const {shell, page} = new_page();
|
|
156
|
+
gobj_send_event(page, "EV_SET_NAV_MODE", {value: "sideways"}, page);
|
|
157
|
+
expect(yui_shell_nav_mode(shell)).toBe("stack");
|
|
158
|
+
expect(errors().some((e) => e.includes("unknown nav_mode 'sideways'"))).toBe(true);
|
|
159
|
+
});
|