clock-digital12 and clock-digital had become the same module (same lib/clock code, same right-click settings), differing only in the starting format. Keep one: the Digital Clock now starts in 12-hour mode with AM/PM, and its "Time format" setting switches to 24-hour. - components/clock-digital12 is gone (and from scripts/components.txt); lib/clock drops digital12_info/digital12_config. - The default panel loads clock-digital. - "clock-digital12" stays an alias (find_module, slot_of, saved panels) and is never listed in the module picker, even if an old .wasm is still installed. - panel.edn gets :version 2. A version-1 panel is migrated once: the old 12-hour clock becomes the Digital Clock with its settings (state.edn :module-config) moved over in 12-hour mode; a panel that had the old 24-hour Digital Clock keeps 24-hour. The file is rewritten afterwards. - Tests updated, plus a migration test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hgnZsS91fwCreut8FL
This commit is contained in:
25 files changed
+207
-925
No files matched your search
@@ -370,7 +370,7 @@ test "right-click a task-bar pill for the window's menu: Minimize, Maximize, Qui
|
||||
test "right-click a panel module to replace it in place, or remove it" {
|
||||
let comp = new_comp("swap")
|
||||
let before = comp.shell.slots()
|
||||
let clock = rect_of(comp, "clock-digital12")
|
||||
let clock = rect_of(comp, "clock-digital")
|
||||
assert_true(clock.w > 0)
|
||||
let find_row = fn(label : String) {
|
||||
let mut i = -1
|
||||
@@ -396,7 +396,7 @@ test "right-click a panel module to replace it in place, or remove it" {
|
||||
assert_eq(comp.desired_cursor(), 4U)
|
||||
click_at(comp, ix, iy, 11U)
|
||||
assert_true(!comp.shell.menu_open)
|
||||
assert_eq(comp.shell.slot_of("clock-digital12"), "")
|
||||
assert_eq(comp.shell.slot_of("clock-digital"), "")
|
||||
let after = comp.shell.slots()
|
||||
assert_eq(after.length(), before.length())
|
||||
assert_eq(after[after.length() - 1], comp.shell.slot_of("clock-binary")) // same place in the panel
|
||||
@@ -417,6 +417,8 @@ test "right-click a panel module to replace it in place, or remove it" {
|
||||
///|
|
||||
test "right-click a module for its own settings: they apply at once and are remembered" {
|
||||
let comp = new_comp("modcfg")
|
||||
// A fresh instance next to nothing else: drop the default panel's clock first.
|
||||
assert_true(comp.shell.unload_slot(comp.shell.slot_of("clock-digital")))
|
||||
assert_true(comp.shell.load_module("clock-digital"))
|
||||
ignore(comp.compose_frame())
|
||||
let clock = rect_of(comp, "clock-digital")
|
||||
@@ -441,23 +443,25 @@ test "right-click a module for its own settings: they apply at once and are reme
|
||||
}
|
||||
t
|
||||
}
|
||||
assert_false(time_text().has_suffix("M")) // 24-hour by default
|
||||
assert_true(time_text().has_suffix("AM") || time_text().has_suffix("PM")) // 12-hour by default
|
||||
click_at(comp, clock.x + clock.w / 2, clock.y + clock.h / 2, 1U, btn=273U)
|
||||
assert_true(comp.shell.menu_open)
|
||||
assert_eq(comp.shell.menu_rows[0].label, "Module settings...")
|
||||
assert_eq(comp.shell.menu_rows[1].label, "System settings...")
|
||||
click_at(comp, comp.shell.menu_rect.x + 60, row_y(0), 10U)
|
||||
// The module's own menu: a "Time format" heading, its two choices, and the "Show date" switch.
|
||||
// The module's own menu: a "Time format" heading, its two choices, then the switches.
|
||||
assert_true(comp.shell.menu_open)
|
||||
assert_eq(comp.shell.menu_title, "Digital Clock settings")
|
||||
let h12 = find_row("12-hour")
|
||||
assert_true(h12 > 0 && find_row("Time format") == h12 - 2)
|
||||
assert_true(comp.shell.menu_rows[h12 - 1].ticked) // 24-hour
|
||||
click_at(comp, comp.shell.menu_rect.x + 60, row_y(h12), 20U)
|
||||
assert_true(comp.shell.menu_open) // stays open, now ticking 12-hour
|
||||
assert_true(comp.shell.menu_rows[find_row("12-hour")].ticked)
|
||||
assert_true(time_text().has_suffix("AM") || time_text().has_suffix("PM"))
|
||||
assert_eq(comp.shell.module_setting("clock-digital", "format"), Some("12-hour"))
|
||||
let h24 = find_row("24-hour")
|
||||
assert_true(h24 > 0 && find_row("Time format") == h24 - 1)
|
||||
assert_true(comp.shell.menu_rows[h24 + 1].ticked) // 12-hour
|
||||
assert_true(find_row("Show AM/PM") >= 0)
|
||||
click_at(comp, comp.shell.menu_rect.x + 60, row_y(h24), 20U)
|
||||
assert_true(comp.shell.menu_open) // stays open, now ticking 24-hour
|
||||
assert_true(comp.shell.menu_rows[find_row("24-hour")].ticked)
|
||||
assert_eq(find_row("Show AM/PM"), -1) // only offered in 12-hour mode
|
||||
assert_false(time_text().has_suffix("M"))
|
||||
assert_eq(comp.shell.module_setting("clock-digital", "format"), Some("24-hour"))
|
||||
// A heading does nothing; Escape closes.
|
||||
click_at(comp, comp.shell.menu_rect.x + 60, row_y(find_row("Time format")), 30U)
|
||||
assert_true(comp.shell.menu_open)
|
||||
@@ -467,7 +471,7 @@ test "right-click a module for its own settings: they apply at once and are reme
|
||||
assert_true(comp.shell.unload_slot(comp.shell.slot_of("clock-digital")))
|
||||
assert_true(comp.shell.load_module("clock-digital"))
|
||||
ignore(comp.compose_frame())
|
||||
assert_true(time_text().has_suffix("AM") || time_text().has_suffix("PM"))
|
||||
assert_false(time_text().has_suffix("M"))
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -529,6 +533,50 @@ test "the panel is saved to panel.edn and restored" {
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
test "a panel saved with the old 12-hour clock gets the Digital Clock with the same settings" {
|
||||
if @sys.getenv("CHANDRA_TEST_CONFIG") == "1" {
|
||||
let dir = @sys.getenv("XDG_CONFIG_HOME") + "/chandra"
|
||||
assert_true(@sys.mkdir_p(dir))
|
||||
let state0 = @sys.read_file_bytes(dir + "/state.edn")
|
||||
let write = fn(name : String, text : String) {
|
||||
ignore(@sys.write_file_bytes(dir + "/" + name, @utf8.encode(text)))
|
||||
}
|
||||
let boot = fn() {
|
||||
let s = @shell.DesktopShell::new("x")
|
||||
s.persist = true
|
||||
s.set_output(@scene.ThemeTokens::moon_night(), 1280, 720)
|
||||
ignore(s.slots())
|
||||
s
|
||||
}
|
||||
// The default panel's 12-hour clock, its date line switched off.
|
||||
write("panel.edn", "{:panel [\"tasks\" \"clock-digital12\" \"logout\"]}\n")
|
||||
write("state.edn", "{:module-config {\"clock-digital12\" {\"date\" \"off\"} \"clock-digital\" {\"format\" \"24-hour\"}}}\n")
|
||||
let a = boot()
|
||||
assert_true(a.slot_of("clock-digital") != "")
|
||||
assert_eq(a.slot_of("clock-digital12"), a.slot_of("clock-digital")) // the old id is an alias
|
||||
assert_eq(a.module_setting("clock-digital", "format"), Some("12-hour"))
|
||||
assert_eq(a.module_setting("clock-digital", "date"), Some("off"))
|
||||
assert_eq(a.module_setting("clock-digital12", "date"), None)
|
||||
let panel = @utf8.decode_lossy(@sys.read_file_bytes(dir + "/panel.edn"))
|
||||
assert_true(panel.contains("\"clock-digital\"") && !panel.contains("clock-digital12"))
|
||||
assert_true(panel.contains(":version 2"))
|
||||
// Only once: a format chosen afterwards sticks across restarts.
|
||||
a.set_module_setting(a.slot_of("clock-digital"), "format", "24-hour")
|
||||
assert_eq(boot().module_setting("clock-digital", "format"), Some("24-hour"))
|
||||
// A panel that had the (then 24-hour) Digital Clock keeps it in 24-hour mode.
|
||||
write("panel.edn", "{:panel [\"tasks\" \"clock-digital\"]}\n")
|
||||
write("state.edn", "{}\n")
|
||||
assert_eq(boot().module_setting("clock-digital", "format"), Some("24-hour"))
|
||||
// A panel saved since then is left alone.
|
||||
write("panel.edn", "{:panel [\"tasks\" \"clock-digital\"]\n :version 2}\n")
|
||||
write("state.edn", "{}\n")
|
||||
assert_eq(boot().module_setting("clock-digital", "format"), None)
|
||||
write("panel.edn", "")
|
||||
ignore(@sys.write_file_bytes(dir + "/state.edn", state0))
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
test "the wasm picker opens the settings module's Panel tab, which loads and unloads modules" {
|
||||
let comp = new_comp("manager")
|
||||
@@ -591,7 +639,7 @@ test "dragging a panel module reorders it" {
|
||||
let comp = new_comp("wdrag")
|
||||
let order0 = comp.shell.slots()
|
||||
let moon = rect_of(comp, "moon-disc")
|
||||
let clock = rect_of(comp, "clock-digital12")
|
||||
let clock = rect_of(comp, "clock-digital")
|
||||
assert_true(moon.x < clock.x)
|
||||
let cy = (clock.y + clock.h / 2).to_double()
|
||||
comp.handle_input(@nested.InputEvent::PointerMove((clock.x + clock.w / 2).to_double(), cy), 1U)
|
||||
@@ -605,8 +653,8 @@ test "dragging a panel module reorders it" {
|
||||
let order1 = comp.shell.slots()
|
||||
assert_eq(order1.length(), order0.length())
|
||||
assert_true(order1 != order0)
|
||||
assert_eq(order1[order1.length() - 2], comp.shell.slot_of("clock-digital12"))
|
||||
assert_true(rect_of(comp, "clock-digital12").x < rect_of(comp, "moon-disc").x)
|
||||
assert_eq(order1[order1.length() - 2], comp.shell.slot_of("clock-digital"))
|
||||
assert_true(rect_of(comp, "clock-digital").x < rect_of(comp, "moon-disc").x)
|
||||
assert_true(comp.desired_cursor() != 17U)
|
||||
}
|
||||
|
||||
|
||||
@@ -42,9 +42,9 @@ test "inspector shows the WIT interface of the hovered component" {
|
||||
ignore(@sys.write_file_bytes("_build/inspector_launcher.png", png))
|
||||
|
||||
// Clock, panel, window title bar and desktop resolve to their own components.
|
||||
let (cx, cy) = center_of(comp, "clock-digital12")
|
||||
let (cx, cy) = center_of(comp, "clock-digital")
|
||||
comp.handle_input(@nested.InputEvent::PointerMove(cx, cy), 5U)
|
||||
assert_eq(comp.shell.hover_id, comp.shell.slot_of("clock-digital12"))
|
||||
assert_eq(comp.shell.hover_id, comp.shell.slot_of("clock-digital"))
|
||||
comp.handle_input(@nested.InputEvent::PointerMove(1270.0, 5.0), 6U)
|
||||
assert_eq(comp.shell.hover_id, "desktop")
|
||||
|
||||
|
||||
@@ -87,6 +87,11 @@ fn DesktopShell::remember_module_setting(self : DesktopShell, id : String, key :
|
||||
self.module_cfg.set(id, m)
|
||||
}
|
||||
}
|
||||
self.write_module_cfg()
|
||||
}
|
||||
|
||||
///| Write `:module-config` to state.edn, keeping every other key (a no-op without `persist`).
|
||||
fn DesktopShell::write_module_cfg(self : DesktopShell) -> Unit {
|
||||
if !self.persist {
|
||||
return
|
||||
}
|
||||
@@ -107,6 +112,35 @@ fn DesktopShell::remember_module_setting(self : DesktopShell, id : String, key :
|
||||
write_state_file(entries)
|
||||
}
|
||||
|
||||
///| A panel saved before the 12-hour clock (clock-digital12) became part of the Digital Clock
|
||||
/// (panel.edn version 1, `saved` its module list as written): keep each clock as it was. The
|
||||
/// 12-hour clock's settings become the Digital Clock's, starting from 12-hour mode; a panel that
|
||||
/// had only the Digital Clock keeps it in 24-hour mode (its old default) unless a format was chosen.
|
||||
/// A panel with both now has two Digital Clocks sharing the Digital Clock's settings.
|
||||
fn DesktopShell::migrate_module_cfg(self : DesktopShell, saved : Array[String]) -> Unit {
|
||||
self.read_module_cfg()
|
||||
let had12 = saved.contains("clock-digital12")
|
||||
let had24 = saved.contains("clock-digital")
|
||||
let old12 = self.module_cfg.get("clock-digital12")
|
||||
if had12 && !had24 {
|
||||
let m : Map[String, String] = { "format": "12-hour" }
|
||||
match old12 {
|
||||
Some(o) => for k, v in o { m.set(k, v) }
|
||||
None => ()
|
||||
}
|
||||
self.module_cfg.set("clock-digital", m)
|
||||
} else if had24 && !had12 {
|
||||
match self.module_cfg.get("clock-digital") {
|
||||
Some(m) => if !m.contains("format") { m.set("format", "24-hour") }
|
||||
None => self.module_cfg.set("clock-digital", { "format": "24-hour" })
|
||||
}
|
||||
}
|
||||
if (had12 && !had24) || (had24 && !had12) || old12 is Some(_) {
|
||||
self.module_cfg.remove("clock-digital12")
|
||||
self.write_module_cfg()
|
||||
}
|
||||
}
|
||||
|
||||
///| The setting `key` of module `id` as last chosen, if any.
|
||||
pub fn DesktopShell::module_setting(self : DesktopShell, id : String, key : String) -> String? {
|
||||
self.read_module_cfg()
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
///| Modules loaded into a fresh panel, in order. `tasks` stretches, so what follows it packs right.
|
||||
let default_panel : Array[String] = [
|
||||
"launcher", "inspector", "layout", "tasks", "moon-disc", "network", "clock-digital12", "screenshot",
|
||||
"launcher", "inspector", "layout", "tasks", "moon-disc", "network", "clock-digital", "screenshot",
|
||||
"session-settings", "logout",
|
||||
]
|
||||
|
||||
@@ -25,7 +25,7 @@ fn fresh_panel(has_battery : Bool) -> Array[String] {
|
||||
}
|
||||
let out : Array[String] = []
|
||||
for m in default_panel {
|
||||
if m == "clock-digital12" {
|
||||
if m == "clock-digital" {
|
||||
out.push("battery")
|
||||
}
|
||||
out.push(m)
|
||||
@@ -37,7 +37,21 @@ fn fresh_panel(has_battery : Bool) -> Array[String] {
|
||||
test "a fresh panel gets the battery module only on a machine with a battery" {
|
||||
assert_false(fresh_panel(false).contains("battery"))
|
||||
let p = fresh_panel(true)
|
||||
assert_eq(p.search("battery").unwrap() + 1, p.search("clock-digital12").unwrap())
|
||||
assert_eq(p.search("battery").unwrap() + 1, p.search("clock-digital").unwrap())
|
||||
}
|
||||
|
||||
///| Modules folded into another one: old id -> the module that took over. The old id still
|
||||
/// works everywhere a module is named (saved panels, load_module), it is just never listed:
|
||||
/// a stale build/components/clock-digital12.wasm or an old installed copy stays out of the picker.
|
||||
/// - clock-digital12, the 12-hour clock, is the Digital Clock, which now starts in 12-hour mode.
|
||||
let retired_modules : Map[String, String] = { "clock-digital12": "clock-digital" }
|
||||
|
||||
///| The id a module goes by now ("clock-digital12" -> "clock-digital").
|
||||
fn current_module_id(id : String) -> String {
|
||||
match retired_modules.get(id) {
|
||||
Some(n) => n
|
||||
None => id
|
||||
}
|
||||
}
|
||||
|
||||
///| The module whose popup holds the wasm picker (its Modules tab).
|
||||
@@ -111,7 +125,7 @@ fn DesktopShell::scan_catalog(self : DesktopShell) -> Unit {
|
||||
for dir in module_dirs() {
|
||||
for f in @wasm.list_wasm_files(dir) {
|
||||
let id = stem(f)
|
||||
if !seen.contains(id) {
|
||||
if !seen.contains(id) && !retired_modules.contains(id) {
|
||||
seen.set(id, true)
|
||||
self.catalog.push({ id, path: dir + "/" + f, name: "" })
|
||||
}
|
||||
@@ -145,6 +159,7 @@ fn DesktopShell::name_catalog(self : DesktopShell) -> Unit {
|
||||
|
||||
///| Catalog entry for module id `id`.
|
||||
fn DesktopShell::find_module(self : DesktopShell, id : String) -> CatalogEntry? {
|
||||
let id = current_module_id(id)
|
||||
for e in self.catalog {
|
||||
if e.id == id {
|
||||
return Some(e)
|
||||
@@ -199,7 +214,8 @@ fn wall_secs() -> Int {
|
||||
|
||||
///| Panels saved before the wallpaper chooser and the module manager moved into the settings
|
||||
/// module list "wallpaper" or "module-manager": the settings module takes the first one's place
|
||||
/// (a panel that already has it just drops them).
|
||||
/// (a panel that already has it just drops them). Retired modules (clock-digital12) become
|
||||
/// the module that replaced them.
|
||||
fn migrate_panel(entries : Array[String]) -> Array[String] {
|
||||
let has_settings = entries.contains("session-settings")
|
||||
let out : Array[String] = []
|
||||
@@ -209,7 +225,7 @@ fn migrate_panel(entries : Array[String]) -> Array[String] {
|
||||
out.push("session-settings")
|
||||
}
|
||||
} else {
|
||||
out.push(e)
|
||||
out.push(current_module_id(e))
|
||||
}
|
||||
}
|
||||
out
|
||||
@@ -223,6 +239,13 @@ test "a saved panel's wallpaper button becomes the settings module" {
|
||||
assert_eq(migrate_panel(["clock"]), ["clock"])
|
||||
}
|
||||
|
||||
///|
|
||||
test "a saved panel's 12-hour clock becomes the digital clock" {
|
||||
assert_eq(migrate_panel(["tasks", "clock-digital12", "logout"]), ["tasks", "clock-digital", "logout"])
|
||||
assert_eq(current_module_id("clock-digital12"), "clock-digital")
|
||||
assert_eq(current_module_id("clock-binary"), "clock-binary")
|
||||
}
|
||||
|
||||
///| Load the panel on first use: the saved layout if there is one, else the default modules.
|
||||
fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit {
|
||||
if self.booted {
|
||||
@@ -230,10 +253,20 @@ fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit {
|
||||
}
|
||||
self.booted = true
|
||||
self.scan_catalog()
|
||||
let entries = match self.load_panel_config() {
|
||||
let saved = self.load_panel_config()
|
||||
let entries = match saved {
|
||||
Some(e) => migrate_panel(e)
|
||||
None => fresh_panel(read_battery().state != 0)
|
||||
}
|
||||
match saved {
|
||||
Some(old) if saved_panel_version() < panel_version => {
|
||||
// Once, before the modules load so they pick up the moved settings; then the file is
|
||||
// rewritten with the new names and version (also keeping modules that fail to load).
|
||||
self.migrate_module_cfg(old)
|
||||
write_panel_file(entries)
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
for e in entries {
|
||||
let path = if e.has_prefix("/") {
|
||||
e
|
||||
@@ -380,6 +413,7 @@ pub fn DesktopShell::slot_module(self : DesktopShell, slot : String) -> String {
|
||||
///| Slot of the first loaded instance of module `id` ("" if none).
|
||||
pub fn DesktopShell::slot_of(self : DesktopShell, id : String) -> String {
|
||||
self.ensure_booted()
|
||||
let id = current_module_id(id)
|
||||
for w in self.widgets {
|
||||
if w.module_id == id {
|
||||
return w.slot
|
||||
@@ -1007,30 +1041,74 @@ fn read_config_file(name : String) -> Bytes {
|
||||
}
|
||||
|
||||
///| Write the loaded modules, in panel order, as EDN:
|
||||
/// {:panel ["launcher" "layout" "tasks" "/home/me/my-widget.wasm"]}
|
||||
/// {:panel ["launcher" "layout" "tasks" "/home/me/my-widget.wasm"] :version 2}
|
||||
/// (catalog modules by name, others by path). A no-op unless `persist` is on.
|
||||
pub fn DesktopShell::save_panel_config(self : DesktopShell) -> Unit {
|
||||
if !self.persist || !self.booted {
|
||||
return
|
||||
}
|
||||
write_panel_file(self.widgets.map(w => w.module_id))
|
||||
}
|
||||
|
||||
///| panel.edn's format version (`:version`; files without one are 1). 2: written after the
|
||||
/// 12-hour clock (clock-digital12) became part of the Digital Clock, whose default went from
|
||||
/// 24-hour to 12-hour; an older file gets its clock settings moved over once (migrate_module_cfg).
|
||||
let panel_version : Int = 2
|
||||
|
||||
///|
|
||||
fn write_panel_file(names : Array[String]) -> Unit {
|
||||
let sb = StringBuilder::new()
|
||||
sb.write_string(";; Chandra panel: the wasm modules loaded into it, in order\n")
|
||||
sb.write_string("{:panel [")
|
||||
let mut first = true
|
||||
for w in self.widgets {
|
||||
for n in names {
|
||||
if !first {
|
||||
sb.write_string("\n ")
|
||||
}
|
||||
first = false
|
||||
sb.write_string("\"" + w.module_id + "\"")
|
||||
sb.write_string("\"" + n + "\"")
|
||||
}
|
||||
sb.write_string("]}\n")
|
||||
sb.write_string("]\n :version " + panel_version.to_string() + "}\n")
|
||||
let dir = panel_config_dir()
|
||||
if @sys.mkdir_p(dir) {
|
||||
ignore(@sys.write_file_bytes(dir + "/panel.edn", @utf8.encode(sb.to_string())))
|
||||
}
|
||||
}
|
||||
|
||||
///| The `:version` of the saved panel.edn (1 when it has none).
|
||||
fn saved_panel_version() -> Int {
|
||||
let text = @utf8.decode_lossy(read_config_file("panel.edn"))
|
||||
panel_text_version(text)
|
||||
}
|
||||
|
||||
///|
|
||||
fn panel_text_version(text : String) -> Int {
|
||||
match text.find(":version") {
|
||||
None => 1
|
||||
Some(i) => {
|
||||
let mut v = 0
|
||||
let mut seen = false
|
||||
for j = i + 8; j < text.length(); j = j + 1 {
|
||||
let c = text[j]
|
||||
if c >= '0' && c <= '9' {
|
||||
v = v * 10 + (c.to_int() - '0'.to_int())
|
||||
seen = true
|
||||
} else if seen || (c != ' ' && c != '\t' && c != '\n' && c != '\r' && c != ',') {
|
||||
break
|
||||
}
|
||||
}
|
||||
if seen { v } else { 1 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
test "panel.edn version" {
|
||||
assert_eq(panel_text_version("{:panel [\"clock-digital12\"]}"), 1)
|
||||
assert_eq(panel_text_version("{:panel [\"clock-digital\"]\n :version 2}\n"), 2)
|
||||
assert_eq(panel_text_version("{:version 12 :panel []}"), 12)
|
||||
}
|
||||
|
||||
///| The module list saved in panel.edn; None when persistence is off or there is no saved panel.
|
||||
fn DesktopShell::load_panel_config(self : DesktopShell) -> Array[String]? {
|
||||
if !self.persist {
|
||||
|
||||
@@ -97,13 +97,15 @@ fn drain() -> Array[HostRequest] {
|
||||
test "a module's own settings (module-config) are listed and set through wasmer" {
|
||||
let p = load_module("clock-digital")
|
||||
let items = p.config_items()
|
||||
assert_eq(items.length(), 2)
|
||||
assert_eq(items[0], { key: "format", label: "Time format", choices: ["24-hour", "12-hour"], value: "24-hour" })
|
||||
// 12-hour by default: Time format, Show AM/PM, Show date.
|
||||
assert_eq(items.length(), 3)
|
||||
assert_eq(items[0], { key: "format", label: "Time format", choices: ["24-hour", "12-hour"], value: "12-hour" })
|
||||
assert_eq(items[1].choices.length(), 0) // an on/off switch
|
||||
assert_true(p.set_config("format", "12-hour"))
|
||||
assert_false(p.set_config("format", "12-hour")) // unchanged
|
||||
assert_true(p.set_config("format", "24-hour"))
|
||||
assert_false(p.set_config("format", "24-hour")) // unchanged
|
||||
assert_false(p.set_config("bogus", "x"))
|
||||
assert_eq(p.config_items()[0].value, "12-hour")
|
||||
assert_eq(p.config_items()[0].value, "24-hour")
|
||||
assert_eq(p.config_items().length(), 2) // no AM/PM switch in 24-hour mode
|
||||
let mut ampm = false
|
||||
for op in p.render(p.pref_w, p.pref_h, test_tokens()) {
|
||||
match op {
|
||||
@@ -111,7 +113,7 @@ test "a module's own settings (module-config) are listed and set through wasmer"
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
assert_true(ampm)
|
||||
assert_false(ampm)
|
||||
p.unload()
|
||||
// Modules without the export have no settings, and setting one is a no-op.
|
||||
let l = load_module("layout")
|
||||
@@ -287,12 +289,12 @@ test "interface explorer module toggles through the inspector capability" {
|
||||
}
|
||||
|
||||
///|
|
||||
test "moon and 12-hour clock modules render from the clock capability" {
|
||||
test "moon and digital clock modules render from the clock capability" {
|
||||
let m = load_module("moon-disc")
|
||||
assert_true(m.render(36, 36, test_tokens()).length() > 3)
|
||||
m.unload()
|
||||
let c = load_module("clock-digital12")
|
||||
let c = load_module("clock-digital")
|
||||
let ts = texts_of(c.render(120, 36, test_tokens()))
|
||||
assert_true(ts[0].has_suffix("AM") || ts[0].has_suffix("PM"))
|
||||
assert_true(ts[0].has_suffix("AM") || ts[0].has_suffix("PM")) // 12-hour by default
|
||||
c.unload()
|
||||
}
|
||||
Reference in new issue
Block a user