From a2c9c05de2dfabbb2bb614390c8e03023dad2bd1 Mon Sep 17 00:00:00 2001 From: Méven Car Date: Tue, 29 Nov 2022 18:16:59 +0000 Subject: 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. --- src/tests/kfileitemmodeltest.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/tests/kfileitemmodeltest.cpp') 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; -- cgit v1.3