4. Replace tests/smoke.luau
Navigation · State · Data · Host · about 30 minutesroute, round-trip, and rejection test
The deterministic test drives route and filter actions, restores their saved snapshot, and proves malformed external data cannot replace current state.
When to use it
Replace the generated smoke test so check and test cover the complete deterministic state boundary without depending on a browser storage implementation.
- The encoded snapshot comes from the real application rather than a duplicated hand-written encoding.
- The test changes current state before restoring, so a false-positive no-op cannot pass.
- The invalid payload check proves the previously valid route and filter remain intact.
Focused example
--!strict
local app = require("app/main")
local initial = app.snapshot()
assert(initial.location == "/", "application must start at the library")
assert(initial.filter == "all", "application must start with the all filter")
app.handle("reading.open", "reading/open", "")
app.handle("reading.filter", "reading/filter-toggle", "")
local saved = app.snapshot()
assert(saved.location == "/notes/7", "note route was not generated")
assert(saved.filter == "favorites", "filter did not change")
app.handle("reading.back", "reading/back", "")
app.handle("reading.filter", "reading/filter-toggle", "")
assert(app.snapshot().location == "/", "Back did not return to the library")
assert(app.snapshot().filter == "all", "filter did not return to all")
app.handle("reading.restore", "app", saved.encoded)
assert(app.snapshot().location == "/notes/7", "saved route was not restored")
assert(app.snapshot().filter == "favorites", "saved filter was not restored")
local beforeInvalid = app.snapshot()
app.handle("reading.restore", "app", "v=1&filter=unknown&navigation=invalid")
assert(app.snapshot().message == "Saved view is invalid", "invalid snapshot was accepted")
local afterInvalid = app.snapshot()
assert(afterInvalid.location == beforeInvalid.location, "invalid restore changed the route")
assert(afterInvalid.filter == beforeInvalid.filter, "invalid restore changed the filter")
return true