on xenial help sign in
Better visibility tests for indicators
1184266Nick Dedekind
tests/mocks/Unity/Indicators/IndicatorsModel.qml+2−5
@@ -21,12 +21,9 @@ ListModel {
21
21
22 property var indicatorData : undefined
22 property var indicatorData : undefined
23
23
24− function load() {}
24+ function load() {
25+ clear();
25
26
26− // Need to do this dynamically.
27− // Apparently ListModels dont order roles visually when using ListElement
28− // which throws off the filter for non-visible indicators.
29− Component.onCompleted: {
30 append({ "identifier": "indicator-fake1",
27 append({ "identifier": "indicator-fake1",
31 "position": 0,
28 "position": 0,
32 "widgetSource": "qrc:/tests/indciators/qml/fake_menu_widget1.qml",
29 "widgetSource": "qrc:/tests/indciators/qml/fake_menu_widget1.qml",
tests/mocks/Unity/Indicators/qml/fake_menu_widget2.qml+1−3
@@ -19,7 +19,5 @@ import QtQuick 2.0
19Rectangle {
19Rectangle {
20 width: 40
20 width: 40
21 height: 40
21 height: 40
22− color : "yellow"
22+ color : "blue"
23−
24− enabled: false
25}
23}
tests/mocks/Unity/Indicators/qml/fake_menu_widget3.qml+1−1
@@ -19,5 +19,5 @@ import QtQuick 2.0
19Rectangle {
19Rectangle {
20 width: 40
20 width: 40
21 height: 40
21 height: 40
22− color : "blue"
22+ color : "yellow"
23}
23}
tests/qmltests/Panel/tst_IndicatorRow.qml+2−1
@@ -32,6 +32,8 @@ Item {
32
32
33 function init_test()
33 function init_test()
34 {
34 {
35+ indicatorModel.load();
36+
35 indicatorRow.state = "initial";
37 indicatorRow.state = "initial";
36 indicatorRow.currentItem = null;
38 indicatorRow.currentItem = null;
37 indicatorRow.unitProgress = 0.0;
39 indicatorRow.unitProgress = 0.0;
@@ -53,7 +55,6 @@ Item {
53
55
54 Indicators.IndicatorsModel {
56 Indicators.IndicatorsModel {
55 id: indicatorModel
57 id: indicatorModel
56− Component.onCompleted: load()
57 }
58 }
58
59
59 UT.UnityTestCase {
60 UT.UnityTestCase {
tests/qmltests/Panel/tst_Indicators.qml+60−8
@@ -83,6 +83,8 @@ Item {
83 when: windowShown
83 when: windowShown
84
84
85 function init() {
85 function init() {
86+ indicators.initialise();
87+
86 indicators.hide();
88 indicators.hide();
87 tryCompare(indicators.hideAnimation, "running", false);
89 tryCompare(indicators.hideAnimation, "running", false);
88 tryCompare(indicators, "state", "initial");
90 tryCompare(indicators, "state", "initial");
@@ -161,21 +163,71 @@ Item {
161 compare(indicators.fullyOpened, true);
163 compare(indicators.fullyOpened, true);
162 }
164 }
163
165
166+ function init_invisible_indicator(identifier) {
167+ tryCompareFunction(function() { return findChild(indicators, identifier+"-widget") !== undefined }, true);
168+ var item = findChild(indicators, identifier+"-widget");
169+
170+ item.enabled = false;
171+ }
172+
164 function test_row_visible_menuContent_visible_data() { return [
173 function test_row_visible_menuContent_visible_data() { return [
165− {tag: "visible", index: 0, name: "indicator-fake1", visible: true },
174+ {tag: "first", visible: [false, true, true, true, true] },
166− {tag: "invisible", index: 1, name: "indicator-fake2", visible: false }]
175+ {tag: "adjacent", visible: [true, false, false, true, true] },
176+ {tag: "bounds", visible: [false, true, true, true, false] },
177+ {tag: "disjoint", visible: [true, false, true, false, true] },
178+ {tag: "last", visible: [true, true, true, true, false] }];
167 }
179 }
168
180
169 function test_row_visible_menuContent_visible(data) {
181 function test_row_visible_menuContent_visible(data) {
182+
183+ indicators.show();
184+
185+ var indicatorTabs = findChild(indicators, "tabs");
186+ var rowRepeater = findChild(indicators, "rowRepeater")
187+
188+
189+ for (var i = 0; i< data.visible.length; i++) {
190+ if (data.visible[i] === false)
191+ init_invisible_indicator("indicator-fake" + (i + 1));
192+ }
193+
194+ for (i = 0; i < data.visible.length; i++) {
195+ var shouldBeVisible = data.visible[i];
196+
197+ // check item visibility
198+ var indicatorItem = rowRepeater.itemAt(i);
199+ tryCompare(indicatorItem, "visible", shouldBeVisible);
200+ // check tab visibility
201+ tryCompareFunction(function() { return findChild(indicatorTabs, "indicator-fake" + (i + 1)) !== undefined }, shouldBeVisible);
202+ }
203+ }
204+
205+ function test_indicator_visible_correct_tabs_data() { return [
206+ {tag: "current-first", currentIndex: 0, visible: [false, true, true, true, true], expected: 1 },
207+ {tag: "current-last", currentIndex: 4, visible: [true, true, true, true, false], expected: 3 },
208+ {tag: "after", currentIndex: 0, visible: [true, false, true, true, true], expected: 0 },
209+ {tag: "before", currentIndex: 1, visible: [false, true, true, true, true], expected: 1 }];
210+ }
211+
212+ function test_indicator_visible_correct_tabs(data) {
213+
170 var indicatorTabs = findChild(indicators, "tabs");
214 var indicatorTabs = findChild(indicators, "tabs");
171− var rowRepeater = findChild(indicators, "rowRepeater");
215+ var indicatorRow = findChild(indicators, "indicatorRow");
216+
217+ indicators.show();
218+ indicatorRow.setCurrentItem(data.currentIndex);
219+ tryCompare(indicators, "fullyOpened", true);
220+
221+ for (var i = 0; i< data.visible.length; i++) {
222+ if (data.visible[i] === false)
223+ init_invisible_indicator("indicator-fake" + (i + 1));
224+ }
172
225
173− var indicatorItem = rowRepeater.itemAt(data.index);
226+ // check for current selected item
227+ tryCompare(indicatorRow, "currentItemIndex", data.expected);
228+ // check for current selected tab
174− tryCompareFunction(function() { return indicatorItem.width > 0}, true);
229+ tryCompareFunction(function() { return findChild(indicatorTabs, "indicator-fake" + (data.expected + 1)) === indicatorTabs.selectedTab }, true);
175− tryCompare(indicatorItem, "visible", data.visible);
176
230
177− var indicatorTab = findChild(indicatorTabs, data.name)
178− tryCompareFunction(function() { return indicatorTab !== undefined }, data.visible);
179 }
231 }
180 }
232 }
181}
233}
tests/qmltests/Panel/tst_Panel.qml+2
@@ -56,6 +56,8 @@ Item {
56 }
56 }
57
57
58 function init() {
58 function init() {
59+ panel.indicators.initialise();
60+
59 searchClicked = false;
61 searchClicked = false;
60 panel.indicators.hide();
62 panel.indicators.hide();
61 tryCompare(panel.indicators.hideAnimation, "running", false);
63 tryCompare(panel.indicators.hideAnimation, "running", false);