Warning, /frameworks/kirigami/autotests/tst_scrollablepage.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2023 Fushan Wen <qydwhotmail@gmail.com>
0003
0004 SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006
0007 import QtQuick
0008 import QtQuick.Layouts
0009 import QtQuick.Controls as QQC
0010 import QtTest
0011 import org.kde.kirigami as Kirigami
0012
0013 TestCase {
0014 id: testCase
0015
0016 width: 400
0017 height: 400
0018 name: "ScrollablePageTest"
0019 visible: false
0020
0021 SignalSpy {
0022 id: currentItemChangedSpy
0023 target: mainWindow.pageStack
0024 signalName: "currentItemChanged"
0025 }
0026
0027 // Simulate KCM.ScrollViewKCM
0028 Kirigami.ApplicationWindow {
0029 id: mainWindow
0030 width: 480
0031 height: 360
0032 pageStack.initialPage: Kirigami.Page {
0033 id: root
0034 function clickFirst() {
0035 userList.itemAtIndex(0).clicked();
0036 }
0037 property alias view: scroll.view
0038 view: ListView {
0039 id: userList
0040 model: 1
0041 delegate: QQC.ItemDelegate {
0042 id: delegate
0043 width: ListView.view.width
0044 text: String(index)
0045 onClicked: {
0046 mainWindow.pageStack.pop();
0047 mainWindow.pageStack.push(subPageComponent);
0048 console.log("clicked")
0049 }
0050 }
0051 }
0052 QQC.ScrollView {
0053 id: scroll
0054 anchors.fill: parent
0055 property Flickable view
0056 activeFocusOnTab: false
0057 contentItem: view
0058 onViewChanged: {
0059 view.parent = scroll;
0060 }
0061 Kirigami.Theme.colorSet: Kirigami.Theme.View
0062 Kirigami.Theme.inherit: false
0063 }
0064 }
0065 }
0066
0067 Component {
0068 id: subPageComponent
0069 Kirigami.ScrollablePage {
0070 readonly property alias success: realNametextField.activeFocus
0071 focus: true
0072 ColumnLayout {
0073 QQC.TextField {
0074 id: realNametextField
0075 focus: true
0076 text: "This item should be focused by default"
0077 }
0078 QQC.TextField {
0079 id: userNameField
0080 text: "ddeeff"
0081 }
0082 }
0083 }
0084 }
0085
0086 function initTestCase() {
0087 mainWindow.show()
0088 mainWindow.requestActivate();
0089 tryVerify(() => mainWindow.active);
0090 }
0091
0092 function cleanupTestCase() {
0093 mainWindow.close()
0094 }
0095
0096 function test_defaultFocusInScrollablePage() {
0097 mainWindow.pageStack.currentItem.clickFirst();
0098 if (!(mainWindow.pageStack.currentItem instanceof Kirigami.ScrollablePage)) {
0099 currentItemChangedSpy.wait()
0100 }
0101 verify(mainWindow.pageStack.currentItem instanceof Kirigami.ScrollablePage)
0102 // Consolidate the workaround for QTBUG-44043
0103 // https://invent.kde.org/frameworks/kirigami/-/commit/fd253ea5d9fa3f33411e54a596c021f51b5a102a
0104 tryVerify(() => mainWindow.pageStack.currentItem.success)
0105 }
0106 }
0107
0108
0109