carlos / movement Public

Clone
git clone https://amadan.net/carlos/movement

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3// The browser drive: the whole app in a real Chromium, wired exactly
4// as cmd/movement/main.go wires it — loud on any console error, failed
5// request, 4xx/5xx, or JS value that leaked to the screen unrendered.
6// Not part of the plain suite:
7//
8// go test -tags browser ./...
9//
10// It needs a Chromium: on PATH, via RASTRILLO_CHROME, or in a
11// Playwright cache. A skip is not a pass — with no browser this fails,
12// unless RASTRILLO_BROWSER_OPTIONAL is set, which makes the skip a
13// deliberate visible choice rather than an accident.
14package movementtest
15
16import (
17 "io"
18 "log/slog"
19 "net/http"
20 "path/filepath"
21 "testing"
22
23 "github.com/carlosframework/rastrillo/db"
24 "github.com/carlosframework/rastrillo/harness"
25 "github.com/chromedp/chromedp"
26
27 movement "amadan.net/carlos/movement/internal/movement"
28)
29
30// TestBrowserWalk is the minimal loud walk: the home screen arrives
31// with nothing wrong anywhere the rig watches. Grow it with the app —
32// each screen a flow reaches earns a Screen() line, and an expected
33// probe (a signed-out 401, say) earns a rig.Allow.
34func TestBrowserWalk(t *testing.T) {
35 rig := harness.New(t, func(origin string) http.Handler {
36 // The scaffold's own wiring, origin included: the rig hands
37 // the app its localhost origin before serving — the same seam
38 // main.go fills from MOVEMENT_ORIGIN.
39 logger := slog.New(slog.NewTextHandler(io.Discard, nil))
40 d, err := db.Open(filepath.Join(t.TempDir(), "app.db"), logger)
41 if err != nil {
42 t.Fatalf("db.Open: %v", err)
43 }
44 t.Cleanup(func() { d.Close() })
45 movement.SetLogger(logger)
46 env := testEnv()
47 env.Origin = origin // the rig picks its own localhost port
48 mux, err := movement.App(d, env)
49 if err != nil {
50 t.Fatalf("App: %v", err)
51 }
52 return mux
53 })
54 rig.Run(chromedp.Navigate(rig.Origin + "/"))
55 rig.Screen("body", "home")
56}
57