on xenial help sign in
add a test to check hiding of the keyboard indicator
b4a96ffLukáš Tinkl
qml/Panel/IndicatorItemRow.qml+9−1
@@ -17,7 +17,10 @@
17import QtQuick 2.4
17import QtQuick 2.4
18import QtQuick.Window 2.2
18import QtQuick.Window 2.2
19import Ubuntu.Components 1.3
19import Ubuntu.Components 1.3
20+
21+// for indicator-keyboard
20import AccountsService 0.1
22import AccountsService 0.1
23+import Unity.InputInfo 0.1
21
24
22Item {
25Item {
23 id: root
26 id: root
@@ -128,6 +131,11 @@ Item {
128 property bool forceAlignmentAnimationDisabled: false
131 property bool forceAlignmentAnimationDisabled: false
129 }
132 }
130
133
134+ InputDeviceModel {
135+ id: keyboardsModel
136+ deviceFilter: InputInfo.Keyboard
137+ }
138+
131 onCurrentItemChanged: {
139 onCurrentItemChanged: {
132 if (d.previousItem) {
140 if (d.previousItem) {
133 d.firstItemSwitch = false;
141 d.firstItemSwitch = false;
@@ -189,7 +197,7 @@ Item {
189 // HACK for indicator-session
197 // HACK for indicator-session
190 readonly property bool hideSessionIndicator: identifier == "indicator-session" && Math.min(Screen.width, Screen.height) <= units.gu(60)
198 readonly property bool hideSessionIndicator: identifier == "indicator-session" && Math.min(Screen.width, Screen.height) <= units.gu(60)
191 // HACK for indicator-keyboard
199 // HACK for indicator-keyboard
192− readonly property bool hideKeyboardIndicator: identifier == "indicator-keyboard" && (AccountsService.keymaps.length < 2 || !hasKeyboard)
200+ readonly property bool hideKeyboardIndicator: identifier == "indicator-keyboard" && (AccountsService.keymaps.length < 2 || keyboardsModel.count == 0)
193
201
194
202
195 height: row.height
203 height: row.height
tests/mocks/Unity/Indicators/IndicatorsModel.qml+28−1
@@ -21,6 +21,15 @@ Indicators.FakeIndicatorsModel {
21 id: root
21 id: root
22
22
23 property var originalModelData: [
23 property var originalModelData: [
24+ {
25+ "identifier": "indicator-keyboard",
26+ "indicatorProperties": {
27+ "enabled": true,
28+ "busName": "com.canonical.indicators.fake0",
29+ "menuObjectPath": "/com/canonical/indicators/fake0",
30+ "actionsObjectPath": "/com/canonical/indicators/fake0"
31+ }
32+ },
24 {
33 {
25 "identifier": "fake-indicator-bluetooth",
34 "identifier": "fake-indicator-bluetooth",
26 "indicatorProperties": {
35 "indicatorProperties": {
@@ -74,6 +83,15 @@ Indicators.FakeIndicatorsModel {
74 "menuObjectPath": "/com/canonical/indicators/fake6",
83 "menuObjectPath": "/com/canonical/indicators/fake6",
75 "actionsObjectPath": "/com/canonical/indicators/fake6"
84 "actionsObjectPath": "/com/canonical/indicators/fake6"
76 }
85 }
86+ },
87+ {
88+ "identifier": "fake-indicator-session",
89+ "indicatorProperties": {
90+ "enabled": true,
91+ "busName": "com.canonical.indicators.fake7",
92+ "menuObjectPath": "/com/canonical/indicators/fake7",
93+ "actionsObjectPath": "/com/canonical/indicators/fake7"
94+ }
77 }
95 }
78 ]
96 ]
79
97
@@ -81,6 +99,11 @@ Indicators.FakeIndicatorsModel {
81 unload();
99 unload();
82 root.modelData = originalModelData;
100 root.modelData = originalModelData;
83
101
102+ Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake0",
103+ getUnityMenuModelData("indicator-keyboard",
104+ "Czech (F)",
105+ "",
106+ [ "image://theme/indicator-keyboard-Cs-1" ]));
84 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake1",
107 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake1",
85 getUnityMenuModelData("fake-indicator-bluetooth",
108 getUnityMenuModelData("fake-indicator-bluetooth",
86 "Bluetooth (F)",
109 "Bluetooth (F)",
@@ -111,6 +134,11 @@ Indicators.FakeIndicatorsModel {
111 "Upcoming Events (F)",
134 "Upcoming Events (F)",
112 "12:04",
135 "12:04",
113 []));
136 []));
137+ Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake7",
138+ getUnityMenuModelData("fake-indicator-session",
139+ "System (F)",
140+ "",
141+ ["image://theme/system-devices-panel"]));
114 }
142 }
115
143
116 function getUnityMenuModelData(identifier, title, label, icons) {
144 function getUnityMenuModelData(identifier, title, label, icons) {
@@ -173,6 +201,5 @@ Indicators.FakeIndicatorsModel {
173 break;
201 break;
174 }
202 }
175 }
203 }
176−
177 }
204 }
178}
205}
tests/qmltests/Panel/tst_IndicatorItemRow.qml+25
@@ -21,6 +21,8 @@ import "../../../qml/Panel"
21import Ubuntu.Components 1.3
21import Ubuntu.Components 1.3
22import Unity.Test 0.1 as UT
22import Unity.Test 0.1 as UT
23import Unity.Indicators 0.1 as Indicators
23import Unity.Indicators 0.1 as Indicators
24+import AccountsService 0.1
25+import Unity.InputInfo 0.1
24
26
25IndicatorTest {
27IndicatorTest {
26 id: root
28 id: root
@@ -285,5 +287,28 @@ IndicatorTest {
285 // should go back to 0
287 // should go back to 0
286 tryCompare(findChild(indicatorsRow, "highlight"), "highlightCenterOffset", 0);
288 tryCompare(findChild(indicatorsRow, "highlight"), "highlightCenterOffset", 0);
287 }
289 }
290+
291+ function test_hidingKeyboardIndicator_data() {
292+ return [
293+ { tag: "No keyboard, no keymap", keyboard: false, keymaps: [], hidden: true },
294+ { tag: "No keyboard, one keymap", keyboard: false, keymaps: ["us"], hidden: true },
295+ { tag: "No keyboard, 2 keymaps", keyboard: false, keymaps: ["us", "cs"], hidden: true },
296+ { tag: "Keyboard, no keymap", keyboard: true, keymaps: [], hidden: true },
297+ { tag: "Keyboard, one keymap", keyboard: true, keymaps: ["us"], hidden: true },
298+ { tag: "Keyboard, 2 keymaps", keyboard: true, keymaps: ["us", "cs"], hidden: false }
299+ ];
300+ }
301+
302+ function test_hidingKeyboardIndicator(data) {
303+ var item = findChild(indicatorsRow, root.originalModelData[0]["identifier"] + "-panelItem");
304+ AccountsService.keymaps = data.keymaps;
305+ if (data.keyboard) {
306+ MockInputDeviceBackend.addMockDevice("/kbd0", InputInfo.Keyboard);
307+ }
308+ tryCompare(item, "hidden", data.hidden);
309+ if (data.keyboard) {
310+ MockInputDeviceBackend.removeDevice("/kbd0");
311+ }
312+ }
288 }
313 }
289}
314}