Internal
Public Access
Add Delete Folder to the profile tree context menu
ProfileRepository::deleteFolder() removes a folder without ever deleting
the profiles or subfolders inside it -- everything directly under the
deleted folder shifts up to take its place (its parent, or the top level
if it had none), exactly as if that one path segment were removed from
each affected path. This is a labels-only operation (a "folder" is just a
grouping string on each profile, not a container that owns them), so
that's the least-surprising behavior versus silently bulk-deleting saved
connections.
Right-clicking a folder in the tree now offers "Delete Folder"; if it
isn't empty, a confirmation states exactly how many profiles/subfolders
will move and to where.
Covered by 7 new unit tests, which caught the same class of bug fixed in
3fab2f9: the new code's own folder-path remap also bound an unguarded
null QString (a folder moving to root) against the `folder_path NOT
NULL` column.
Fixes #20.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -61,6 +61,12 @@ private slots:
|
||||
void folderCreateAndListRoundTrips();
|
||||
void folderCreateIgnoresDuplicates();
|
||||
void folderPathIsNormalized();
|
||||
void deleteEmptyFolderRemovesIt();
|
||||
void deleteFolderMovesDirectProfilesToParent();
|
||||
void deleteRootLevelFolderMovesProfilesToRoot();
|
||||
void deleteFolderShiftsSubfoldersAndTheirProfilesUp();
|
||||
void deleteFolderRejectsEmptyPath();
|
||||
void deleteNonexistentFolderSucceedsAsNoOp();
|
||||
|
||||
private:
|
||||
std::unique_ptr<QTemporaryDir> m_tempDir;
|
||||
@@ -284,5 +290,86 @@ void TestProfileRepository::folderPathIsNormalized()
|
||||
QCOMPARE(folders[0], QStringLiteral("Work/Servers"));
|
||||
}
|
||||
|
||||
void TestProfileRepository::deleteEmptyFolderRemovesIt()
|
||||
{
|
||||
QVERIFY(m_repo->createFolder(QStringLiteral("Empty")));
|
||||
QVERIFY(m_repo->deleteFolder(QStringLiteral("Empty")));
|
||||
QCOMPARE(m_repo->listFolders().size(), size_t(0));
|
||||
}
|
||||
|
||||
void TestProfileRepository::deleteFolderMovesDirectProfilesToParent()
|
||||
{
|
||||
QVERIFY(m_repo->createFolder(QStringLiteral("Work")));
|
||||
Profile profile = makeSshProfile();
|
||||
profile.folderPath = QStringLiteral("Work");
|
||||
const std::optional<Profile> created = m_repo->createProfile(profile);
|
||||
QVERIFY(created.has_value());
|
||||
|
||||
QVERIFY(m_repo->deleteFolder(QStringLiteral("Work")));
|
||||
QCOMPARE(m_repo->listFolders().size(), size_t(0));
|
||||
|
||||
const std::optional<Profile> fetched = m_repo->getProfile(created->id);
|
||||
QVERIFY(fetched.has_value());
|
||||
// Deleting a folder is never destructive to profiles -- they shift up
|
||||
// to take its place, here landing at the root since "Work" had no
|
||||
// parent of its own.
|
||||
QCOMPARE(fetched->folderPath, QString());
|
||||
}
|
||||
|
||||
void TestProfileRepository::deleteRootLevelFolderMovesProfilesToRoot()
|
||||
{
|
||||
Profile profile = makeRdpProfile();
|
||||
profile.folderPath = QStringLiteral("Solo");
|
||||
const std::optional<Profile> created = m_repo->createProfile(profile);
|
||||
QVERIFY(created.has_value());
|
||||
|
||||
QVERIFY(m_repo->deleteFolder(QStringLiteral("Solo")));
|
||||
const std::optional<Profile> fetched = m_repo->getProfile(created->id);
|
||||
QVERIFY(fetched.has_value());
|
||||
QCOMPARE(fetched->folderPath, QString());
|
||||
}
|
||||
|
||||
void TestProfileRepository::deleteFolderShiftsSubfoldersAndTheirProfilesUp()
|
||||
{
|
||||
QVERIFY(m_repo->createFolder(QStringLiteral("Work/Servers")));
|
||||
|
||||
Profile inTarget = makeSshProfile(QStringLiteral("InWork"));
|
||||
inTarget.folderPath = QStringLiteral("Work");
|
||||
const std::optional<Profile> createdInTarget = m_repo->createProfile(inTarget);
|
||||
QVERIFY(createdInTarget.has_value());
|
||||
|
||||
Profile inSubfolder = makeRdpProfile(QStringLiteral("InServers"));
|
||||
inSubfolder.folderPath = QStringLiteral("Work/Servers");
|
||||
const std::optional<Profile> createdInSubfolder = m_repo->createProfile(inSubfolder);
|
||||
QVERIFY(createdInSubfolder.has_value());
|
||||
|
||||
QVERIFY(m_repo->deleteFolder(QStringLiteral("Work")));
|
||||
|
||||
// "Work/Servers" shifts up to become root-level "Servers"; the profile
|
||||
// that was directly in "Work" moves to root; nothing is deleted.
|
||||
const auto folders = m_repo->listFolders();
|
||||
QCOMPARE(folders.size(), size_t(1));
|
||||
QCOMPARE(folders[0], QStringLiteral("Servers"));
|
||||
|
||||
const std::optional<Profile> fetchedInTarget = m_repo->getProfile(createdInTarget->id);
|
||||
QVERIFY(fetchedInTarget.has_value());
|
||||
QCOMPARE(fetchedInTarget->folderPath, QString());
|
||||
|
||||
const std::optional<Profile> fetchedInSubfolder = m_repo->getProfile(createdInSubfolder->id);
|
||||
QVERIFY(fetchedInSubfolder.has_value());
|
||||
QCOMPARE(fetchedInSubfolder->folderPath, QStringLiteral("Servers"));
|
||||
}
|
||||
|
||||
void TestProfileRepository::deleteFolderRejectsEmptyPath()
|
||||
{
|
||||
QVERIFY(!m_repo->deleteFolder(QString()));
|
||||
QVERIFY(!m_repo->lastError().isEmpty());
|
||||
}
|
||||
|
||||
void TestProfileRepository::deleteNonexistentFolderSucceedsAsNoOp()
|
||||
{
|
||||
QVERIFY(m_repo->deleteFolder(QStringLiteral("Never/Created")));
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestProfileRepository)
|
||||
#include "test_profile_repository.moc"
|
||||
|
||||
Reference in New Issue
Block a user