on xenial help sign in
Fixed PanelMenuPage tests
4a079b9Nick Dedekind
qml/Panel/PanelMenuPage.qml+13−13
@@ -73,12 +73,12 @@ PageStack {
73 Page {
73 Page {
74 id: page
74 id: page
75
75
76− property alias menuModel: mainMenu.model
76+ property alias menuModel: listView.model
77 property alias title: backLabel.title
77 property alias title: backLabel.title
78 property bool isSubmenu: false
78 property bool isSubmenu: false
79
79
80 function reset() {
80 function reset() {
81− mainMenu.positionViewAtBeginning();
81+ listView.positionViewAtBeginning();
82 }
82 }
83
83
84 property QtObject factory: root.factory.createObject(page, { menuModel: page.menuModel } )
84 property QtObject factory: root.factory.createObject(page, { menuModel: page.menuModel } )
@@ -98,8 +98,8 @@ PageStack {
98 }
98 }
99
99
100 ListView {
100 ListView {
101− id: mainMenu
101+ id: listView
102− objectName: "mainMenu"
102+ objectName: "listView"
103
103
104 anchors {
104 anchors {
105 top: page.isSubmenu ? backLabel.bottom : parent.top
105 top: page.isSubmenu ? backLabel.bottom : parent.top
@@ -116,7 +116,7 @@ PageStack {
116 }
116 }
117 // TODO - does ever frame.
117 // TODO - does ever frame.
118 onBottomMarginChanged: {
118 onBottomMarginChanged: {
119− mainMenu.positionViewAtIndex(mainMenu.currentIndex, ListView.End)
119+ listView.positionViewAtIndex(listView.currentIndex, ListView.End)
120 }
120 }
121 }
121 }
122
122
@@ -155,11 +155,11 @@ PageStack {
155 }
155 }
156
156
157 Connections {
157 Connections {
158− target: mainMenu.model ? mainMenu.model : null
158+ target: listView.model ? listView.model : null
159 onRowsAboutToBeRemoved: {
159 onRowsAboutToBeRemoved: {
160 // track current item deletion.
160 // track current item deletion.
161− if (mainMenu.selectedIndex >= first && mainMenu.selectedIndex <= last) {
161+ if (listView.selectedIndex >= first && listView.selectedIndex <= last) {
162− mainMenu.selectedIndex = -1;
162+ listView.selectedIndex = -1;
163 }
163 }
164 }
164 }
165 }
165 }
@@ -175,13 +175,13 @@ PageStack {
175
175
176 onLoaded: {
176 onLoaded: {
177 if (item.hasOwnProperty("selected")) {
177 if (item.hasOwnProperty("selected")) {
178− item.selected = mainMenu.selectedIndex == index;
178+ item.selected = listView.selectedIndex == index;
179 }
179 }
180 if (item.hasOwnProperty("menuSelected")) {
180 if (item.hasOwnProperty("menuSelected")) {
181− item.menuSelected.connect(function() { mainMenu.selectedIndex = index; });
181+ item.menuSelected.connect(function() { listView.selectedIndex = index; });
182 }
182 }
183 if (item.hasOwnProperty("menuDeselected")) {
183 if (item.hasOwnProperty("menuDeselected")) {
184− item.menuDeselected.connect(function() { mainMenu.selectedIndex = -1; });
184+ item.menuDeselected.connect(function() { listView.selectedIndex = -1; });
185 }
185 }
186 if (item.hasOwnProperty("menuData")) {
186 if (item.hasOwnProperty("menuData")) {
187 item.menuData = Qt.binding(function() { return model; });
187 item.menuData = Qt.binding(function() { return model; });
@@ -211,10 +211,10 @@ PageStack {
211 // TODO: Fixes lp#1243146
211 // TODO: Fixes lp#1243146
212 // This is a workaround for a Qt bug. https://bugreports.qt-project.org/browse/QTBUG-34351
212 // This is a workaround for a Qt bug. https://bugreports.qt-project.org/browse/QTBUG-34351
213 Connections {
213 Connections {
214− target: mainMenu
214+ target: listView
215 onSelectedIndexChanged: {
215 onSelectedIndexChanged: {
216 if (loader.item && loader.item.hasOwnProperty("selected")) {
216 if (loader.item && loader.item.hasOwnProperty("selected")) {
217− loader.item.selected = mainMenu.selectedIndex == index;
217+ loader.item.selected = listView.selectedIndex == index;
218 }
218 }
219 }
219 }
220 }
220 }
tests/qmltests/Panel/tst_PanelMenuPage.qml+59−47
@@ -16,42 +16,52 @@
16
16
17import QtQuick 2.4
17import QtQuick 2.4
18import QtTest 1.0
18import QtTest 1.0
19+import Ubuntu.Components 1.3
19import Unity.Test 0.1 as UT
20import Unity.Test 0.1 as UT
20−import Unity.Indicators 0.1 as Indicators
21+import QMenuModel 0.1
21import Ubuntu.Settings.Menus 0.1 as Menus
22import Ubuntu.Settings.Menus 0.1 as Menus
22import "../../../qml/Panel"
23import "../../../qml/Panel"
24+import "../../../qml/Panel/Indicators"
23
25
24Item {
26Item {
25 id: testView
27 id: testView
26 width: units.gu(40)
28 width: units.gu(40)
27 height: units.gu(70)
29 height: units.gu(70)
28
30
29− IndicatorPage {
31+ UnityMenuModel {
32+ id: unityMenuModel
33+ modelData: fullMenuData
34+ }
35+
36+ PanelMenuPage {
30 id: page
37 id: page
31 anchors.fill: parent
38 anchors.fill: parent
32
39
33− identifier: "test-indicator"
40+ menuModel: unityMenuModel
34− busName: "com.caninical.indicator.test"
41+ submenuIndex: 0
35− actionsObjectPath: "/com/canonical/indicator/test"
42+
36− menuObjectPath: "/com/canonical/indicator/test"
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
37
56
38− factory {
57+ Menus.StandardMenu {
39− _map: {
58+ signal menuSelected
40− "default": {
59+ signal menuDeselected
41− "com.canonical.indicator.test" : testMenu
42 }
60 }
43 }
61 }
44 }
62 }
45 }
63 }
46
64
47− Component {
48− id: testMenu
49− Menus.StandardMenu {
50− signal menuSelected
51− signal menuDeselected
52− }
53− }
54−
55 property var fullMenuData: [{
65 property var fullMenuData: [{
56 "rowData": { // 1
66 "rowData": { // 1
57 "label": "root",
67 "label": "root",
@@ -126,43 +136,43 @@ Item {
126 "submenu": []
136 "submenu": []
127 }]; // end row 1
137 }]; // end row 1
128
138
129− function initializeMenuData(data) {
130− Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicator/test",
131− data);
132− }
133−
134 UT.UnityTestCase {
139 UT.UnityTestCase {
135 name: "IndicatorPage"
140 name: "IndicatorPage"
136
141
137 function init() {
142 function init() {
138− initializeMenuData([]);
143+ page.submenuIndex = 0;
144+ unityMenuModel.modelData = [];
145+ tryCompareFunction(function() { return page.currentPage == null }, true);
139 }
146 }
140
147
141− function test_reloadData() {
148+ function test_loadData() {
142− var mainMenu = findChild(page, "mainMenu");
149+ unityMenuModel.modelData = fullMenuData;
143
150
151+ tryCompareFunction(function() { return page.currentPage != null }, true);
152+ var listView = findChild(page.currentPage, "listView", 50);
153+ verify(listView);
144− tryCompare(mainMenu, "count", 0);
154+ tryCompare(listView, "count", 3);
145
155
146− initializeMenuData(fullMenuData);
156+ unityMenuModel.modelData = [];
147− tryCompare(mainMenu, "count", 3);
157+ tryCompareFunction(function() { return page.currentPage == null }, true);
148−
149− initializeMenuData([]);
150− tryCompare(mainMenu, "count", 0);
151 }
158 }
152
159
153− function test_traverse_rootMenuType_data() {
160+ function test_traverse_submenuIndex_data() {
154− return [
161+ return [,
155− { tag: "Incorrect", rootMenuType: "com.canonical.indicator", expectedCount: 0},
156− { tag: "Correct", rootMenuType: "com.canonical.indicator.root", expectedCount: 3},
162+ { tag: "Correct", submenuIndex: 0, expectedCount: 3},
163+ { tag: "Incorrect", submenuIndex: 1, expectedCount: 0}
157 ]
164 ]
158 }
165 }
159
166
160− function test_traverse_rootMenuType(data) {
167+ function test_traverse_submenuIndex(data) {
161− page.rootMenuType = data.rootMenuType;
168+ page.submenuIndex = data.submenuIndex;
162− initializeMenuData(fullMenuData);
169+ unityMenuModel.modelData = fullMenuData;
163
170
171+ tryCompareFunction(function() { return page.currentPage != null }, data.expectedCount > 0);
172+ if (data.expectedCount > 0) {
164− var mainMenu = findChild(page, "mainMenu");
173+ var listView = findChild(page.currentPage, "listView", 50);
165− tryCompare(mainMenu, "count", data.expectedCount);
174+ tryCompare(listView, "count", data.expectedCount);
175+ }
166 }
176 }
167
177
168 function test_remove_selected_item_data() {
178 function test_remove_selected_item_data() {
@@ -173,20 +183,22 @@ Item {
173 }
183 }
174
184
175 function test_remove_selected_item(data) {
185 function test_remove_selected_item(data) {
186+ unityMenuModel.modelData = fullMenuData;
176− var mainMenu = findChild(page, "mainMenu");
187+ var listView = findChild(page.currentPage, "listView", 50);
177− initializeMenuData(fullMenuData);
178
188
179 var menuId = "menu"+data.remove
189 var menuId = "menu"+data.remove
180− var menu = findChild(page, menuId);
190+ var menu = findChild(listView, menuId);
191+ verify(menu);
181
192
182 menu.menuSelected();
193 menu.menuSelected();
183− compare(mainMenu.currentIndex, data.remove, "Incorrect index selected");
194+ compare(listView.currentIndex, data.remove, "Incorrect index selected");
184− mainMenu.model.removeRow(data.remove);
195+ listView.model.removeRow(data.remove);
185
196
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");
187
198
188 // now make sure selecting a new menu works.
199 // now make sure selecting a new menu works.
189 var menu1 = findChild(page, "menu1");
200 var menu1 = findChild(page, "menu1");
201+ verify(menu1);
190 menu1.menuSelected();
202 menu1.menuSelected();
191 compare(menu1.selected, true, "Item not selected");
203 compare(menu1.selected, true, "Item not selected");
192 }
204 }