Add headless UI tests with kittest
This commit is contained in:
@@ -97,8 +97,39 @@ cargo build --release # target/release/jsoncanvas-desktop[.exe]
|
||||
needed; install `xdg-desktop-portal` and a backend for your desktop if it is
|
||||
not already present.
|
||||
|
||||
Run the tests with `cargo test` (the model, geometry, Markdown and editing logic
|
||||
are covered headless — no display required).
|
||||
## Tests
|
||||
|
||||
`cargo test` runs everything, headless and without a display. Each module's
|
||||
tests are a child module of it in a file of its own — `src/view/tests.rs` for
|
||||
`src/view.rs` — so they still reach private state without the module itself
|
||||
carrying a thousand lines of test code. The GUI is tested the same way as the
|
||||
rest:
|
||||
|
||||
* **Widgets** are driven through
|
||||
[`egui_kittest`](https://crates.io/crates/egui_kittest), which builds the real
|
||||
`App` on a real `egui::Context` and finds widgets by the label on them:
|
||||
|
||||
```rust
|
||||
harness.get_by_label("Close & Fit").click();
|
||||
harness.run();
|
||||
assert_eq!(harness.state().view.editing(), None);
|
||||
```
|
||||
|
||||
* **Canvas gestures** — clicks, drags and the wheel on cards, which are painted
|
||||
rather than built from widgets — go through the `pass` helper in `view.rs`,
|
||||
which runs one frame of `CanvasView::show` against synthetic input at chosen
|
||||
coordinates.
|
||||
|
||||
* **How it looks** is covered by snapshot tests, which render a frame with
|
||||
`wgpu` and compare it with the images in `tests/snapshots`. A failure writes
|
||||
`<name>.diff.png` and `<name>.new.png` beside the expected image; after an
|
||||
intentional change, re-record with `UPDATE_SNAPSHOTS=1 cargo test`. Rendering
|
||||
falls back to Mesa's software Vulkan driver, so no GPU is needed.
|
||||
|
||||
Driving the built binary with synthetic input (`xdotool` and friends) is *not*
|
||||
the way to test this: under a Wayland compositor the X pointer warp is scaled,
|
||||
`--sync` can block until it is killed, and window captures come back stale, so
|
||||
the results are slow and misleading.
|
||||
|
||||
## Keyboard shortcuts
|
||||
|
||||
|
||||
Reference in New Issue
Block a user