fix(ui): derive Library Type dropdowns from library_types — audiobooks was missing
The audiobook library type shipped backend-complete (LibraryTypeAudiobooks constant, allowed extensions, MIME map, schema seed row, GET /api/libraries/types) but neither create-library form offered it: the admin Create Library modal and the setup wizard's add-library step both hardcoded their <option> lists to the original three types (ebooks/comics/manga), so an audiobook library could not be created from the UI. Both dropdowns now render from the same DB-backed library_types table the create API resolves types against — a future type appears without template edits (the exact drift the rendering-ownership rule warns about): - templates/utils.go: OrderedLibraryTypes pins the historical dropdown order (ebooks, comics, manga, audiobooks) and appends unknown future types by name; LibraryTypeDisplayName renders labels with a capitalize-the-name fallback for types added without a label - templates/admin_library.templ: new LibraryTypeOptions fragment used by the modal's select; AdminLibrary takes the types list - templates/setup.templ: Setup takes the types list, same fragment - internal/router/helpers.go: libraryTypeOptionsFor fetches via LibraryService.GetLibraryTypes, falling back to the built-in type names on DB failure so the forms stay usable (CreateLibrary still resolves the name against the DB, so the fallback is never authoritative) - internal/router/frontend.go, internal/router/setup.go: pass the list into the two pages Tests: - templates/utils_test.go: pure unit tests for ordering + labels - cmd/server/tests/admin_library_page_test.go: SSR regression — /admin/library must offer all four library types, audiobooks exactly once (options come from the DB loop, not a hardcode)
This commit is contained in:
1 parent
327fc2c0f9
commit
9e831085ef
10 files changed
+593
-346
No files matched your search
+42
-1
@@ -1,6 +1,10 @@
|
||||
package templates
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"bookhoard/internal/database"
|
||||
)
|
||||
|
||||
func TestGroupTunableSettings(t *testing.T) {
|
||||
entries := []SettingEntry{
|
||||
@@ -54,3 +58,40 @@ func TestThemeCheckClass(t *testing.T) {
|
||||
t.Errorf("inactive theme should be hidden, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// The library-type dropdown renders from DB rows; ordering and labels are
|
||||
// presentation policy (OrderedLibraryTypes / LibraryTypeDisplayName).
|
||||
func TestOrderedLibraryTypes(t *testing.T) {
|
||||
// The DB query returns ORDER BY name; the dropdown must not reshuffle
|
||||
// the historical UI order, and unknown (future) types append by name.
|
||||
types := []database.LibraryTypes{
|
||||
{Name: "audiobooks"}, {Name: "comics"}, {Name: "ebooks"},
|
||||
{Name: "manga"}, {Name: "videos"},
|
||||
}
|
||||
got := OrderedLibraryTypes(types)
|
||||
want := []string{"ebooks", "comics", "manga", "audiobooks", "videos"}
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("got %d types, want %d", len(got), len(want))
|
||||
}
|
||||
for i, name := range want {
|
||||
if got[i].Name != name {
|
||||
t.Errorf("position %d = %q, want %q", i, got[i].Name, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibraryTypeDisplayName(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"ebooks": "Ebooks",
|
||||
"comics": "Comics",
|
||||
"manga": "Manga",
|
||||
"audiobooks": "Audiobooks",
|
||||
"videos": "Videos", // unknown type: capitalized fallback
|
||||
"": "",
|
||||
}
|
||||
for name, want := range cases {
|
||||
if got := LibraryTypeDisplayName(name); got != want {
|
||||
t.Errorf("LibraryTypeDisplayName(%q) = %q, want %q", name, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user