Skip to content
quarry Artifact [13c7789edc]
Login

Artifact [13c7789edc]

Artifact 13c7789edcb1041fa842c52cf646fe6d60721f491dbbacd241bee5a70c7e6213:


package web

import (
	"strings"
	"testing"
)

// countHook is how many landing-number marks a render carries.
func countHook(html string) int { return strings.Count(html, `data-hook="landing-number"`) }

// Every list of landings leads each row with its !N: the flat listing,
// the queue's strata row and each rung folded under it.
func TestLandingListsShowTheNumber(t *testing.T) {
	var flat strings.Builder
	if err := noHooks.template(landingListPage).ExecuteTemplate(&flat, "l-list-body", pageData{
		Repo: "quarry", Nav: ticketNav{Repo: "quarry"},
		Landings: []landingRow{
			{ID: "aa11bb22cc33", Number: 4, Branch: "a", Target: "trunk", State: "open", Title: "A"},
			{ID: "dd44ee55ff66", Branch: "b", Target: "trunk", State: "open", Title: "B"},
		},
	}); err != nil {
		t.Fatal(err)
	}
	if n := countHook(flat.String()); n != 1 {
		t.Errorf("FAIL: the flat listing carries %d number marks, want 1 (the unnumbered row has none)", n)
	}
	base := landingRow{ID: "aa11bb22cc33", Number: 4, Branch: "a", Target: "trunk", State: "open", Title: "A", Position: 1, Depth: 2}
	top := landingRow{ID: "dd44ee55ff66", Number: 5, Branch: "b", Target: "a", State: "open", Title: "B", Position: 2, Depth: 2}
	var grouped strings.Builder
	if err := noHooks.template(landingListPage).ExecuteTemplate(&grouped, "l-list-body", pageData{
		Repo: "quarry", Nav: ticketNav{Repo: "quarry"},
		LandingGroups: []landingGroup{{landingRow: base, Segments: []landingRow{base, top}}},
	}); err != nil {
		t.Fatal(err)
	}
	if n := countHook(grouped.String()); n != 3 {
		t.Errorf("FAIL: the strata row carries %d number marks, want 3 (the row and both rungs)", n)
	}
	if !t.Failed() {
		t.Log("ok: listing rows and strata rungs lead with !N")
	}
}

// The landing page names itself by number: in its own heading, or on
// the meta line when the message has no subject to head the page with.
func TestTheLandingPageLeadsWithItsNumber(t *testing.T) {
	d := landingDetail{landingRow: landingRow{ID: "aa11bb22cc33", Number: 12, Branch: "a", Target: "trunk", State: "open", Title: "Fix it"}}
	for _, own := range []bool{true, false} {
		var buf strings.Builder
		if err := noHooks.template(landingPage).ExecuteTemplate(&buf, "landing-body", pageData{
			Title: "!12 Fix it", Repo: "quarry", Landing: &d, OwnH1: own, HideH1: !own,
		}); err != nil {
			t.Fatal(err)
		}
		html := buf.String()
		if n := countHook(html); n != 1 {
			t.Errorf("FAIL: own heading %v: %d number marks, want 1", own, n)
		}
		if got := strings.Contains(html, `<h1 class="l-title">`); got != own {
			t.Errorf("FAIL: own heading %v, but the body drew one: %v", own, got)
		}
	}
	if !t.Failed() {
		t.Log("ok: !12 heads the page, or leads the meta line under an sr-only heading")
	}
}

// The review queue names each landing by number too.
func TestTheReviewQueueShowsTheNumber(t *testing.T) {
	queue := []queueRow{{Repo: "quarry", ID: "7be08128b9420890", Number: 9, Branch: "x", Target: "trunk", Title: "X"}}
	var b strings.Builder
	if err := noHooks.template(inboxPage).ExecuteTemplate(&b, "content", pageData{Title: "inbox", AttnFilter: "landings", LandingQueue: queue}); err != nil {
		t.Fatal(err)
	}
	if n := countHook(b.String()); n != 1 {
		t.Errorf("FAIL: the queue row carries %d number marks, want 1", n)
	} else {
		t.Log("ok: the queue row leads with !9")
	}
}

// A merge row names the landing it settled by number, and so does a
// landing's own event row.
func TestTheTimelineNamesLandingsByNumber(t *testing.T) {
	var b strings.Builder
	if err := noHooks.template(timelinePage).ExecuteTemplate(&b, "tl-body", pageData{Repo: "quarry", Days: []tlDay{{
		Date: "2026-09-30",
		Rows: []tlRow{
			{Kind: "ci", Hash: strings.Repeat("a", 64), Short: "aaaaaaaaaaaa", Landing: strings.Repeat("b", 64), LandingTitle: "B", LandingNumber: 3},
			{Kind: "l", Hash: strings.Repeat("c", 64), Title: "Landing: C", LandingNumber: 4},
			{Kind: "t", Hash: strings.Repeat("d", 64), Title: "Ticket"},
		},
	}}}); err != nil {
		t.Fatal(err)
	}
	if n := countHook(b.String()); n != 2 {
		t.Errorf("FAIL: the timeline carries %d number marks, want 2 (merge and landing rows)", n)
	} else {
		t.Log("ok: the merge and the landing event name !3 and !4; the ticket row names none")
	}
}