X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/a6b4348ddbc8fdf64ddb2c454e7fa2179e82c61b..128f797d73ba8118072767cbead7f22590b522db:/src/tests/dolphinmainwindowtest.cpp diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp index f620cb6ba..b22afa142 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: @@ -844,7 +846,7 @@ void DolphinMainWindowTest::testAccessibilityTree() // after going forwards which is probably not intended. } } - QCOMPARE_GE(testedObjectsSizeAfterTraversingForwards, 12); // The test did not reach many objects while using the Tab key to move through Dolphin. Did the + QCOMPARE_GE(testedObjectsSizeAfterTraversingForwards, 11); // The test did not reach many objects while using the Tab key to move through Dolphin. Did the // test run correctly? } @@ -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{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();