| 1 | package thintest |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | // TestPagesSettingsSections: Paul, 2026-11-09: Settings split into |
| 10 | // sections, each at its own URL with the menu of all of them, the current |
| 11 | // one marked; Connections and the Notebook moved under it; the old URLs |
| 12 | // lead to their sections; the conversation's header leads there too. |
| 13 | func TestPagesSettingsSections(t *testing.T) { |
| 14 | r := newToolRig(t) |
| 15 | owner := r.inst.Cookie() |
| 16 | links := []string{`data-settings-link="thinking"`, `data-settings-link="connections"`, `data-settings-link="machines"`, `data-settings-link="housekeeping"`, `data-settings-link="notebook"`, `data-settings-link="teams"`} |
| 17 | for _, tc := range []struct{ path, current, want string }{ |
| 18 | {"/conversation/settings", "thinking", `data-root`}, |
| 19 | {"/conversation/settings/thinking", "thinking", `data-thinking-words`}, |
| 20 | {"/conversation/settings/connections", "connections", `data-connections`}, |
| 21 | {"/conversation/settings/machines", "machines", `data-machines`}, |
| 22 | {"/runners/enrol", "machines", `data-my-machines`}, |
| 23 | {"/conversation/settings/housekeeping", "housekeeping", `data-hk-settings`}, |
| 24 | {"/conversation/settings/notebook", "notebook", `data-notebook-reset`}, |
| 25 | } { |
| 26 | page := r.get(owner, tc.path, 200) |
| 27 | for _, l := range links { |
| 28 | if !strings.Contains(page, l) { |
| 29 | t.Fatalf("%s: the menu lacks %s", tc.path, l) |
| 30 | } |
| 31 | } |
| 32 | if strings.Count(page, `aria-current="page" `) > 0 || !strings.Contains(page, `data-settings-link="`+tc.current+`" aria-current="page"`) { |
| 33 | t.Fatalf("%s: %s is not the one current section", tc.path, tc.current) |
| 34 | } |
| 35 | if !strings.Contains(page, tc.want) { |
| 36 | t.Fatalf("%s lacks %s", tc.path, tc.want) |
| 37 | } |
| 38 | if tc.path != "/conversation/settings" && (!strings.Contains(page, `href="/conversation/settings" rel="up"`) || strings.Contains(page, `data-root`)) { |
| 39 | t.Fatalf("%s: no way back to Settings", tc.path) |
| 40 | } |
| 41 | } |
| 42 | // Usage is a page of the app's sidebar (connectors spec S4), not a |
| 43 | // Settings section. |
| 44 | if strings.Contains(r.get(owner, "/conversation/settings", 200), `data-settings-link="usage"`) { |
| 45 | t.Fatal("a usage section appeared") |
| 46 | } |
| 47 | noFollow := &http.Client{CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }} |
| 48 | for old, to := range map[string]string{"/conversation/connections": "/conversation/settings/connections", "/conversation/notebook": "/conversation/settings/notebook", "/settings/thinking": "/conversation/settings/thinking"} { |
| 49 | req, _ := http.NewRequest("GET", r.inst.URL+old, nil) |
| 50 | req.AddCookie(owner) |
| 51 | res, err := noFollow.Do(req) |
| 52 | if err != nil { |
| 53 | t.Fatal(err) |
| 54 | } |
| 55 | res.Body.Close() |
| 56 | if res.StatusCode != http.StatusSeeOther || res.Header.Get("Location") != to { |
| 57 | t.Fatalf("%s: %d to %q, want %s", old, res.StatusCode, res.Header.Get("Location"), to) |
| 58 | } |
| 59 | } |
| 60 | chat := r.get(owner, "/conversation", 200) |
| 61 | if !strings.Contains(chat, `href="/conversation/settings/connections" equipo-header-button`) || !strings.Contains(chat, `href="/conversation/settings/notebook" equipo-header-button`) { |
| 62 | t.Fatal("the conversation's header does not lead to the sections") |
| 63 | } |
| 64 | } |
| 65 | |