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