Skip to content
quarry Artifact [03d5baf576]
Login

Artifact [03d5baf576]

Artifact 03d5baf57613fa8fcc1e3859ca9d99a83a76990397828dd62b3ce8c6c169f0b1:


package web

import (
	"strings"
	"testing"
)

// The form must say what THIS repository does. It used to promise "New
// tickets start local to this forge" on every tracker, including one
// that had chosen the other answer — a page telling its reader the
// opposite of what it was about to do.
func TestTheNewTicketFormSaysWhereThisRepositorysTicketsGo(t *testing.T) {
	for _, c := range []struct{ tier, want, notWant string }{
		{"local", "start local to this forge", "keeps its tracker in the code history"},
		{"fossil", "keeps its tracker in the code history", "start local to this forge"},
	} {
		var b strings.Builder
		if err := noHooks.template(ticketNewPage).ExecuteTemplate(&b, "content",
			pageData{Repo: "alpha", CanAdmin: true, TicketTier: c.tier}); err != nil {
			t.Fatal(err)
		}
		got := b.String()
		if !strings.Contains(got, c.want) {
			t.Errorf("FAIL: a %q tracker does not say %q", c.tier, c.want)
		} else if strings.Contains(got, c.notWant) {
			t.Errorf("FAIL: a %q tracker also says %q", c.tier, c.notWant)
		} else {
			t.Logf("ok: a %q tracker says so", c.tier)
		}
		// And the destination agrees with the sentence beside it.
		checked := strings.Contains(got, `<option value="1" selected>`)
		if checked != (c.tier == "fossil") {
			t.Errorf("FAIL: %q tracker, box checked=%v", c.tier, checked)
		} else {
			t.Logf("ok: a %q tracker's box is checked=%v", c.tier, checked)
		}
	}
}

// The tier moves a DEFAULT and never a gate: a reader without `a` never
// sees the control at all, so a repository cannot use this setting to
// reopen the door ticket.new closed.
func TestTheTierNeverOffersTheFossilBoxToANonAdmin(t *testing.T) {
	var b strings.Builder
	if err := noHooks.template(ticketNewPage).ExecuteTemplate(&b, "content",
		pageData{Repo: "alpha", CanAdmin: false, TicketTier: "fossil"}); err != nil {
		t.Fatal(err)
	}
	if strings.Contains(b.String(), `name="fossil"`) {
		t.Error("FAIL: a non-admin is offered the fossil box on a fossil-native tracker")
	} else {
		t.Log("ok: no admin letter, no box, whatever the repository prefers")
	}
}