From a639a94753f51ca16d255c6e871e6479fcf6297f Mon Sep 17 00:00:00 2001 From: Kiryl Kaveryn Date: Tue, 16 Jul 2024 17:26:20 +0400 Subject: [PATCH] [bookmarks] [tests] unit tests for the `recently deleted` feature Signed-off-by: Kiryl Kaveryn --- map/map_tests/bookmarks_test.cpp | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/map/map_tests/bookmarks_test.cpp b/map/map_tests/bookmarks_test.cpp index cbbb27d5a4..657652b979 100644 --- a/map/map_tests/bookmarks_test.cpp +++ b/map/map_tests/bookmarks_test.cpp @@ -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