| 1 | package thintest |
| 2 | |
| 3 | import ( |
| 4 | "io" |
| 5 | "net/http" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | // TestPagesSettingsRail: Paul, 2026-11-10: "The settings nav should |
| 11 | // probably replace the main nav on this view, right?" Every Settings page |
| 12 | // carries the Settings nav in the rail itself: "‹ Equipo" first (to the |
| 13 | // Conversation without scripts), then the sections, Add a connection |
| 14 | // under Connections, the current one marked. The rail marks its nav as |
| 15 | // arriving only when the person crossed into or out of Settings. |
| 16 | func TestPagesSettingsRail(t *testing.T) { |
| 17 | r := &toolRig{rig: newRig(t)} |
| 18 | owner := r.inst.Cookie() |
| 19 | get := func(path, referer string) string { |
| 20 | t.Helper() |
| 21 | req, _ := http.NewRequest("GET", r.inst.URL+path, nil) |
| 22 | req.AddCookie(owner) |
| 23 | if referer != "" { |
| 24 | req.Header.Set("Referer", r.inst.URL+referer) |
| 25 | } |
| 26 | res, err := http.DefaultClient.Do(req) |
| 27 | if err != nil { |
| 28 | t.Fatal(err) |
| 29 | } |
| 30 | defer res.Body.Close() |
| 31 | raw, _ := io.ReadAll(res.Body) |
| 32 | if res.StatusCode != 200 { |
| 33 | t.Fatalf("GET %s: %d", path, res.StatusCode) |
| 34 | } |
| 35 | return string(raw) |
| 36 | } |
| 37 | rail := func(page string) string { |
| 38 | _, after, ok := strings.Cut(page, "<nav rst-shell-nav equipo-settings-rail") |
| 39 | if !ok { |
| 40 | return "" |
| 41 | } |
| 42 | nav, _, _ := strings.Cut(after, "</nav>") |
| 43 | return nav |
| 44 | } |
| 45 | for path, current := range map[string]string{ |
| 46 | "/conversation/settings/thinking": "thinking", |
| 47 | "/conversation/settings/connections": "connections", |
| 48 | "/conversation/settings/connections/add": "connections-add", |
| 49 | "/conversation/settings/machines": "machines", |
| 50 | "/conversation/settings/machines/add": "machines-add", |
| 51 | "/conversation/settings/housekeeping": "housekeeping", |
| 52 | "/conversation/settings/notebook": "notebook", |
| 53 | } { |
| 54 | nav := rail(get(path, "")) |
| 55 | if nav == "" { |
| 56 | t.Fatalf("%s: no Settings nav in the rail", path) |
| 57 | } |
| 58 | for _, want := range []string{`<a href="/conversation" equipo-settings-leave data-settings-leave>`, ">Equipo</span>", `data-rail-settings="thinking"`, `data-rail-settings="connections"`, `href="/conversation/settings/connections/add" equipo-settings-sub data-rail-settings="connections-add"`, `data-rail-settings="machines"`, `data-rail-settings="housekeeping"`, `data-rail-settings="notebook"`, `data-rail-settings="teams"`} { |
| 59 | if !strings.Contains(nav, want) { |
| 60 | t.Fatalf("%s: the rail's Settings nav lacks %s", path, want) |
| 61 | } |
| 62 | } |
| 63 | if strings.Count(nav, `aria-current="page"`) != 1 || !strings.Contains(nav, `data-rail-settings="`+current+`" aria-current="page"`) { |
| 64 | t.Fatalf("%s: %s is not the one current entry", path, current) |
| 65 | } |
| 66 | if strings.Index(nav, "data-settings-leave") > strings.Index(nav, "data-rail-settings") { |
| 67 | t.Fatalf("%s: Equipo is not first", path) |
| 68 | } |
| 69 | } |
| 70 | if rail(get("/conversation", "")) != "" { |
| 71 | t.Fatal("the Settings nav is in the rail outside Settings") |
| 72 | } |
| 73 | // Arriving: only across the boundary, and only the nav that is new. |
| 74 | if !strings.Contains(get("/conversation/settings/thinking", "/conversation"), "equipo-settings-rail data-arriving") { |
| 75 | t.Fatal("entering Settings does not mark its nav arriving") |
| 76 | } |
| 77 | if strings.Contains(get("/conversation/settings/connections", "/conversation/settings/thinking"), "data-arriving") { |
| 78 | t.Fatal("moving between sections marks a nav arriving") |
| 79 | } |
| 80 | if !strings.Contains(get("/conversation", "/conversation/settings/thinking"), `id="rail" data-arriving`) { |
| 81 | t.Fatal("leaving Settings does not mark the main nav arriving") |
| 82 | } |
| 83 | if strings.Contains(get("/tasks", "/conversation"), "data-arriving") { |
| 84 | t.Fatal("an ordinary page marks its nav arriving") |
| 85 | } |
| 86 | } |
| 87 | |