on xenial help sign in
Added test for menu item selection on remove
commit685ff7caf4b9fa5c070a2be90db02f63dc926bba authorNick Dedekind <nick.dedekind@canonical.com> dateTue 21 Oct 2014, 14:21 (12 years ago) parent1955e18
2 files changed+61−10
qml/Panel/Indicators/DefaultIndicatorPage.qml+2−1 tests/qmltests/Panel/Indicators/tst_DefaultIndicatorPage.qml+59−9
qml/Panel/Indicators/DefaultIndicatorPage.qml+2−1
@@ -29,6 +29,7 @@ IndicatorBase {
2929 //const
3030 property string title: rootActionState.title
3131 property alias highlightFollowsCurrentItem : mainMenu.highlightFollowsCurrentItem
32+ readonly property alias factory: _factory
3233
3334 Indicators.UnityMenuModelStack {
3435 id: menuStack
@@ -181,7 +182,7 @@ IndicatorBase {
181182 }
182183
183184 MenuItemFactory {
184− id: factory
185+ id: _factory
185186 rootModel: main.menuModel ? main.menuModel : null
186187 menuModel: mainMenu.model ? mainMenu.model : null
187188 }
tests/qmltests/Panel/Indicators/tst_DefaultIndicatorPage.qml+59−9
@@ -18,6 +18,7 @@ import QtQuick 2.0
1818import QtTest 1.0
1919import Unity.Test 0.1 as UT
2020import QMenuModel 0.1
21+import Ubuntu.Settings.Menus 0.1 as Menus
2122import "../../../../qml/Panel/Indicators"
2223
2324Item {
@@ -37,8 +38,27 @@ Item {
3738
3839 identifier: "test-indicator"
3940 rootMenuType: "com.canonical.indicator.root"
41+
42+ factory {
43+ _map: {
44+ "default": {
45+ "com.canonical.indicator.test" : testMenu
46+ }
47+ }
48+ }
4049 }
4150
51+ Component {
52+ id: testMenu
53+ Menus.StandardMenu {
54+ property QtObject menuData: null
55+ property int menuIndex: -1
56+
57+ signal menuSelected
58+ signal menuDeselected
59+ }
60+ }
61+
4262 property var fullMenuData: [{
4363 "rowData": { // 1
4464 "label": "root",
@@ -55,39 +75,39 @@ Item {
5575 },
5676 "submenu": [{
5777 "rowData": { // 1.1
58− "label": "menu1",
78+ "label": "menu0",
5979 "sensitive": true,
6080 "isSeparator": false,
6181 "icon": "",
62− "type": "",
82+ "type": "com.canonical.indicator.test",
6383 "ext": {},
64− "action": "",
84+ "action": "menu0",
6585 "actionState": {},
6686 "isCheck": false,
6787 "isRadio": false,
6888 "isToggled": false,
6989 }}, {
7090 "rowData": { // 1.2
71− "label": "menu2",
91+ "label": "menu1",
7292 "sensitive": true,
7393 "isSeparator": false,
7494 "icon": "",
75− "type": "",
95+ "type": "com.canonical.indicator.test",
7696 "ext": {},
77− "action": "",
97+ "action": "menu1",
7898 "actionState": {},
7999 "isCheck": false,
80100 "isRadio": false,
81101 "isToggled": false,
82102 }}, {
83103 "rowData": { // row 1.2
84− "label": "menu3",
104+ "label": "menu2",
85105 "sensitive": true,
86106 "isSeparator": false,
87107 "icon": "",
88− "type": "",
108+ "type": "com.canonical.indicator.test",
89109 "ext": {},
90− "action": "",
110+ "action": "menu2",
91111 "actionState": {},
92112 "isCheck": false,
93113 "isRadio": false,
@@ -152,5 +172,35 @@ Item {
152172 var mainMenu = findChild(page, "mainMenu");
153173 tryCompare(mainMenu, "count", data.expectedCount);
154174 }
175+
176+ function test_remove_selected_item_data() {
177+ return [
178+ { remove: 0 },
179+ { remove: 2 },
180+ ]
181+ }
182+
183+ function test_remove_selected_item(data) {
184+ var mainMenu = findChild(page, "mainMenu");
185+ page.menuModel.modelData = fullMenuData;
186+
187+ tryCompare(mainMenu, "count", 3);
188+
189+ var menuId = "menu"+data.remove
190+
191+ tryCompareFunction(function() { return findChild(page, menuId) !== null;}, true);
192+ var menu = findChild(page, menuId);
193+
194+ menu.menuSelected();
195+ compare(mainMenu.currentIndex, data.remove, "Incorrect index selected");
196+ mainMenu.model.removeRow(data.remove);
197+
198+ compare(mainMenu.currentIndex, -1, "Current index should be reset after current item removal");
199+
200+ // now make sure selecting a new menu works.
201+ var menu1 = findChild(page, "menu1");
202+ menu1.menuSelected();
203+ compare(menu1.selected, true, "Item not selected");
204+ }
155205 }
156206}