Skip to content

Commit

Permalink
[bookmarks] [tests] unit tests for the recently deleted feature
Browse files Browse the repository at this point in the history
Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
  • Loading branch information
kirylkaveryn authored and biodranik committed Aug 15, 2024
1 parent ea7a17b commit a639a94
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions map/map_tests/bookmarks_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1530,4 +1530,46 @@ UNIT_CLASS_TEST(Runner, Bookmarks_BrokenFile)
auto kmlData = LoadKmlFile(fileName, KmlFileType::Binary);
TEST(kmlData == nullptr, ());
}

UNIT_CLASS_TEST(Runner, Bookmarks_RecentlyDeleted)
{
BookmarkManager bmManager(BM_CALLBACKS);
bmManager.EnableTestMode(true);
auto const dir = GetBookmarksDirectory();
bool const delDirOnExit = Platform::MkDir(dir) == Platform::ERR_OK;
SCOPE_GUARD(dirDeleter, [&](){ if (delDirOnExit) (void)Platform::RmDir(dir); });

std::string const filePath = base::JoinPath(dir, "file" + std::string{kKmlExtension});
BookmarkManager::KMLDataCollection kmlDataCollection;
kmlDataCollection.emplace_back(filePath, LoadKmlData(MemReader(kmlString, std::strlen(kmlString)), KmlFileType::Text));

FileWriter w(filePath);
w.Write(kmlDataCollection.data(), kmlDataCollection.size());

TEST(kmlDataCollection.back().second, ());
bmManager.CreateCategories(std::move(kmlDataCollection));
TEST_EQUAL(bmManager.GetBmGroupsCount(), 1, ());
TEST_EQUAL(bmManager.GetRecentlyDeletedCategoriesCount(), 0, ());

auto const groupId = bmManager.GetUnsortedBmGroupsIdList().front();

bmManager.GetEditSession().DeleteBmCategory(groupId, false /* permanently */);
TEST_EQUAL(bmManager.GetBmGroupsCount(), 0, ());

auto const deletedCategories = bmManager.GetRecentlyDeletedCategories();
TEST_EQUAL(deletedCategories->size(), 1, ());
TEST_EQUAL(bmManager.GetRecentlyDeletedCategoriesCount(), 1, ());

auto const & deletedCategory = deletedCategories->front();
auto const deletedFilePath = deletedCategory.first;
TEST_EQUAL(base::FileNameFromFullPath(deletedCategory.first), base::FileNameFromFullPath(filePath), ());

bmManager.DeleteRecentlyDeletedCategoriesAtPaths({ deletedFilePath });
TEST_EQUAL(bmManager.GetBmGroupsCount(), 0, ());
TEST_EQUAL(bmManager.GetRecentlyDeletedCategoriesCount(), 0, ());
TEST_EQUAL(bmManager.GetRecentlyDeletedCategories()->size(), 0, ());

TEST(!Platform::IsFileExistsByFullPath(filePath), ());
TEST(!Platform::IsFileExistsByFullPath(deletedFilePath), ());
}
} // namespace bookmarks_test

0 comments on commit a639a94

Please sign in to comment.