package thintest import ( "net/http" "net/url" "regexp" "strconv" "strings" "testing" "time" "amadan.net/oficina/equipo/internal/equipo" ) // TestPagesSettingsPattern: Paul, 2026-11-11: "Can we make sure all the // settings screens have proper UX and aren't just random forms?" Every // Settings section, Teams included, opens with the one Settings head (a // title and one line) beside the Settings menu, current; Housekeeping is // a Status group (the state in words with Pause beside it) and a Quiet // hours group of fields with the savebar, never the two mixed; without // script Save is a plain submit and the forms still post. func TestPagesSettingsPattern(t *testing.T) { r := newToolRig(t) owner := r.inst.Cookie() for _, tc := range []struct{ path, current, head string }{ {"/conversation/settings/thinking", "thinking", "Thinking words"}, {"/conversation/settings/connections", "connections", "Connections"}, {"/conversation/settings/connections/add", "connections", "Add a connection"}, {"/conversation/settings/housekeeping", "housekeeping", "Housekeeping"}, {"/conversation/settings/notebook", "notebook", "Notebook"}, {"/teams", "teams", "Teams"}, } { page := r.get(owner, tc.path, 200) if !strings.Contains(page, `

`+tc.head+`

`) || strings.Count(page, "

") != 1 { t.Errorf("%s: not one Settings head %q with its line", tc.path, tc.head) } if !strings.Contains(page, `data-settings-link="`+tc.current+`" aria-current="page"`) || !strings.Contains(page, `data-rail-settings="`+tc.current+`"`) { t.Errorf("%s: the Settings menu and rail do not mark %s", tc.path, tc.current) } } hk := r.get(owner, "/conversation/settings/housekeeping", 200) status := between(t, hk, `
`) for _, want := range []string{`

Status

`, "Housekeeping is on", `action="/settings/housekeeping/pause"`, `data-hk-pause`, `data-hk-activity`} { if !strings.Contains(status, want) { t.Errorf("Status lacks %s", want) } } quiet := between(t, hk, `
`) for _, want := range []string{`data-savebar-form`, `

Quiet hours

`, `rst-switch`, `data-enables="hk-hours"`, `
Save`, `data-savebar-discard hidden`, `data-savebar-unsaved hidden`} { if !strings.Contains(quiet, want) { t.Errorf("Quiet hours lacks %s", want) } } // Never mixed: no Pause in the savebar's group, no savebar in Status. if strings.Contains(quiet, "data-hk-pause") || strings.Contains(status, "data-savebar") || strings.Count(hk, "data-savebar-form") != 1 { t.Error("a group mixes controls that apply at once with fields saved from the bar") } // Without script Save is a plain post that comes back here. rev := regexp.MustCompile(`name="revision" value="(\d+)"`).FindStringSubmatch(quiet)[1] if code, to := r.post(owner, "/settings/housekeeping/quiet", url.Values{"revision": {rev}, "on": {"1"}, "from": {"21"}, "until": {"7"}}); code != http.StatusSeeOther || to != "/conversation/settings/housekeeping" { t.Fatalf("Save without script: %d to %q", code, to) } if q := r.housekeeping().Quiet; q.From != 21 || q.Until != 7 { t.Fatalf("quiet hours without script: %+v", q) } // Quiet hours off: the switch is off and the hours are drawn anyway, // for settings.js to turn off with it. h := r.housekeeping() if _, err := r.client.SetQuiet(r.ctx, h.Paused, 3, 3, h.Revision); err != nil { t.Fatal(err) } off := r.get(owner, "/conversation/settings/housekeeping", 200) if strings.Contains(between(t, off, `id="hk-quiet-on"`, `>`), "checked") || !strings.Contains(off, `data-hk-quiet-from`) { t.Error("quiet hours off: the switch is on, or the hours are gone") } // Thinking words apply at once: no Save, the old button only without script. thinking := r.get(owner, "/conversation/settings/thinking", 200) if !strings.Contains(thinking, `

Word set

Your choice takes effect immediately.

`) || !strings.Contains(thinking, ``) || strings.Contains(thinking, "data-savebar") { t.Error("Thinking words is not one group that applies at once") } } // TestPagesSettingsTeams: Teams as a Settings section (Paul, 2026-11-11: // "Teams UI is all over the place too"): the current team one header row // with its address and no zero count; each remembered team a row that // opens it, its address and "Last signed in" in words with the exact time // on hover, Forget a quiet button; Add a team a button over a compact // form, the address first, the long explanation as help beside it. func TestPagesSettingsTeams(t *testing.T) { r := newToolRig(t) owner := r.inst.Cookie() link, err := r.inst.Store.RememberTeam(r.ctx, equipo.Actor{Address: Owner}, equipo.TeamLink{Origin: "https://studio.example.com", Name: "Studio"}, equipo.Mutation{RequestID: "pages-teams"}) if err != nil { t.Fatal(err) } at := time.Now().Add(-4*24*time.Hour - time.Hour).UTC() if _, err := r.inst.DB.Writer().Exec("UPDATE team_links SET last_signed_in_at = ? WHERE id = ?", at, link.ID); err != nil { t.Fatal(err) } page := r.get(owner, "/teams", 200) current := between(t, page, `data-team-current`, `
`) host := strings.TrimPrefix(strings.TrimPrefix(r.inst.URL, "http://"), "https://") if !strings.Contains(current, ``) || !strings.Contains(current, `

`+host+`

`) || strings.Contains(current, "data-team-needs>") { t.Error("the current team is not one row with its address and no zero count") } row := between(t, page, `data-team-name="Studio"`, ``) for _, want := range []string{ `
Studio`, `studio.example.com`, `title="` + at.Format("2006-01-02 15:04") + ` UTC">Last signed in 4 days ago`, ``, } { if !strings.Contains(row, want) { t.Errorf("the remembered row lacks %s", want) } } add := between(t, page, `
`, `
`) if !strings.Contains(add, ``) || strings.Index(add, `name="origin"`) > strings.Index(add, `name="name"`) || !strings.Contains(add, "Each team has its own sign-in") { t.Error("Add a team is not a button over a compact form, the address first, with its help") } if strings.Contains(page, "Add links to other Equipo instances") || strings.Contains(page, "Forget this link") { t.Error("the old paragraph or Forget this link is still on the page") } // Without script Forget still posts and comes back to Teams. if code, to := r.post(owner, "/teams/links/"+link.ID+"/forget", url.Values{"request_id": {"pages-forget"}, "revision": {strconv.FormatInt(link.Revision, 10)}}); code != http.StatusSeeOther || to != "/teams" { t.Fatalf("Forget without script: %d to %q", code, to) } if after := r.get(owner, "/teams", 200); strings.Contains(after, `data-team-name="Studio"`) || !strings.Contains(after, "No other teams yet.") { t.Error("Forget without script did not forget, or no empty line") } } // between is the part of page from start up to the first end after it. func between(t *testing.T, page, start, end string) string { t.Helper() i := strings.Index(page, start) if i < 0 { t.Fatalf("no %s", start) } j := strings.Index(page[i:], end) if j < 0 { t.Fatalf("no %s after %s", end, start) } return page[i : i+j] }