| 1 |
/* |
| 2 |
* Copyright 2014 Canonical Ltd. |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU Lesser General Public License as published by |
| 6 |
* the Free Software Foundation; version 3. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
import QtQuick |
| 18 |
import QtTest |
| 19 |
import Lomiri.Test |
| 20 |
import Lomiri.Components |
| 21 |
import Lomiri.Components.ListItems |
| 22 |
|
| 23 |
Item { |
| 24 |
width: units.gu(40) |
| 25 |
height: units.gu(71) |
| 26 |
|
| 27 |
Column { |
| 28 |
ComboButton { |
| 29 |
id: combo |
| 30 |
} |
| 31 |
|
| 32 |
ComboButton { |
| 33 |
id: rectCombo |
| 34 |
onClicked: expanded = false |
| 35 |
|
| 36 |
Rectangle { |
| 37 |
id: rect |
| 38 |
width: parent.width |
| 39 |
height: units.gu(40) |
| 40 |
gradient: Gradient { |
| 41 |
GradientStop { |
| 42 |
position: 0.0 |
| 43 |
color: "red" |
| 44 |
} |
| 45 |
GradientStop { |
| 46 |
position: 0.5 |
| 47 |
color: "green" |
| 48 |
} |
| 49 |
GradientStop { |
| 50 |
position: 1.0 |
| 51 |
color: "blue" |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
ComboButton { |
| 58 |
id: columnCombo |
| 59 |
expandedHeight: -1 |
| 60 |
Column { |
| 61 |
id: column |
| 62 |
anchors { |
| 63 |
left: parent.left |
| 64 |
right: parent.right |
| 65 |
} |
| 66 |
height: childrenRect.height |
| 67 |
Repeater { |
| 68 |
model: 5 |
| 69 |
Rectangle { |
| 70 |
width: parent.width |
| 71 |
height: units.gu(5) |
| 72 |
color: Qt.rgba(Math.random(1), Math.random(1), Math.random(1), 1); |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
ComboButton { |
| 79 |
id: longCombo |
| 80 |
expandedHeight: units.gu(40) |
| 81 |
Rectangle { |
| 82 |
id: longRect |
| 83 |
height: units.gu(10) |
| 84 |
color: "cyan" |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
ComboButton { |
| 89 |
id: listCombo |
| 90 |
ListView { |
| 91 |
id: list |
| 92 |
model: 20 |
| 93 |
height: listCombo.comboListHeight |
| 94 |
delegate: Standard { |
| 95 |
text: modelData |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
SignalSpy { id: spy } |
| 102 |
|
| 103 |
LomiriTestCase { |
| 104 |
name: "ComboButton" |
| 105 |
when: windowShown |
| 106 |
|
| 107 |
function cleanup() { |
| 108 |
rectCombo.expanded = |
| 109 |
columnCombo.expanded = |
| 110 |
longCombo.expanded = |
| 111 |
listCombo.expanded = false; |
| 112 |
spy.clear(); |
| 113 |
spy.signalName = ""; |
| 114 |
spy.target = undefined; |
| 115 |
} |
| 116 |
|
| 117 |
function test_0_defaults() { |
| 118 |
compare(combo.expanded, false, "not expanded by default"); |
| 119 |
compare(combo.collapsedHeight, combo.implicitHeight, "collapsedHeight is implicitHeight"); |
| 120 |
compare(combo.expandedHeight, combo.collapsedHeight + units.gu(19.5), "expanded height default"); |
| 121 |
var lheight = combo.expandedHeight - combo.collapsedHeight - combo.__styleInstance.comboListMargin; |
| 122 |
compare(combo.comboListHeight, lheight, "comboListHeight default"); |
| 123 |
compare(combo.comboList.length, 0, "comboList is empty"); |
| 124 |
verify(combo.font === Qt.font({family: "Ubuntu", pixelSize: FontUtils.sizeToPixels("medium")}), "Default font differs."); |
| 125 |
} |
| 126 |
|
| 127 |
function test_comboListWidth() { |
| 128 |
var comboListHolder = findChild(rectCombo, "combobutton_combolist"); |
| 129 |
compare(rect.width, comboListHolder.width, "rectCombo list content width is not adjusted"); |
| 130 |
comboListHolder = findChild(columnCombo, "combobutton_combolist"); |
| 131 |
compare(column.width, comboListHolder.width, "columnCombo list content width is not adjusted"); |
| 132 |
comboListHolder = findChild(longCombo, "combobutton_combolist"); |
| 133 |
compare(longRect.width, comboListHolder.width, "longCombo list content width is not adjusted"); |
| 134 |
comboListHolder = findChild(listCombo, "combobutton_combolist"); |
| 135 |
compare(list.width, comboListHolder.width, "listCombo list content width is not adjusted"); |
| 136 |
} |
| 137 |
|
| 138 |
function test_expandRectComboThroughProperty() { |
| 139 |
rectCombo.expanded = true; |
| 140 |
waitForRendering(rectCombo); |
| 141 |
var comboListPanel = findChild(rectCombo, "combobutton_combopanel"); |
| 142 |
tryCompareFunction(function() { return comboListPanel.visible}, true); |
| 143 |
} |
| 144 |
|
| 145 |
function test_expandRectComboThroughClick() { |
| 146 |
var dropDown = findChild(rectCombo, "combobutton_dropdown"); |
| 147 |
mouseClick(dropDown, dropDown.width / 2, dropDown.height / 2); |
| 148 |
waitForRendering(rectCombo); |
| 149 |
compare(rectCombo.expanded, true, "combo is not expanded"); |
| 150 |
var comboListPanel = findChild(rectCombo, "combobutton_combopanel"); |
| 151 |
tryCompareFunction(function() { return comboListPanel.visible}, true); |
| 152 |
} |
| 153 |
|
| 154 |
function test_autoCollapse() { |
| 155 |
var dropDown = findChild(rectCombo, "combobutton_dropdown"); |
| 156 |
var comboListPanel = findChild(rectCombo, "combobutton_combopanel"); |
| 157 |
mouseClick(dropDown, dropDown.width / 2, dropDown.height / 2); |
| 158 |
waitForRendering(rectCombo); |
| 159 |
compare(rectCombo.expanded, true, "combo is not expanded"); |
| 160 |
tryCompareFunction(function() { return comboListPanel.visible}, true); |
| 161 |
|
| 162 |
mouseClick(rectCombo, rectCombo.width / 2, rectCombo.collapsedHeight / 2); |
| 163 |
waitForRendering(rectCombo); |
| 164 |
compare(rectCombo.expanded, false, "combo is not collapsed"); |
| 165 |
tryCompareFunction(function() { return comboListPanel.visible}, false); |
| 166 |
} |
| 167 |
|
| 168 |
function test_flickRectCombo() { |
| 169 |
skip("FIXME: Broken on Qt 5.12"); |
| 170 |
// the test is flaky on powerpc target |
| 171 |
// https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1315244 |
| 172 |
var dropDown = findChild(rectCombo, "combobutton_dropdown"); |
| 173 |
var comboListPanel = findChild(rectCombo, "combobutton_combopanel"); |
| 174 |
var comboList = findChild(rectCombo, "combobutton_combolist"); |
| 175 |
mouseClick(dropDown, dropDown.width / 2, dropDown.height / 2); |
| 176 |
waitForRendering(rectCombo); |
| 177 |
tryCompareFunction(function() { return comboListPanel.visible}, true); |
| 178 |
verify(comboList.height > rectCombo.expandedHeight); |
| 179 |
// comboList flicker is the combolist parent's parent |
| 180 |
var comboListFlicker = findChild(rectCombo, "combobutton_contentflicker"); |
| 181 |
compare(comboListFlicker.interactive, true, "combo list holder must be interactive"); |
| 182 |
|
| 183 |
// drag the rectangle, the Flickable should be moving |
| 184 |
var x = comboListFlicker.width / 2; |
| 185 |
var y = comboListFlicker.height / 2; |
| 186 |
var dy = comboListFlicker.height / 6; |
| 187 |
spy.target = comboListFlicker; |
| 188 |
spy.signalName = "onMovementEnded"; |
| 189 |
mouseDrag(comboList, x, y, 0, -dy); |
| 190 |
waitForRendering(comboListFlicker); |
| 191 |
spy.wait(); |
| 192 |
} |
| 193 |
|
| 194 |
function test_autoExpandHeight() { |
| 195 |
var comboListPanel = findChild(columnCombo, "combobutton_combopanel"); |
| 196 |
var comboList = findChild(columnCombo, "combobutton_combolist"); |
| 197 |
columnCombo.expanded = true; |
| 198 |
waitForRendering(columnCombo); |
| 199 |
tryCompareFunction(function() { return comboListPanel.visible}, true); |
| 200 |
var comboListFlicker = findChild(columnCombo, "combobutton_contentflicker"); |
| 201 |
waitForRendering(comboListFlicker); |
| 202 |
compare(comboListFlicker.interactive, false, "combo list holder must not be interactive"); |
| 203 |
tryCompare(comboListFlicker, 'height', columnCombo.comboListHeight, 500, "combo list height differs from the holder height"); |
| 204 |
} |
| 205 |
|
| 206 |
function test_emptyComboExpanded() { |
| 207 |
var comboListPanel = findChild(combo, "combobutton_combopanel"); |
| 208 |
var comboList = findChild(combo, "combobutton_combolist"); |
| 209 |
combo.expanded = true; |
| 210 |
waitForRendering(combo); |
| 211 |
waitForRendering(comboListPanel); |
| 212 |
tryCompareFunction(function() { return comboListPanel.visible}, false, 1000); |
| 213 |
} |
| 214 |
|
| 215 |
function test_longCombo() { |
| 216 |
var comboListPanel = findChild(longCombo, "combobutton_combopanel"); |
| 217 |
var comboList = findChild(longCombo, "combobutton_combolist"); |
| 218 |
longCombo.expanded = true; |
| 219 |
waitForRendering(longCombo); |
| 220 |
waitForRendering(comboListPanel); |
| 221 |
tryCompareFunction(function() { return comboListPanel.visible}, true); |
| 222 |
verify(comboListPanel.height < longCombo.expandedHeight); |
| 223 |
} |
| 224 |
|
| 225 |
function test_listCombo() { |
| 226 |
var comboListPanel = findChild(listCombo, "combobutton_combopanel"); |
| 227 |
var comboList = findChild(listCombo, "combobutton_combolist"); |
| 228 |
listCombo.expanded = true; |
| 229 |
waitForRendering(listCombo); |
| 230 |
waitForRendering(comboListPanel); |
| 231 |
tryCompareFunction(function() { return comboListPanel.visible}, true); |
| 232 |
|
| 233 |
compare(list.height, comboList.height, "list and comboList height differs"); |
| 234 |
} |
| 235 |
|
| 236 |
function test_expand_via_keyboard() { |
| 237 |
rectCombo.forceActiveFocus(); |
| 238 |
waitForRendering(rectCombo); |
| 239 |
tryCompare(rectCombo, 'expanded', false, 500, "ComboBox not expanded after focus"); |
| 240 |
keyClick(Qt.Key_Space); |
| 241 |
waitForRendering(rectCombo); |
| 242 |
tryCompare(rectCombo, 'expanded', true, 500, "ComboBox was expanded via the Space key"); |
| 243 |
keyClick(Qt.Key_Space); |
| 244 |
waitForRendering(rectCombo); |
| 245 |
tryCompare(rectCombo, 'expanded', false, 500, "ComboBox was collapsed via the Space key"); |
| 246 |
} |
| 247 |
} |
| 248 |
} |