oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package thintest
2
3import (
4 "net/http"
5 "net/url"
6 "regexp"
7 "strconv"
8 "strings"
9 "testing"
10 "time"
11
12 "amadan.net/oficina/equipo/internal/equipo"
13)
14
15// TestPagesSettingsPattern: Paul, 2026-11-11: "Can we make sure all the
16// settings screens have proper UX and aren't just random forms?" Every
17// Settings section, Teams included, opens with the one Settings head (a
18// title and one line) beside the Settings menu, current; Housekeeping is
19// a Status group (the state in words with Pause beside it) and a Quiet
20// hours group of fields with the savebar, never the two mixed; without
21// script Save is a plain submit and the forms still post.
22func TestPagesSettingsPattern(t *testing.T) {
23 r := newToolRig(t)
24 owner := r.inst.Cookie()
25 for _, tc := range []struct{ path, current, head string }{
26 {"/conversation/settings/thinking", "thinking", "Thinking words"},
27 {"/conversation/settings/connections", "connections", "Connections"},
28 {"/conversation/settings/connections/add", "connections", "Add a connection"},
29 {"/conversation/settings/housekeeping", "housekeeping", "Housekeeping"},
30 {"/conversation/settings/notebook", "notebook", "Notebook"},
31 {"/teams", "teams", "Teams"},
32 } {
33 page := r.get(owner, tc.path, 200)
34 if !strings.Contains(page, `<header equipo-sp-head><h1>`+tc.head+`</h1><p>`) || strings.Count(page, "<h1>") != 1 {
35 t.Errorf("%s: not one Settings head %q with its line", tc.path, tc.head)
36 }
37 if !strings.Contains(page, `data-settings-link="`+tc.current+`" aria-current="page"`) || !strings.Contains(page, `data-rail-settings="`+tc.current+`"`) {
38 t.Errorf("%s: the Settings menu and rail do not mark %s", tc.path, tc.current)
39 }
40 }
41
42 hk := r.get(owner, "/conversation/settings/housekeeping", 200)
43 status := between(t, hk, `<section equipo-sp-group id="hk-status"`, `</section>`)
44 for _, want := range []string{`<h2 id="hk-status-h">Status</h2>`, "Housekeeping is on", `action="/settings/housekeeping/pause"`, `data-hk-pause`, `data-hk-activity`} {
45 if !strings.Contains(status, want) {
46 t.Errorf("Status lacks %s", want)
47 }
48 }
49 quiet := between(t, hk, `<form method="post" action="/settings/housekeeping/quiet"`, `</form>`)
50 for _, want := range []string{`data-savebar-form`, `<h2 id="hk-quiet-h">Quiet hours</h2>`, `rst-switch`, `data-enables="hk-hours"`, `<fieldset equipo-sp-row id="hk-hours"`, `data-savebar`, `<button rst-btn="primary" type="submit" data-savebar-save>Save</button>`, `data-savebar-discard hidden`, `data-savebar-unsaved hidden`} {
51 if !strings.Contains(quiet, want) {
52 t.Errorf("Quiet hours lacks %s", want)
53 }
54 }
55 // Never mixed: no Pause in the savebar's group, no savebar in Status.
56 if strings.Contains(quiet, "data-hk-pause") || strings.Contains(status, "data-savebar") || strings.Count(hk, "data-savebar-form") != 1 {
57 t.Error("a group mixes controls that apply at once with fields saved from the bar")
58 }
59 // Without script Save is a plain post that comes back here.
60 rev := regexp.MustCompile(`name="revision" value="(\d+)"`).FindStringSubmatch(quiet)[1]
61 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" {
62 t.Fatalf("Save without script: %d to %q", code, to)
63 }
64 if q := r.housekeeping().Quiet; q.From != 21 || q.Until != 7 {
65 t.Fatalf("quiet hours without script: %+v", q)
66 }
67 // Quiet hours off: the switch is off and the hours are drawn anyway,
68 // for settings.js to turn off with it.
69 h := r.housekeeping()
70 if _, err := r.client.SetQuiet(r.ctx, h.Paused, 3, 3, h.Revision); err != nil {
71 t.Fatal(err)
72 }
73 off := r.get(owner, "/conversation/settings/housekeeping", 200)
74 if strings.Contains(between(t, off, `id="hk-quiet-on"`, `>`), "checked") || !strings.Contains(off, `data-hk-quiet-from`) {
75 t.Error("quiet hours off: the switch is on, or the hours are gone")
76 }
77
78 // Thinking words apply at once: no Save, the old button only without script.
79 thinking := r.get(owner, "/conversation/settings/thinking", 200)
80 if !strings.Contains(thinking, `<h2 id="thinking-set-h">Word set</h2><p>Your choice takes effect immediately.</p>`) || !strings.Contains(thinking, `<noscript><button equipo-btn data-primary type="submit">Use these words</button></noscript>`) || strings.Contains(thinking, "data-savebar") {
81 t.Error("Thinking words is not one group that applies at once")
82 }
83}
84
85// TestPagesSettingsTeams: Teams as a Settings section (Paul, 2026-11-11:
86// "Teams UI is all over the place too"): the current team one header row
87// with its address and no zero count; each remembered team a row that
88// opens it, its address and "Last signed in" in words with the exact time
89// on hover, Forget a quiet button; Add a team a button over a compact
90// form, the address first, the long explanation as help beside it.
91func TestPagesSettingsTeams(t *testing.T) {
92 r := newToolRig(t)
93 owner := r.inst.Cookie()
94 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"})
95 if err != nil {
96 t.Fatal(err)
97 }
98 at := time.Now().Add(-4*24*time.Hour - time.Hour).UTC()
99 if _, err := r.inst.DB.Writer().Exec("UPDATE team_links SET last_signed_in_at = ? WHERE id = ?", at, link.ID); err != nil {
100 t.Fatal(err)
101 }
102 page := r.get(owner, "/teams", 200)
103 current := between(t, page, `data-team-current`, `</section>`)
104 host := strings.TrimPrefix(strings.TrimPrefix(r.inst.URL, "http://"), "https://")
105 if !strings.Contains(current, `<a equipo-row-link equipo-current-team href="/work">`) || !strings.Contains(current, `<p equipo-sp-desc>`+host+`</p>`) || strings.Contains(current, "data-team-needs>") {
106 t.Error("the current team is not one row with its address and no zero count")
107 }
108 row := between(t, page, `data-team-name="Studio"`, `</li>`)
109 for _, want := range []string{
110 `<a equipo-row-link href="https://studio.example.com" rel="noreferrer">Studio</a>`,
111 `<span>studio.example.com</span>`,
112 `title="` + at.Format("2006-01-02 15:04") + ` UTC">Last signed in 4 days ago</time>`,
113 `<button type="submit" rst-btn data-quiet equipo-team-forget data-team-forget aria-label="Forget Studio">Forget</button>`,
114 } {
115 if !strings.Contains(row, want) {
116 t.Errorf("the remembered row lacks %s", want)
117 }
118 }
119 add := between(t, page, `<details equipo-team-add data-team-add>`, `</details>`)
120 if !strings.Contains(add, `<summary rst-btn>`) || strings.Index(add, `name="origin"`) > strings.Index(add, `name="name"`) || !strings.Contains(add, "Each team has its own sign-in") {
121 t.Error("Add a team is not a button over a compact form, the address first, with its help")
122 }
123 if strings.Contains(page, "Add links to other Equipo instances") || strings.Contains(page, "Forget this link") {
124 t.Error("the old paragraph or Forget this link is still on the page")
125 }
126 // Without script Forget still posts and comes back to Teams.
127 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" {
128 t.Fatalf("Forget without script: %d to %q", code, to)
129 }
130 if after := r.get(owner, "/teams", 200); strings.Contains(after, `data-team-name="Studio"`) || !strings.Contains(after, "No other teams yet.") {
131 t.Error("Forget without script did not forget, or no empty line")
132 }
133}
134
135// between is the part of page from start up to the first end after it.
136func between(t *testing.T, page, start, end string) string {
137 t.Helper()
138 i := strings.Index(page, start)
139 if i < 0 {
140 t.Fatalf("no %s", start)
141 }
142 j := strings.Index(page[i:], end)
143 if j < 0 {
144 t.Fatalf("no %s after %s", end, start)
145 }
146 return page[i : i+j]
147}
148