summaryrefslogtreecommitdiffstats
path: root/test/feedcontainer.cpp
diff options
context:
space:
mode:
authortau3 <smr.oznob@gmail.com>2021-04-09 02:18:36 +0400
committertau3 <smr.oznob@gmail.com>2021-04-09 02:18:36 +0400
commitb9de2ab2f708cd07b368ae9cf11ce5817fdfb48e (patch)
treec0fc8f28db21fbec8b44cbd8b4b0246d4f14a64d /test/feedcontainer.cpp
parent77cd6b96609688ba8910799623f50c70053e9baa (diff)
commit after reset
Diffstat (limited to 'test/feedcontainer.cpp')
-rw-r--r--test/feedcontainer.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/feedcontainer.cpp b/test/feedcontainer.cpp
index a66cd419..8e34df62 100644
--- a/test/feedcontainer.cpp
+++ b/test/feedcontainer.cpp
@@ -382,6 +382,60 @@ TEST_CASE("sort_feeds() sorts by number of articles in a feed "
}
}
+TEST_CASE("sort_feeds() and keep in-group order", "[FeedContainer]")
+{
+ ConfigContainer cfg;
+ Cache rsscache(":memory:", &cfg);
+
+ const std::map<std::string, int> name_to_unreads = {
+ {"a", 3}, {"b", 2}, {"c", 1}, {"d", 1}, {"e", 1}
+ };
+
+ std::vector<std::shared_ptr<RssFeed>> feeds;
+ for (const auto& entry : name_to_unreads) {
+ const auto feed = std::make_shared<RssFeed>(&rsscache, "");
+ feed->set_title(entry.first);
+ for (int i = 0; i < entry.second; ++i) {
+ feed->add_item(std::make_shared<RssItem>(&rsscache));
+ }
+ feeds.push_back(feed);
+ }
+ FeedContainer feedcontainer;
+ feedcontainer.set_feeds(feeds);
+
+ FeedSortStrategy strategy;
+ strategy.sm = FeedSortMethod::UNREAD_ARTICLE_COUNT;
+ SECTION("acsending order") {
+ strategy.sd = SortDirection::ASC;
+ feedcontainer.sort_feeds(strategy);
+ const auto sorted_feeds = feedcontainer.get_all_feeds();
+
+ std::vector<std::string> actual;
+ for (const auto& feed : sorted_feeds) {
+ auto title = feed->title();
+ actual.push_back(title);
+ }
+
+ const std::vector<std::string> expected = {"a", "b", "c", "d", "e"};
+ REQUIRE(expected == actual);
+ }
+
+ SECTION("descending order") {
+ strategy.sd = SortDirection::DESC;
+ feedcontainer.sort_feeds(strategy);
+ const auto sorted_feeds = feedcontainer.get_all_feeds();
+
+ std::vector<std::string> actual;
+ for (const auto& feed : sorted_feeds) {
+ auto title = feed->title();
+ actual.push_back(title);
+ }
+
+ const std::vector<std::string> expected = {"c", "d", "e", "b", "a"};
+ REQUIRE(expected == actual);
+ }
+}
+
TEST_CASE("sort_feeds() sorts by number of unread articles if `feed-sort-order` "
"is \"unreadarticlecount\"",
"[FeedContainer]")