on xenial help sign in
fixed tests
commit4bf584d670871d1eb4440d52f6efb6a689a2001b authorNick Dedekind <nicholas.dedekind@gmail.com> dateTue 14 Jan 2014, 16:44 (13 years ago) parent09e3927
13 files changed+93−88
qml/Panel/IndicatorRow.qml+1−1 qml/Panel/Indicators.qml+4−4 qml/Panel/Indicators/VisibleIndicatorsModel.qml+40−37 qml/Panel/MenuContent.qml+7−1 tests/mocks/Unity/Indicators/IndicatorsModel.qml+5−5 tests/mocks/Unity/Indicators/qml/fake_menu_page1.qml−1 tests/mocks/Unity/Indicators/qml/fake_menu_page2.qml−1 tests/mocks/Unity/Indicators/qml/fake_menu_page3.qml−1 tests/mocks/Unity/Indicators/qml/fake_menu_page4.qml−1 tests/mocks/Unity/Indicators/qml/fake_menu_page5.qml−1 tests/qmltests/Panel/tst_IndicatorRow.qml+3−1 tests/qmltests/Panel/tst_Indicators.qml+27−20 tests/qmltests/Panel/tst_MenuContent.qml+6−14
qml/Panel/IndicatorRow.qml+1−1
@@ -84,7 +84,7 @@ Item {
8484 id: itemWrapper
8585 objectName: "item" + index
8686 height: indicatorRow.height
87− width: visible ? indicatorItem.width : 0
87+ width: indicatorItem.width
8888 opacity: 1 - indicatorRow.unitProgress
8989 y: 0
9090 state: "standard"
qml/Panel/Indicators.qml+4−4
@@ -181,7 +181,7 @@ Showable {
181181 }
182182
183183 VisibleIndicatorsModel {
184− id: indicatorsModel
184+ id: visibleIndicators
185185 }
186186
187187 MenuContent {
@@ -194,7 +194,7 @@ Showable {
194194 top: indicatorRow.bottom
195195 bottom: handle.top
196196 }
197− indicatorsModel: indicatorsModel
197+ indicatorsModel: visibleIndicators.model
198198 clip: !indicators.fullyOpened
199199 activeHeader: indicators.state == "hint" || indicators.state == "reveal"
200200 enabled: contentEnabled
@@ -255,7 +255,7 @@ Showable {
255255 right: parent.right
256256 }
257257 height: indicators.panelHeight
258− indicatorsModel: indicatorsModel
258+ indicatorsModel: visibleIndicators.model
259259 state: indicators.state
260260 unitProgress: indicators.unitProgress
261261
@@ -429,6 +429,6 @@ Showable {
429429
430430 Component.onCompleted: initialise();
431431 function initialise() {
432− indicatorsModel.load();
432+ visibleIndicators.load();
433433 }
434434}
qml/Panel/Indicators/VisibleIndicatorsModel.qml+40−37
@@ -21,56 +21,59 @@ import QtQuick 2.0
2121import Unity.Indicators 0.1 as Indicators
2222import Utils 0.1
2323
24−SortFilterProxyModel {
25− id: filteredIndicators
24+Item {
25+ property SortFilterProxyModel model: filterModel
2626
27− model: Indicators.VisibleIndicatorsModel {
28− id: visibleIndicatorsModel
29− model: indicatorsModel
27+ SortFilterProxyModel {
28+ id: filterModel
29+ filterRole: Indicators.IndicatorsModelRole.IsVisible
30+ filterRegExp: RegExp("^true$")
31+ dynamicSortFilter: true
32+
33+ model: Indicators.VisibleIndicatorsModel {
34+ id: visibleIndicatorsModel
35+ model: indicatorsModel
36+ }
3037 }
3138
32− filterRole: Indicators.IndicatorsModelRole.IsVisible
33− filterRegExp: RegExp("^true$")
34− dynamicSortFilter: true
3539
36− property Item __container: Item {
37− Indicators.IndicatorsModel {
38− id: indicatorsModel
39− }
40+ Indicators.IndicatorsModel {
41+ id: indicatorsModel
42+ }
4043
41− Repeater {
42− id: repeater
43− model: indicatorsModel
44+ Repeater {
45+ id: repeater
46+ model: indicatorsModel
4447
45− property var visibleIndicators: undefined
46− onVisibleIndicatorsChanged: {
47− if (visibleIndicators !== undefined) {
48− visibleIndicatorsModel.visible = visibleIndicators;
49− }
48+ property var visibleIndicators: undefined
49+ onVisibleIndicatorsChanged: {
50+ if (visibleIndicators !== undefined) {
51+ visibleIndicatorsModel.visible = visibleIndicators;
5052 }
53+ }
5154
52− delegate: IndicatorDelegate {
53− id: item
54− Component.onCompleted: {
55− for(var pName in indicatorProperties) {
56− if (item.hasOwnProperty(pName)) {
57− item[pName] = indicatorProperties[pName];
58− }
55+ delegate: IndicatorDelegate {
56+ id: item
57+ objectName: model.identifier + "-delegate"
58+ Component.onCompleted: {
59+ for(var pName in indicatorProperties) {
60+ if (item.hasOwnProperty(pName)) {
61+ item[pName] = indicatorProperties[pName];
5962 }
60− updateVisibility();
6163 }
64+ updateVisibility();
65+ }
6266
63− onEnabledChanged: {
64− updateVisibility()
65− }
67+ onEnabledChanged: {
68+ updateVisibility()
69+ }
6670
67− function updateVisibility() {
68− if (repeater.visibleIndicators === undefined) {
69− repeater.visibleIndicators = {}
70− }
71− repeater.visibleIndicators[model.identifier] = enabled;
72− repeater.visibleIndicatorsChanged();
71+ function updateVisibility() {
72+ if (repeater.visibleIndicators === undefined) {
73+ repeater.visibleIndicators = {}
7374 }
75+ repeater.visibleIndicators[model.identifier] = enabled;
76+ repeater.visibleIndicatorsChanged();
7477 }
7578 }
7679 }
qml/Panel/MenuContent.qml+7−1
@@ -70,7 +70,7 @@ MainView {
7070
7171 Repeater {
7272 id: repeater
73− model: indicatorsModel ? indicatorsModel : null
73+ model: content.indicatorsModel ? content.indicatorsModel : null
7474 objectName: "tabsRepeater"
7575
7676 // FIXME: This is needed because tabs dont handle repeaters well.
@@ -126,6 +126,12 @@ MainView {
126126 property: "title"
127127 value: loader.item && loader.item.hasOwnProperty("title") && loader.item.title !== "" ? loader.item.title : model.identifier
128128 }
129+
130+ Binding {
131+ target: loader.item
132+ property: "objectName"
133+ value: identifier + "-page"
134+ }
129135 }
130136 }
131137 }
tests/mocks/Unity/Indicators/IndicatorsModel.qml+5−5
@@ -28,35 +28,35 @@ ListModel {
2828 "position": 0,
2929 "widgetSource": "qrc:/tests/indciators/qml/fake_menu_widget1.qml",
3030 "pageSource": "qrc:/tests/indciators/qml/fake_menu_page1.qml",
31− "indicatorProperties": ""
31+ "indicatorProperties": { enabled: true }
3232 });
3333
3434 append({ "identifier": "indicator-fake2",
3535 "position": 1,
3636 "widgetSource": "qrc:/tests/indciators/qml/fake_menu_widget2.qml",
3737 "pageSource": "qrc:/tests/indciators/qml/fake_menu_page2.qml",
38− "indicatorProperties": ""
38+ "indicatorProperties": { enabled: true }
3939 });
4040
4141 append({ "identifier": "indicator-fake3",
4242 "position": 2,
4343 "widgetSource": "qrc:/tests/indciators/qml/fake_menu_widget3.qml",
4444 "pageSource": "qrc:/tests/indciators/qml/fake_menu_page3.qml",
45− "indicatorProperties": ""
45+ "indicatorProperties": { enabled: true }
4646 });
4747
4848 append({ "identifier": "indicator-fake4",
4949 "position": 3,
5050 "widgetSource": "qrc:/tests/indciators/qml/fake_menu_widget4.qml",
5151 "pageSource": "qrc:/tests/indciators/qml/fake_menu_page4.qml",
52− "indicatorProperties": ""
52+ "indicatorProperties": { enabled: true }
5353 });
5454
5555 append({ "identifier": "indicator-fake5",
5656 "position": 4,
5757 "widgetSource": "qrc:/tests/indciators/qml/fake_menu_widget5.qml",
5858 "pageSource": "qrc:/tests/indciators/qml/fake_menu_page5.qml",
59− "indicatorProperties": ""
59+ "indicatorProperties": { enabled: true }
6060 });
6161 }
6262}
tests/mocks/Unity/Indicators/qml/fake_menu_page1.qml−1
@@ -19,7 +19,6 @@ import Unity.Indicators 0.1 as Indicators
1919
2020Indicators.FakeMenuPage {
2121 id: menu_plugin1
22− objectName: "menu_page1"
2322
2423 Rectangle {
2524 id: contents
tests/mocks/Unity/Indicators/qml/fake_menu_page2.qml−1
@@ -19,7 +19,6 @@ import Unity.Indicators 0.1 as Indicators
1919
2020Indicators.FakeMenuPage {
2121 id: menu_plugin2
22− objectName: "menu_page2"
2322
2423 Rectangle {
2524 id: contents
tests/mocks/Unity/Indicators/qml/fake_menu_page3.qml−1
@@ -19,7 +19,6 @@ import Unity.Indicators 0.1 as Indicators
1919
2020Indicators.FakeMenuPage {
2121 id: menu_plugin3
22− objectName: "menu_page3"
2322
2423 Rectangle {
2524 id: contents
tests/mocks/Unity/Indicators/qml/fake_menu_page4.qml−1
@@ -19,7 +19,6 @@ import Unity.Indicators 0.1 as Indicators
1919
2020Indicators.FakeMenuPage {
2121 id: menu_plugin4
22− objectName: "menu_page4"
2322
2423 Rectangle {
2524 id: contents
tests/mocks/Unity/Indicators/qml/fake_menu_page5.qml−1
@@ -19,7 +19,6 @@ import Unity.Indicators 0.1 as Indicators
1919
2020Indicators.FakeMenuPage {
2121 id: menu_plugin5
22− objectName: "menu_page5"
2322
2423 Rectangle {
2524 id: contents
tests/qmltests/Panel/tst_IndicatorRow.qml+3−1
@@ -51,6 +51,8 @@ Item {
5151 }
5252
5353 indicatorsModel: indicatorModel
54+
55+ Component.onCompleted: indicatorModel.load()
5456 }
5557
5658 Indicators.IndicatorsModel {
@@ -122,7 +124,7 @@ Item {
122124 indicatorRow.unitProgress = data.progress;
123125 indicatorRow.setCurrentItemIndex(data.index);
124126
125− compare(indicatorRow.currentItem.opacity, data.current, "Indicator opacity did not match for current item");
127+ tryCompare(indicatorRow.currentItem, "opacity", data.current);
126128
127129 for (var i = 0; i < indicatorRow.row.count; i++) {
128130 tryCompare(get_indicator_item_at(i), "opacity", i === data.index ? data.current: data.other);
tests/qmltests/Panel/tst_Indicators.qml+27−20
@@ -104,9 +104,11 @@ Item {
104104
105105 var indicatorRow = findChild(indicators, "indicatorRow")
106106 verify(indicatorRow !== undefined)
107+ var indicatorRowItems = findChild(indicatorRow, "indicatorRowItems");
108+ verify(indicatorRowItems !== undefined)
107109
108− for (var i = 0; i < indicatorRow.row.count; i++) {
109− var indicatorItem = findChild(indicatorRow.row, "item" + i);
110+ for (var i = 0; i < indicatorRowItems.count; i++) {
111+ var indicatorItem = findChild(indicatorRowItems, "item" + i);
110112
111113 if (!indicatorItem.visible)
112114 continue;
@@ -164,8 +166,8 @@ Item {
164166 }
165167
166168 function init_invisible_indicator(identifier) {
167− tryCompareFunction(function() { return findChild(indicators, identifier+"-widget") !== undefined }, true);
168− var item = findChild(indicators, identifier+"-widget");
169+ tryCompareFunction(function() { return findChild(indicators, identifier+"-delegate") !== undefined }, true);
170+ var item = findChild(indicators, identifier+"-delegate");
169171
170172 item.enabled = false;
171173 }
@@ -183,32 +185,36 @@ Item {
183185 indicators.show();
184186
185187 var indicatorTabs = findChild(indicators, "tabs");
186− var indicatorRow = findChild(indicators, "indicatorRow");
188+ var indicatorRowItems = findChild(indicators, "indicatorRowItems");
187189
188190
191+ var count = data.visible.length
189192 for (var i = 0; i< data.visible.length; i++) {
190− if (data.visible[i] === false)
193+ if (data.visible[i] === false) {
191194 init_invisible_indicator("indicator-fake" + (i + 1));
195+ count--;
196+ }
192197 }
193198
199+ tryCompare(indicatorRowItems, "count", count);
200+
194201 for (i = 0; i < data.visible.length; i++) {
195− var shouldBeVisible = data.visible[i];
202+ var widgetName = "indicator-fake" + (i + 1 + "-widget");
203+ var pageName = "indicator-fake" + (i + 1 + "-page");
196204
197− // check item visibility
198− var indicatorItem = findChild(indicatorRow.row, "item" + i);
199− verify(indicatorItem !== undefined);
200− tryCompare(indicatorItem, "visible", shouldBeVisible);
205+ // check for item
206+ tryCompareFunction(function() { return findChild(indicatorRowItems, widgetName) !== undefined }, data.visible[i]);
201207
202− // check tab visibility
203− tryCompareFunction(function() { return findChild(indicatorTabs, "indicator-fake" + (i + 1)) !== undefined }, shouldBeVisible);
208+ // check for tab
209+ tryCompareFunction(function() { return findChild(indicatorTabs, pageName) !== undefined }, data.visible[i]);
204210 }
205211 }
206212
207213 function test_indicator_visible_correct_tabs_data() { return [
208− {tag: "current-first", currentIndex: 0, visible: [false, true, true, true, true], expected: 1 },
209− {tag: "current-last", currentIndex: 4, visible: [true, true, true, true, false], expected: 3 },
210− {tag: "after", currentIndex: 0, visible: [true, false, true, true, true], expected: 0 },
211− {tag: "before", currentIndex: 1, visible: [false, true, true, true, true], expected: 1 }];
214+ {tag: "current-first", currentIndex: 0, visible: [false, true, true, true, true], expectedIndex: 0, expectedTab: "indicator-fake2" },
215+ {tag: "current-last", currentIndex: 4, visible: [true, true, true, true, false], expectedIndex: 3, expectedTab: "indicator-fake4" },
216+ {tag: "after", currentIndex: 0, visible: [true, false, true, true, true], expectedIndex: 0, expectedTab: "indicator-fake1" },
217+ {tag: "before", currentIndex: 1, visible: [false, true, true, true, true], expectedIndex: 1, expectedTab: "indicator-fake2" }];
212218 }
213219
214220 function test_indicator_visible_correct_tabs(data) {
@@ -221,15 +227,16 @@ Item {
221227 tryCompare(indicators, "fullyOpened", true);
222228
223229 for (var i = 0; i< data.visible.length; i++) {
224− if (data.visible[i] === false)
230+ if (data.visible[i] === false) {
225231 init_invisible_indicator("indicator-fake" + (i + 1));
232+ }
226233 }
227234
228235 // check for current selected item
229− tryCompare(indicatorRow, "currentItemIndex", data.expected);
236+ tryCompare(indicatorRow, "currentItemIndex", data.expectedIndex);
230237
231238 // check for current selected tab
232− tryCompareFunction(function() { return findChild(indicatorTabs, "indicator-fake" + (data.expected + 1)) === indicatorTabs.selectedTab }, true);
239+ tryCompareFunction(function() { return findChild(indicatorTabs, data.expectedTab) === indicatorTabs.selectedTab }, true);
233240
234241 }
235242 }
tests/qmltests/Panel/tst_MenuContent.qml+6−14
@@ -27,11 +27,11 @@ Item {
2727 height: units.gu(70)
2828
2929 property var indicator_status: {
30− 'menu_page1': { 'started': false, 'reset': 0 },
31− 'menu_page2': { 'started': false, 'reset': 0 },
32− 'menu_page3': { 'started': false, 'reset': 0 },
33− 'menu_page4': { 'started': false, 'reset': 0 },
34− 'menu_page5': { 'started': false, 'reset': 0 }
30+ 'indicator-fake1-page': { 'started': false, 'reset': 0 },
31+ 'indicator-fake2-page': { 'started': false, 'reset': 0 },
32+ 'indicator-fake3-page': { 'started': false, 'reset': 0 },
33+ 'indicator-fake4-page': { 'started': false, 'reset': 0 },
34+ 'indicator-fake5-page': { 'started': false, 'reset': 0 }
3535 }
3636
3737 // Dummy objects
@@ -49,14 +49,6 @@ Item {
4949 indicatorsModel: indicatorsModel
5050 contentReleaseInterval: 50
5151 height: parent.height - 50
52−
53− visibleIndicators: {
54− 'indicator-fake1': true,
55− 'indicator-fake2': true,
56− 'indicator-fake3': true,
57− 'indicator-fake4': true,
58− 'indicator-fake5': true
59− }
6052 }
6153
6254 Rectangle {
@@ -96,7 +88,7 @@ Item {
9688 }
9789
9890 function get_test_menu_objecName(index) {
99− return "menu_page"+(index+1);
91+ return "indicator-fake" + (index + 1) + "-page";
10092 }
10193
10294 property string testTabObjectName : ""