Warning, /frameworks/kirigami/autotests/tst_overlaysheet.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 QtQuick.Controls as QQC2
0009 import QtQuick.Layouts
0010 import QtTest
0011 import org.kde.kirigami as Kirigami
0012 
0013 TestCase {
0014     id: root
0015 
0016     name: "OverlaySheetTest"
0017     visible: true
0018     when: windowShown
0019 
0020     width: 500
0021     height: 500
0022 
0023     Component {
0024         id: emptyComponent
0025         Kirigami.OverlaySheet {}
0026     }
0027 
0028     Component {
0029         id: itemContentComponent
0030         Kirigami.OverlaySheet {
0031             Rectangle {
0032                 implicitWidth: 100
0033                 implicitHeight: 200
0034             }
0035         }
0036     }
0037 
0038     Component {
0039         id: viewContentWithImplicitSizeComponent
0040         Kirigami.OverlaySheet {
0041             ListView {
0042                 implicitWidth: 100
0043                 implicitHeight: 200
0044             }
0045         }
0046     }
0047 
0048     Component {
0049         id: viewContentWithPreferredSizeComponent
0050         Kirigami.OverlaySheet {
0051             ListView {
0052                 Layout.preferredWidth: 100
0053                 Layout.preferredHeight: 200
0054             }
0055         }
0056     }
0057 
0058     Component {
0059         id: itemContentWithMixedSizesComponent
0060         Kirigami.OverlaySheet {
0061             Rectangle {
0062                 implicitWidth: 100
0063                 implicitHeight: 200
0064 
0065                 Layout.preferredWidth: 300
0066                 Layout.preferredHeight: 400
0067             }
0068         }
0069     }
0070 
0071     Component {
0072         id: viewContentWithMixedSizesComponent
0073         Kirigami.OverlaySheet {
0074             ListView {
0075                 implicitWidth: 100
0076                 implicitHeight: 200
0077 
0078                 Layout.preferredWidth: 300
0079                 Layout.preferredHeight: 400
0080             }
0081         }
0082     }
0083 
0084     function setupWarningsFilter() {
0085         // no nullable property access errors are allowed
0086         failOnWarning(/\bnull\b/);
0087     }
0088 
0089     // Note about implicit size comparison: we don't know how much space
0090     // header+footer+paddings would take, but the sum should be no less than
0091     // the implicit or preferred size given. And the difference between
0092     // implicit and preferred size is big enough (200px) that it is unlikely
0093     // to get an overlap.
0094 
0095     function test_init() {
0096         setupWarningsFilter();
0097         {
0098             const sheet = createTemporaryObject(emptyComponent, null);
0099             verify(sheet);
0100             verify(!sheet.parent);
0101         }
0102         {
0103             const sheet = createTemporaryObject(emptyComponent, this);
0104             verify(sheet);
0105             compare(sheet.parent, this);
0106         }
0107         {
0108             const sheet = createTemporaryObject(viewContentWithImplicitSizeComponent, this);
0109             verify(sheet);
0110             verify(sheet.implicitWidth >= 100);
0111             verify(sheet.implicitHeight >= 200);
0112         }
0113         {
0114             const sheet = createTemporaryObject(viewContentWithPreferredSizeComponent, this);
0115             verify(sheet);
0116             verify(sheet.implicitWidth >= 100);
0117             verify(sheet.implicitHeight >= 200);
0118         }
0119     }
0120 
0121     // Layout.preferred* takes precedence over implicit size
0122     function test_sizeHintPrecedence() {
0123         setupWarningsFilter();
0124         {
0125             // first, make sure 100x200 sheet's total implicit size is smaller than 300x400
0126             const sheet = createTemporaryObject(itemContentComponent, this);
0127             verify(sheet);
0128             verify(sheet.implicitWidth >= 100 && sheet.implicitWidth < 300);
0129             verify(sheet.implicitHeight >= 200 && sheet.implicitHeight < 400);
0130         }
0131         {
0132             const sheet = createTemporaryObject(itemContentWithMixedSizesComponent, this);
0133             verify(sheet);
0134             verify(sheet.implicitWidth >= 300);
0135             verify(sheet.implicitHeight >= 400);
0136         }
0137         {
0138             const sheet = createTemporaryObject(viewContentWithMixedSizesComponent, this);
0139             verify(sheet);
0140             verify(sheet.implicitWidth >= 300);
0141             verify(sheet.implicitHeight >= 400);
0142         }
0143     }
0144 }