package web
import (
"html/template"
"strings"
"testing"
)
// The three administrative tables are grids on a mouse and label-value pairs
// on a phone, where the media query drops the .thead and prints each cell's
// data-label as its prefix instead. Without the attribute the collapsed row
// renders as bare figures — "1200.25 3d 4", "12 40 6h" — which no reader can
// decode, and nothing in Go or in a desktop render says so. Every cell whose
// only column heading was the .thead is asserted here.
func TestAdminTablesLabelCollapsedCells(t *testing.T) {
tmpl, err := template.ParseFS(templateFS, "templates/*.html")
if err != nil {
t.Fatalf("ParseFS: %v", err)
}
cases := []struct {
name string
data any
want []string
}{
{
"series-row",
seriesRowView{Key: "asura:x", Title: "Chronicles", Site: "asura", Ch: "1200.25", Age: "3d", Readers: 4},
[]string{`data-label="ch"`, `data-label="checked"`, `data-label="readers"`},
},
{
"lanes",
lanesView{Rows: []laneRow{{Site: "asura", Due: 12, Checked: 40, Gap: "6h", Ran: "4m ago"}}},
[]string{`data-label="due"`, `data-label="checked"`, `data-label="gap"`},
},
{
// The Site table's figures are a range over one slice, so their
// labels are the ones overviewView puts on the figs.
"overview",
overviewView{Sites: []siteRow{{Site: "asura", Figs: []fig{
{Label: "series", Href: "/admin/series", Count: 143},
{Label: "stale", Count: 0},
}}}},
[]string{`data-label="series"`, `data-label="stale"`},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
var out strings.Builder
if err := tmpl.ExecuteTemplate(&out, tc.name, tc.data); err != nil {
t.Fatalf("ExecuteTemplate: %v", err)
}
for _, want := range tc.want {
if !strings.Contains(out.String(), want) {
t.Errorf("missing %s: the collapsed phone row renders this cell as a bare figure", want)
}
}
})
}
}