package web
import (
"os"
"path/filepath"
"strings"
"testing"
"craftdesign.group/quarry/internal/oltp"
)
// A LOOKING aid, not a guard: writes the teams directory and one team's
// page with the real production data. Off unless QUARRY_SHOT is set.
func TestWriteTeamShots(t *testing.T) {
out := os.Getenv("QUARRY_SHOT")
if out == "" {
t.Skip("QUARRY_SHOT unset")
}
dir := filepath.Dir(out)
if err := os.WriteFile(filepath.Join(dir, "quarry.css"), []byte(sheet), 0o644); err != nil {
t.Fatal(err)
}
rows := []teamRow{
{Name: "craft-design-group", Title: "Craft Design Group",
Descr: "quarry and zit, and the tools around them", Members: 1, Repos: 0},
{Name: "firestorm-dataworks", Title: "FireStorm DataWorks",
Descr: "Data engineering and the pipelines behind it", Members: 1, Repos: 0},
}
var dirBuf strings.Builder
if err := teamsPage.Execute(&dirBuf, pageData{Title: "Teams", HideH1: true,
Explore: "teams", SheetURL: "quarry.css",
FleetTotal: 20, PeopleTotal: 3100, TeamsTotal: len(rows), Teams: rows}); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(out, []byte(dirBuf.String()), 0o644); err != nil {
t.Fatal(err)
}
// One team, populated the way it will look once repositories and
// members are in it โ an empty page shows nothing about layout.
td := teamDetail{
Team: teamRow{Name: "craft-design-group", Title: "Craft Design Group",
Descr: "quarry and zit, and the tools around them", Members: 3, Repos: 2},
Repos: []teamRepo{
{Repo: "quarry", Added: "2026-09-10T09:00:00Z"},
{Repo: "zit", Added: "2026-09-11T14:00:00Z"},
},
Members: []teamMember{
{Account: "dmestas", Owner: true, Listed: true},
{Account: "lou", Caps: oltp.Maintain.Caps(), Listed: true},
{Account: "zeitgeist", Caps: "", Listed: false},
},
CanManage: true,
}
var one strings.Builder
if err := teamPage.Execute(&one, pageData{Title: "Craft Design Group",
OwnH1: true, SheetURL: "quarry.css", Team: &td}); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, "team-one.html"), []byte(one.String()), 0o644); err != nil {
t.Fatal(err)
}
t.Logf("ok: wrote %s and team-one.html", out)
}
// The People screen, with all three routes present โ the state that
// shows whether the layout distinguishes them.
func TestWriteTeamPeopleShot(t *testing.T) {
out := os.Getenv("QUARRY_SHOT_PEOPLE")
if out == "" {
t.Skip("QUARRY_SHOT_PEOPLE unset")
}
if err := os.WriteFile(filepath.Join(filepath.Dir(out), "quarry.css"), []byte(sheet), 0o644); err != nil {
t.Fatal(err)
}
tp := teamPeople{
Team: teamRow{Name: "craft-design-group", Title: "Craft Design Group"},
Repos: 2, CanManage: true, Presets: oltp.Presets,
People: []teamPersonRow{
{Account: "dmestas", Member: true, Owner: true,
Direct: []teamDirectRow{{Repo: "quarry", Caps: "a"}, {Repo: "zit", Caps: "a"}}},
{Account: "lou", Member: true, Caps: oltp.Maintain.Caps()},
{Account: "zeitgeist", Member: true},
{Account: "calionauta", Direct: []teamDirectRow{{Repo: "quarry", Caps: "uv3bBC78"}}},
},
}
var buf strings.Builder
if err := teamPeoplePage.Execute(&buf, pageData{Title: "Craft Design Group ยท People",
OwnH1: true, SheetURL: "quarry.css", TeamPeople: &tp}); 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)
}