Skip to content
quarry Artifact [7f7b5cdc1f]
Login

Artifact [7f7b5cdc1f]

Artifact 7f7b5cdc1fb0810aac43fb0cdb8ea65c6e0c4fc00403070bf1df8105484bedc8:


package web

import (
	"bytes"
	"strings"
	"testing"
)

// A record whose branch is already on its target has nothing left to
// merge; the page said to Reject it and offered only a dead Accept, with
// the working control out of sight at the foot of the thread. The
// settling control belongs in the decide box, for who may settle it.
func TestALandedRecordOffersToCloseWhereItSaysSo(t *testing.T) {
	render := func(canReject bool) string {
		d := landingDetail{
			landingRow: landingRow{ID: strings.Repeat("b", 64), Branch: "work",
				Target: "trunk", State: "open"},
			CanAccept: true, CanReject: canReject, Mergeable: "up-to-date",
		}
		if got := d.AcceptState(); got != "landed" {
			t.Fatalf("FAIL: fixture produced state %q, not landed", got)
		}
		var buf bytes.Buffer
		if err := noHooks.template(landingPage).Execute(&buf, pageData{Title: "Landing", Repo: "quarry",
			Section: "landings", Landing: &d}); err != nil {
			t.Fatal(err)
		}
		return buf.String()
	}

	html := render(true)
	i := strings.Index(html, `data-hook="close-as-landed"`)
	if i < 0 {
		t.Fatal("FAIL: a landed record offers no close control to who may reject")
	}
	tag := html[i:]
	tag = tag[:strings.Index(tag, ">")]
	if strings.Contains(tag, "disabled") {
		t.Errorf("FAIL: the close control is disabled: %s", tag)
	}
	if !strings.Contains(tag, `/landing/`+strings.Repeat("b", 12)+`/reject"`) {
		t.Errorf("FAIL: the close control does not post to this record's reject: %s", tag)
	}
	if !strings.Contains(html[:i], `type="hidden" name="message"`) {
		t.Error("FAIL: closing carries no remark saying why the record settled")
	}
	t.Log("ok: a landed record is closed from the decide box")

	if strings.Contains(render(false), `data-hook="close-as-landed"`) {
		t.Error("FAIL: the close control is offered to someone who may not reject")
	}
}