Skip to content
quarry Artifact [098f2a316b]
Login

Artifact [098f2a316b]

Artifact 098f2a316be1c73549befd812cdff8c2dbd3e3d20156945fbb2af13ed97a75bf:


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, `data-hook="close-as-landed"`) {
		t.Error("FAIL: close-as-landed offered right after an update")
	}
	if got := render(time.Now().Add(-10 * time.Minute)); !strings.Contains(got, `data-hook="close-as-landed"`) {
		t.Error("FAIL: close-as-landed not offered for a branch already in its target")
	}
}