package view import ( "fmt" "regexp" "strings" "testing" ) // The tests of the Help page that depend on who is reading it. The one that // every link of every page lands on a topic is TestEveryHelpLinkLandsOnATopic // (server_test.go). // helpViewers are the readers of the Help page and the sections each is shown. var helpViewers = []struct { name string meta Meta inbound bool groups []string }{ {"global", Meta{User: "admin", IsGlobal: true}, true, []string{"Overview", "Outbound", "Inbound", "Server", "Account"}}, {"global, inbound feature off", Meta{User: "admin", IsGlobal: true}, false, []string{"Overview", "Outbound", "Server", "Account"}}, {"domain, outbound only", Meta{User: "ops", HasOutbound: true}, true, []string{"Outbound", "Account"}}, {"domain, inbound only", Meta{User: "ops", HasInbound: true}, true, []string{"Inbound", "Account"}}, {"domain, inbound only, feature off", Meta{User: "ops", HasInbound: true}, false, []string{"Account"}}, {"domain, both", Meta{User: "ops", HasOutbound: true, HasInbound: true}, true, []string{"Outbound", "Inbound", "Account"}}, {"domain, both, feature off", Meta{User: "ops", HasOutbound: true, HasInbound: true}, false, []string{"Outbound", "Account"}}, } // Each reader is shown the sections of the pages they can open and no other, // numbered one after the other, and the menu lists the same sections. func TestHelpShowsEachRoleOnlyItsSections(t *testing.T) { groupTitle := regexp.MustCompile(`(\d+)
"), strings.Count(m[2], "
/data/antispam/`,
`With the inbound relay on there is a second number, for the Inbound log, with the same range.`)
for _, v := range helpViewers {
out := renderSignedIn(t, "help", NewHelp(v.meta, v.inbound))
shown := strings.Contains(out, `id="inbound-log"`)
if want := v.inbound && (v.meta.IsGlobal || v.meta.HasInbound); shown != want {
t.Errorf("%s: inbound log topic shown = %v, want %v", v.name, shown, want)
}
}
if HelpInboundLog != "inbound-log" || HelpFilterLists != "filter-lists" {
t.Errorf("anchors %q and %q", HelpInboundLog, HelpFilterLists)
}
}