@@ -17,222 +17,158 @@
1717import QtQuick 2.1
1818import QtQuick.Layouts 1.1
1919import QtTest 1.0
20−import ".."
21−import "../../../../qml/Panel/New"
20+import "../../../../qml/Panel"
2221import Ubuntu.Components 0.1
2322import Unity.Test 0.1 as UT
2423import Unity.Indicators 0.1 as Indicators
2524
26−Rectangle {
25+IndicatorTest {
26+ id: root
2727 width: units.gu(100)
2828 height: units.gu(30)
29− color: "white"
30−
31− Component.onCompleted: {
32− Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake1",
33− "/com/canonical/indicators/fake1",
34− "/com/canonical/indicators/fake1",
35− {
36− "title": "Bluetooth",
37− "icons": [ "image://theme/bluetooth-active" ],
38− });
39− Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake2",
40− "/com/canonical/indicators/fake2",
41− "/com/canonical/indicators/fake2",
42− {
43− "title": "Network",
44− "icons": [ "image://theme/simcard-error", "image://theme/wifi-high" ],
45− });
46− Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake3",
47− "/com/canonical/indicators/fake3",
48− "/com/canonical/indicators/fake3",
49− {
50− "title": "Sound",
51− "icons": [ "image://theme/audio-volume-high" ],
52− });
53− Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake4",
54− "/com/canonical/indicators/fake4",
55− "/com/canonical/indicators/fake4",
56− {
57− "title": "Battery",
58− "icons": [ "image://theme/battery-020" ],
59− });
60− Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake5",
61− "/com/canonical/indicators/fake5",
62− "/com/canonical/indicators/fake5",
63− {
64− "title": "Location",
65− "icons": [ "image://theme/gps" ],
66− });
67− Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake6",
68− "/com/canonical/indicators/fake6",
69− "/com/canonical/indicators/fake6",
70− {
71− "title": "Notifications",
72− "icons": [ "image://theme/messages-new" ],
73− });
74− Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake7",
75− "/com/canonical/indicators/fake7",
76− "/com/canonical/indicators/fake7",
77− {
78− "title": "Upcoming Events",
79− "label": "12:04",
80− });
81− }
8229
83− Indicators.FakeIndicatorsModel {
84− id: indicatorsModel
85−
86− indicatorData: [
87− {
88− "identifier": "indicator-fake1",
89− "indicatorProperties": {
90− "enabled": true,
91− "busName": "com.canonical.indicators.fake1",
92− "menuObjectPath": "/com/canonical/indicators/fake1",
93− "actionsObjectPath": "/com/canonical/indicators/fake1"
94− }
95− },
96− {
97− "identifier": "indicator-fake2",
98− "indicatorProperties": {
99− "enabled": true,
100− "busName": "com.canonical.indicators.fake2",
101− "menuObjectPath": "/com/canonical/indicators/fake2",
102− "actionsObjectPath": "/com/canonical/indicators/fake2"
103− }
104− },
105− {
106− "identifier": "indicator-fake3",
107− "indicatorProperties": {
108− "enabled": true,
109− "busName": "com.canonical.indicators.fake3",
110− "menuObjectPath": "/com/canonical/indicators/fake3",
111− "actionsObjectPath": "/com/canonical/indicators/fake3"
112− }
113− },
114− {
115− "identifier": "indicator-fake4",
116− "indicatorProperties": {
117− "enabled": true,
118− "busName": "com.canonical.indicators.fake4",
119− "menuObjectPath": "/com/canonical/indicators/fake4",
120− "actionsObjectPath": "/com/canonical/indicators/fake4"
121− }
122− },
123− {
124− "identifier": "indicator-fake5",
125− "indicatorProperties": {
126− "enabled": true,
127− "busName": "com.canonical.indicators.fake5",
128− "menuObjectPath": "/com/canonical/indicators/fake5",
129− "actionsObjectPath": "/com/canonical/indicators/fake5"
130− }
131− },
132− {
133− "identifier": "indicator-fake6",
134− "indicatorProperties": {
135− "enabled": true,
136− "busName": "com.canonical.indicators.fake6",
137− "menuObjectPath": "/com/canonical/indicators/fake6",
138− "actionsObjectPath": "/com/canonical/indicators/fake6"
139− }
140− },
141− {
142− "identifier": "indicator-fake7",
143− "indicatorProperties": {
144− "enabled": true,
145− "busName": "com.canonical.indicators.fake7",
146− "menuObjectPath": "/com/canonical/indicators/fake7",
147− "actionsObjectPath": "/com/canonical/indicators/fake7"
148− }
149− },
150− {
151− "identifier": "indicator-fake8",
152− "indicatorProperties": {
153− "enabled": true,
154− "busName": "com.canonical.indicators.fake1",
155− "menuObjectPath": "/com/canonical/indicators/fake1",
156− "actionsObjectPath": "/com/canonical/indicators/fake1"
30+
31+ RowLayout {
32+ anchors.fill: parent
33+ anchors.margins: units.gu(1)
34+
35+ Rectangle {
36+ id: itemArea
37+ color: "blue"
38+ Layout.fillWidth: true
39+ Layout.fillHeight: true
40+
41+ Rectangle {
42+ color: "black"
43+ anchors.fill: indicatorsBar
44+ }
45+
46+ IndicatorsBar {
47+ id: indicatorsBar
48+ height: expanded ? units.gu(7) : units.gu(3)
49+ width: units.gu(30)
50+ anchors.centerIn: parent
51+ indicatorsModel: root.indicatorsModel
52+
53+ Behavior on height {
54+ NumberAnimation {
55+ id: heightAnimation
56+ duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing
57+ }
15758 }
158− },
159− {
160− "identifier": "indicator-fake9",
161− "indicatorProperties": {
162− "enabled": true,
163− "busName": "com.canonical.indicators.fake1",
164− "menuObjectPath": "/com/canonical/indicators/fake1",
165− "actionsObjectPath": "/com/canonical/indicators/fake1"
59+
60+ MouseArea {
61+ anchors.fill: parent
62+ enabled: !indicatorsBar.expanded
63+ onPressed: {
64+ indicatorsBar.selectItemAt(mouse.x);
65+ indicatorsBar.expanded = true
66+ }
16667 }
167− },
168− {
169− "identifier": "indicator-fake10",
170− "indicatorProperties": {
171− "enabled": true,
172− "busName": "com.canonical.indicators.fake1",
173− "menuObjectPath": "/com/canonical/indicators/fake1",
174− "actionsObjectPath": "/com/canonical/indicators/fake1"
68+ }
69+ }
70+
71+ ColumnLayout {
72+ Layout.alignment: Qt.AlignTop
73+ Layout.fillWidth: false
74+
75+ Button {
76+ Layout.fillWidth: true
77+ text: indicatorsBar.expanded ? "Collapse" : "Expand"
78+ onClicked: indicatorsBar.expanded = !indicatorsBar.expanded
79+ }
80+
81+ Rectangle {
82+ Layout.preferredHeight: units.dp(1);
83+ Layout.fillWidth: true;
84+ color: "black"
85+ }
86+
87+ Repeater {
88+ model: root.indicatorData
89+ RowLayout {
90+ CheckBox {
91+ checked: true
92+ onCheckedChanged: checked ? insertIndicator(index) : removeIndicator(index);
93+ }
94+ Label { text: modelData["identifier"] }
17595 }
176− },
177− ]
96+ }
97+ }
17898 }
17999
180− Rectangle {
181− id: itemArea
182− color: "blue"
183− anchors {
184− top: parent.top
185− bottom: parent.bottom
100+ UT.UnityTestCase {
101+ name: "IndicatorsBar"
102+ when: windowShown
103+
104+ function init() {
105+ indicatorsBar.expanded = false;
106+ tryCompare(heightAnimation, "running", false);
186107 }
187− width: units.gu(50)
188108
189− Rectangle {
190− color: "black"
191− anchors.fill: indicatorsBar
109+ function test_expandSelectedItem_data() {
110+ return [
111+ { index: 0 },
112+ { index: 2 },
113+ { index: 4 }
114+ ];
192115 }
193116
194− IndicatorsBar {
195− id: indicatorsBar
196− height: expanded ? units.gu(7) : units.gu(3)
197− width: units.gu(30)
198− anchors.centerIn: parent
199− indicatorsModel: indicatorsModel
200−
201− Behavior on height { NumberAnimation { duration: 1000; easing: UbuntuAnimation.StandardEasing } }
202−
203− MouseArea {
204− anchors.fill: parent
205− enabled: !indicatorsBar.expanded
206− onPressed: {
207− console.log("click")
208− indicatorsBar.selectItemAt(mouse.x);
209− indicatorsBar.expanded = true
210− }
211− }
117+ // Rough check that expanding a selected item keeps it within the area of the original item.
118+ function test_expandSelectedItem(data) {
119+ var dataItem = findChild(indicatorsBar, root.indicatorData[data.index]["identifier"]+"-panelItem");
120+ verify(dataItem !== null);
121+
122+ var mappedPosition = indicatorsBar.mapFromItem(dataItem, dataItem.width/2, dataItem.height/2);
123+
124+ indicatorsBar.selectItemAt(mappedPosition.x);
125+ indicatorsBar.expanded = true;
126+
127+ // wait for animations to finish
128+ tryCompare(heightAnimation, "running", false);
129+
130+ var mappedRect = indicatorsBar.mapFromItem(dataItem, 0, 0, dataItem.width, dataItem.height);
131+
132+ // mappedPosition contained within mappedRect
133+ verify(mappedRect.x <= mappedPosition.x)
134+ verify(mappedRect.x + mappedRect.width >= mappedPosition.x)
212135 }
213− }
214136
215− ColumnLayout {
216− anchors {
217− top: parent.top
218− bottom: button.top
219− left: itemArea.right
220− right: parent.right
137+ function test_scrollOffset() {
138+ indicatorsBar.expanded = true;
139+ tryCompare(heightAnimation, "running", false);
140+
141+ var dataItem = findChild(indicatorsBar, root.indicatorData[root.indicatorData.length-1]["identifier"]+"-panelItem");
142+ verify(dataItem !== null);
143+
144+ var row = findChild(indicatorsBar, "indicatorRow");
145+ // test will not work without these conditions
146+ verify(row.width >= indicatorsBar.width + dataItem.width);
147+
148+ var mappedPosition = indicatorsBar.mapFromItem(dataItem, dataItem.width/2, dataItem.height/2);
149+ indicatorsBar.addScrollOffset(-dataItem.width);
150+ var newMappedPosition = indicatorsBar.mapFromItem(dataItem, dataItem.width/2, dataItem.height/2);
151+
152+ compare(mappedPosition.x, newMappedPosition.x - dataItem.width);
221153 }
222− }
223154
224− Button {
225− id: button
226− anchors {
227− left: parent.left
228− right: parent.right
229− bottom: parent.bottom
155+ function test_selectItemWhenExpanded_data() {
156+ return [
157+ { index: 3 },
158+ { index: 4 }
159+ ];
230160 }
231− text: indicatorsBar.expanded ? "Collapse" : "Expand"
232− onClicked: indicatorsBar.expanded = !indicatorsBar.expanded
233− }
234161
235− UT.UnityTestCase {
236− name: "IndicatorsRow"
162+ function test_selectItemWhenExpanded(data) {
163+ indicatorsBar.expanded = true;
164+ tryCompare(heightAnimation, "running", false);
165+
166+ var dataItem = findChild(indicatorsBar, root.indicatorData[data.index]["identifier"]+"-panelItem");
167+ if (indicatorsBar.mapFromItem(dataItem, dataItem.width/2, dataItem.height/2).x < 0) {
168+ skip("Out of bounds");
169+ }
170+ mouseClick(dataItem, dataItem.width/2, dataItem.height/2);
171+ verify(dataItem.selected === true);
172+ }
237173 }
238174}