package web
import (
"fmt"
"net/url"
"strings"
"testing"
)
// An axis with more values than a menu can hold is a search box offering
// the busiest few: tcl's 1,152 authors were 43 KB of options on every
// ticket list (jva, 2026-10-30). A short axis stays a menu, and a value
// chosen outside the suggestions is still the one selected.
func TestALongFacetIsASearchBoxOfTheBusiest(t *testing.T) {
var authors []ticketFacet
for i := 0; i < 60; i++ {
authors = append(authors, ticketFacet{Value: fmt.Sprintf("a%02d", i), Open: i})
}
subs := []ticketFacet{{Value: "web", Open: 3}, {Value: "db", Open: 9}}
cs := ticketFilters(nil, subs, authors, url.Values{"author": {"a00"}})
got := map[string]ticketFilterControl{}
for _, c := range cs {
got[c.Key] = c
}
a := got["author"]
if !a.Search || len(a.Options) != facetSuggested || a.Options[0] != "a59" || a.Options[29] != "a30" {
t.Errorf("FAIL: authors: search %v, %d options from %q to %q", a.Search, len(a.Options), a.Options[0], a.Options[len(a.Options)-1])
}
if a.Selected != "a00" {
t.Errorf("FAIL: an author outside the suggestions lost its selection: %q", a.Selected)
}
if s := got["subsystem"]; s.Search || strings.Join(s.Options, ",") != "web,db" {
t.Errorf("FAIL: a short axis changed: search %v options %v", s.Search, s.Options)
}
}