package web
import (
"encoding/json"
"strings"
"testing"
)
// #381: a stack whose middle rung conflicts lands the rungs below it,
// and the strip says so instead of "nothing in this stack lands".
func TestAStoppedStackSaysWhatLandingLands(t *testing.T) {
render := func(landCount int) string {
var stack stackView
if err := json.Unmarshal([]byte(`{"segments":[
{"id":"r1aaaaaaaaaa","number":1,"position":1,"state":"open"},
{"id":"r2aaaaaaaaaa","number":2,"position":2,"state":"open","preflight":"conflict","preflightConflicts":["s2.txt"]},
{"id":"r3aaaaaaaaaa","number":3,"position":3,"state":"open"}],
"preflight":"stops","stopsAt":2,"landTo":"r1aaaaaaaaaa","landCount":`+itoa(landCount)+`}`), &stack); err != nil {
t.Fatal(err)
}
var buf strings.Builder
if err := noHooks.template(landingPage).ExecuteTemplate(&buf, "landing-body", pageData{Repo: "quarry",
Landing: &landingDetail{landingRow: landingRow{ID: "r3aaaaaaaaaa", Branch: "s3", Target: "s2", State: "open"},
Position: 3, Stack: stack}}); err != nil {
t.Fatal(err)
}
return buf.String()
}
got := render(1)
if !strings.Contains(got, `data-hook="stack-stops-lands" data-count="1"`) || strings.Contains(got, "Nothing in this stack lands") {
t.Error("FAIL: a stack that lands its bottom rung says nothing in it lands")
}
if got := render(0); !strings.Contains(got, `data-hook="stack-stops-lands" data-count="0"`) {
t.Error("FAIL: a stack stopped at its base does not say nothing lands")
}
}