package web
import (
"strings"
"testing"
)
// A folded column is a narrow strip. It must not draw its cards: the
// strip is display:flex, so cards rendered into one lie down in a row
// and run off the page. Empty columns fold by default, which hid this
// until somebody folded a column that held tickets.
func TestAFoldedColumnDrawsNoCards(t *testing.T) {
render := func(expanded bool) string {
t.Helper()
card := cardView{T: ticketSummary{ID: strings.Repeat("a", 40), Title: "a folded card"}}
d := pageData{
Board: []boardLane{{Label: "", Count: 1, Columns: []boardColumn{{
Status: "Open", Word: "Open",
Expanded: expanded, ToggleURL: "/tickets?view=board",
Cards: []cardView{card},
}}}},
GroupBy: "status",
}
var buf strings.Builder
if err := ticketBoardPage.ExecuteTemplate(&buf, "board-body", d); err != nil {
t.Fatal(err)
}
return buf.String()
}
folded := render(false)
if !strings.Contains(folded, "board-col folded") {
t.Fatalf("the column did not fold: %s", folded)
}
if strings.Contains(folded, "a folded card") {
t.Errorf("a folded column drew its cards:\n%s", folded)
}
// Folded still names what it holds, and is still a way back open.
if !strings.Contains(folded, "unfold") {
t.Errorf("a folded column offers no way to open it:\n%s", folded)
}
open := render(true)
if strings.Contains(open, "board-col folded") {
t.Fatalf("the expanded column folded: %s", open)
}
if !strings.Contains(open, "a folded card") {
t.Errorf("an expanded column drew no cards:\n%s", open)
}
}
// Every board built outside boardData must say which columns are open:
// the zero value folds, and a folded column now draws nothing, so a
// board that forgets this renders empty rather than sideways.
func TestTheFoldDefaultOpensColumnsThatHoldTickets(t *testing.T) {
board := []boardLane{{Columns: []boardColumn{
{Status: "Open", Cards: []cardView{{T: ticketSummary{Title: "held"}}}},
{Status: "Closed"},
}}}
expandNonEmpty(board)
if !board[0].Columns[0].Expanded {
t.Error("a column holding tickets stayed folded")
}
if board[0].Columns[1].Expanded {
t.Error("an empty column was opened")
}
}