test(dashboard): Update tests for library filtering feature

- Update TestGetViewAllURL_SystemCollections to use collectionID and libraryID parameters
- Test both with and without library_id in URL
- Update TestBuildSections_ConvertsServiceTypesToHandlerTypes expected values
- All collections now link to /collections/{id} (system and user treated equally)
This commit is contained in:
2026-03-02 13:11:39 -05:00
parent be4230266e
commit fb6a57884d
+41 -29
View File
@@ -46,7 +46,7 @@ func TestBuildSections_ConvertsServiceTypesToHandlerTypes(t *testing.T) {
}, },
} }
result := BuildSections(serviceSections) result := BuildSections(serviceSections, "")
assert.Equal(t, 2, len(result), "should have 2 sections") assert.Equal(t, 2, len(result), "should have 2 sections")
@@ -57,13 +57,13 @@ func TestBuildSections_ConvertsServiceTypesToHandlerTypes(t *testing.T) {
assert.Equal(t, "Books you're currently reading", section1.Description, "Description should be string") assert.Equal(t, "Books you're currently reading", section1.Description, "Description should be string")
assert.Equal(t, "📖", section1.Icon, "Icon should be string") assert.Equal(t, "📖", section1.Icon, "Icon should be string")
assert.Equal(t, 1, section1.Priority, "Priority should be number") assert.Equal(t, 1, section1.Priority, "Priority should be number")
assert.Equal(t, "/section/continue-reading", section1.ViewAllURL, "ViewAllURL should match system collection") assert.Equal(t, "/collections/00000000-0000-0000-0000-000000000000", section1.ViewAllURL, "ViewAllURL should match collection URL")
section2 := result[1] section2 := result[1]
assert.Equal(t, "my-favorites", section2.ID) assert.Equal(t, "my-favorites", section2.ID)
assert.False(t, section2.IsSystem, "IsSystem should be boolean false") assert.False(t, section2.IsSystem, "IsSystem should be boolean false")
assert.Equal(t, "My Favorites", section2.Title) assert.Equal(t, "My Favorites", section2.Title)
assert.Equal(t, "", section2.ViewAllURL, "ViewAllURL should be empty for user collections") assert.Equal(t, "/collections/00000000-0000-0000-0000-000000000000", section2.ViewAllURL, "ViewAllURL should be set for user collections")
} }
func TestBuildSections_ConvertsItemsCorrectly(t *testing.T) { func TestBuildSections_ConvertsItemsCorrectly(t *testing.T) {
@@ -90,7 +90,7 @@ func TestBuildSections_ConvertsItemsCorrectly(t *testing.T) {
}, },
} }
result := BuildSections(serviceSections) result := BuildSections(serviceSections, "")
assert.Equal(t, 1, len(result), "should have 1 section") assert.Equal(t, 1, len(result), "should have 1 section")
section := result[0] section := result[0]
@@ -136,46 +136,58 @@ func TestTextToString_Valid(t *testing.T) {
func TestGetViewAllURL_SystemCollections(t *testing.T) { func TestGetViewAllURL_SystemCollections(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
collectionName string collectionID string
queryType string libraryID string
expected string expected string
}{ }{
{ {
name: "continue-reading", name: "continue-reading with no library",
collectionName: "continue-reading", collectionID: "continue-reading",
queryType: "continue-reading", libraryID: "",
expected: "/section/continue-reading", expected: "/collections/continue-reading",
}, },
{ {
name: "recently-added", name: "continue-reading with library",
collectionName: "recently-added", collectionID: "continue-reading",
queryType: "recently-added", libraryID: "lib-123",
expected: "/section/recently-added", expected: "/collections/continue-reading?library_id=lib-123",
}, },
{ {
name: "recently-read", name: "recently-added with no library",
collectionName: "recently-read", collectionID: "recently-added",
queryType: "recently-read", libraryID: "",
expected: "/history", expected: "/collections/recently-added",
}, },
{ {
name: "not-started", name: "recently-read with library",
collectionName: "not-started", collectionID: "recently-read",
queryType: "not-started", libraryID: "lib-456",
expected: "/section/not-started", expected: "/collections/recently-read?library_id=lib-456",
}, },
{ {
name: "user collection", name: "not-started with no library",
collectionName: "my-favorites", collectionID: "not-started",
queryType: "filter", libraryID: "",
expected: "", expected: "/collections/not-started",
},
{
name: "user collection with library",
collectionID: "my-favorites",
libraryID: "lib-789",
expected: "/collections/my-favorites?library_id=lib-789",
},
{
name: "empty collection ID",
collectionID: "",
libraryID: "lib-123",
expected: "",
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
result := getViewAllURL(tt.collectionName) result := getViewAllURL(tt.collectionID, tt.libraryID)
assert.Equal(t, tt.expected, result, "getViewAllURL mismatch") assert.Equal(t, tt.expected, result, "getViewAllURL mismatch")
}) })
} }