[bookmarks] [tests] unit tests for the recently deleted feature

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn 2024-07-16 17:26:20 +04:00 committed by Alexander Borsuk
parent ea7a17ba68
commit a639a94753

View file

@ -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