2
* Copyright 2013 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; version 3.
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 General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
import "../../../Components"
20
import Ubuntu.Components.ListItems 0.1 as ListItem
21
import Ubuntu.Components 0.1
22
import Unity.Test 0.1 as UT
25
You should see 6 green squares (from "A" to "F") and a button "View all (12)".
26
Once you press that button other 6 green squares (from "G" to "L") should show up.
29
width: gridRect.width + controls.width
37
anchors.top: parent.top
38
anchors.right: parent.right
39
ListItem.ValueSelector {
40
id: collapsedRowCountSelector
41
text: "collapsedRowCount"
47
Label { anchors.verticalCenter: parent.verticalCenter
50
id: expandableCheckBox
56
Label { anchors.verticalCenter: parent.verticalCenter
67
ListElement { name: "A" }
68
ListElement { name: "B" }
69
ListElement { name: "C" }
70
ListElement { name: "D" }
71
ListElement { name: "E" }
72
ListElement { name: "F" }
73
ListElement { name: "G" }
74
ListElement { name: "H" }
75
ListElement { name: "I" }
76
ListElement { name: "J" }
77
ListElement { name: "K" }
78
ListElement { name: "L" }
86
anchors.top: parent.top
87
anchors.left: parent.left
93
maximumNumberOfColumns: 3
95
collapsedRowCountSelector.values[collapsedRowCountSelector.selectedIndex]
96
filter: filterCheckBox.checked
97
expandable: expandableCheckBox.checked
98
minimumHorizontalSpacing: units.gu(1)
99
delegateWidth: units.gu(6)
100
delegateHeight: units.gu(6)
101
verticalSpacing: units.gu(1)
103
delegate: Rectangle {
104
// So that it can be identified by countVisibleDelegates()
105
property bool isGridDelegate: true
111
anchors.centerIn: parent
122
function test_turningFilterOffShowsAllElements() {
123
tryCompareFunction(countVisibleDelegates, 6)
125
filterCheckBox.checked = false
127
tryCompareFunction(countVisibleDelegates, 12)
129
// back to initial state
130
filterCheckBox.checked = true
133
function test_collapsedRowCount() {
134
for (var i = 0; i < 4; ++i) {
135
collapsedRowCountSelector.selectedIndex = i
136
// We have 3 elements per row.
137
// row count == index + 1
138
tryCompareFunction(countVisibleDelegates, 3*(i+1))
141
// back to initial state
142
collapsedRowCountSelector.selectedIndex = 1
145
// Checks that the filter toggle button, the one that says "View All (xy)",
146
// shows up only when it's possible for the grid to be expanded.
147
function test_filterToggleButton() {
148
var filterToggleButton = findChild(filterGrid, "filterToggleButton");
150
for (var i = 0; i < 4; ++i) {
151
collapsedRowCountSelector.selectedIndex = i
152
// row count == index + 1
153
// The total number of rows is 4.
155
expandableCheckBox.checked = false
156
compare(filterToggleButton.visible, false)
157
expandableCheckBox.checked = true
160
compare(filterToggleButton.visible, true)
162
compare(filterToggleButton.visible, false)
165
// back to initial state
166
collapsedRowCountSelector.selectedIndex = 1
167
expandableCheckBox.checked = true
170
function countVisibleDelegates() {
171
return __countVisibleDelegates(filterGrid.visibleChildren, 0)
174
function __countVisibleDelegates(objList, total) {
175
for (var i = 0; i < objList.length; ++i) {
176
var child = objList[i];
177
if (child.isGridDelegate !== undefined) {
180
total = __countVisibleDelegates(child.visibleChildren, total)