Warning, /frameworks/kirigami/autotests/tst_globaldrawer.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 2.15
0008 import QtQuick.Controls 2.15 as QQC2
0009 import QtQuick.Layouts 1.15
0010 import org.kde.kirigami 2.20 as Kirigami
0011 import QtTest 1.15
0012 
0013 Kirigami.ApplicationItem {
0014     id: root
0015 
0016     width: 500
0017     height: 500
0018     visible: true
0019 
0020     globalDrawer: Kirigami.GlobalDrawer {
0021         id: drawer
0022 
0023         drawerOpen: true
0024 
0025         header: Rectangle {
0026             id: headerItem
0027             implicitHeight: 50
0028             implicitWidth: 50
0029             color: "red"
0030             radius: 20 // to see its bounds
0031         }
0032 
0033         // Create some item which we can use to measure actual header height
0034         Rectangle {
0035             id: topItem
0036             Layout.fillWidth: true
0037             Layout.fillHeight: true
0038             color: "green"
0039             radius: 20 // to see its bounds
0040         }
0041     }
0042 
0043     TestCase {
0044         name: "GlobalDrawerHeader"
0045         when: windowShown
0046 
0047         function test_headerItemVisibility() {
0048             const overlay = QQC2.Overlay.overlay;
0049             verify(headerItem.height !== 0);
0050 
0051             // Due to margins, position won't be exactly zero...
0052             let position = topItem.mapToItem(overlay, 0, 0);
0053             verify(position.y > 0);
0054             const oldY = position.y;
0055 
0056             // ...but with visible header it would be greater than with invisible.
0057             headerItem.visible = false;
0058             waitForRendering(overlay);
0059             position = topItem.mapToItem(overlay, 0, 0);
0060             verify(position.y < oldY);
0061 
0062             // And now return it back to where we started.
0063             headerItem.visible = true;
0064             waitForRendering(overlay);
0065             position = topItem.mapToItem(overlay, 0, 0);
0066             verify(position.y === oldY);
0067         }
0068     }
0069 }