Skip to content

Commit

Permalink
Add tests to remove all files when sycing with or without nextcloudcmd.
Browse files Browse the repository at this point in the history
Signed-off-by: Camila Ayres <[email protected]>
  • Loading branch information
camilasan authored and mgallien committed Jun 28, 2024
1 parent da374fa commit 25c7a73
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions test/testsyncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,75 @@ private slots:
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}

void testRemoveAllFilesWithNextcloudCmd()
{
FakeFolder fakeFolder{FileInfo{}};
auto nextcloudCmdSyncOptions = fakeFolder.syncEngine().syncOptions();
nextcloudCmdSyncOptions.setIsCmd(true);
fakeFolder.syncEngine().setSyncOptions(nextcloudCmdSyncOptions);
ConfigFile().setPromptDeleteFiles(true);
QSignalSpy displayDialogSignal(&fakeFolder.syncEngine(), &SyncEngine::aboutToRemoveAllFiles);

fakeFolder.remoteModifier().mkdir("folder");
fakeFolder.remoteModifier().insert("folder/file1");
fakeFolder.remoteModifier().insert("folder/file2");
fakeFolder.remoteModifier().insert("folder/file3");
fakeFolder.remoteModifier().mkdir("folder2");
fakeFolder.remoteModifier().insert("file1");
fakeFolder.remoteModifier().insert("file2");
fakeFolder.remoteModifier().insert("file3");

QVERIFY(fakeFolder.syncOnce());

fakeFolder.remoteModifier().remove("folder");
fakeFolder.remoteModifier().remove("folder2");
fakeFolder.remoteModifier().remove("file1");
fakeFolder.remoteModifier().remove("file2");
fakeFolder.remoteModifier().remove("file3");

QVERIFY(fakeFolder.syncOnce());
// the signal to display the dialog should not be emitted
QCOMPARE(displayDialogSignal.count(), 0);
QCOMPARE(fakeFolder.remoteModifier().find("folder"), nullptr);
QCOMPARE(fakeFolder.remoteModifier().find("folder2"), nullptr);
QCOMPARE(fakeFolder.remoteModifier().find("file1"), nullptr);
}

void testRemoveAllFilesWithoutNextcloudCmd()
{
FakeFolder fakeFolder{FileInfo{}};
auto nextcloudCmdSyncOptions = fakeFolder.syncEngine().syncOptions();
nextcloudCmdSyncOptions.setIsCmd(false);
fakeFolder.syncEngine().setSyncOptions(nextcloudCmdSyncOptions);
ConfigFile().setPromptDeleteFiles(true);
QSignalSpy displayDialogSignal(&fakeFolder.syncEngine(), &SyncEngine::aboutToRemoveAllFiles);

fakeFolder.remoteModifier().mkdir("folder");
fakeFolder.remoteModifier().insert("folder/file1");
fakeFolder.remoteModifier().insert("folder/file2");
fakeFolder.remoteModifier().insert("folder/file3");
fakeFolder.remoteModifier().mkdir("folder2");
fakeFolder.remoteModifier().insert("file1");
fakeFolder.remoteModifier().insert("file2");
fakeFolder.remoteModifier().insert("file3");

QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

fakeFolder.remoteModifier().remove("folder");
fakeFolder.remoteModifier().remove("folder2");
fakeFolder.remoteModifier().remove("file1");
fakeFolder.remoteModifier().remove("file2");
fakeFolder.remoteModifier().remove("file3");

QVERIFY(fakeFolder.syncOnce());
// the signal to show the dialog should be emitted
QCOMPARE(displayDialogSignal.count(), 1);
QCOMPARE(fakeFolder.remoteModifier().find("folder"), nullptr);
QCOMPARE(fakeFolder.remoteModifier().find("folder2"), nullptr);
QCOMPARE(fakeFolder.remoteModifier().find("file1"), nullptr);
}
};

QTEST_GUILESS_MAIN(TestSyncEngine)
Expand Down

0 comments on commit 25c7a73

Please sign in to comment.