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
|
/*
* Copyright 2014-2015 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.0
import Lomiri.Components 1.3
import Lomiri.Components.Styles 1.3
Item {
width: units.gu(40)
height: units.gu(71)
ListModel {
id: testModel
Component.onCompleted: reload()
function reload() {
clear();
for (var i = 0; i < 25; i++) {
append({data: i});
}
}
}
ListItemActions {
id: actions
actions: Action {
iconName: "delete"
}
}
property real expandedHeight
Column {
id: defColumn
anchors.fill: parent
spacing: units.gu(0.5)
ListItem {
id: defaults
}
ListView {
id: listView
width: parent.width
height: units.gu(28)
clip: true
model: testModel
delegate: ListItem {
objectName: "listItem" + index
Label { text: "ListItem " + modelData }
expansion.height: expandedHeight
leadingActions: actions
}
}
Flickable {
id: flickable
width: parent.width
height: units.gu(28)
clip: true
contentHeight: flickableColumn.height
Column {
id: flickableColumn
width: parent.width
Repeater {
model: testModel
ListItem {
objectName: "listItem" + index
Label { text: "ListItem " + modelData }
expansion.height: expandedHeight
leadingActions: actions
onClicked: expansion.expanded = !expansion.expanded
}
}
}
}
}
ListItemTestCase13 {
name: "ListItemExpansion"
when: windowShown
function init() {
expandedHeight = units.gu(12);
}
function cleanup() {
expandedHeight = 0;
// move both views to the top
listView.positionViewAtBeginning();
flickable.contentY = 0;
listView.ViewItems.expandedIndices = [];
flickableColumn.ViewItems.expandedIndices = [];
listView.ViewItems.expansionFlags = ViewItems.Exclusive;
flickableColumn.ViewItems.expansionFlags = ViewItems.Exclusive;
wait(200);
}
function initTestCase() {
compare(defaults.expansion.expanded, false, "Not expanded by default");
compare(defaults.expansion.height, 0, "No expansion height by default");
verify(defColumn.ViewItems.expandedIndices, "ViewItems.expandedIndices not defined");
verify(defColumn.ViewItems.expansionFlags, ViewItems.Exclusive);
}
function test_exclusive_expansion_data() {
return [
{tag: "ListView", test: listView, expand1: 0, expand2: 2},
{tag: "Flickable", test: flickableColumn, expand1: 0, expand2: 2},
];
}
function test_exclusive_expansion(data) {
var item1 = findChild(data.test, "listItem" + data.expand1);
var item2 = findChild(data.test, "listItem" + data.expand2);
verify(item1);
verify(item2);
expand(item1, true);
compare(data.test.ViewItems.expandedIndices.length, 1, "More items expanded");
compare(data.test.ViewItems.expandedIndices[0], data.expand1, "More items expanded");
// expand the other one
expand(item2, true);
compare(data.test.ViewItems.expandedIndices.length, 1, "More items expanded");
compare(data.test.ViewItems.expandedIndices[0], data.expand2, "More items expanded");
}
function test_multiple_expanded_data() {
return [
{tag: "ListView", test: listView, expand1: 0, expand2: 2},
{tag: "Flickable", test: flickableColumn, expand1: 0, expand2: 2},
];
}
function test_multiple_expanded(data) {
var item1 = findChild(data.test, "listItem" + data.expand1);
var item2 = findChild(data.test, "listItem" + data.expand2);
verify(item1);
verify(item2);
data.test.ViewItems.expansionFlags = 0;
expand(item1, true);
expand(item2, true);
compare(data.test.ViewItems.expandedIndices.length, 2, "Different amount of items expanded");
}
function test_locked_while_expanded_data() {
return [
{tag: "ListView, locked", test: listView, expand: 0, flags: 0, xfail: true},
{tag: "Flickable, locked", test: flickableColumn, expand: 0, flags: 0, xfail: true},
{tag: "ListView, unlocked", test: listView, expand: 0, flags: ViewItems.UnlockExpanded, xfail: false},
{tag: "Flickable, unlocked", test: flickableColumn, expand: 0, flags: ViewItems.UnlockExpanded, xfail: false},
];
}
function test_locked_while_expanded(data) {
var item = findChild(data.test, "listItem" + data.expand);
verify(item);
data.test.ViewItems.expansionFlags = data.flags;
expand(item, true);
setupSpy(item, "contentMovementEnded");
swipeNoWait(item, centerOf(item).x, centerOf(item).y, units.gu(10), 0);
if (data.xfail) {
expectFailContinue(data.tag, "No panel swipe is allowed");
}
spyWait();
}
function test_colapse_on_external_click_data() {
return [
{tag: "ListView", test: listView, expand1: 1, clickOn: 0},
{tag: "Flickable", test: flickableColumn, expand1: 1, clickOn: 0},
];
}
function test_colapse_on_external_click(data) {
var item = findChild(data.test, "listItem" + data.expand1);
var clickItem = findChild(data.test, "listItem" + data.clickOn);
verify(item);
verify(clickItem);
var collapsedHeight = item.height;
data.test.ViewItems.expansionFlags = ViewItems.CollapseOnOutsidePress;
expand(item, true);
mouseClick(clickItem, centerOf(clickItem).x, centerOf(clickItem).y);
tryCompareFunction(function() { return item.height; }, collapsedHeight, 500);
}
}
}
|