1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-07-12 16:58:36 +00:00

Sort feed categories before serialization

A function is added for feeds and its categories normalization.
The test will ensure that the order is right.
This commit is contained in:
Ilya Glotov 2019-07-05 19:05:42 +03:00
parent f783b135c7
commit c840268678
No known key found for this signature in database
GPG key ID: 5862B629BFB84D34
2 changed files with 54 additions and 17 deletions

View file

@ -40,3 +40,27 @@ func TestSerialize(t *testing.T) {
t.Error("Serialized feed is incorrect")
}
}
func TestNormalizedCategoriesOrder(t *testing.T) {
var orderTests = []struct {
naturalOrderName string
correctOrderName string
}{
{"Category 2", "Category 1"},
{"Category 3", "Category 2"},
{"Category 1", "Category 3"},
}
var subscriptions SubcriptionList
subscriptions = append(subscriptions, &Subcription{Title: "Feed 1", FeedURL: "http://example.org/feed/1", SiteURL: "http://example.org/1", CategoryName: orderTests[0].naturalOrderName})
subscriptions = append(subscriptions, &Subcription{Title: "Feed 2", FeedURL: "http://example.org/feed/2", SiteURL: "http://example.org/2", CategoryName: orderTests[1].naturalOrderName})
subscriptions = append(subscriptions, &Subcription{Title: "Feed 3", FeedURL: "http://example.org/feed/3", SiteURL: "http://example.org/3", CategoryName: orderTests[2].naturalOrderName})
feeds := normalizeFeeds(subscriptions)
for i, o := range orderTests {
if feeds.Outlines[i].Text != o.correctOrderName {
t.Fatalf("need %v, got %v", o.correctOrderName, feeds.Outlines[i].Text)
}
}
}