@@ -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 }