on xenial help sign in
Still trying to get the mocked Notification to work with the tst_Notifications qmltest.
commit2e39a7ce1ca2398fbfc1e679eb7c3d2f3b14b8d0 authorMirco Müller <mirco.mueller@ubuntu.com> dateFri 9 Jan 2015, 12:02 (12 years ago) parent392265b
5 files changed+51−48
qml/Notifications/Notification.qml+3−3 qml/Notifications/Notifications.qml+1−1 tests/mocks/Unity/Notifications/MockNotificationTypes.cpp+15−12 tests/mocks/Unity/Notifications/MockNotificationTypes.h+4−4 tests/qmltests/Notifications/tst_Notifications.qml+28−28
qml/Notifications/Notification.qml+3−3
@@ -41,7 +41,7 @@ Item {
4141 property int maxHeight
4242 property int margins
4343 readonly property bool draggable: (type === Notification.SnapDecision && state === "contracted") || type === Notification.Interactive || type === Notification.Ephemeral
44− readonly property bool darkOnBright: panel.indicators.shown || type === Notification.SnapDecision
44+ readonly property bool darkOnBright: true //panel.indicators.shown || type === Notification.SnapDecision
4545 readonly property color red: "#fc4949"
4646 readonly property color green: "#3fb24f"
4747 readonly property color sdLightGrey: "#eaeaea"
@@ -80,7 +80,7 @@ Item {
8080 Audio {
8181 id: sound
8282 objectName: "sound"
83− audioRole: MediaPlayer.alert
83+ //audioRole: MediaPlayer.alert
8484 source: hints["suppress-sound"] !== "true" && hints["sound-file"] !== undefined ? hints["sound-file"] : ""
8585 }
8686
@@ -186,7 +186,7 @@ Item {
186186 actions: paths.actions
187187 menuObjectPath: paths.menuObjectPath
188188 onNameOwnerChanged: {
189− if (lastNameOwner != "" && nameOwner == "" && notification.notification != undefined) {
189+ if (lastNameOwner !== "" && nameOwner === "" && notification.notification !== undefined) {
190190 notification.notification.close()
191191 }
192192 lastNameOwner = nameOwner
qml/Notifications/Notifications.qml+1−1
@@ -54,7 +54,7 @@ ListView {
5454 body: model.body
5555 value: model.value
5656 actions: model.actions
57− notificationId: model.id
57+ notificationId: model.nid
5858 notification: notificationList.model.getRaw(notificationId)
5959 maxHeight: notificationList.height
6060 margins: notificationList.margin
tests/mocks/Unity/Notifications/MockNotificationTypes.cpp+15−12
@@ -18,9 +18,10 @@
1818 */
1919
2020#include "MockNotificationTypes.h"
21+#include <QDebug>
2122
2223struct MockNotificationPrivate {
23− unsigned int nid;
24+ unsigned int id;
2425 QString summary;
2526 QString body;
2627 int value;
@@ -47,7 +48,7 @@ void MockNotification::setSummary(const QString &summary) {
4748 if(p->summary != summary) {
4849 p->summary= summary;
4950 Q_EMIT summaryChanged(p->summary);
50− Q_EMIT dataChanged(p->nid);
51+ Q_EMIT dataChanged(p->id);
5152 }
5253}
5354
@@ -59,16 +60,16 @@ void MockNotification::setBody(const QString &body) {
5960 if(p->body != body) {
6061 p->body = body;
6162 Q_EMIT bodyChanged(p->body);
62− Q_EMIT dataChanged(p->nid);
63+ Q_EMIT dataChanged(p->id);
6364 }
6465}
6566
66−unsigned int MockNotification::getNID() const {
67− return p->nid;
67+unsigned int MockNotification::getID() const {
68+ return p->id;
6869}
6970
70−void MockNotification::setNID(const unsigned int nid) {
71− p->nid = nid;
71+void MockNotification::setID(const unsigned int id) {
72+ p->id = id;
7273}
7374
7475int MockNotification::getValue() const {
@@ -79,7 +80,7 @@ void MockNotification::setValue(int value) {
7980 if(p->value != value) {
8081 p->value = value;
8182 Q_EMIT valueChanged(p->value);
82− Q_EMIT dataChanged(p->nid);
83+ Q_EMIT dataChanged(p->id);
8384 }
8485}
8586
@@ -100,7 +101,7 @@ void MockNotification::setIcon(const QString &icon) {
100101 }
101102
102103 Q_EMIT iconChanged(p->icon);
103− Q_EMIT dataChanged(p->nid);
104+ Q_EMIT dataChanged(p->id);
104105}
105106
106107QString MockNotification::getSecondaryIcon() const {
@@ -120,7 +121,7 @@ void MockNotification::setSecondaryIcon(const QString &secondaryIcon) {
120121 }
121122
122123 Q_EMIT secondaryIconChanged(p->secondaryIcon);
123− Q_EMIT dataChanged(p->nid);
124+ Q_EMIT dataChanged(p->id);
124125}
125126
126127MockNotification::Type MockNotification::getType() const {
@@ -163,7 +164,8 @@ void MockNotification::setHints(const QVariantMap& hints) {
163164void MockNotification::invokeAction(const QString &action) {
164165 for(int i=0; i<p->actions.size(); i++) {
165166 if(p->actions[i] == action) {
166− Q_EMIT completed(p->nid);
167+ qDebug() << "MockNotification::invokeAction("<< action << ") called";
168+ Q_EMIT completed(p->id);
167169 return;
168170 }
169171 }
@@ -171,5 +173,6 @@ void MockNotification::invokeAction(const QString &action) {
171173}
172174
173175void MockNotification::close() {
174− Q_EMIT completed(p->nid);
176+ qDebug() << "MockNotification::close() called";
177+ Q_EMIT completed(p->id);
175178}
tests/mocks/Unity/Notifications/MockNotificationTypes.h+4−4
@@ -33,7 +33,7 @@ class MockNotification : public QObject {
3333 Q_ENUMS(Type)
3434 Q_PROPERTY(QString summary READ getSummary WRITE setSummary NOTIFY summaryChanged)
3535 Q_PROPERTY(QString body READ getBody WRITE setBody NOTIFY bodyChanged)
36− Q_PROPERTY(unsigned int nid READ getNID WRITE setNID NOTIFY nidChanged)
36+ Q_PROPERTY(unsigned int nid READ getID WRITE setID NOTIFY idChanged)
3737 Q_PROPERTY(int value READ getValue WRITE setValue NOTIFY valueChanged)
3838 Q_PROPERTY(QString icon READ getIcon WRITE setIcon NOTIFY iconChanged)
3939 Q_PROPERTY(QString secondaryIcon READ getSecondaryIcon WRITE setSecondaryIcon NOTIFY secondaryIconChanged)
@@ -52,7 +52,7 @@ public:
5252Q_SIGNALS:
5353 void summaryChanged(const QString &summary);
5454 void bodyChanged(const QString &body);
55− void nidChanged(const unsigned int nid);
55+ void idChanged(const unsigned int id);
5656 void valueChanged(int value);
5757 void iconChanged(const QString &icon);
5858 void secondaryIconChanged(const QString &secondaryIcon);
@@ -71,8 +71,8 @@ public:
7171 void setSummary(const QString &summary);
7272 QString getBody() const;
7373 void setBody(const QString &body);
74− unsigned int getNID() const;
75− void setNID(const unsigned int nid);
74+ unsigned int getID() const;
75+ void setID(const unsigned int id);
7676 int getValue() const;
7777 void setValue(int value);
7878 QString getIcon() const;
tests/qmltests/Notifications/tst_Notifications.qml+28−28
@@ -33,8 +33,7 @@ Item {
3333 Notification {
3434 id: mockNotificationDefault
3535 type: Notification.PlaceHolder
36− nid: 1 //mockModel.getNextId()
37− //hints: {}
36+ nid: 1
3837 summary: ""
3938 body: ""
4039 icon: ""
@@ -47,18 +46,11 @@ Item {
4746 dynamicRoles: true
4847
4948 signal actionInvoked(string actionId)
50− property var internalId: 0
5149
52− function getNextId() {
53− return internalId++
54− }
55−
56− function getRaw(nid) {
57− print ("Looking for:", nid)
50+ function getRaw(id) {
5851 for (var i = 0; i < mockModel.count; i++) {
59− if (nid === mockModel.get(i).nid) {
60− print ("Found something...", i)
61− return mockModel.get(i).notification
52+ if (id === mockModel.get(i).nid) {
53+ return mockModel.get(i)
6254 }
6355 }
6456 }
@@ -72,7 +64,7 @@ Item {
7264 Notification {
7365 id: mock2over1SnapDecisionNotification
7466 type: Notification.SnapDecision
75− nid: 2 //mockModel.getNextId()
67+ nid: 2
7668 hints: {"x-canonical-private-affirmative-tint": "true"}
7769 summary: "Theatre at Ferria Stadium"
7870 body: "at Ferria Stadium in Bilbao, Spain\n07578545317"
@@ -85,12 +77,20 @@ Item {
8577
8678 function add2over1SnapDecisionNotification() {
8779 mockModel.append(mock2over1SnapDecisionNotification)
80+
81+ // trying out/debugging stuff
82+ mockModel.getRaw(2).close()
83+ print("summary:", mock2over1SnapDecisionNotification.summary)
84+ print("summary:", mockModel.getRaw(2).summary)
85+ print("summary:", mockModel.get(1).summary)
86+ mock2over1SnapDecisionNotification.close()
87+ mock2over1SnapDecisionNotification.invokeAction("ok_id")
8888 }
8989
9090 Notification {
9191 id: mockEphemeralNotification
9292 type: Notification.Ephemeral
93− nid: 3 //mockModel.getNextId()
93+ nid: 3
9494 summary: "Cole Raby"
9595 body: "I did not expect it to be that late."
9696 icon: "../graphics/avatars/amanda.png"
@@ -105,7 +105,7 @@ Item {
105105 Notification {
106106 id: mockEphemeralNonShapedIconNotification
107107 type: Notification.Ephemeral
108− nid: 4 //mockModel.getNextId()
108+ nid: 4
109109 hints: {"x-canonical-non-shaped-icon": "true"}
110110 summary: "Contacts"
111111 body: "Synchronised contacts-database with cloud-storage."
@@ -121,7 +121,7 @@ Item {
121121 Notification {
122122 id: mockEphemeralIconSummaryNotification
123123 type: Notification.Ephemeral
124− nid: 5 //mockModel.getNextId()
124+ nid: 5
125125 hints: {"x-canonical-non-shaped-icon": "false"}
126126 summary: "Photo upload completed"
127127 body: ""
@@ -137,7 +137,7 @@ Item {
137137 Notification {
138138 id: mockInteractiveNotification
139139 type: Notification.Interactive
140− nid: 6 //mockModel.getNextId()
140+ nid: 6
141141 summary: "Interactive notification"
142142 body: "This is a notification that can be clicked"
143143 icon: "../graphics/avatars/anna_olsson.png"
@@ -152,7 +152,7 @@ Item {
152152 Notification {
153153 id: mockConfirmationNotification
154154 type: Notification.Confirmation
155− nid: 7 //mockModel.getNextId()
155+ nid: 7
156156 hints: {"x-canonical-non-shaped-icon": "true"}
157157 summary: "Confirmation notification"
158158 body: ""
@@ -169,7 +169,7 @@ Item {
169169 Notification {
170170 id: mock2ndConfirmationNotification
171171 type: Notification.Confirmation
172− nid: 8 //mockModel.getNextId()
172+ nid: 8
173173 hints: {"x-canonical-non-shaped-icon": "true",
174174 "x-canonical-value-bar-tint": "true"}
175175 summary: "Confirmation notification"
@@ -295,7 +295,7 @@ Item {
295295 {
296296 tag: "2-over-1 Snap Decision with button-tint",
297297 type: Notification.SnapDecision,
298− //nid: mockModel.getNextId(),
298+ nid: 2,
299299 hints: {"x-canonical-private-affirmative-tint": "true"},
300300 summary: "Theatre at Ferria Stadium",
301301 body: "at Ferria Stadium in Bilbao, Spain\n07578545317",
@@ -321,7 +321,7 @@ Item {
321321 {
322322 tag: "Ephemeral notification - icon-summary layout",
323323 type: Notification.Ephemeral,
324− //nid: mockModel.getNextId(),
324+ nid: 3,
325325 hints: {},
326326 summary: "Photo upload completed",
327327 body: "",
@@ -345,7 +345,7 @@ Item {
345345 {
346346 tag: "Ephemeral notification - check suppression of secondary icon for icon-summary layout",
347347 type: Notification.Ephemeral,
348− //nid: mockModel.getNextId(),
348+ nid: 4,
349349 hints: {"x-canonical-private-affirmative-tint": "false",
350350 "sound-file": "dummy.ogg",
351351 "suppress-sound": "true"},
@@ -372,7 +372,7 @@ Item {
372372 {
373373 tag: "Interactive notification",
374374 type: Notification.Interactive,
375− //nid: mockModel.getNextId(),
375+ nid: 5,
376376 hints: {"x-canonical-private-affirmative-tint": "false",
377377 "sound-file": "dummy.ogg"},
378378 summary: "Interactive notification",
@@ -397,7 +397,7 @@ Item {
397397 {
398398 tag: "Snap Decision without secondary icon and no button-tint",
399399 type: Notification.SnapDecision,
400− //nid: mockModel.getNextId(),
400+ nid: 6,
401401 hints: {"x-canonical-private-affirmative-tint": "false",
402402 "sound-file": "dummy.ogg"},
403403 summary: "Bro Coly",
@@ -423,7 +423,7 @@ Item {
423423 {
424424 tag: "Ephemeral notification",
425425 type: Notification.Ephemeral,
426− //nid: mockModel.getNextId(),
426+ nid: 7,
427427 hints: {"x-canonical-private-affirmative-tint": "false",
428428 "sound-file": "dummy.ogg"},
429429 summary: "Cole Raby",
@@ -448,7 +448,7 @@ Item {
448448 {
449449 tag: "Ephemeral notification with non-shaped icon",
450450 type: Notification.Ephemeral,
451− //nid: mockModel.getNextId(),
451+ nid: 8,
452452 hints: {"x-canonical-private-affirmative-tint": "false",
453453 "x-canonical-non-shaped-icon": "true"},
454454 summary: "Contacts",
@@ -473,7 +473,7 @@ Item {
473473 {
474474 tag: "Confirmation notification with value",
475475 type: Notification.Confirmation,
476− //nid: mockModel.getNextId(),
476+ nid: 9,
477477 hints: {"x-canonical-non-shaped-icon": "true"},
478478 summary: "",
479479 body: "",
@@ -497,7 +497,7 @@ Item {
497497 {
498498 tag: "Confirmation notification with value, label and tint",
499499 type: Notification.Confirmation,
500− //nid: mockModel.getNextId(),
500+ nid: 10,
501501 hints: {"x-canonical-non-shaped-icon": "true",
502502 "x-canonical-value-bar-tint" : "true"},
503503 summary: "",