@@ -1,191 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
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.
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 General Public License for more details.
12− *
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/>.
15− */
16−
17−import QtQuick 2.0
18−import QtTest 1.0
19−import ".."
20−import "../../../qml/Components"
21−import Ubuntu.Components.ListItems 0.1 as ListItem
22−import Ubuntu.Components 0.1
23−import Unity.Test 0.1 as UT
24−
25−Item {
26− width: flowRect.width + controls.width
27− height: units.gu(80)
28−
29− Column {
30− id: controls
31− width: units.gu(40)
32− height: parent.height
33− anchors.top: parent.top
34− anchors.right: parent.right
35− ListItem.ValueSelector {
36− id: maxColumnsSelector
37− text: "maximumNumberOfColumns"
38− values: [2,4,8,13,1000]
39− selectedIndex: 1
40− }
41− ListItem.ValueSelector {
42− id: minHSpacingSelector
43− text: "minHorizontalSpacing"
44− values: [0,units.gu(2),units.gu(8),units.gu(25)]
45− selectedIndex: 0
46− }
47− }
48−
49− ListModel {
50− id: fakeModel
51− ListElement { name: "A" }
52− ListElement { name: "B" }
53− ListElement { name: "C" }
54− ListElement { name: "D" }
55− ListElement { name: "E" }
56− ListElement { name: "F" }
57− ListElement { name: "G" }
58− ListElement { name: "H" }
59− ListElement { name: "I" }
60− ListElement { name: "J" }
61− ListElement { name: "K" }
62− ListElement { name: "L" }
63− ListElement { name: "M" }
64− ListElement { name: "N" }
65− ListElement { name: "O" }
66− ListElement { name: "P" }
67− ListElement { name: "Q" }
68− ListElement { name: "R" }
69− ListElement { name: "S" }
70− ListElement { name: "T" }
71− ListElement { name: "U" }
72− }
73−
74− Rectangle {
75− id: flowRect
76− width: units.gu(80)
77− height: parent.height
78− color: "grey"
79− anchors.top: parent.top
80− anchors.left: parent.left
81−
82− ResponsiveFlowView {
83− id: flow
84− anchors.fill: parent
85− model: fakeModel
86− minimumHorizontalSpacing:
87− minHSpacingSelector.values[minHSpacingSelector.selectedIndex]
88− verticalSpacing: units.gu(2)
89− maximumNumberOfColumns:
90− maxColumnsSelector.values[maxColumnsSelector.selectedIndex]
91− referenceDelegateWidth: units.gu(6)
92−
93− delegate: Rectangle {
94− // So that it can be identified by test code
95− property bool isFlowDelegate: true
96− color: "grey"
97− border.color: "red"
98− border.width: 1
99−
100− // IMPORTANT: always use flow's cellWidth and cellHeight here to get
101− // ResponsiveFlowView's intended result
102− width: flow.cellWidth
103− height: flow.cellHeight
104−
105− Rectangle {
106− color: "green"
107− anchors.centerIn: parent
108− width: units.gu(6)
109− height: units.gu(6)
110− Text {
111− anchors.centerIn: parent
112− text: name
113− }
114− }
115−
116− Text { x:0; y:0; text:"(" + parent.x + ", " + parent.y + ")"}
117− }
118− }
119− }
120−
121− UT.UnityTestCase {
122− name: "ResponsiveFlowView"
123− when: windowShown
124−
125− function test_maximumNumberOfColumns_data() {
126− var data = new Array()
127−
128− data.push({selectedIndex: 0, maxColumnCount:2, columnCount: 2})
129− data.push({selectedIndex: 1, maxColumnCount:4, columnCount: 4})
130− data.push({selectedIndex: 2, maxColumnCount:8, columnCount: 8})
131− data.push({selectedIndex: 4, maxColumnCount:1000, columnCount: 13})
132−
133− return data
134− }
135−
136− /* Change ResponsiveFlowView's maximumNumberOfColumns property and check
137− that the resulting number of columns matches expectations */
138− function test_maximumNumberOfColumns(data) {
139− minHSpacingSelector.selectedIndex = 0
140−
141− // sanity checks
142− compare(maxColumnsSelector.values[data.selectedIndex], data.maxColumnCount)
143− compare(minHSpacingSelector.values[0], 0)
144−
145− maxColumnsSelector.selectedIndex = data.selectedIndex
146− tryCompareFunction(countFlowDelegatesOnFirstRow, data.columnCount);
147− compare(flow.columns, data.columnCount)
148− }
149−
150− function test_minimumHorizontalSpacing_data() {
151− var data = new Array()
152−
153− data.push({selectedIndex: 0, minHSpacing:0, columnCount: 13})
154− data.push({selectedIndex: 1, minHSpacing:units.gu(2), columnCount: 9})
155− data.push({selectedIndex: 2, minHSpacing:units.gu(8), columnCount: 5})
156− data.push({selectedIndex: 3, minHSpacing:units.gu(25), columnCount: 2})
157−
158− return data
159− }
160−
161− /* Change ResponsiveFlowView's minimumHorizontalSpacing property and check
162− that the resulting number of columns matches expectations */
163− function test_minimumHorizontalSpacing(data) {
164− maxColumnsSelector.selectedIndex = 4
165−
166− // sanity checks
167− compare(maxColumnsSelector.values[4], 1000)
168− compare(minHSpacingSelector.values[data.selectedIndex], data.minHSpacing)
169−
170− minHSpacingSelector.selectedIndex = data.selectedIndex
171− tryCompareFunction(countFlowDelegatesOnFirstRow, data.columnCount);
172− compare(flow.columns, data.columnCount)
173− }
174−
175− function countFlowDelegatesOnFirstRow() {
176− return __countFlowDelegatesOnFirstRow(flow.visibleChildren, 0)
177− }
178−
179− function __countFlowDelegatesOnFirstRow(objList, total) {
180− for (var i = 0; i < objList.length; ++i) {
181− var child = objList[i];
182− if (child.isFlowDelegate !== undefined && child.y === 0) {
183− ++total;
184− } else {
185− total = __countFlowDelegatesOnFirstRow(child.visibleChildren, total)
186− }
187− }
188− return total
189− }
190− }
191−}