[frameworks/kirigami] autotests: autotests: fix flaky test_defaultFocusInScrollablePage
Méven Car <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit d9f1cbe17751ef54d7f7aec1ee9604fdedd9dac0 by Méven Car.
Committed on 18/07/2026 at 13:49.
Pushed by meven into branch 'master'.
autotests: fix flaky test_defaultFocusInScrollablePage
The test clicked the first list item right after the window activated, but a
ListView creates its delegate asynchronously. When the delegate at index 0 did
not exist yet, itemAtIndex(0) returned null and calling clicked() on it threw
"Cannot call method 'clicked' of null", failing the test on loaded machines.
Wait for the first item to exist before clicking it.
M +8 -1 autotests/tst_scrollablepage.qml
https://invent.kde.org/frameworks/kirigami/-/commit/d9f1cbe17751ef54d7f7aec1ee9604fdedd9dac0
diff --git a/autotests/tst_scrollablepage.qml b/autotests/tst_scrollablepage.qml
index dbdbc290b..d7927b54a 100644
--- a/autotests/tst_scrollablepage.qml
+++ b/autotests/tst_scrollablepage.qml
@@ -30,6 +30,9 @@ TestCase {
function clickFirst() {
(userList.itemAtIndex(0) as QQC.ItemDelegate).clicked();
}
+ function firstItemReady(): bool {
+ return userList.itemAtIndex(0) !== null;
+ }
property alias view: scroll.view
view: ListView {
id: userList
@@ -104,7 +107,11 @@ TestCase {
}
function test_defaultFocusInScrollablePage() {
- (mainWindow.pageStack.currentItem as FirstPage).clickFirst();
+ const firstPage = mainWindow.pageStack.currentItem as FirstPage;
+ // The ListView creates its delegate asynchronously, so wait until the first item exists
+ // before clicking it. Otherwise itemAtIndex(0) returns null and the click throws.
+ tryVerify(() => firstPage.firstItemReady());
+ firstPage.clickFirst();
if (!(mainWindow.pageStack.currentItem instanceof Kirigami.ScrollablePage)) {
currentItemChangedSpy.wait()
}