Skip to content
quarry Artifact [b8b7de5bde]
Login

Artifact [b8b7de5bde]

Artifact b8b7de5bdebc6d2de1f6ac2f53603acd30bc33489498f4c1ada1d60881fe9f98:


package web

import (
	"encoding/json"
	"strings"
	"testing"
)

func renderLandingBody(t *testing.T, d *landingDetail) string {
	t.Helper()
	var buf strings.Builder
	if err := noHooks.template(landingPage).ExecuteTemplate(&buf, "landing-body", pageData{Repo: "quarry", Landing: d}); err != nil {
		t.Fatal(err)
	}
	return buf.String()
}

// A rung above the bottom of a stack says its "clean" was probed
// against the rung below, not the trunk it will meet — the probe is
// pairwise and nobody should read clean as will-land (1f8c4148, shape
// 3; the chain probe is zit#211). The bottom rung, and a standalone
// landing, say nothing of the kind.
func TestAStackedRungSaysWhatItsProbeWasAgainst(t *testing.T) {
	top := &landingDetail{landingRow: landingRow{ID: "cccc2222cccc", Branch: "feature-b", Target: "feature-a", State: "open"}}
	top.Mergeable = "clean"
	if err := json.Unmarshal([]byte(`{"base":"bbbb1111bbbb","top":"cccc2222cccc","segments":[
		{"id":"bbbb1111bbbb","branch":"feature-a","target":"trunk","position":1,"landable":true},
		{"id":"cccc2222cccc","branch":"feature-b","target":"feature-a","position":2}]}`), &top.Stack); err != nil {
		t.Fatal(err)
	}
	got := renderLandingBody(t, top)
	if !strings.Contains(got, `data-hook="probed-against-rung-below"`) || !strings.Contains(got, "<code>trunk</code>") {
		t.Fatal("FAIL: a stacked rung does not say its probe was against the rung below")
	}
	t.Log("ok: the top rung names feature-a as what it was probed against and trunk as what is unknown")

	base := &landingDetail{landingRow: landingRow{ID: "bbbb1111bbbb", Branch: "feature-a", Target: "trunk", State: "open"}}
	base.Mergeable = "clean"
	base.Stack = top.Stack
	if strings.Contains(renderLandingBody(t, base), `data-hook="probed-against-rung-below"`) {
		t.Fatal("FAIL: the bottom rung, probed against trunk itself, carries the label")
	}
	alone := &landingDetail{landingRow: landingRow{ID: "dddd", Branch: "fix", Target: "trunk", State: "open"}}
	alone.Mergeable = "clean"
	if strings.Contains(renderLandingBody(t, alone), `data-hook="probed-against-rung-below"`) {
		t.Fatal("FAIL: a standalone landing carries the label")
	}
	t.Log("ok: the bottom rung and a standalone landing say nothing")
}