on xenial help sign in
Fixed PanelMenuPage tests
commit4a079b9ec2b62b6f1917d8eff9a921bf2ea0c1e5 authorNick Dedekind <nick.dedekind@canonical.com> dateWed 5 Oct 2016, 12:17 (10 years ago) parentf1a543e
2 files changed+72−60
qml/Panel/PanelMenuPage.qml+13−13 tests/qmltests/Panel/tst_PanelMenuPage.qml+59−47
qml/Panel/PanelMenuPage.qml+13−13
@@ -73,12 +73,12 @@ PageStack {
7373 Page {
7474 id: page
7575
76− property alias menuModel: mainMenu.model
76+ property alias menuModel: listView.model
7777 property alias title: backLabel.title
7878 property bool isSubmenu: false
7979
8080 function reset() {
81− mainMenu.positionViewAtBeginning();
81+ listView.positionViewAtBeginning();
8282 }
8383
8484 property QtObject factory: root.factory.createObject(page, { menuModel: page.menuModel } )
@@ -98,8 +98,8 @@ PageStack {
9898 }
9999
100100 ListView {
101− id: mainMenu
102− objectName: "mainMenu"
101+ id: listView
102+ objectName: "listView"
103103
104104 anchors {
105105 top: page.isSubmenu ? backLabel.bottom : parent.top
@@ -116,7 +116,7 @@ PageStack {
116116 }
117117 // TODO - does ever frame.
118118 onBottomMarginChanged: {
119− mainMenu.positionViewAtIndex(mainMenu.currentIndex, ListView.End)
119+ listView.positionViewAtIndex(listView.currentIndex, ListView.End)
120120 }
121121 }
122122
@@ -155,11 +155,11 @@ PageStack {
155155 }
156156
157157 Connections {
158− target: mainMenu.model ? mainMenu.model : null
158+ target: listView.model ? listView.model : null
159159 onRowsAboutToBeRemoved: {
160160 // track current item deletion.
161− if (mainMenu.selectedIndex >= first && mainMenu.selectedIndex <= last) {
162− mainMenu.selectedIndex = -1;
161+ if (listView.selectedIndex >= first && listView.selectedIndex <= last) {
162+ listView.selectedIndex = -1;
163163 }
164164 }
165165 }
@@ -175,13 +175,13 @@ PageStack {
175175
176176 onLoaded: {
177177 if (item.hasOwnProperty("selected")) {
178− item.selected = mainMenu.selectedIndex == index;
178+ item.selected = listView.selectedIndex == index;
179179 }
180180 if (item.hasOwnProperty("menuSelected")) {
181− item.menuSelected.connect(function() { mainMenu.selectedIndex = index; });
181+ item.menuSelected.connect(function() { listView.selectedIndex = index; });
182182 }
183183 if (item.hasOwnProperty("menuDeselected")) {
184− item.menuDeselected.connect(function() { mainMenu.selectedIndex = -1; });
184+ item.menuDeselected.connect(function() { listView.selectedIndex = -1; });
185185 }
186186 if (item.hasOwnProperty("menuData")) {
187187 item.menuData = Qt.binding(function() { return model; });
@@ -211,10 +211,10 @@ PageStack {
211211 // TODO: Fixes lp#1243146
212212 // This is a workaround for a Qt bug. https://bugreports.qt-project.org/browse/QTBUG-34351
213213 Connections {
214− target: mainMenu
214+ target: listView
215215 onSelectedIndexChanged: {
216216 if (loader.item && loader.item.hasOwnProperty("selected")) {
217− loader.item.selected = mainMenu.selectedIndex == index;
217+ loader.item.selected = listView.selectedIndex == index;
218218 }
219219 }
220220 }
tests/qmltests/Panel/tst_PanelMenuPage.qml+59−47
@@ -16,42 +16,52 @@
1616
1717import QtQuick 2.4
1818import QtTest 1.0
19+import Ubuntu.Components 1.3
1920import Unity.Test 0.1 as UT
20−import Unity.Indicators 0.1 as Indicators
21+import QMenuModel 0.1
2122import Ubuntu.Settings.Menus 0.1 as Menus
2223import "../../../qml/Panel"
24+import "../../../qml/Panel/Indicators"
2325
2426Item {
2527 id: testView
2628 width: units.gu(40)
2729 height: units.gu(70)
2830
29− IndicatorPage {
31+ UnityMenuModel {
32+ id: unityMenuModel
33+ modelData: fullMenuData
34+ }
35+
36+ PanelMenuPage {
3037 id: page
3138 anchors.fill: parent
3239
33− identifier: "test-indicator"
34− busName: "com.caninical.indicator.test"
35− actionsObjectPath: "/com/canonical/indicator/test"
36− menuObjectPath: "/com/canonical/indicator/test"
40+ menuModel: unityMenuModel
41+ submenuIndex: 0
42+
43+ factory: factoryComponent
44+ }
45+
46+ Component {
47+ id: factoryComponent
48+
49+ Object {
50+ function load(model) {
51+ return standardMenuComponent;
52+ }
53+
54+ Component {
55+ id: standardMenuComponent
3756
38− factory {
39− _map: {
40− "default": {
41− "com.canonical.indicator.test" : testMenu
57+ Menus.StandardMenu {
58+ signal menuSelected
59+ signal menuDeselected
4260 }
4361 }
4462 }
4563 }
4664
47− Component {
48− id: testMenu
49− Menus.StandardMenu {
50− signal menuSelected
51− signal menuDeselected
52− }
53− }
54−
5565 property var fullMenuData: [{
5666 "rowData": { // 1
5767 "label": "root",
@@ -126,43 +136,43 @@ Item {
126136 "submenu": []
127137 }]; // end row 1
128138
129− function initializeMenuData(data) {
130− Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicator/test",
131− data);
132− }
133−
134139 UT.UnityTestCase {
135140 name: "IndicatorPage"
136141
137142 function init() {
138− initializeMenuData([]);
143+ page.submenuIndex = 0;
144+ unityMenuModel.modelData = [];
145+ tryCompareFunction(function() { return page.currentPage == null }, true);
139146 }
140147
141− function test_reloadData() {
142− var mainMenu = findChild(page, "mainMenu");
148+ function test_loadData() {
149+ unityMenuModel.modelData = fullMenuData;
143150
144− tryCompare(mainMenu, "count", 0);
151+ tryCompareFunction(function() { return page.currentPage != null }, true);
152+ var listView = findChild(page.currentPage, "listView", 50);
153+ verify(listView);
154+ tryCompare(listView, "count", 3);
145155
146− initializeMenuData(fullMenuData);
147− tryCompare(mainMenu, "count", 3);
148−
149− initializeMenuData([]);
150− tryCompare(mainMenu, "count", 0);
156+ unityMenuModel.modelData = [];
157+ tryCompareFunction(function() { return page.currentPage == null }, true);
151158 }
152159
153− function test_traverse_rootMenuType_data() {
154− return [
155− { tag: "Incorrect", rootMenuType: "com.canonical.indicator", expectedCount: 0},
156− { tag: "Correct", rootMenuType: "com.canonical.indicator.root", expectedCount: 3},
160+ function test_traverse_submenuIndex_data() {
161+ return [,
162+ { tag: "Correct", submenuIndex: 0, expectedCount: 3},
163+ { tag: "Incorrect", submenuIndex: 1, expectedCount: 0}
157164 ]
158165 }
159166
160− function test_traverse_rootMenuType(data) {
161− page.rootMenuType = data.rootMenuType;
162− initializeMenuData(fullMenuData);
167+ function test_traverse_submenuIndex(data) {
168+ page.submenuIndex = data.submenuIndex;
169+ unityMenuModel.modelData = fullMenuData;
163170
164− var mainMenu = findChild(page, "mainMenu");
165− tryCompare(mainMenu, "count", data.expectedCount);
171+ tryCompareFunction(function() { return page.currentPage != null }, data.expectedCount > 0);
172+ if (data.expectedCount > 0) {
173+ var listView = findChild(page.currentPage, "listView", 50);
174+ tryCompare(listView, "count", data.expectedCount);
175+ }
166176 }
167177
168178 function test_remove_selected_item_data() {
@@ -173,20 +183,22 @@ Item {
173183 }
174184
175185 function test_remove_selected_item(data) {
176− var mainMenu = findChild(page, "mainMenu");
177− initializeMenuData(fullMenuData);
186+ unityMenuModel.modelData = fullMenuData;
187+ var listView = findChild(page.currentPage, "listView", 50);
178188
179189 var menuId = "menu"+data.remove
180− var menu = findChild(page, menuId);
190+ var menu = findChild(listView, menuId);
191+ verify(menu);
181192
182193 menu.menuSelected();
183− compare(mainMenu.currentIndex, data.remove, "Incorrect index selected");
184− mainMenu.model.removeRow(data.remove);
194+ compare(listView.currentIndex, data.remove, "Incorrect index selected");
195+ listView.model.removeRow(data.remove);
185196
186− compare(mainMenu.currentIndex, -1, "Current index should be reset after current item removal");
197+ compare(listView.currentIndex, -1, "Current index should be reset after current item removal");
187198
188199 // now make sure selecting a new menu works.
189200 var menu1 = findChild(page, "menu1");
201+ verify(menu1);
190202 menu1.menuSelected();
191203 compare(menu1.selected, true, "Item not selected");
192204 }