package web
import (
"bytes"
"strings"
"testing"
)
// The recent renders can be narrowed to one surface. The control rides
// the page's own form, and the live refresh asks with the page's query
// so a tick does not reset it.
func TestOpsRecentRendersHaveASurfaceFilter(t *testing.T) {
var b bytes.Buffer
if err := noHooks.template(opsPage).Execute(&b, pageData{Ops: opsView{Surface: "api"}, FleetTab: "ops"}); err != nil {
t.Fatal(err)
}
html := b.String()
i := strings.Index(html, `data-hook="ops-surface-filter"`)
if i < 0 {
t.Fatal("no surface filter control on the ops page")
}
ctl := html[strings.LastIndex(html[:i], "<select"):]
ctl = ctl[:strings.Index(ctl, "</select>")]
for _, want := range []string{`name="surface"`, `form="ops-controls"`, `value=""`,
`value="web"`, `value="api" selected`} {
if !strings.Contains(ctl, want) {
t.Errorf("surface control lacks %s:\n%s", want, ctl)
}
}
if !strings.Contains(html, `id="ops-controls"`) {
t.Error("the control names a form the page does not have")
}
if !strings.Contains(html, `@get('/fleet/ops.sse' + location.search)`) {
t.Error("the live refresh does not carry the page's query")
}
}