Skip to content
quarry Artifact [3e499bccd9]
Login

Artifact [3e499bccd9]

Artifact 3e499bccd9fe288e4757284683fa856948bb90678a58802f0485a7a07556f978:


package web

import (
	"strings"
	"testing"
	"time"
)

// Right after an update from the target, an "up-to-date" read is the
// index catching up, not landed work: the close-as-landed control is not
// drawn then (#924 was settled by it). Once the window has passed, a
// branch that really is already in its target is offered it again.
func TestNoCloseAsLandedRightAfterAnUpdate(t *testing.T) {
	render := func(at time.Time) string {
		var buf strings.Builder
		err := noHooks.template(landingPage).ExecuteTemplate(&buf, "landing-body", pageData{
			Repo: "quarry", CanTrigger: true,
			Landing: &landingDetail{
				landingRow: landingRow{ID: "aa11bb22cc33", Branch: "b", Target: "trunk", State: "open"},
				CanAccept:  true, CanReject: true, Mergeable: "up-to-date",
				Events: []landingEvent{{State: "updated", User: "dmestas", Date: at.UTC().Format("2006-01-02T15:04:05.000")}},
			},
		})
		if err != nil {
			t.Fatal(err)
		}
		return buf.String()
	}
	if got := render(time.Now()); strings.Contains(got, "landed by another route") {
		t.Error("FAIL: close-as-landed offered right after an update")
	}
	if got := render(time.Now().Add(-10 * time.Minute)); !strings.Contains(got, "landed by another route") {
		t.Error("FAIL: close-as-landed not offered for a branch already in its target")
	}
}