[frameworks/kirigami] autotests: autotests: fix flaky keyboard list navigation test

Méven Car <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit d6e4000642024d523e7df81afdcba477cf67fa10 by Méven Car.
Committed on 20/07/2026 at 10:53.
Pushed by meven into branch 'master'.

autotests: fix flaky keyboard list navigation test

test_press pressed Down and expected the list to move to the next item, but the
list only navigates when it has active keyboard focus. The test relied on focus
reaching the list on its own after the window was shown, which does not always
happen in time (seen failing on Windows and on Linux with Qt 6.12), so the key
went nowhere and currentIndexChanged never fired.

Give the list active focus before pressing the key.

M  +6    -2    autotests/tst_listskeynavigation.qml

https://invent.kde.org/frameworks/kirigami/-/commit/d6e4000642024d523e7df81afdcba477cf67fa10

diff --git a/autotests/tst_listskeynavigation.qml b/autotests/tst_listskeynavigation.qml
index 49745d9af..032cb6115 100644
--- a/autotests/tst_listskeynavigation.qml
+++ b/autotests/tst_listskeynavigation.qml
@@ -58,9 +58,13 @@ TestCase {
         compare(window.pageStack.depth, 1);
         compare(window.pageStack.currentIndex, 0);
 
-        compare(window.pageStack.currentItem.flickable.currentIndex, 0);
+        const flickable = window.pageStack.currentItem.flickable;
+        compare(flickable.currentIndex, 0);
+        // Give the list keyboard focus so the arrow key navigates it.
+        flickable.forceActiveFocus();
+        tryVerify(() => flickable.activeFocus);
         keyClick(Qt.Key_Down);
         compare(spy.count, 1);
-        compare(window.pageStack.currentItem.flickable.currentIndex, 1);
+        compare(flickable.currentIndex, 1);
     }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.