-- Run: lua test/statusbar_dirty.lua -- The bar is part of the tree, so a tick has to repaint the field that changed and leave -- the rest of the screen alone. The clock is pinned unsynced so its text is constant and -- every other field can be steered on its own. package.path = "sdcard/.lua/lib/?.lua;test/?.lua;" .. package.path local device = require("fake_device").install() local ui = require "ui" local nav = require "nav" local statusbar = require "statusbar" device.clockSynced = false -- History is the arguments this state was started with, so a route to go back to is -- stated the way main.lua would have received it. nav.start { app = "Settings", history = { { app = "Home" } } } -- What main.lua builds, minus the app: chrome above, whatever is left below. local function screen() if not statusbar.isVisible() then return ui.box { w = "fill", h = "fill" } end return ui.box { w = "fill", h = "fill", statusbar.node(), ui.box { w = "fill", h = "fill" } } end ui.mount(screen) local built = tree.getCount() assert(device.labelled "--:--:--", "the bar built no clock") assert(device.labelled "117kB", "the bar built no memory slot") assert(device.labelled(nav.getTitle()), "the bar built no title") local function tick() device.invalidated = {} statusbar.tick() return #device.invalidated end assert(tick() == 0, "an unchanged bar repaints nothing") device.freeHeap = device.freeHeap - 32000 assert(tick() == 1, "only the memory slot repaints") assert(device.labelled "148kB", "the memory slot kept its old text") assert(tree.getCount() == built, "a field update rebuilt the screen") device.status = { state = "connected", ssid = "x", ip = "", rssi = -50 } assert(tick() == 1, "the signal strength repaints the icon and nothing else") assert(tick() == 0, "and settles again afterwards") -- A longer title needs a wider box, which only a rebuild can give it. nav.setTitle "settings - wifi" statusbar.tick() assert(device.labelled "settings - wifi", "a renamed app did not reach the bar") assert(tick() == 0, "and settles again afterwards") -- The back control is offered only when there is somewhere to go back to. It carries no -- label, so it is counted as what it is: the one thing in the bar a finger can press. local function pressable() local count = 0 for _, entry in ipairs(device.nodes) do if entry.interactive then count = count + 1 end end return count end assert(pressable() == 1, "the bar offered no back control with history behind it") nav.start { app = "Settings" } ui.rebuild() assert(pressable() == 0, "the bar offered back with no history behind it") -- Fullscreen is chrome choosing not to build itself, so the app's node is the whole tree. statusbar.setFullscreen(true) assert(not device.labelled "--:--:--", "the bar survived fullscreen") statusbar.setFullscreen(false) assert(device.labelled "--:--:--", "the bar did not come back") print "ok"