package web
import (
"os"
"path/filepath"
"strings"
"testing"
)
// A LOOKING aid for /me at phone width — the sessions table in its
// stacked form and the push control, both of which are laid out by
// rules that only apply below 40rem. Off unless QUARRY_SHOT_ACCOUNT is
// set. Two real user-agent strings, because the point of the device
// name is that it replaces one.
func TestWriteAccountShot(t *testing.T) {
out := os.Getenv("QUARRY_SHOT_ACCOUNT")
if out == "" {
t.Skip("QUARRY_SHOT_ACCOUNT unset")
}
if err := os.WriteFile(filepath.Join(filepath.Dir(out), "quarry.css"),
[]byte(sheet), 0o644); err != nil {
t.Fatal(err)
}
const iphone = "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) " +
"AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.0 Mobile/15E148 Safari/604.1"
const mac = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) " +
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36"
me := meView{Name: "dmestas", Created: "2026-06-01T00:00:00Z",
Email: accountEmailView{Available: true, Confirmed: "[email protected]",
Status: "confirmed"},
Sessions: []sessionRow{
{ID: "s1", Created: "2026-09-12T14:00:00Z", LastSeen: "2026-09-12T19:00:00Z",
IP: "2a09:bac3:bdd1:2e46::49c:5", Agent: iphone},
{ID: "s2", Created: "2026-09-12T12:00:00Z", LastSeen: "2026-09-12T15:00:00Z",
IP: "2a09:bac3:bdd6:2628::3cd:19", Agent: iphone},
},
Notify: &prefsView{
// A full matrix, because an empty one is exactly as wide as
// the page and proves nothing about the width the real one
// takes. Three channels and a timing column is what an
// account actually sees.
Columns: []prefCol{{Key: "inapp", Label: "in-page"},
{Key: "email", Label: "email"}, {Key: "push", Label: "push"}},
Rows: []prefRow{
{Family: "mention", Label: "Mentions of me", Timing: "as it happens",
Cells: []prefCell{{Name: "mention.inapp", Column: "inapp", On: true},
{Name: "mention.email", Column: "email"},
{Name: "mention.push", Column: "push", On: true}}},
{Family: "landing", Label: "Landings I may accept", Timing: "as it happens",
Cells: []prefCell{{Name: "landing.inapp", Column: "inapp", On: true},
{Name: "landing.email", Column: "email", On: true},
{Name: "landing.push", Column: "push"}}},
{Family: "ticket", Label: "Tickets I follow", Timing: "batched",
Digest: true, Selected: "daily", Chosen: true,
Options: []prefDigestOption{{Value: "", Label: "the forge's window"},
{Value: "daily", Label: "daily", On: true},
{Value: "weekly", Label: "weekly"}},
Cells: []prefCell{{Name: "ticket.inapp", Column: "inapp", On: true},
{Name: "ticket.email", Column: "email"},
{Name: "ticket.push", Column: "push"}}},
},
Push: pushView{State: "on", Words: "enabled", Devices: []pushDeviceRow{
{Hash: "h1", UA: iphone, At: "2026-09-12T11:00:00Z"},
{Hash: "h2", UA: mac, At: "2026-09-08T09:00:00Z", Pending: true},
}},
},
}
var buf strings.Builder
if err := mePageTmpl.Execute(&buf, pageData{Title: "dmestas", HideH1: true,
SheetURL: "quarry.css", User: "dmestas", Me: &me}); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(out, []byte(buf.String()), 0o644); err != nil {
t.Fatal(err)
}
t.Logf("ok: wrote %s", out)
}