on xenial help sign in
fixed up mock unitymenumodel dodgeyness
commit4af4e83d40ad2ca057a58fd0d8b2977f92100182 authorNick Dedekind <nick.dedekind@canonical.com> dateWed 1 Oct 2014, 13:47 (12 years ago) parent8f2ddc5
11 files changed+112−101
qml/Greeter/Clock.qml+1−1 tests/mocks/QMenuModel/unitymenumodel.cpp−11 tests/mocks/QMenuModel/unitymenumodel.h−5 tests/mocks/Unity/Indicators/IndicatorsModel.qml+31−33 tests/mocks/Unity/Indicators/RootActionState.qml+15−7 tests/mocks/Unity/Indicators/fakeunitymenumodelcache.cpp−2 tests/mocks/Unity/Indicators/fakeunitymenumodelcache.h−1 tests/qmltests/Greeter/tst_Clock.qml+51−34 tests/qmltests/Panel/Indicators/tst_DefaultIndicatorWidget.qml−1 tests/qmltests/Panel/tst_IndicatorItemRow.qml+8−3 tests/qmltests/Panel/tst_IndicatorsBar.qml+6−3
qml/Greeter/Clock.qml+1−1
@@ -47,7 +47,7 @@ Item {
4747 menu: timeModel.model
4848 onUpdated: {
4949 if (timeLabel.text != rightLabel) {
50− timeLabel.text = rightLabel;
50+ if (rightLabel != "") timeLabel.text = rightLabel;
5151 clock.currentDate = new Date();
5252 }
5353 }
tests/mocks/QMenuModel/unitymenumodel.cpp−11
@@ -56,17 +56,6 @@ void UnityMenuModel::setModelData(const QVariant& data)
5656 endResetModel();
5757}
5858
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−
7059void UnityMenuModel::insertRow(int row, const QVariant& data)
7160{
7261 row = qMin(row, rowCount());
tests/mocks/QMenuModel/unitymenumodel.h−5
@@ -35,7 +35,6 @@ class Q_DECL_EXPORT UnityMenuModel : public QAbstractListModel
3535
3636 // internal mock properties
3737 Q_PROPERTY(QVariant modelData READ modelData WRITE setModelData NOTIFY modelDataChanged)
38− Q_PROPERTY(QVariantMap rootProperties READ rootProperties WRITE setRootProperties NOTIFY rootPropertiesChanged)
3938
4039public:
4140 UnityMenuModel(QObject *parent = nullptr);
@@ -48,9 +47,6 @@ public:
4847 QVariant modelData() const;
4948 void setModelData(const QVariant& data);
5049
51− QVariantMap rootProperties() const;
52− void setRootProperties(const QVariantMap& data);
53−
5450 QByteArray busName() const;
5551 void setBusName(const QByteArray &busName);
5652
@@ -91,7 +87,6 @@ Q_SIGNALS:
9187
9288 // Internal mock usage
9389 void modelDataChanged();
94− void rootPropertiesChanged();
9590
9691private:
9792 QVariantMap rowData(int row) const;
tests/mocks/Unity/Indicators/IndicatorsModel.qml+31−33
@@ -24,64 +24,62 @@ Indicators.FakeIndicatorsModel {
2424 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake1",
2525 "/com/canonical/indicators/fake1",
2626 "/com/canonical/indicators/fake1",
27− {
28− "title": "Bluetooth (F)",
29− "icons": [ "image://theme/bluetooth-active" ],
30− },
31− getUnityMenuModelData("fake-indicator-bluetooth"));
27+ getUnityMenuModelData("fake-indicator-bluetooth",
28+ "Bluetooth (F)",
29+ "",
30+ [ "image://theme/bluetooth-active" ]));
3231 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake2",
3332 "/com/canonical/indicators/fake2",
3433 "/com/canonical/indicators/fake2",
35− {
36− "title": "Network (F)",
37− "icons": [ "image://theme/simcard-error", "image://theme/wifi-high" ],
38− },
39− getUnityMenuModelData("fake-indicator-network"));
34+ getUnityMenuModelData("fake-indicator-network",
35+ "Network (F)",
36+ "",
37+ [ "image://theme/simcard-error", "image://theme/wifi-high" ]));
4038 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake3",
4139 "/com/canonical/indicators/fake3",
4240 "/com/canonical/indicators/fake3",
43− {
44− "title": "Messages (F)",
45− "icons": [ "image://theme/messages-new" ],
46− },
47− getUnityMenuModelData("fake-indicator-sound"));
41+ getUnityMenuModelData("fake-indicator-sound",
42+ "Messages (F)",
43+ "",
44+ [ "image://theme/messages-new" ]));
4845 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake4",
4946 "/com/canonical/indicators/fake4",
5047 "/com/canonical/indicators/fake4",
51− {
52− "title": "Sound (F)",
53− "icons": [ "image://theme/audio-volume-high" ],
54− },
55− getUnityMenuModelData("fake-indicator-power"));
48+ getUnityMenuModelData("fake-indicator-power",
49+ "Sound (F)",
50+ "",
51+ [ "image://theme/audio-volume-high" ]));
5652 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake5",
5753 "/com/canonical/indicators/fake5",
5854 "/com/canonical/indicators/fake5",
59− {
60− "title": "Battery (F)",
61− "icons": [ "image://theme/battery-020" ],
62− },
63− getUnityMenuModelData("fake-indicator-bluetooth"));
55+ getUnityMenuModelData("fake-indicator-power",
56+ "Battery (F)",
57+ "",
58+ [ "image://theme/battery-020" ]));
6459 Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake6",
6560 "/com/canonical/indicators/fake6",
6661 "/com/canonical/indicators/fake6",
67− {
68− "title": "Upcoming Events (F)",
69− "label": "12:04",
70− },
71− getUnityMenuModelData("fake-indicator-datetime"));
62+ getUnityMenuModelData("fake-indicator-datetime",
63+ "Upcoming Events (F)",
64+ "12:04",
65+ []));
7266 }
7367
74− function getUnityMenuModelData(identifier) {
68+ function getUnityMenuModelData(identifier, title, label, icons) {
7569 var root = [{
7670 "rowData": { // 1
77− "label": "root",
71+ "label": "",
7872 "sensitive": true,
7973 "isSeparator": false,
8074 "icon": "",
8175 "type": "com.canonical.indicator.root",
8276 "ext": {},
8377 "action": "",
84− "actionState": {},
78+ "actionState": {
79+ "title": title,
80+ "label": label,
81+ "icons": icons
82+ },
8583 "isCheck": false,
8684 "isRadio": false,
8785 "isToggled": false,
tests/mocks/Unity/Indicators/RootActionState.qml+15−7
@@ -21,13 +21,21 @@ import QtQuick 2.0
2121
2222Item {
2323 property var menu: null
24− property bool valid: true
25− property string title: menu && menu.rootProperties.hasOwnProperty("title") ? menu.rootProperties["title"] : ""
26− property string leftLabel: menu && menu.rootProperties.hasOwnProperty("pre-label") ? menu.rootProperties["pre-label"] : ""
27− property string rightLabel: menu && menu.rootProperties.hasOwnProperty("label") ? menu.rootProperties["label"] : ""
28− property var icons: menu && menu.rootProperties.hasOwnProperty("icons") ? menu.rootProperties["icons"] : []
29− property string accessibleName: menu && menu.rootProperties.hasOwnProperty("accessible-desc") ? menu.rootProperties["accessible-desc"] : ""
30− visible: menu && menu.rootProperties.hasOwnProperty("visible") ? menu.rootProperties["visible"] : true
24+ property bool valid: cachedState !== undefined
25+ property string title: cachedState && cachedState.hasOwnProperty("title") ? cachedState["title"] : ""
26+ property string leftLabel: cachedState && cachedState.hasOwnProperty("pre-label") ? cachedState["pre-label"] : ""
27+ property string rightLabel: cachedState && cachedState.hasOwnProperty("label") ? cachedState["label"] : ""
28+ property var icons: cachedState && cachedState.hasOwnProperty("icons") ? cachedState["icons"] : []
29+ property string accessibleName: cachedState && cachedState.hasOwnProperty("accessible-desc") ? cachedState["accessible-desc"] : ""
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+ }
3139
3240 signal updated
3341
tests/mocks/Unity/Indicators/fakeunitymenumodelcache.cpp−2
@@ -50,13 +50,11 @@ bool FakeUnityMenuModelCache::contains(const QByteArray& path)
5050void FakeUnityMenuModelCache::setCachedModelData(const QByteArray& bus,
5151 const QByteArray& path,
5252 const QVariantMap& actions,
53− const QVariantMap& properties,
5453 const QVariant& data)
5554{
5655 // keep a ref forever!
5756 if (!m_models.contains(path)) {
5857 m_models[path] = model(bus, path, actions);
5958 }
60− m_models[path]->setRootProperties(properties);
6159 m_models[path]->setModelData(data);
6260}
tests/mocks/Unity/Indicators/fakeunitymenumodelcache.h−1
@@ -43,7 +43,6 @@ public:
4343 Q_INVOKABLE void setCachedModelData(const QByteArray& bus,
4444 const QByteArray& path,
4545 const QVariantMap& actions,
46− const QVariantMap& properties = QVariantMap(),
4746 const QVariant& data = QVariant());
4847
4948private:
tests/qmltests/Greeter/tst_Clock.qml+51−34
@@ -19,7 +19,7 @@ import QtTest 1.0
1919import ".."
2020import "../../../qml/Greeter"
2121import Ubuntu.Components 0.1
22−import QMenuModel 0.1
22+import Unity.Indicators 0.1 as Indicators
2323import Unity.Test 0.1 as UT
2424
2525Rectangle {
@@ -36,56 +36,73 @@ Rectangle {
3636 }
3737 }
3838
39− UnityMenuModel {
40− id: menuModel
41− modelData: [{
42− "rowData": {
43− "actionState": { "label": Qt.formatTime(new Date("October 13, 1975 11:13:00")) }
44− }
45− }]
39+ function updateDatetimeModelTime(label) {
40+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicator.datetime",
41+ "/com/canonical/indicator/datetime/phone",
42+ "/com/canonical/indicator/datetime",
43+ [{
44+ "rowData": {
45+ "actionState": { "label": label }
46+ }
47+ }]);
4648 }
4749
4850 UT.UnityTestCase {
4951 name: "Clock"
52+ when: windowShown
5053
5154 function init() {
52− var cachedModel = findChild(clock, "timeModel");
53− verify(cachedModel !== undefined);
54− cachedModel.model = menuModel;
55+ updateDatetimeModelTime(Qt.formatTime(new Date("October 13, 1975 12:14:00")));
56+ clock.visible = true;
5557 }
5658
57− function test_customDate() {
58− var dateObj = new Date("October 13, 1975 11:13:00")
59− var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)
60− var timeString = Qt.formatTime(dateObj)
59+ // Test that the date portion of the clock updates with custom value.
60+ // Time portion is controlled by indicators
61+ function test_updateDate() {
62+ var dateLabel = findChild(clock, "dateLabel");
63+ var timeLabel = findChild(clock, "timeLabel");
6164
62− clock.currentDate = dateObj
63− var dateLabel = findChild(clock, "dateLabel")
64− compare(dateLabel.text, dateString, "Not the expected date")
65− var timeLabel = findChild(clock, "timeLabel")
66− compare(timeLabel.text, timeString, "Not the expected time")
65+ var timeString = Qt.formatTime(new Date("October 13, 1975 12:14:00"));
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+
72+ compare(dateLabel.text, dateString, "Not the expected date");
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+
80+ compare(dateLabel.text, dateString2, "Not the expected date");
81+ compare(timeLabel.text,timeString, "Time should come from indicators");
6782 }
6883
69− function test_dateUpdate() {
70− var dateObj = new Date("October 13, 1975 11:13:00")
71− var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)
72− var timeString = Qt.formatTime(dateObj)
84+ // Test that the date portion of the clock updates with custom value.
85+ // Time portion is controlled by indicators
86+ function test_updateTime() {
87+ var timeLabel = findChild(clock, "timeLabel");
7388
74− clock.visible = false
75− var timeModel = findInvisibleChild(clock, "timeModel")
89+ var timeString1 = Qt.formatTime(new Date("October 13, 1975 11:15:00"));
90+ var timeString2 = Qt.formatTime(new Date("October 14, 1976 12:16:00"));
7691
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");
7894
79− clock.currentDate = dateObj
95+ updateDatetimeModelTime(timeString2);
96+ compare(timeLabel.text, timeString2, "Time should come from indicators");
97+ }
8098
81− var dateLabel = findChild(clock, "dateLabel")
82− compare(dateLabel.text, dateString, "Not the expected date")
83− var timeLabel = findChild(clock, "timeLabel")
84− compare(timeLabel.text, timeString, "Not the expected time")
99+ function test_indicatorDisconnect() {
100+ clock.visible = false
101+ var timeModel = findInvisibleChild(clock, "timeModel")
102+ compare(timeModel.menuObjectPath, "", "Clock shouldn't be connected to Indicators when not visible.")
85103
86104 clock.visible = true
87−
88− verify(timeModel.menuObjectPath != "", "Should be connected to Indicators.")
105+ verify(timeModel.menuObjectPath !== "", "Should be connected to Indicators.")
89106 }
90107 }
91108}
tests/qmltests/Panel/Indicators/tst_DefaultIndicatorWidget.qml−1
@@ -33,7 +33,6 @@ Item {
3333 top: parent.top
3434 }
3535
36− menuModel: UnityMenuModel {}
3736 busName: "test"
3837 actionsObjectPath: "test"
3938 menuObjectPath: "test"
tests/qmltests/Panel/tst_IndicatorItemRow.qml+8−3
@@ -116,6 +116,11 @@ IndicatorTest {
116116 wait(1); // row seems to take a bit of time for item x values to update.
117117 }
118118
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+
119124 function test_indicatorRowChanges_data() {
120125 return [
121126 { remove: [0, 2] },
@@ -196,7 +201,7 @@ IndicatorTest {
196201
197202 function test_lateralPositionChangesCurrentItem(data) {
198203 indicatorsRow.expanded = true;
199− tryCompare(heightAnimation, "running", false);
204+ wait_for_expansion_to_settle();
200205
201206 var fromItem = findChild(indicatorsRow, indicatorsModel.originalModelData[data.from]["identifier"]+"-panelItem");
202207 verify(fromItem !== null);
@@ -220,7 +225,7 @@ IndicatorTest {
220225 // testing that positive changes to the lateral position offset shifts the highlight offset to the right
221226 function test_positiveLateralPositionChangesHighlightOffset() {
222227 indicatorsRow.expanded = true;
223− tryCompare(heightAnimation, "running", false);
228+ wait_for_expansion_to_settle();
224229
225230 var highlight = findChild(indicatorsRow, "highlight");
226231 var item = findChild(indicatorsRow, indicatorsModel.originalModelData[2]["identifier"]+"-panelItem");
@@ -245,7 +250,7 @@ IndicatorTest {
245250 // testing that negative changes to the lateral position offset shifts the highlight offset to the left
246251 function test_negativeLateralPositionChangesHighlightOffset() {
247252 indicatorsRow.expanded = true;
248− tryCompare(heightAnimation, "running", false);
253+ wait_for_expansion_to_settle();
249254
250255 var highlight = findChild(indicatorsRow, "highlight");
251256 var item = findChild(indicatorsRow, indicatorsModel.originalModelData[2]["identifier"]+"-panelItem");
tests/qmltests/Panel/tst_IndicatorsBar.qml+6−3
@@ -114,6 +114,11 @@ IndicatorTest {
114114 ];
115115 }
116116
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+
117122 // Rough check that expanding a selected item keeps it within the area of the original item.
118123 function test_expandSelectedItem(data) {
119124 var dataItem = findChild(indicatorsBar, indicatorsModel.originalModelData[data.index]["identifier"]+"-panelItem");
@@ -136,8 +141,6 @@ IndicatorTest {
136141
137142 function test_scrollOffset() {
138143 indicatorsBar.expanded = true;
139− tryCompare(heightAnimation, "running", false);
140−
141144 var dataItem = findChild(indicatorsBar, indicatorsModel.originalModelData[indicatorsModel.originalModelData.length-1]["identifier"]+"-panelItem");
142145 verify(dataItem !== null);
143146
@@ -161,7 +164,7 @@ IndicatorTest {
161164
162165 function test_selectItemWhenExpanded(data) {
163166 indicatorsBar.expanded = true;
164− tryCompare(heightAnimation, "running", false);
167+ wait_for_expansion_to_settle();
165168
166169 var dataItem = findChild(indicatorsBar, indicatorsModel.originalModelData[data.index]["identifier"]+"-panelItem");
167170 if (indicatorsBar.mapFromItem(dataItem, dataItem.width/2, dataItem.height/2).x < 0) {