From 980d4f71a978e7e437bbe9d0100c095d84a0b4fa Mon Sep 17 00:00:00 2001 From: Sebastian Englbrecht Date: Mon, 25 May 2026 13:30:09 +0200 Subject: dolphinmainwindowtest: ensure consistent starting state for places panel tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In a fresh test environment there is no saved session, so the places panel may not be visible. Explicitly show it before testing. Additionally, focus-related assertions require the window to be the active window — setFocus() on dock widget contents has no effect on an inactive window. Replace the weak QTRY_VERIFY_WITH_TIMEOUT(activeWindow() != nullptr, 100) with requestActivate() + qWaitForWindowActive() to enforce this precondition. --- src/tests/dolphinmainwindowtest.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp index 24d2025b7..84271786c 100644 --- a/src/tests/dolphinmainwindowtest.cpp +++ b/src/tests/dolphinmainwindowtest.cpp @@ -524,9 +524,16 @@ void DolphinMainWindowTest::testFocusPlacesPanel() m_mainWindow->show(); QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); QVERIFY(m_mainWindow->isVisible()); - QTRY_VERIFY_WITH_TIMEOUT(QApplication::activeWindow() != nullptr, 100); + m_mainWindow->windowHandle()->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(m_mainWindow.data())); QWidget *placesPanel = reinterpret_cast(m_mainWindow->m_placesPanel); + QAction *showPlacesPanelAction = m_mainWindow->actionCollection()->action(QStringLiteral("show_places_panel")); + if (!showPlacesPanelAction->isChecked()) { + showPlacesPanelAction->trigger(); + // trigger() moves focus to the panel; restore it so the test starts from a defined state. + m_mainWindow->activeViewContainer()->view()->setFocus(); + } QVERIFY2(QTest::qWaitFor( [&]() { return placesPanel && placesPanel->isVisible() && placesPanel->width() > 0 && placesPanel->height() > 0; @@ -535,7 +542,6 @@ void DolphinMainWindowTest::testFocusPlacesPanel() "The test couldn't be initialised properly. The places panel should be visible."); QAction *focusPlacesPanelAction = m_mainWindow->actionCollection()->action(QStringLiteral("focus_places_panel")); - QAction *showPlacesPanelAction = m_mainWindow->actionCollection()->action(QStringLiteral("show_places_panel")); focusPlacesPanelAction->trigger(); QVERIFY(placesPanel->hasFocus()); @@ -582,6 +588,13 @@ void DolphinMainWindowTest::testPlacesPanelWidthResistance() QVERIFY(m_mainWindow->isVisible()); QWidget *placesPanel = reinterpret_cast(m_mainWindow->m_placesPanel); + // ensure panel is visible even in a fresh env without a saved session. + { + QAction *showPlacesPanelAction = m_mainWindow->actionCollection()->action(QStringLiteral("show_places_panel")); + if (!showPlacesPanelAction->isChecked()) { + showPlacesPanelAction->trigger(); + } + } QVERIFY2(QTest::qWaitFor( [&]() { return placesPanel && placesPanel->isVisible() && placesPanel->width() > 0; -- cgit v1.3.1