┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/tests/dolphinmainwindowtest.cpp
diff options
context:
space:
mode:
authorAkseli Lahtinen <[email protected]>2024-12-19 10:04:16 +0000
committerMéven Car <[email protected]>2024-12-19 10:04:16 +0000
commiteca160ae5a2dbd5590e4bae22cddde488dbacf74 (patch)
treefca5a83742c53cdaba71f24f9dfea5a3b7024f25 /src/tests/dolphinmainwindowtest.cpp
parente977737a182c5787d91d18f2d267027ba4f9dc24 (diff)
dolphinview: Update thumbnail on filename change
If filename of an item was updated previously, it would modify the model before the file was actually changed. This led to the model calling a signal that would try to run a previewjob, but since the filename is not actually changed yet on disk, it would fail. This patch moves the model updating after copyjob. Copyjob will take care of the file renaming if there is already existing file. We just need to update the model correctly after the job has succeeded. BUG:497555
Diffstat (limited to 'src/tests/dolphinmainwindowtest.cpp')
-rw-r--r--src/tests/dolphinmainwindowtest.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp
index f620cb6ba..37e042219 100644
--- a/src/tests/dolphinmainwindowtest.cpp
+++ b/src/tests/dolphinmainwindowtest.cpp
@@ -10,6 +10,7 @@
#include "dolphintabwidget.h"
#include "dolphinviewcontainer.h"
#include "kitemviews/kfileitemmodel.h"
+#include "kitemviews/kfileitemmodelrolesupdater.h"
#include "kitemviews/kitemlistcontainer.h"
#include "kitemviews/kitemlistcontroller.h"
#include "kitemviews/kitemlistselectionmanager.h"
@@ -58,6 +59,7 @@ private Q_SLOTS:
void testAccessibilityTree();
void testAutoSaveSession();
void testInlineRename();
+ void testThumbnailAfterRename();
void cleanupTestCase();
private:
@@ -937,6 +939,52 @@ void DolphinMainWindowTest::testInlineRename()
QCOMPARE(view->m_model->count(), 4);
}
+void DolphinMainWindowTest::testThumbnailAfterRename()
+{
+ // Create testdir and red square jpg for testing
+ QScopedPointer<TestDir> testDir{new TestDir()};
+ QImage testImage(256, 256, QImage::Format_Mono);
+ testImage.setColorCount(1);
+ testImage.setColor(0, qRgba(255, 0, 0, 255)); // Index #0 = Red
+ for (short x = 0; x < 256; ++x) {
+ for (short y = 0; y < 256; ++y) {
+ testImage.setPixel(x, y, 0);
+ }
+ }
+ testImage.save(testDir.data()->path() + "/a.jpg");
+
+ // Open dir and show it
+ m_mainWindow->openDirectories({testDir->url()}, false);
+ DolphinView *view = m_mainWindow->activeViewContainer()->view();
+ // Prepare signal spies
+ QSignalSpy viewDirectoryLoadingCompletedSpy(view, &DolphinView::directoryLoadingCompleted);
+ QSignalSpy itemsChangedSpy(view->m_model, &KFileItemModel::itemsChanged);
+ QSignalSpy modelDirectoryLoadingCompletedSpy(view->m_model, &KFileItemModel::directoryLoadingCompleted);
+ QSignalSpy previewUpdatedSpy(view->m_view->m_modelRolesUpdater, &KFileItemModelRolesUpdater::previewJobFinished);
+ // Show window and check that our preview has been updated, then wait for it to appear
+ m_mainWindow->show();
+ QVERIFY(viewDirectoryLoadingCompletedSpy.wait());
+ QVERIFY(previewUpdatedSpy.wait());
+ QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
+ QVERIFY(m_mainWindow->isVisible());
+ QTest::qWait(500); // we need to wait for the file widgets to become visible
+
+ // Set image selected and rename it to b.jpg, make sure editing role is working
+ view->markUrlsAsSelected({QUrl(testDir->url().toString() + "/a.jpg")});
+ view->updateViewState();
+ view->renameSelectedItems();
+ QVERIFY(view->m_view->m_editingRole);
+ QTest::keyClick(QApplication::focusWidget(), Qt::Key_B);
+ QTest::keyClick(QApplication::focusWidget(), Qt::Key_Enter);
+ QVERIFY(itemsChangedSpy.wait()); // Make sure that rename worked
+
+ // Check that preview gets updated and filename is correct
+ QVERIFY(previewUpdatedSpy.wait());
+ QVERIFY(!view->m_view->m_editingRole);
+ QCOMPARE(view->m_model->fileItem(0).name(), "b.jpg");
+ QCOMPARE(view->m_model->count(), 1);
+}
+
void DolphinMainWindowTest::cleanupTestCase()
{
m_mainWindow->showNormal();