package web
import (
"os"
"path/filepath"
"strings"
"testing"
"craftdesign.group/quarry/internal/api"
)
// A LOOKING aid for the REPOSITORY board after the card became a shared
// component. The refactor is meant to change nothing here, and "the
// tests pass" does not prove that about a layout. Off unless
// QUARRY_SHOT_REPOBOARD is set.
func TestWriteRepoBoardShot(t *testing.T) {
out := os.Getenv("QUARRY_SHOT_REPOBOARD")
if out == "" {
t.Skip("QUARRY_SHOT_REPOBOARD unset")
}
if err := os.WriteFile(filepath.Join(filepath.Dir(out), "quarry.css"),
[]byte(sheet), 0o644); err != nil {
t.Fatal(err)
}
rows := []ticketSummary{
{Repo: "quarry", ID: "8318bd2819ca7f31aa", Title: "Teams: organisations that own repositories and carry grants",
Status: "Open", Priority: "Low", Assignee: "dmestas", Updated: "2026-09-13T20:10:00Z"},
{Repo: "quarry", ID: "085786dd870e4455bb", Title: "The Reader preset grants wiki and ticket editing",
Status: "Open", Priority: "High", Severity: "Important", Updated: "2026-09-13T17:05:00Z"},
{Repo: "quarry", ID: "b906985a303c1122cc", Title: "ci: supersede and label queries are exact only below the scan",
Status: "Fixed", Priority: "Medium", Assignee: "lou", Updated: "2026-09-12T11:00:00Z"},
}
vocab := api.DefaultTicketVocabulary
labels := columnLabels(rows, "status", vocab)
data := pageData{Title: "Tickets", Repo: "quarry", Section: "tickets",
Board: buildBoard(rows, "status", "", vocab, cardView{
LaneBy: "", GroupBy: "status", ColumnLabels: labels}),
GroupBy: "status", ColumnLabels: labels, SheetURL: "quarry.css",
Nav: ticketNav{Repo: "quarry", View: "board", Open: 2, Closed: 1},
}
data.allowCards(true)
var buf strings.Builder
if err := noHooks.template(ticketBoardPage).Execute(&buf, data); 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)
}
// The CROSS-TRACKER board: the same board across every tracker the
// reader can reach. Read-only on purpose — see the board branch in the
// /tickets handler — so this shot is also the check that no move
// control appears.
func TestWriteAcrossBoardShot(t *testing.T) {
out := os.Getenv("QUARRY_SHOT_ACROSSBOARD")
if out == "" {
t.Skip("QUARRY_SHOT_ACROSSBOARD unset")
}
if err := os.WriteFile(filepath.Join(filepath.Dir(out), "quarry.css"),
[]byte(sheet), 0o644); err != nil {
t.Fatal(err)
}
rows := []ticketSummary{
{Repo: "quarry", ID: "8318bd2819ca7f31aa", Title: "Teams: organisations that own repositories and carry grants",
Status: "Open", Priority: "Low", Assignee: "dmestas", Updated: "2026-09-13T20:10:00Z"},
{Repo: "zit", ID: "b906985a303c1122cc", Title: "ci: supersede and label queries are exact only below the scan",
Status: "Open", Priority: "Medium", Updated: "2026-09-13T18:40:00Z"},
{Repo: "orchard", ID: "44aa77bb11cc2233dd", Title: "Prune the graft table when a mirror is withdrawn",
Status: "Review", Priority: "High", Updated: "2026-09-13T12:00:00Z"},
{Repo: "zit", ID: "82eb641adb994411dd", Title: "An orphan tk mirror is still listed on the fleet",
Status: "Fixed", Updated: "2026-09-12T09:00:00Z"},
}
vocab := api.DefaultTicketVocabulary
labels := columnLabels(rows, "status", vocab)
data := pageData{Title: "Tickets", HideH1: true, Across: true,
Board: buildBoard(rows, "status", "", vocab, cardView{
GroupBy: "status", ColumnLabels: labels, ShowRepo: true}),
GroupBy: "status", ColumnLabels: labels, SheetURL: "quarry.css",
Nav: ticketNav{Base: "/tickets", View: "board", Open: 3, Closed: 1},
}
// Read-only: the whole point. allowCards(false) is what the handler
// does, and the shot must show what the page shows.
data.allowCards(false)
for li := range data.Board {
for ci := range data.Board[li].Columns {
col := &data.Board[li].Columns[ci]
col.Expanded = len(col.Cards) > 0
}
}
var buf strings.Builder
if err := noHooks.template(ticketBoardPage).Execute(&buf, data); 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)
}