Skip to content
quarry Artifact [224ee6a042]
Login

Artifact [224ee6a042]

Artifact 224ee6a0423acbbe33ffce0c49e36d45fddbfce1d2cdad8febdde8e2b2f97d9e:


package web

import (
	"strings"
	"testing"
)

// A failing trunk puts a dot inside the Timeline tab; a passing one
// leaves the tab exactly as it was.
func TestAFailingTrunkMarksTheTimelineTab(t *testing.T) {
	link := navlink("/r/q", "timeline", "Timeline", "", true, 12)
	if got := withdot(link, false); got != link {
		t.Errorf("FAIL: a green trunk changed the tab: %s", got)
	}
	got := string(withdot(link, true))
	i, j := strings.Index(got, `data-hook="trunk-red"`), strings.LastIndex(got, "</a>")
	if i < 0 || j < i {
		t.Errorf("FAIL: a red trunk has no dot inside the tab: %s", got)
	}
}

// Just accepted, the merge's run is still going: the record says the
// merge is being checked, not that the branch's checks passed.
func TestAnAcceptedLandingSaysItsMergeIsBeingChecked(t *testing.T) {
	l := landingDetail{MergeCI: "ci-run", MergeCIRun: "run1"}
	l.State = "accepted"
	s := l.ChecksSummary()
	if s.State != "wait" || !s.Merge {
		t.Errorf("FAIL: a running merge reads as %+v", s)
	}
}

// Settled, the merge's own run is the row under the merge headline,
// and the branch's premerge rows say they were before landing: the
// two used to sit together, the merge's run linked nowhere.
func TestASettledLandingLinksTheMergeRunAndLabelsPremergeRows(t *testing.T) {
	var buf strings.Builder
	if err := noHooks.template(landingPage).ExecuteTemplate(&buf, "landing-body", pageData{
		Repo: "quarry",
		Landing: &landingDetail{
			landingRow: landingRow{ID: "aa11bb22cc33", Branch: "b", Target: "trunk", State: "accepted"},
			MergeCI:    "ci-pass", MergeCIRun: "27b8a1a6977a0000",
			Checks: []ciRunRow{{RunID: "b9b44233ba4d0000", Workflow: "test", Status: "cancelled"}},
		},
	}); err != nil {
		t.Fatal(err)
	}
	got := buf.String()
	for _, want := range []string{`data-hook="merge-run"`, `/ci/run/27b8a1a6977a"`, `data-hook="premerge-label"`} {
		if !strings.Contains(got, want) {
			t.Errorf("FAIL: settled landing lacks %s", want)
		}
	}
	if i, j := strings.Index(got, `data-hook="merge-run"`), strings.Index(got, `data-hook="premerge-label"`); i > j {
		t.Error("FAIL: the premerge label comes before the merge run")
	}
	if got := recordBody(t, "open", "x"); strings.Contains(got, `data-hook="merge-run"`) || strings.Contains(got, `data-hook="premerge-label"`) {
		t.Error("FAIL: an open record shows merge-run markers")
	}
}