From 051bc3665a169e261d57ecab1f70baaa31a4a1ad Mon Sep 17 00:00:00 2001 From: Wendi Gan Date: Fri, 3 Oct 2025 00:28:12 +0800 Subject: Add integration test for split view activation and tab title update after renaming a folder In a split-view tab, the child folder is opened in the left view and other tabs, while the parent folder is opened in the right view. After renaming the child folder from the right view: - The activated view should not switch to the left view. - All tab titles should be updated. CCBUG: 496414 --- src/tests/dolphinmainwindowtest.cpp | 82 ++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) (limited to 'src/tests/dolphinmainwindowtest.cpp') diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp index 6e702b0a3..ac7c14432 100644 --- a/src/tests/dolphinmainwindowtest.cpp +++ b/src/tests/dolphinmainwindowtest.cpp @@ -68,6 +68,7 @@ private Q_SLOTS: void testInlineRename(); void testThumbnailAfterRename(); void testViewModeAfterDynamicView(); + void testActivationAndTabTitleAfterRenameOpeningFolder(); void cleanupTestCase(); private: @@ -421,7 +422,7 @@ void DolphinMainWindowTest::testCreateFileAction() QCOMPARE(file.size(), 0); } - void DolphinMainWindowTest::testCreateFileActionRequiresWritePermission() +void DolphinMainWindowTest::testCreateFileActionRequiresWritePermission() { QScopedPointer testDir{new TestDir()}; QString testDirUrl(QDir::cleanPath(testDir->url().toString())); @@ -1145,6 +1146,85 @@ void DolphinMainWindowTest::testViewModeAfterDynamicView() QVERIFY(ViewProperties(view->viewPropertiesUrl()).dynamicViewPassed()); } +void DolphinMainWindowTest::testActivationAndTabTitleAfterRenameOpeningFolder() +{ + QScopedPointer testDir{new TestDir()}; + testDir->createDir("a"); + const QUrl parentDirUrl = QUrl::fromLocalFile(testDir->url().toLocalFile()); + const QUrl childDirUrl = QUrl::fromLocalFile(testDir->url().toLocalFile() + "/a"); + + auto tabWidget = m_mainWindow->findChild("tabWidget"); + QVERIFY(tabWidget); + + // Tab 0: Open childDirUrl + m_mainWindow->openDirectories({childDirUrl}, false); + m_mainWindow->show(); + QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); + QVERIFY(m_mainWindow->isVisible()); + + // Tab 0: Enable split view + m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->setChecked(true); + m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger(); + QVERIFY(tabWidget->currentTabPage()->splitViewEnabled()); + + // Tab 1: Open childDirUrl + tabWidget->openNewActivatedTab(childDirUrl); + + // Tab 1: Open parentDirUrl in right view + m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->setChecked(true); + m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger(); + QVERIFY(tabWidget->currentTabPage()->splitViewEnabled()); + + DolphinView *view = m_mainWindow->activeViewContainer()->view(); + view->m_model->loadDirectory(parentDirUrl); + view->setUrl(parentDirUrl); + + // Check current view is right view + QVERIFY(tabWidget->currentTabPage()->secondaryViewContainer()->isActive()); + + // Check all tab titles are correct + // Tab 0: (a) | a + // Tab 1: (a) | parentDir + const QString parentDirName = QFileInfo(parentDirUrl.toString()).fileName(); + const QString childDirName = QFileInfo(childDirUrl.toString()).fileName(); + const QString expectedTab0Title = QStringLiteral("(%1) | %2").arg(childDirName, childDirName); + const QString expectedTab1Title = QStringLiteral("(%1) | %2").arg(childDirName, parentDirName); + QCOMPARE(tabWidget->tabText(0), expectedTab0Title); + QCOMPARE(tabWidget->tabText(1), expectedTab1Title); + + // Prepare signal spies + QSignalSpy viewDirectoryLoadingCompletedSpy(view, &DolphinView::directoryLoadingCompleted); + QSignalSpy itemsChangedSpy(view->m_model, &KFileItemModel::itemsChanged); + + QVERIFY(viewDirectoryLoadingCompletedSpy.wait()); + QTest::qWait(0); + + // Rename child dir to "b" + view->markUrlsAsSelected({childDirUrl}); + view->updateViewState(); + view->renameSelectedItems(); // Rename inline + + QTest::keyClick(QApplication::focusWidget(), Qt::Key_B); + QTest::keyClick(QApplication::focusWidget(), Qt::Key_Enter); + QVERIFY(itemsChangedSpy.wait()); // Make sure that rename worked + + // Check current view is right view + QVERIFY(tabWidget->currentTabPage()->secondaryViewContainer()->isActive()); + + // Check navigator in left view is inactive + auto leftViewNavigator = tabWidget->currentTabPage()->primaryViewContainer()->urlNavigator(); + QVERIFY(!leftViewNavigator->isActive()); + + // Check all tab titles are correct after rename + // Tab 0: (b) | b + // Tab 1: (b) | parentDir + const QString newChildDirName = QStringLiteral("b"); + const QString expectedNewTab0Title = QStringLiteral("(%1) | %2").arg(newChildDirName, newChildDirName); + const QString expectedNewTab1Title = QStringLiteral("(%1) | %2").arg(newChildDirName, parentDirName); + QCOMPARE(tabWidget->tabText(0), expectedNewTab0Title); + QCOMPARE(tabWidget->tabText(1), expectedNewTab1Title); +} + void DolphinMainWindowTest::cleanupTestCase() { m_mainWindow->showNormal(); -- cgit v1.3