Warning, /frameworks/kirigami/autotests/tst_keynavigation.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * SPDX-FileCopyrightText: 2016 Aleix Pol Gonzalez <aleixpol@kde.org>
0003 * SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
0004 *
0005 * SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007
0008 import QtQuick
0009 import QtQuick.Controls
0010 import QtQuick.Window
0011 import org.kde.kirigami as Kirigami
0012 import QtTest
0013 import "../tests"
0014
0015 TestCase {
0016 id: testCase
0017 width: 400
0018 height: 400
0019 name: "KeyboardNavigation"
0020
0021 Component {
0022 id: mainComponent
0023 KeyboardTest {
0024 id: window
0025
0026 width: 480
0027 height: 360
0028
0029 readonly property SignalSpy spyLastKey: SignalSpy {
0030 target: window.pageStack.currentItem
0031 signalName: "lastKeyChanged"
0032 }
0033 }
0034 }
0035
0036 // The following methods are adaptation of QtTest internals
0037
0038 function waitForWindowActive(window: Window) {
0039 tryVerify(() => window.active);
0040 }
0041
0042 function ensureWindowShown(window: Window) {
0043 window.requestActivate();
0044 waitForWindowActive(window);
0045 wait(0);
0046 }
0047
0048 function test_press() {
0049 const window = createTemporaryObject(mainComponent, this);
0050 verify(window);
0051 const spy = window.spyLastKey;
0052 verify(spy.valid);
0053
0054 ensureWindowShown(window);
0055
0056 compare(window.pageStack.depth, 2);
0057 compare(window.pageStack.currentIndex, 1);
0058
0059 let keyCount = 0;
0060
0061 keyClick("A");
0062 keyCount += 1;
0063 compare(spy.count, keyCount);
0064 compare(window.pageStack.currentItem.lastKey, "A");
0065
0066 keyClick(Qt.Key_Left, Qt.AltModifier);
0067 keyCount += 1;
0068 compare(spy.count, keyCount);
0069 compare(window.pageStack.currentIndex, 0);
0070 compare(window.pageStack.currentItem.lastKey, "");
0071
0072 keyClick("B")
0073 keyCount += 1;
0074 compare(spy.count, keyCount);
0075 compare(window.pageStack.currentItem.lastKey, "B");
0076 }
0077 }