Warning, /frameworks/kirigami/autotests/tst_menudialog.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 0008 import org.kde.kirigami as Kirigami 0009 import QtTest 0010 0011 TestCase { 0012 id: root 0013 0014 name: "MenuDialogTest" 0015 visible: true 0016 when: windowShown 0017 0018 width: 300 0019 height: 300 0020 0021 Component { 0022 id: menuDialogComponent 0023 Kirigami.MenuDialog { 0024 readonly property Kirigami.Action actionA: Kirigami.Action { 0025 text: "Action A" 0026 } 0027 0028 preferredWidth: 200 0029 0030 actions: [actionA] 0031 } 0032 } 0033 0034 Component { 0035 id: spyComponent 0036 SignalSpy {} 0037 } 0038 0039 function findChildIf(parent: Item, predicate /*(Item) -> bool*/): Item { 0040 for (const child of parent.children) { 0041 if (predicate(child)) { 0042 return child; 0043 } else { 0044 const item = findChildIf(child, predicate); 0045 if (item !== null) { 0046 return item; 0047 } 0048 } 0049 } 0050 return null; 0051 } 0052 0053 function testClosed() { 0054 const dialog = createTemporaryObject(this, menuDialogComponent); 0055 verify(dialog); 0056 0057 const { actionA } = dialog; 0058 0059 const dialogClosedSpy = createTemporaryObject(this, spyComponent, { 0060 target: dialog, 0061 signalName: "closed", 0062 }); 0063 const actionSpy = createTemporaryObject(this, spyComponent, { 0064 target: actionA, 0065 signalName: "triggered", 0066 }); 0067 0068 dialog.open(); 0069 tryVerify(() => dialog.opened); 0070 0071 const delegate = findChildIf(dialog.contentItem, item => item.action === actionA) as QQC2.ItemDelegate; 0072 verify(delegate); 0073 0074 mouseClick(delegate); 0075 compare(actionSpy.count, 1); 0076 compare(dialogClosedSpy.count, 1); 0077 tryVerify(() => !dialog.visible); 0078 } 0079 }