Warning, /frameworks/kirigami/autotests/tst_inlineviewheader.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 QtTest
0009 import org.kde.kirigami as Kirigami
0010 
0011 TestCase {
0012     id: testCase
0013 
0014     name: "InlineViewHeaderTests"
0015     when: windowShown
0016 
0017     width: 300
0018     height: 300
0019     visible: true
0020 
0021     Component {
0022         id: emptyComponent
0023         Kirigami.InlineViewHeader {}
0024     }
0025 
0026     Component {
0027         id: actionableComponent
0028         Kirigami.InlineViewHeader {
0029             readonly property Kirigami.Action kActionA: Kirigami.Action {
0030                 text: "Kirigami Action A"
0031             }
0032             readonly property Kirigami.Action kActionB: Kirigami.Action {
0033                 text: "Kirigami Action B"
0034                 visible: false
0035             }
0036             readonly property Kirigami.Action kActionC: Kirigami.Action {
0037                 text: "Kirigami Action C"
0038             }
0039 
0040             actions: [kActionA, kActionB, kActionC]
0041         }
0042     }
0043 
0044     function test_sizing() {
0045         const emptyHeader = createTemporaryObject(emptyComponent, this);
0046         verify(emptyHeader);
0047         const labelOnlyHeader = createTemporaryObject(emptyComponent, this, { text: "Name" });
0048         verify(labelOnlyHeader);
0049         const multiLinelabelOnlyHeader = createTemporaryObject(emptyComponent, this, {
0050             text: "First Line followed by\nSecond Line"
0051         });
0052         verify(multiLinelabelOnlyHeader);
0053         const actionsOnlyHeader = createTemporaryObject(actionableComponent, this);
0054         verify(actionsOnlyHeader);
0055         const fullHeader = createTemporaryObject(actionableComponent, this, { text: "Name" });
0056         verify(fullHeader);
0057         // Let them polish and instantiate delegates
0058         wait(1100);
0059 
0060         // check that implicit height is more than just vertical padding
0061         verify(emptyHeader.implicitHeight > emptyHeader.topPadding + emptyHeader.bottomPadding);
0062 
0063         // implicit height stays the same regardless of text label content:
0064         compare(emptyHeader.implicitHeight, labelOnlyHeader.implicitHeight);
0065 
0066         // label elides instead of wrapping:
0067         compare(emptyHeader.implicitHeight, multiLinelabelOnlyHeader.implicitHeight);
0068 
0069         // label contributes to the width
0070         verify(labelOnlyHeader.implicitWidth > labelOnlyHeader.leftPadding + labelOnlyHeader.rightPadding)
0071 
0072         compare(actionsOnlyHeader.implicitHeight, fullHeader.implicitHeight);
0073 
0074         verify(fullHeader.implicitWidth > actionsOnlyHeader.implicitWidth);
0075         verify(actionsOnlyHeader.implicitWidth > emptyHeader.implicitWidth);
0076         verify(labelOnlyHeader.implicitWidth > emptyHeader.implicitWidth);
0077     }
0078 }