on xenial help sign in
fixed up mock unitymenumodel dodgeyness
4af4e83Nick Dedekind
qml/Greeter/Clock.qml+1−1
@@ -47,7 +47,7 @@ Item {
47 menu: timeModel.model
47 menu: timeModel.model
48 onUpdated: {
48 onUpdated: {
49 if (timeLabel.text != rightLabel) {
49 if (timeLabel.text != rightLabel) {
50− timeLabel.text = rightLabel;
50+ if (rightLabel != "") timeLabel.text = rightLabel;
51 clock.currentDate = new Date();
51 clock.currentDate = new Date();
52 }
52 }
53 }
53 }
tests/mocks/QMenuModel/unitymenumodel.cpp−11
@@ -56,17 +56,6 @@ void UnityMenuModel::setModelData(const QVariant& data)
56 endResetModel();
56 endResetModel();
57}
57}
58
58
59−QVariantMap UnityMenuModel::rootProperties() const
60−{
61− return m_rootProperties;
62−}
63−
64−void UnityMenuModel::setRootProperties(const QVariantMap& data)
65−{
66− m_rootProperties = data;
67− Q_EMIT rootPropertiesChanged();
68−}
69−
70void UnityMenuModel::insertRow(int row, const QVariant& data)
59void UnityMenuModel::insertRow(int row, const QVariant& data)
71{
60{
72 row = qMin(row, rowCount());
61 row = qMin(row, rowCount());
tests/mocks/QMenuModel/unitymenumodel.h−5
@@ -35,7 +35,6 @@ class Q_DECL_EXPORT UnityMenuModel : public QAbstractListModel
35
35
36 // internal mock properties
36 // internal mock properties
37 Q_PROPERTY(QVariant modelData READ modelData WRITE setModelData NOTIFY modelDataChanged)
37 Q_PROPERTY(QVariant modelData READ modelData WRITE setModelData NOTIFY modelDataChanged)
38− Q_PROPERTY(QVariantMap rootProperties READ rootProperties WRITE setRootProperties NOTIFY rootPropertiesChanged)
39
38
40public:
39public:
41 UnityMenuModel(QObject *parent = nullptr);
40 UnityMenuModel(QObject *parent = nullptr);
@@ -48,9 +47,6 @@ public:
48 QVariant modelData() const;
47 QVariant modelData() const;
49 void setModelData(const QVariant& data);
48 void setModelData(const QVariant& data);
50
49
51− QVariantMap rootProperties() const;
52− void setRootProperties(const QVariantMap& data);
53−
54 QByteArray busName() const;
50 QByteArray busName() const;
55 void setBusName(const QByteArray &busName);
51 void setBusName(const QByteArray &busName);
56
52
@@ -91,7 +87,6 @@ Q_SIGNALS:
91
87
92 // Internal mock usage
88 // Internal mock usage
93 void modelDataChanged();
89 void modelDataChanged();
94− void rootPropertiesChanged();
95
90
96private:
91private:
97 QVariantMap rowData(int row) const;
92 QVariantMap rowData(int row) const;
tests/mocks/Unity/Indicators/IndicatorsModel.qml+31−33
@@ -24,64 +24,62 @@ Indicators.FakeIndicatorsModel {
24 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake1",
24 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake1",
25 "/com/canonical/indicators/fake1",
25 "/com/canonical/indicators/fake1",
26 "/com/canonical/indicators/fake1",
26 "/com/canonical/indicators/fake1",
27− {
27+ getUnityMenuModelData("fake-indicator-bluetooth",
28− "title": "Bluetooth (F)",
28+ "Bluetooth (F)",
29+ "",
29− "icons": [ "image://theme/bluetooth-active" ],
30+ [ "image://theme/bluetooth-active" ]));
30− },
31− getUnityMenuModelData("fake-indicator-bluetooth"));
32 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake2",
31 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake2",
33 "/com/canonical/indicators/fake2",
32 "/com/canonical/indicators/fake2",
34 "/com/canonical/indicators/fake2",
33 "/com/canonical/indicators/fake2",
35− {
34+ getUnityMenuModelData("fake-indicator-network",
36− "title": "Network (F)",
35+ "Network (F)",
36+ "",
37− "icons": [ "image://theme/simcard-error", "image://theme/wifi-high" ],
37+ [ "image://theme/simcard-error", "image://theme/wifi-high" ]));
38− },
39− getUnityMenuModelData("fake-indicator-network"));
40 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake3",
38 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake3",
41 "/com/canonical/indicators/fake3",
39 "/com/canonical/indicators/fake3",
42 "/com/canonical/indicators/fake3",
40 "/com/canonical/indicators/fake3",
43− {
41+ getUnityMenuModelData("fake-indicator-sound",
44− "title": "Messages (F)",
42+ "Messages (F)",
43+ "",
45− "icons": [ "image://theme/messages-new" ],
44+ [ "image://theme/messages-new" ]));
46− },
47− getUnityMenuModelData("fake-indicator-sound"));
48 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake4",
45 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake4",
49 "/com/canonical/indicators/fake4",
46 "/com/canonical/indicators/fake4",
50 "/com/canonical/indicators/fake4",
47 "/com/canonical/indicators/fake4",
51− {
48+ getUnityMenuModelData("fake-indicator-power",
52− "title": "Sound (F)",
49+ "Sound (F)",
50+ "",
53− "icons": [ "image://theme/audio-volume-high" ],
51+ [ "image://theme/audio-volume-high" ]));
54− },
55− getUnityMenuModelData("fake-indicator-power"));
56 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake5",
52 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake5",
57 "/com/canonical/indicators/fake5",
53 "/com/canonical/indicators/fake5",
58 "/com/canonical/indicators/fake5",
54 "/com/canonical/indicators/fake5",
59− {
55+ getUnityMenuModelData("fake-indicator-power",
60− "title": "Battery (F)",
56+ "Battery (F)",
57+ "",
61− "icons": [ "image://theme/battery-020" ],
58+ [ "image://theme/battery-020" ]));
62− },
63− getUnityMenuModelData("fake-indicator-bluetooth"));
64 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake6",
59 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake6",
65 "/com/canonical/indicators/fake6",
60 "/com/canonical/indicators/fake6",
66 "/com/canonical/indicators/fake6",
61 "/com/canonical/indicators/fake6",
67− {
62+ getUnityMenuModelData("fake-indicator-datetime",
68− "title": "Upcoming Events (F)",
63+ "Upcoming Events (F)",
69− "label": "12:04",
64+ "12:04",
70− },
65+ []));
71− getUnityMenuModelData("fake-indicator-datetime"));
72 }
66 }
73
67
74− function getUnityMenuModelData(identifier) {
68+ function getUnityMenuModelData(identifier, title, label, icons) {
75 var root = [{
69 var root = [{
76 "rowData": { // 1
70 "rowData": { // 1
77− "label": "root",
71+ "label": "",
78 "sensitive": true,
72 "sensitive": true,
79 "isSeparator": false,
73 "isSeparator": false,
80 "icon": "",
74 "icon": "",
81 "type": "com.canonical.indicator.root",
75 "type": "com.canonical.indicator.root",
82 "ext": {},
76 "ext": {},
83 "action": "",
77 "action": "",
84− "actionState": {},
78+ "actionState": {
79+ "title": title,
80+ "label": label,
81+ "icons": icons
82+ },
85 "isCheck": false,
83 "isCheck": false,
86 "isRadio": false,
84 "isRadio": false,
87 "isToggled": false,
85 "isToggled": false,
tests/mocks/Unity/Indicators/RootActionState.qml+15−7
@@ -21,13 +21,21 @@ import QtQuick 2.0
21
21
22Item {
22Item {
23 property var menu: null
23 property var menu: null
24− property bool valid: true
24+ property bool valid: cachedState !== undefined
25− property string title: menu && menu.rootProperties.hasOwnProperty("title") ? menu.rootProperties["title"] : ""
25+ property string title: cachedState && cachedState.hasOwnProperty("title") ? cachedState["title"] : ""
26− property string leftLabel: menu && menu.rootProperties.hasOwnProperty("pre-label") ? menu.rootProperties["pre-label"] : ""
26+ property string leftLabel: cachedState && cachedState.hasOwnProperty("pre-label") ? cachedState["pre-label"] : ""
27− property string rightLabel: menu && menu.rootProperties.hasOwnProperty("label") ? menu.rootProperties["label"] : ""
27+ property string rightLabel: cachedState && cachedState.hasOwnProperty("label") ? cachedState["label"] : ""
28− property var icons: menu && menu.rootProperties.hasOwnProperty("icons") ? menu.rootProperties["icons"] : []
28+ property var icons: cachedState && cachedState.hasOwnProperty("icons") ? cachedState["icons"] : []
29− property string accessibleName: menu && menu.rootProperties.hasOwnProperty("accessible-desc") ? menu.rootProperties["accessible-desc"] : ""
29+ property string accessibleName: cachedState && cachedState.hasOwnProperty("accessible-desc") ? cachedState["accessible-desc"] : ""
30− visible: menu && menu.rootProperties.hasOwnProperty("visible") ? menu.rootProperties["visible"] : true
30+ visible: cachedState && cachedState.hasOwnProperty("visible") ? cachedState["visible"] : true
31+
32+ property var cachedState: menu ? menu.get(0, "actionState") : undefined
33+ Connections {
34+ target: menu
35+ onModelDataChanged: {
36+ cachedState = menu.get(0, "actionState");
37+ }
38+ }
31
39
32 signal updated
40 signal updated
33
41
tests/mocks/Unity/Indicators/fakeunitymenumodelcache.cpp−2
@@ -50,13 +50,11 @@ bool FakeUnityMenuModelCache::contains(const QByteArray& path)
50void FakeUnityMenuModelCache::setCachedModelData(const QByteArray& bus,
50void FakeUnityMenuModelCache::setCachedModelData(const QByteArray& bus,
51 const QByteArray& path,
51 const QByteArray& path,
52 const QVariantMap& actions,
52 const QVariantMap& actions,
53− const QVariantMap& properties,
54 const QVariant& data)
53 const QVariant& data)
55{
54{
56 // keep a ref forever!
55 // keep a ref forever!
57 if (!m_models.contains(path)) {
56 if (!m_models.contains(path)) {
58 m_models[path] = model(bus, path, actions);
57 m_models[path] = model(bus, path, actions);
59 }
58 }
60− m_models[path]->setRootProperties(properties);
61 m_models[path]->setModelData(data);
59 m_models[path]->setModelData(data);
62}
60}
tests/mocks/Unity/Indicators/fakeunitymenumodelcache.h−1
@@ -43,7 +43,6 @@ public:
43 Q_INVOKABLE void setCachedModelData(const QByteArray& bus,
43 Q_INVOKABLE void setCachedModelData(const QByteArray& bus,
44 const QByteArray& path,
44 const QByteArray& path,
45 const QVariantMap& actions,
45 const QVariantMap& actions,
46− const QVariantMap& properties = QVariantMap(),
47 const QVariant& data = QVariant());
46 const QVariant& data = QVariant());
48
47
49private:
48private:
tests/qmltests/Greeter/tst_Clock.qml+51−34
@@ -19,7 +19,7 @@ import QtTest 1.0
19import ".."
19import ".."
20import "../../../qml/Greeter"
20import "../../../qml/Greeter"
21import Ubuntu.Components 0.1
21import Ubuntu.Components 0.1
22−import QMenuModel 0.1
22+import Unity.Indicators 0.1 as Indicators
23import Unity.Test 0.1 as UT
23import Unity.Test 0.1 as UT
24
24
25Rectangle {
25Rectangle {
@@ -36,56 +36,73 @@ Rectangle {
36 }
36 }
37 }
37 }
38
38
39− UnityMenuModel {
39+ function updateDatetimeModelTime(label) {
40− id: menuModel
40+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicator.datetime",
41− modelData: [{
41+ "/com/canonical/indicator/datetime/phone",
42+ "/com/canonical/indicator/datetime",
43+ [{
42− "rowData": {
44+ "rowData": {
43− "actionState": { "label": Qt.formatTime(new Date("October 13, 1975 11:13:00")) }
45+ "actionState": { "label": label }
44− }
46+ }
45− }]
47+ }]);
46 }
48 }
47
49
48 UT.UnityTestCase {
50 UT.UnityTestCase {
49 name: "Clock"
51 name: "Clock"
52+ when: windowShown
50
53
51 function init() {
54 function init() {
52− var cachedModel = findChild(clock, "timeModel");
55+ updateDatetimeModelTime(Qt.formatTime(new Date("October 13, 1975 12:14:00")));
53− verify(cachedModel !== undefined);
56+ clock.visible = true;
54− cachedModel.model = menuModel;
55 }
57 }
56
58
57− function test_customDate() {
59+ // Test that the date portion of the clock updates with custom value.
58− var dateObj = new Date("October 13, 1975 11:13:00")
60+ // Time portion is controlled by indicators
59− var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)
61+ function test_updateDate() {
60− var timeString = Qt.formatTime(dateObj)
62+ var dateLabel = findChild(clock, "dateLabel");
63+ var timeLabel = findChild(clock, "timeLabel");
61
64
62− clock.currentDate = dateObj
65+ var timeString = Qt.formatTime(new Date("October 13, 1975 12:14:00"));
63− var dateLabel = findChild(clock, "dateLabel")
66+
67+ // initial date.
68+ var dateObj = new Date("October 13, 1975 11:13:00");
69+ var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate);
70+ clock.currentDate = dateObj;
71+
64− compare(dateLabel.text, dateString, "Not the expected date")
72+ compare(dateLabel.text, dateString, "Not the expected date");
65− var timeLabel = findChild(clock, "timeLabel")
73+ compare(timeLabel.text, timeString, "Time should come from indicators");
74+
75+ // update date.
76+ var dateObj2 = new Date("October 14, 1976 13:15:00");
77+ var dateString2 = Qt.formatDate(dateObj2, Qt.DefaultLocaleLongDate);
78+ clock.currentDate = dateObj2;
79+
66− compare(timeLabel.text, timeString, "Not the expected time")
80+ compare(dateLabel.text, dateString2, "Not the expected date");
81+ compare(timeLabel.text,timeString, "Time should come from indicators");
67 }
82 }
68
83
69− function test_dateUpdate() {
84+ // Test that the date portion of the clock updates with custom value.
70− var dateObj = new Date("October 13, 1975 11:13:00")
85+ // Time portion is controlled by indicators
71− var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)
86+ function test_updateTime() {
72− var timeString = Qt.formatTime(dateObj)
87+ var timeLabel = findChild(clock, "timeLabel");
73
88
74− clock.visible = false
89+ var timeString1 = Qt.formatTime(new Date("October 13, 1975 11:15:00"));
75− var timeModel = findInvisibleChild(clock, "timeModel")
90+ var timeString2 = Qt.formatTime(new Date("October 14, 1976 12:16:00"));
76
91
77− compare(timeModel.menuObjectPath, "", "Clock shouldn't be connected to Indicators when not visible.")
92+ updateDatetimeModelTime(timeString1);
93+ compare(timeLabel.text, timeString1, "Time should come from indicators");
78
94
79− clock.currentDate = dateObj
95+ updateDatetimeModelTime(timeString2);
96+ compare(timeLabel.text, timeString2, "Time should come from indicators");
97+ }
80
98
81− var dateLabel = findChild(clock, "dateLabel")
99+ function test_indicatorDisconnect() {
82− compare(dateLabel.text, dateString, "Not the expected date")
100+ clock.visible = false
83− var timeLabel = findChild(clock, "timeLabel")
101+ var timeModel = findInvisibleChild(clock, "timeModel")
84− compare(timeLabel.text, timeString, "Not the expected time")
102+ compare(timeModel.menuObjectPath, "", "Clock shouldn't be connected to Indicators when not visible.")
85
103
86 clock.visible = true
104 clock.visible = true
87−
88− verify(timeModel.menuObjectPath != "", "Should be connected to Indicators.")
105+ verify(timeModel.menuObjectPath !== "", "Should be connected to Indicators.")
89 }
106 }
90 }
107 }
91}
108}
tests/qmltests/Panel/Indicators/tst_DefaultIndicatorWidget.qml−1
@@ -33,7 +33,6 @@ Item {
33 top: parent.top
33 top: parent.top
34 }
34 }
35
35
36− menuModel: UnityMenuModel {}
37 busName: "test"
36 busName: "test"
38 actionsObjectPath: "test"
37 actionsObjectPath: "test"
39 menuObjectPath: "test"
38 menuObjectPath: "test"
tests/qmltests/Panel/tst_IndicatorItemRow.qml+8−3
@@ -116,6 +116,11 @@ IndicatorTest {
116 wait(1); // row seems to take a bit of time for item x values to update.
116 wait(1); // row seems to take a bit of time for item x values to update.
117 }
117 }
118
118
119+ function wait_for_expansion_to_settle() {
120+ tryCompare(heightAnimation, "running", false);
121+ wait(200); // put a little extra wait in for things to settle
122+ }
123+
119 function test_indicatorRowChanges_data() {
124 function test_indicatorRowChanges_data() {
120 return [
125 return [
121 { remove: [0, 2] },
126 { remove: [0, 2] },
@@ -196,7 +201,7 @@ IndicatorTest {
196
201
197 function test_lateralPositionChangesCurrentItem(data) {
202 function test_lateralPositionChangesCurrentItem(data) {
198 indicatorsRow.expanded = true;
203 indicatorsRow.expanded = true;
199− tryCompare(heightAnimation, "running", false);
204+ wait_for_expansion_to_settle();
200
205
201 var fromItem = findChild(indicatorsRow, indicatorsModel.originalModelData[data.from]["identifier"]+"-panelItem");
206 var fromItem = findChild(indicatorsRow, indicatorsModel.originalModelData[data.from]["identifier"]+"-panelItem");
202 verify(fromItem !== null);
207 verify(fromItem !== null);
@@ -220,7 +225,7 @@ IndicatorTest {
220 // testing that positive changes to the lateral position offset shifts the highlight offset to the right
225 // testing that positive changes to the lateral position offset shifts the highlight offset to the right
221 function test_positiveLateralPositionChangesHighlightOffset() {
226 function test_positiveLateralPositionChangesHighlightOffset() {
222 indicatorsRow.expanded = true;
227 indicatorsRow.expanded = true;
223− tryCompare(heightAnimation, "running", false);
228+ wait_for_expansion_to_settle();
224
229
225 var highlight = findChild(indicatorsRow, "highlight");
230 var highlight = findChild(indicatorsRow, "highlight");
226 var item = findChild(indicatorsRow, indicatorsModel.originalModelData[2]["identifier"]+"-panelItem");
231 var item = findChild(indicatorsRow, indicatorsModel.originalModelData[2]["identifier"]+"-panelItem");
@@ -245,7 +250,7 @@ IndicatorTest {
245 // testing that negative changes to the lateral position offset shifts the highlight offset to the left
250 // testing that negative changes to the lateral position offset shifts the highlight offset to the left
246 function test_negativeLateralPositionChangesHighlightOffset() {
251 function test_negativeLateralPositionChangesHighlightOffset() {
247 indicatorsRow.expanded = true;
252 indicatorsRow.expanded = true;
248− tryCompare(heightAnimation, "running", false);
253+ wait_for_expansion_to_settle();
249
254
250 var highlight = findChild(indicatorsRow, "highlight");
255 var highlight = findChild(indicatorsRow, "highlight");
251 var item = findChild(indicatorsRow, indicatorsModel.originalModelData[2]["identifier"]+"-panelItem");
256 var item = findChild(indicatorsRow, indicatorsModel.originalModelData[2]["identifier"]+"-panelItem");
tests/qmltests/Panel/tst_IndicatorsBar.qml+6−3
@@ -114,6 +114,11 @@ IndicatorTest {
114 ];
114 ];
115 }
115 }
116
116
117+ function wait_for_expansion_to_settle() {
118+ tryCompare(heightAnimation, "running", false);
119+ wait(200); // put a little extra wait in for things to settle
120+ }
121+
117 // Rough check that expanding a selected item keeps it within the area of the original item.
122 // Rough check that expanding a selected item keeps it within the area of the original item.
118 function test_expandSelectedItem(data) {
123 function test_expandSelectedItem(data) {
119 var dataItem = findChild(indicatorsBar, indicatorsModel.originalModelData[data.index]["identifier"]+"-panelItem");
124 var dataItem = findChild(indicatorsBar, indicatorsModel.originalModelData[data.index]["identifier"]+"-panelItem");
@@ -136,8 +141,6 @@ IndicatorTest {
136
141
137 function test_scrollOffset() {
142 function test_scrollOffset() {
138 indicatorsBar.expanded = true;
143 indicatorsBar.expanded = true;
139− tryCompare(heightAnimation, "running", false);
140−
141 var dataItem = findChild(indicatorsBar, indicatorsModel.originalModelData[indicatorsModel.originalModelData.length-1]["identifier"]+"-panelItem");
144 var dataItem = findChild(indicatorsBar, indicatorsModel.originalModelData[indicatorsModel.originalModelData.length-1]["identifier"]+"-panelItem");
142 verify(dataItem !== null);
145 verify(dataItem !== null);
143
146
@@ -161,7 +164,7 @@ IndicatorTest {
161
164
162 function test_selectItemWhenExpanded(data) {
165 function test_selectItemWhenExpanded(data) {
163 indicatorsBar.expanded = true;
166 indicatorsBar.expanded = true;
164− tryCompare(heightAnimation, "running", false);
167+ wait_for_expansion_to_settle();
165
168
166 var dataItem = findChild(indicatorsBar, indicatorsModel.originalModelData[data.index]["identifier"]+"-panelItem");
169 var dataItem = findChild(indicatorsBar, indicatorsModel.originalModelData[data.index]["identifier"]+"-panelItem");
167 if (indicatorsBar.mapFromItem(dataItem, dataItem.width/2, dataItem.height/2).x < 0) {
170 if (indicatorsBar.mapFromItem(dataItem, dataItem.width/2, dataItem.height/2).x < 0) {