Skip to content
quarry Artifact [108798f4da]
Login

Artifact [108798f4da]

Artifact 108798f4da93af17e75347cda6e228d0f96b7cfa05b59cb4b6f1cc9dab95faf6:


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(canAccept, canReject bool) string {
		d := landingDetail{
			landingRow: landingRow{ID: strings.Repeat("b", 64), Branch: "work",
				Target: "trunk", State: "open"},
			CanAccept: canAccept, CanReject: canReject, Mergeable: "up-to-date",
		}
		if got := d.AcceptState(); canAccept && 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()
	}

	// Who may accept closes it as accepted, as a branch merged by hand
	// reads (dmestas, after jva's ^2641): one end state for landed work.
	html := render(true, true)
	i := strings.Index(html, `data-hook="close-as-landed"`)
	if i < 0 {
		t.Fatal("FAIL: a landed record offers no close control")
	}
	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)+`/accept"`) {
		t.Errorf("FAIL: the close control does not post to this record's accept: %s", tag)
	}
	t.Log("ok: closed as accepted by who may accept")

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