ECOSYSTEM / ROUTER

Testing navigation

Find pages by their component name and drive the stack from a test.

Ecosystem package janelkit-router Navigation between screens: page stacks that keep their state, parallel sections, results with await and transitions. pip install janelkit-router
ROUTER · PAGE 5 / 6~1 min read
Alpha / 0.2 — These pages document JanelKit 0.2 and its packages. Each series (0.1, 0.2…) may change the public API, always with migration notes: see Changes and migration. The website uses Svelte; the desktop examples use Python and JanelKit, not JavaScript.

Find pages and drive the stack

With janelkit.inspect, a page is found by the name of its component: app.find("Detail"). The stack is a name in the script, so a test can read it and drive it: app.get("nav").push(...). A covered page and a hidden section do not appear in find, exactly as the user cannot reach them.

python
# tests/test_navigation.py, for the stack example in Overview.
from janelkit.inspect import mount

def test_the_draft_survives_the_detail_page():
    with mount("src/App.janel") as app:
        app.find(label="Draft").type("hello")
        app.find("button", text="Open detail").click()
        assert app.find("Detail")
        app.find("button", text="Back").click()
        assert app.find(label="Draft").value == "hello"
Copy

How it works

  1. The draft is typed on Home, then Home is covered by Detail.
  2. find("Detail") succeeds only while the Detail page is the visible one.
  3. After Back, the same Home instance is visible again, with its draft.

A larger example

apps/challenges/gestor, in the JanelKit repository, is a project manager built with sections, pages, results with await and questions before leaving. Its tests show how to drive each of them.

English documentation based on the JanelKit source. For additional details, browse the source docs ↗.