Files
mesh-catalog/modules/mesh-mail-web/internal/web/quiet_test.go
T
jochen af89a69670 issue 1859: the page shown after an act records nothing, so each act leaves one line
Review round 1 F1 (ADR 0517 §3, §5): a form act went back to the list or the pane, which recorded page
opened or opened again, and the script's refresh did too, so last looked became the last act and opened
counts grew. The redirect after an act carries acted=1 and the refresh an X-Mail-Refresh header; that page
records nothing. The 1860 test now follows each redirect and counts every line, and reminds the task (F2,
1858/AC9), which the store's own integration test also reads back as a date.
2026-10-22 20:26:54 +02:00

65 lines
2.6 KiB
Go

package web
// Review round 1 F1 (novox/hq ADR 0517 §3, §5: no act writes two lines): the page shown after an act — the
// redirect a form act answers, or the script's refresh — records nothing; opening the page or a mail does.
import (
"net/http"
"net/url"
"testing"
"time"
)
// followed is GET of the address a 303 named, with cookie, as a browser follows it.
func followed(t *testing.T, s http.Handler, location string, cookie *http.Cookie, header map[string]string) int {
t.Helper()
r := newGet(location, cookie)
for k, v := range header {
r.Header.Set(k, v)
}
return serve(s, r).Code
}
// 1859/AC5, 1858/AC4: a tick, undo, remind or correction, and the page it goes back to, record no line;
// the act's own line is its verb's (the reader's), so the page asks record nothing at all.
func TestThePageShownAfterAnActRecordsNothing(t *testing.T) {
for _, tc := range []struct {
path string
form url.Values
}{
{"/item", url.Values{"id": {"3"}, "item": {"task 1"}, "mode": {"everything"}, "act": {"handle"}}},
{"/item", url.Values{"id": {"3"}, "item": {"task 1"}, "mode": {"everything"}, "act": {"remind"}}},
{"/correct", url.Values{"id": {"3"}, "mode": {"work"}, "read-later": {"on"}}},
} {
reading, b := paneBundle(t)
s, cookie, token := signedIn(t, b)
tc.form.Set(FormTokenField, token)
code, _, h := post(t, s, tc.path, tc.form, cookie, false)
if code != http.StatusSeeOther {
t.Fatalf("%s: status %d", tc.path, code)
}
if code := followed(t, s, h.Get("Location"), cookie, nil); code != http.StatusOK {
t.Fatalf("%s: the page after it: status %d", tc.path, code)
}
if rec := reading.callsOf("record"); len(rec) != 0 {
t.Fatalf("%s and the page it went back to (%s) recorded %v, want nothing: the act's line is its own", tc.path, h.Get("Location"), rec)
}
}
// The script's own refresh after an act records nothing either.
reading, b := paneBundle(t)
s, cookie, _ := signedIn(t, b)
for _, path := range []string{"/?mode=everything", "/read?id=3&mode=everything"} {
followed(t, s, path, cookie, map[string]string{RefreshHeader: "1"})
}
if rec := reading.callsOf("record"); len(rec) != 0 {
t.Fatalf("the script's refreshes recorded %v, want nothing", rec)
}
// Opening the page and a mail still record one line each.
followed(t, s, "/?mode=everything", cookie, nil)
followed(t, s, "/read?id=3&mode=work", cookie, nil)
if rec := reading.callsOf("record"); len(rec) != 2 || rec[0].Args["what"] != "page opened" || rec[1].Args["what"] != "opened" {
t.Fatalf("opening the page and a mail recorded %v, want page opened then opened", rec)
}
_ = time.Now
}