on xenial help sign in
add a test to check hiding of the keyboard indicator
commitb4a96ff28433ad449cdd2230dda4e74e81f4c04e authorLukáš Tinkl <lukas.tinkl@canonical.com> dateMon 11 Jul 2016, 14:48 (10 years ago) parent3dbd619
3 files changed+62−2
qml/Panel/IndicatorItemRow.qml+9−1 tests/mocks/Unity/Indicators/IndicatorsModel.qml+28−1 tests/qmltests/Panel/tst_IndicatorItemRow.qml+25
qml/Panel/IndicatorItemRow.qml+9−1
@@ -17,7 +17,10 @@
1717import QtQuick 2.4
1818import QtQuick.Window 2.2
1919import Ubuntu.Components 1.3
20+
21+// for indicator-keyboard
2022import AccountsService 0.1
23+import Unity.InputInfo 0.1
2124
2225Item {
2326 id: root
@@ -128,6 +131,11 @@ Item {
128131 property bool forceAlignmentAnimationDisabled: false
129132 }
130133
134+ InputDeviceModel {
135+ id: keyboardsModel
136+ deviceFilter: InputInfo.Keyboard
137+ }
138+
131139 onCurrentItemChanged: {
132140 if (d.previousItem) {
133141 d.firstItemSwitch = false;
@@ -189,7 +197,7 @@ Item {
189197 // HACK for indicator-session
190198 readonly property bool hideSessionIndicator: identifier == "indicator-session" && Math.min(Screen.width, Screen.height) <= units.gu(60)
191199 // 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)
193201
194202
195203 height: row.height
tests/mocks/Unity/Indicators/IndicatorsModel.qml+28−1
@@ -21,6 +21,15 @@ Indicators.FakeIndicatorsModel {
2121 id: root
2222
2323 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+ },
2433 {
2534 "identifier": "fake-indicator-bluetooth",
2635 "indicatorProperties": {
@@ -74,6 +83,15 @@ Indicators.FakeIndicatorsModel {
7483 "menuObjectPath": "/com/canonical/indicators/fake6",
7584 "actionsObjectPath": "/com/canonical/indicators/fake6"
7685 }
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+ }
7795 }
7896 ]
7997
@@ -81,6 +99,11 @@ Indicators.FakeIndicatorsModel {
8199 unload();
82100 root.modelData = originalModelData;
83101
102+ Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake0",
103+ getUnityMenuModelData("indicator-keyboard",
104+ "Czech (F)",
105+ "",
106+ [ "image://theme/indicator-keyboard-Cs-1" ]));
84107 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake1",
85108 getUnityMenuModelData("fake-indicator-bluetooth",
86109 "Bluetooth (F)",
@@ -111,6 +134,11 @@ Indicators.FakeIndicatorsModel {
111134 "Upcoming Events (F)",
112135 "12:04",
113136 []));
137+ Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake7",
138+ getUnityMenuModelData("fake-indicator-session",
139+ "System (F)",
140+ "",
141+ ["image://theme/system-devices-panel"]));
114142 }
115143
116144 function getUnityMenuModelData(identifier, title, label, icons) {
@@ -173,6 +201,5 @@ Indicators.FakeIndicatorsModel {
173201 break;
174202 }
175203 }
176−
177204 }
178205}
tests/qmltests/Panel/tst_IndicatorItemRow.qml+25
@@ -21,6 +21,8 @@ import "../../../qml/Panel"
2121import Ubuntu.Components 1.3
2222import Unity.Test 0.1 as UT
2323import Unity.Indicators 0.1 as Indicators
24+import AccountsService 0.1
25+import Unity.InputInfo 0.1
2426
2527IndicatorTest {
2628 id: root
@@ -285,5 +287,28 @@ IndicatorTest {
285287 // should go back to 0
286288 tryCompare(findChild(indicatorsRow, "highlight"), "highlightCenterOffset", 0);
287289 }
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+ }
288313 }
289314}