diff options
| author | Méven Car <[email protected]> | 2022-11-29 18:16:59 +0000 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2022-11-29 18:16:59 +0000 |
| commit | a2c9c05de2dfabbb2bb614390c8e03023dad2bd1 (patch) | |
| tree | 5f34ae95e4cb0ea8ee95d3ee17c28b3cacd25ae9 /src/tests | |
| parent | de289800b22c654e8e3d8fbaea7bdb496a021b88 (diff) | |
Exit the deleted directory when it is removed
If current directory is a local file, try to find nearest dir ancestor and
open it. Display warning to the user.
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/kfileitemmodeltest.cpp | 27 | ||||
| -rw-r--r-- | src/tests/testdir.cpp | 11 | ||||
| -rw-r--r-- | src/tests/testdir.h | 1 |
3 files changed, 39 insertions, 0 deletions
diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index f2560d9fc..fef8bd581 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -93,6 +93,7 @@ private Q_SLOTS: void testCreateMimeData(); void testDeleteFileMoreThanOnce(); void testInsertAfterExpand(); + void testCurrentDirRemoved(); private: QStringList itemsInModel() const; @@ -2124,6 +2125,32 @@ void KFileItemModelTest::testInsertAfterExpand() } +void KFileItemModelTest::testCurrentDirRemoved() +{ + m_model->m_dirLister->setAutoUpdate(true); + QSignalSpy currentDirectoryRemovedSpy(m_model, &KFileItemModel::currentDirectoryRemoved); + QVERIFY(currentDirectoryRemovedSpy.isValid()); + QSignalSpy loadingCompletedSpy(m_model, &KFileItemModel::directoryLoadingCompleted); + QVERIFY(loadingCompletedSpy.isValid()); + QSignalSpy dirListerClearSpy(m_model->m_dirLister, &KCoreDirLister::clear); + QVERIFY(dirListerClearSpy.isValid()); + + m_testDir->createFiles({"dir/a.txt", "dir/b.txt"}); + m_model->loadDirectory(QUrl::fromLocalFile(m_testDir->path() + "/dir/")); + QVERIFY(loadingCompletedSpy.wait()); + QCOMPARE(m_model->count(), 2); + QVERIFY(m_model->isConsistent()); + + m_testDir->removeDir("dir"); + QVERIFY(currentDirectoryRemovedSpy.wait()); + + // dirLister calls clear + QCOMPARE(dirListerClearSpy.count(), 2); + QVERIFY(m_model->isConsistent()); + QVERIFY(m_model->m_itemData.isEmpty()); + QCOMPARE(m_model->count(), 0); +} + QStringList KFileItemModelTest::itemsInModel() const { QStringList items; diff --git a/src/tests/testdir.cpp b/src/tests/testdir.cpp index 5d75a5343..6fbc4c426 100644 --- a/src/tests/testdir.cpp +++ b/src/tests/testdir.cpp @@ -96,6 +96,17 @@ void TestDir::removeFile(const QString& path) QFile::remove(absolutePath); } +void TestDir::removeDir(const QString& path) +{ + QString absolutePath = path; + QFileInfo fileInfo(absolutePath); + if (!fileInfo.isAbsolute()) { + absolutePath = TestDir::path() + QLatin1Char('/') + path; + } + QDir dirToRemove = QDir(absolutePath); + dirToRemove.removeRecursively(); +} + void TestDir::makePathAbsoluteAndCreateParents(QString& path) { QFileInfo fileInfo(path); diff --git a/src/tests/testdir.h b/src/tests/testdir.h index d537f9574..921a89185 100644 --- a/src/tests/testdir.h +++ b/src/tests/testdir.h @@ -37,6 +37,7 @@ public: void removeFile(const QString& path); void removeFiles(const QStringList& files); + void removeDir(const QString& path); private: void makePathAbsoluteAndCreateParents(QString& path); |
