@@ -20,6 +20,7 @@ import "../../../qml/Components"
2020import Ubuntu.Components.ListItems 0.1 as ListItem
2121import Ubuntu.Components 0.1
2222import Unity.Test 0.1 as UT
23+import Utils 0.1
2324
2425/*
2526 You should see 6 green squares (from "A" to "F") and a button "View all (12)".
@@ -42,8 +43,14 @@ Rectangle {
4243 values: [1,2,3,4]
4344 selectedIndex: 1
4445 }
46+ ListItem.ValueSelector {
47+ id: modelCountLimitSelector
48+ text: "model count limit"
49+ values: [1, 3, 4, 7, 12]
50+ selectedIndex: 4
51+ }
4552 Row {
46− spacing: units.gu(1)
53+ spacing: units.gu(3)
4754 Label { anchors.verticalCenter: parent.verticalCenter
4855 text: "Filter" }
4956 CheckBox {
@@ -51,6 +58,11 @@ Rectangle {
5158 checked: true
5259 }
5360 }
61+ Row {
62+ spacing: units.gu(3)
63+ Label { text: "rowsWhenCollapsed"}
64+ Label { text: filterGrid.rowsWhenCollapsed }
65+ }
5466 }
5567
5668 ListModel {
@@ -69,6 +81,12 @@ Rectangle {
6981 ListElement { name: "L" }
7082 }
7183
84+ LimitProxyModel {
85+ id: limitedFakeModel
86+ model: fakeModel
87+ limit: modelCountLimitSelector.values[modelCountLimitSelector.selectedIndex]
88+ }
89+
7290 Rectangle {
7391 id: gridRect
7492 width: units.gu(30)
@@ -80,7 +98,7 @@ Rectangle {
8098 FilterGrid {
8199 id: filterGrid
82100 anchors.fill: parent
83− model: fakeModel
101+ model: limitedFakeModel
84102 maximumNumberOfColumns: 3
85103 collapsedRowCount:
86104 collapsedRowCountSelector.values[collapsedRowCountSelector.selectedIndex]
@@ -110,6 +128,7 @@ Rectangle {
110128 when: windowShown
111129
112130 function test_turningFilterOffShowsAllElements() {
131+ modelCountLimitSelector.selectedIndex = 4 // all items
113132 tryCompareFunction(countVisibleDelegates, 6)
114133
115134 filterCheckBox.checked = false
@@ -121,6 +140,8 @@ Rectangle {
121140 }
122141
123142 function test_collapsedRowCount() {
143+ modelCountLimitSelector.selectedIndex = 4 // all items
144+
124145 for (var i = 0; i < 4; ++i) {
125146 collapsedRowCountSelector.selectedIndex = i
126147 // We have 3 elements per row.
@@ -132,6 +153,24 @@ Rectangle {
132153 collapsedRowCountSelector.selectedIndex = 1
133154 }
134155
156+ function test_modelSizeAffectsCollapsedRowCount_data() {
157+ var data = new Array()
158+ data.push({modelLimitIndex: 3, rowsWhenCollapsed: 2, visibleDelegates: 6})
159+ data.push({modelLimitIndex: 2, rowsWhenCollapsed: 2, visibleDelegates: 4})
160+ data.push({modelLimitIndex: 1, rowsWhenCollapsed: 1, visibleDelegates: 3})
161+ data.push({modelLimitIndex: 1, rowsWhenCollapsed: 1, visibleDelegates: 3})
162+ data.push({modelLimitIndex: 0, rowsWhenCollapsed: 1, visibleDelegates: 1})
163+ return data
164+ }
165+
166+ function test_modelSizeAffectsCollapsedRowCount(data) {
167+ collapsedRowCountSelector.selectedIndex = 1 // 2 rows
168+
169+ modelCountLimitSelector.selectedIndex = data.modelLimitIndex
170+ compare(filterGrid.rowsWhenCollapsed, data.rowsWhenCollapsed)
171+ tryCompareFunction(countVisibleDelegates, data.visibleDelegates)
172+ }
173+
135174 function countVisibleDelegates() {
136175 return __countVisibleDelegates(filterGrid.visibleChildren, 0)
137176 }