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)
}