package web
import (
"strings"
"testing"
"time"
)
// Right after Update from trunk the new tip has no runs yet: they are
// dispatched once the poller folds the merge. Re-run is not offered in
// that gap; once it has passed, a required check with no run offers
// Re-run again, as the only way to start one.
func TestReRunIsHiddenWhileAnUpdatesRunsAreDispatched(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"},
Required: []string{"quarry"},
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, "/ci/trigger") {
t.Error("FAIL: Re-run offered while the update's runs are being dispatched")
}
if got := render(time.Now().Add(-10 * time.Minute)); !strings.Contains(got, "/ci/trigger") {
t.Error("FAIL: Re-run not offered for a required check that never ran")
}
}