@@ -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)".
@@ -69,6 +70,20 @@ Rectangle {
6970 ListElement { name: "L" }
7071 }
7172
73+ ListModel {
74+ id: fakeModelTwoItems
75+ ListElement { name: "A" }
76+ ListElement { name: "B" }
77+ }
78+
79+ ListModel {
80+ id: fakeModelFourItems
81+ ListElement { name: "A" }
82+ ListElement { name: "B" }
83+ ListElement { name: "C" }
84+ ListElement { name: "D" }
85+ }
86+
7287 Rectangle {
7388 id: gridRect
7489 width: units.gu(30)
@@ -109,15 +124,21 @@ Rectangle {
109124 name: "FilterGrid"
110125 when: windowShown
111126
127+ function init() {
128+ filterGrid.model = fakeModel
129+ }
130+
131+ function cleanup() {
132+ filterCheckBox.checked = true
133+ collapsedRowCountSelector.selectedIndex = 1
134+ }
135+
112136 function test_turningFilterOffShowsAllElements() {
113137 tryCompareFunction(countVisibleDelegates, 6)
114138
115139 filterCheckBox.checked = false
116140
117141 tryCompareFunction(countVisibleDelegates, 12)
118−
119− // back to initial state
120− filterCheckBox.checked = true
121142 }
122143
123144 function test_collapsedRowCount() {
@@ -127,9 +148,27 @@ Rectangle {
127148 // row count == index + 1
128149 tryCompareFunction(countVisibleDelegates, 3*(i+1))
129150 }
151+ }
130152
131− // back to initial state
132− collapsedRowCountSelector.selectedIndex = 1
153+ function test_modelSizeAffectsCollapsedRowCount_data() {
154+ return [
155+ { tag: "2 items, collapsedRows 1", model: fakeModelTwoItems, collapsedRowCountIndex: 0,
156+ rowsWhenCollapsed: 1, visibleDelegates: 2 },
157+ { tag: "2 items, collapsedRows 2", model: fakeModelTwoItems, collapsedRowCountIndex: 1,
158+ rowsWhenCollapsed: 1, visibleDelegates: 2 },
159+ { tag: "4 items, collapsedRows 1", model: fakeModelFourItems, collapsedRowCountIndex: 0,
160+ rowsWhenCollapsed: 1, visibleDelegates: 3 },
161+ { tag: "4 items, collapsedRows 2", model: fakeModelFourItems, collapsedRowCountIndex: 1,
162+ rowsWhenCollapsed: 2, visibleDelegates: 4 },
163+ ]
164+ }
165+
166+ function test_modelSizeAffectsCollapsedRowCount(data) {
167+ filterGrid.model = data.model
168+ collapsedRowCountSelector.selectedIndex = data.collapsedRowCountIndex
169+
170+ tryCompare(filterGrid, "rowsWhenCollapsed", data.rowsWhenCollapsed)
171+ tryCompareFunction(countVisibleDelegates, data.visibleDelegates)
133172 }
134173
135174 function countVisibleDelegates() {