File: tst_combobutton.13.qml

package info (click to toggle)
lomiri-ui-toolkit 1.3.5110%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 26,436 kB
  • sloc: cpp: 85,830; python: 5,537; sh: 1,344; javascript: 919; ansic: 573; makefile: 204
file content (248 lines) | stat: -rw-r--r-- 10,356 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
 * Copyright 2014 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.4
import QtTest 1.0
import Lomiri.Test 1.3
import Lomiri.Components 1.3
import Lomiri.Components.ListItems 1.3

Item {
    width: units.gu(40)
    height: units.gu(71)

    Column {
        ComboButton {
            id: combo
        }

        ComboButton {
            id: rectCombo
            onClicked: expanded = false

            Rectangle {
                id: rect
                width: parent.width
                height: units.gu(40)
                gradient: Gradient {
                    GradientStop {
                        position: 0.0
                        color: "red"
                    }
                    GradientStop {
                        position: 0.5
                        color: "green"
                    }
                    GradientStop {
                        position: 1.0
                        color: "blue"
                    }
                }
            }
        }

        ComboButton {
            id: columnCombo
            expandedHeight: -1
            Column {
                id: column
                anchors {
                    left: parent.left
                    right: parent.right
                }
                height: childrenRect.height
                Repeater {
                    model: 5
                    Rectangle {
                        width: parent.width
                        height: units.gu(5)
                        color: Qt.rgba(Math.random(1), Math.random(1), Math.random(1), 1);
                    }
                }
            }
        }

        ComboButton {
            id: longCombo
            expandedHeight: units.gu(40)
            Rectangle {
                id: longRect
                height: units.gu(10)
                color: "cyan"
            }
        }

        ComboButton {
            id: listCombo
            ListView {
                id: list
                model: 20
                height: listCombo.comboListHeight
                delegate: Standard {
                    text: modelData
                }
            }
        }
    }

    SignalSpy { id: spy }

    LomiriTestCase {
        name: "ComboButton"
        when: windowShown

        function cleanup() {
            rectCombo.expanded =
            columnCombo.expanded =
            longCombo.expanded =
            listCombo.expanded = false;
            spy.clear();
            spy.signalName = "";
            spy.target = undefined;
        }

        function test_0_defaults() {
            compare(combo.expanded, false, "not expanded by default");
            compare(combo.collapsedHeight, combo.implicitHeight, "collapsedHeight is implicitHeight");
            compare(combo.expandedHeight, combo.collapsedHeight + units.gu(19.5), "expanded height default");
            var lheight = combo.expandedHeight - combo.collapsedHeight - combo.__styleInstance.comboListMargin;
            compare(combo.comboListHeight, lheight, "comboListHeight default");
            compare(combo.comboList.length, 0, "comboList is empty");
            verify(combo.font === Qt.font({family: "Noto Sans", pixelSize: FontUtils.sizeToPixels("medium")}), "Default font differs.");
        }

        function test_comboListWidth() {
            var comboListHolder = findChild(rectCombo, "combobutton_combolist");
            compare(rect.width, comboListHolder.width, "rectCombo list content width is not adjusted");
            comboListHolder = findChild(columnCombo, "combobutton_combolist");
            compare(column.width, comboListHolder.width, "columnCombo list content width is not adjusted");
            comboListHolder = findChild(longCombo, "combobutton_combolist");
            compare(longRect.width, comboListHolder.width, "longCombo list content width is not adjusted");
            comboListHolder = findChild(listCombo, "combobutton_combolist");
            compare(list.width, comboListHolder.width, "listCombo list content width is not adjusted");
        }

        function test_expandRectComboThroughProperty() {
            rectCombo.expanded = true;
            waitForRendering(rectCombo);
            var comboListPanel = findChild(rectCombo, "combobutton_combopanel");
            tryCompareFunction(function() { return comboListPanel.visible}, true);
        }

        function test_expandRectComboThroughClick() {
            var dropDown = findChild(rectCombo, "combobutton_dropdown");
            mouseClick(dropDown, dropDown.width / 2, dropDown.height / 2);
            waitForRendering(rectCombo);
            compare(rectCombo.expanded, true, "combo is not expanded");
            var comboListPanel = findChild(rectCombo, "combobutton_combopanel");
            tryCompareFunction(function() { return comboListPanel.visible}, true);
        }

        function test_autoCollapse() {
            var dropDown = findChild(rectCombo, "combobutton_dropdown");
            var comboListPanel = findChild(rectCombo, "combobutton_combopanel");
            mouseClick(dropDown, dropDown.width / 2, dropDown.height / 2);
            waitForRendering(rectCombo);
            compare(rectCombo.expanded, true, "combo is not expanded");
            tryCompareFunction(function() { return comboListPanel.visible}, true);

            mouseClick(rectCombo, rectCombo.width / 2, rectCombo.collapsedHeight / 2);
            waitForRendering(rectCombo);
            compare(rectCombo.expanded, false, "combo is not collapsed");
            tryCompareFunction(function() { return comboListPanel.visible}, false);
        }

        function test_flickRectCombo() {
            skip("FIXME: Broken on Qt 5.12");
            // the test is flaky on powerpc target
            // https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1315244
            var dropDown = findChild(rectCombo, "combobutton_dropdown");
            var comboListPanel = findChild(rectCombo, "combobutton_combopanel");
            var comboList = findChild(rectCombo, "combobutton_combolist");
            mouseClick(dropDown, dropDown.width / 2, dropDown.height / 2);
            waitForRendering(rectCombo);
            tryCompareFunction(function() { return comboListPanel.visible}, true);
            verify(comboList.height > rectCombo.expandedHeight);
            // comboList flicker is the combolist parent's parent
            var comboListFlicker = findChild(rectCombo, "combobutton_contentflicker");
            compare(comboListFlicker.interactive, true, "combo list holder must be interactive");

            // drag the rectangle, the Flickable should be moving
            var x = comboListFlicker.width / 2;
            var y = comboListFlicker.height / 2;
            var dy = comboListFlicker.height / 6;
            spy.target = comboListFlicker;
            spy.signalName = "onMovementEnded";
            mouseDrag(comboList, x, y, 0, -dy);
            waitForRendering(comboListFlicker);
            spy.wait();
        }

        function test_autoExpandHeight() {
            var comboListPanel = findChild(columnCombo, "combobutton_combopanel");
            var comboList = findChild(columnCombo, "combobutton_combolist");
            columnCombo.expanded = true;
            waitForRendering(columnCombo);
            tryCompareFunction(function() { return comboListPanel.visible}, true);
            var comboListFlicker = findChild(columnCombo, "combobutton_contentflicker");
            waitForRendering(comboListFlicker);
            compare(comboListFlicker.interactive, false, "combo list holder must not be interactive");
            tryCompare(comboListFlicker, 'height', columnCombo.comboListHeight, 500, "combo list height differs from the holder height");
        }

        function test_emptyComboExpanded() {
            var comboListPanel = findChild(combo, "combobutton_combopanel");
            var comboList = findChild(combo, "combobutton_combolist");
            combo.expanded = true;
            waitForRendering(combo);
            waitForRendering(comboListPanel);
            tryCompareFunction(function() { return comboListPanel.visible}, false, 1000);
        }

        function test_longCombo() {
            var comboListPanel = findChild(longCombo, "combobutton_combopanel");
            var comboList = findChild(longCombo, "combobutton_combolist");
            longCombo.expanded = true;
            waitForRendering(longCombo);
            waitForRendering(comboListPanel);
            tryCompareFunction(function() { return comboListPanel.visible}, true);
            verify(comboListPanel.height < longCombo.expandedHeight);
        }

        function test_listCombo() {
            var comboListPanel = findChild(listCombo, "combobutton_combopanel");
            var comboList = findChild(listCombo, "combobutton_combolist");
            listCombo.expanded = true;
            waitForRendering(listCombo);
            waitForRendering(comboListPanel);
            tryCompareFunction(function() { return comboListPanel.visible}, true);

            compare(list.height, comboList.height, "list and comboList height differs");
        }

        function test_expand_via_keyboard() {
            rectCombo.forceActiveFocus();
            waitForRendering(rectCombo);
            tryCompare(rectCombo, 'expanded', false, 500, "ComboBox not expanded after focus");
            keyClick(Qt.Key_Space);
            waitForRendering(rectCombo);
            tryCompare(rectCombo, 'expanded', true, 500, "ComboBox was expanded via the Space key");
            keyClick(Qt.Key_Space);
            waitForRendering(rectCombo);
            tryCompare(rectCombo, 'expanded', false, 500, "ComboBox was collapsed via the Space key");
        }
    }
}