Skip to content
quarry Artifact [895426e14c]
Login

Artifact [895426e14c]

Artifact 895426e14ca3154e27eb4601ee797cc2f801155d404b215e25de676654bccad3:


package web

import (
	"strings"
	"testing"
)

// The propose form chooses the branch first, offers each open landing
// it may land after (never its own, nor one already standing on it),
// and fills the title from the newest check-in.
func TestProposeFormOffersWhereTheBranchMayLand(t *testing.T) {
	srv := strataServer(t, strataIndex(t))
	page := asDan(t, srv, "/r/alpha/landing-new?branch=feat-c")
	for _, want := range []string{`data-hook="landing-new"`, `data-hook="landing-branch"`, `<option value="feat-c" selected>`,
		`data-hook="landing-target"`, `name="title"`, `value="top of the stack"`} {
		if !strings.Contains(page, want) {
			t.Errorf("FAIL: the form lacks %s", want)
		}
	}
	dests := page[strings.Index(page, `data-hook="landing-target"`):]
	dests = dests[:strings.Index(dests, "</fieldset>")]
	for _, id := range []string{"a1", "b2", "d4"} {
		if !strings.Contains(dests, `value="!`+strings.Repeat(id, 6)+`"`) {
			t.Errorf("FAIL: landing %s is not offered as a place to land after", id)
		}
	}
	if strings.Contains(dests, `value="!`+strings.Repeat("c3", 6)+`"`) {
		t.Error("FAIL: the branch's own landing is offered as a place to land it")
	}
	// From the bottom rung's branch, the rungs that stand on it are loops.
	base := asDan(t, srv, "/r/alpha/landing-new?branch=feat-a")
	bd := base[strings.Index(base, `data-hook="landing-target"`):]
	bd = bd[:strings.Index(bd, "</fieldset>")]
	for _, above := range []string{"b2", "c3"} {
		if strings.Contains(bd, `value="!`+strings.Repeat(above, 6)+`"`) {
			t.Errorf("FAIL: %s stands on feat-a and is offered anyway", above)
		}
	}
}

func TestLandingMessageLeadsWithTheTitle(t *testing.T) {
	for _, c := range []struct{ title, body, want string }{
		{"Cap coupons", "Fifty at most.", "Cap coupons\n\nFifty at most."},
		{"Cap coupons", "", "Cap coupons"},
		{"", "Cap coupons\n\nFifty.", "Cap coupons\n\nFifty."},
		{"Cap coupons", "Cap coupons\n\nFifty.", "Cap coupons\n\nFifty."},
	} {
		if got := landingMessage(c.title, c.body); got != c.want {
			t.Errorf("FAIL: landingMessage(%q, %q) = %q, want %q", c.title, c.body, got, c.want)
		}
	}
}