on xenial help sign in
Add tests.
de29d17Michał Karnicki
tests/qmltests/Components/tst_FilterGrid.qml+41−2
@@ -20,6 +20,7 @@ import "../../../qml/Components"
20import Ubuntu.Components.ListItems 0.1 as ListItem
20import Ubuntu.Components.ListItems 0.1 as ListItem
21import Ubuntu.Components 0.1
21import Ubuntu.Components 0.1
22import Unity.Test 0.1 as UT
22import Unity.Test 0.1 as UT
23+import Utils 0.1
23
24
24/*
25/*
25 You should see 6 green squares (from "A" to "F") and a button "View all (12)".
26 You should see 6 green squares (from "A" to "F") and a button "View all (12)".
@@ -42,8 +43,14 @@ Rectangle {
42 values: [1,2,3,4]
43 values: [1,2,3,4]
43 selectedIndex: 1
44 selectedIndex: 1
44 }
45 }
46+ ListItem.ValueSelector {
47+ id: modelCountLimitSelector
48+ text: "model count limit"
49+ values: [1, 3, 4, 7, 12]
50+ selectedIndex: 4
51+ }
45 Row {
52 Row {
46− spacing: units.gu(1)
53+ spacing: units.gu(3)
47 Label { anchors.verticalCenter: parent.verticalCenter
54 Label { anchors.verticalCenter: parent.verticalCenter
48 text: "Filter" }
55 text: "Filter" }
49 CheckBox {
56 CheckBox {
@@ -51,6 +58,11 @@ Rectangle {
51 checked: true
58 checked: true
52 }
59 }
53 }
60 }
61+ Row {
62+ spacing: units.gu(3)
63+ Label { text: "rowsWhenCollapsed"}
64+ Label { text: filterGrid.rowsWhenCollapsed }
65+ }
54 }
66 }
55
67
56 ListModel {
68 ListModel {
@@ -69,6 +81,12 @@ Rectangle {
69 ListElement { name: "L" }
81 ListElement { name: "L" }
70 }
82 }
71
83
84+ LimitProxyModel {
85+ id: limitedFakeModel
86+ model: fakeModel
87+ limit: modelCountLimitSelector.values[modelCountLimitSelector.selectedIndex]
88+ }
89+
72 Rectangle {
90 Rectangle {
73 id: gridRect
91 id: gridRect
74 width: units.gu(30)
92 width: units.gu(30)
@@ -80,7 +98,7 @@ Rectangle {
80 FilterGrid {
98 FilterGrid {
81 id: filterGrid
99 id: filterGrid
82 anchors.fill: parent
100 anchors.fill: parent
83− model: fakeModel
101+ model: limitedFakeModel
84 maximumNumberOfColumns: 3
102 maximumNumberOfColumns: 3
85 collapsedRowCount:
103 collapsedRowCount:
86 collapsedRowCountSelector.values[collapsedRowCountSelector.selectedIndex]
104 collapsedRowCountSelector.values[collapsedRowCountSelector.selectedIndex]
@@ -110,6 +128,7 @@ Rectangle {
110 when: windowShown
128 when: windowShown
111
129
112 function test_turningFilterOffShowsAllElements() {
130 function test_turningFilterOffShowsAllElements() {
131+ modelCountLimitSelector.selectedIndex = 4 // all items
113 tryCompareFunction(countVisibleDelegates, 6)
132 tryCompareFunction(countVisibleDelegates, 6)
114
133
115 filterCheckBox.checked = false
134 filterCheckBox.checked = false
@@ -121,6 +140,8 @@ Rectangle {
121 }
140 }
122
141
123 function test_collapsedRowCount() {
142 function test_collapsedRowCount() {
143+ modelCountLimitSelector.selectedIndex = 4 // all items
144+
124 for (var i = 0; i < 4; ++i) {
145 for (var i = 0; i < 4; ++i) {
125 collapsedRowCountSelector.selectedIndex = i
146 collapsedRowCountSelector.selectedIndex = i
126 // We have 3 elements per row.
147 // We have 3 elements per row.
@@ -132,6 +153,24 @@ Rectangle {
132 collapsedRowCountSelector.selectedIndex = 1
153 collapsedRowCountSelector.selectedIndex = 1
133 }
154 }
134
155
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+
135 function countVisibleDelegates() {
174 function countVisibleDelegates() {
136 return __countVisibleDelegates(filterGrid.visibleChildren, 0)
175 return __countVisibleDelegates(filterGrid.visibleChildren, 0)
137 }
176 }