on xenial help sign in
Extracted SwipeToAct-qmltest into seperate file to simplify testing of left and right swipe-gestures.
commit7f16e39824a4471b33155ff7317d38bf04ea2c2c authorMirco Müller <mirco.mueller@canonical.com> dateFri 24 Oct 2014, 09:16 (12 years ago) parentbb75bba
3 files changed+330−110
tests/qmltests/CMakeLists.txt+1 tests/qmltests/Notifications/tst_Notifications.qml+49−110 tests/qmltests/Notifications/tst_SwipeToAct.qml+280
tests/qmltests/CMakeLists.txt+1
@@ -71,6 +71,7 @@ add_qml_test(Hud Result)
7171add_qml_test(Launcher Launcher)
7272add_qml_test(Notifications Notifications)
7373add_qml_test(Notifications VisualSnapDecisionsQueue)
74+add_qml_test(Notifications SwipeToAct)
7475add_qml_test(Panel ActiveCallHint)
7576add_qml_test(Panel IndicatorRow)
7677add_qml_test(Panel Indicators)
tests/qmltests/Notifications/tst_Notifications.qml+49−110
@@ -84,21 +84,6 @@ Item {
8484 mockModel.append(n)
8585 }
8686
87− function addSwipeToActNotification() {
88− var n = {
89− type: Notification.SnapDecision,
90− hints: {"x-canonical-snap-decisions-swipe": "true"},
91− summary: "Incoming call",
92− body: "Frank Zappa\n+44 (0)7736 027340",
93− icon: "../graphics/avatars/amanda.png",
94− secondaryIcon: "incoming-call",
95− actions: [{ id: "ok_id", label: "Ok"},
96− { id: "cancel_id", label: "Cancel"}]
97− }
98−
99− mockModel.append(n)
100− }
101−
10287 function add2over1SnapDecisionNotification() {
10388 var n = {
10489 type: Notification.SnapDecision,
@@ -217,12 +202,6 @@ Item {
217202 onClicked: rootRow.addSnapDecisionNotification()
218203 }
219204
220− Button {
221− width: parent.width
222− text: "add a SwipeToAct snap-decision"
223− onClicked: rootRow.addSwipeToActNotification()
224− }
225−
226205 Button {
227206 width: parent.width
228207 text: "add a 2over1 snap-decision"
@@ -299,28 +278,7 @@ Item {
299278 secondaryIconVisible: true,
300279 buttonRowVisible: true,
301280 buttonTinted: true,
302− hasSound: false,
303− hasSwipeToAct: false
304− },
305− {
306− tag: "Snap Decision with SwipeToAct-widget",
307− type: Notification.SnapDecision,
308− hints: {"x-canonical-snap-decisions-swipe": "true"},
309− summary: "Incoming call",
310− body: "Frank Zappa\n+44 (0)7736 027340",
311− icon: "../graphics/avatars/amanda.png",
312− secondaryIcon: "../graphics/applicationIcons/facebook.png",
313− actions: myActionModel,
314− summaryVisible: true,
315− bodyVisible: true,
316− iconVisible: true,
317− shapedIcon: true,
318− nonShapedIcon: false,
319− secondaryIconVisible: true,
320− buttonRowVisible: true,
321− buttonTinted: false,
322− hasSound: false,
323− hasSwipeToAct: true
281+ hasSound: false
324282 },
325283 {
326284 tag: "2-over-1 Snap Decision with button-tint",
@@ -341,8 +299,7 @@ Item {
341299 secondaryIconVisible: false,
342300 buttonRowVisible: false,
343301 buttonTinted: true,
344− hasSound: false,
345− hasSwipeToAct: false
302+ hasSound: false
346303 },
347304 {
348305 tag: "Ephemeral notification - icon-summary layout",
@@ -361,8 +318,7 @@ Item {
361318 secondaryIconVisible: true,
362319 buttonRowVisible: false,
363320 buttonTinted: false,
364− hasSound: false,
365− hasSwipeToAct: false
321+ hasSound: false
366322 },
367323 {
368324 tag: "Ephemeral notification - check suppression of secondary icon for icon-summary layout",
@@ -384,8 +340,7 @@ Item {
384340 secondaryIconVisible: true,
385341 buttonRowVisible: false,
386342 buttonTinted: false,
387− hasSound: false,
388− hasSwipeToAct: false
343+ hasSound: false
389344 },
390345 {
391346 tag: "Interactive notification",
@@ -405,8 +360,7 @@ Item {
405360 secondaryIconVisible: false,
406361 buttonRowVisible: false,
407362 buttonTinted: false,
408− hasSound: true,
409− hasSwipeToAct: false
363+ hasSound: true
410364 },
411365 {
412366 tag: "Snap Decision without secondary icon and no button-tint",
@@ -427,8 +381,7 @@ Item {
427381 secondaryIconVisible: false,
428382 buttonRowVisible: true,
429383 buttonTinted: false,
430− hasSound: true,
431− hasSwipeToAct: false
384+ hasSound: true
432385 },
433386 {
434387 tag: "Ephemeral notification",
@@ -448,8 +401,7 @@ Item {
448401 secondaryIconVisible: true,
449402 buttonRowVisible: false,
450403 buttonTinted: false,
451− hasSound: true,
452− hasSwipeToAct: false
404+ hasSound: true
453405 },
454406 {
455407 tag: "Ephemeral notification with non-shaped icon",
@@ -469,8 +421,7 @@ Item {
469421 secondaryIconVisible: false,
470422 buttonRowVisible: false,
471423 buttonTinted: false,
472− hasSound: false,
473− hasSwipeToAct: false
424+ hasSound: false
474425 }
475426 ]
476427 }
@@ -537,61 +488,49 @@ Item {
537488 compare(audioItem.playbackState, data.hasSound ? Audio.PlayingState : Audio.StoppedState, "Audio has wrong state")
538489
539490 if(data.buttonRowVisible) {
540− if(data.hasSwipeToAct) {
541− var swipeButton = findChild(buttonRow, "notify_swipe_button")
542− var slider = findChild(swipeButton, "slider")
543− var swipeMouseArea = findChild(swipeButton, "swipeMouseArea")
544− var x = swipeMouseArea.width / 2
545− var y = swipeMouseArea.height / 2
546− //mouseDrag(swipeButton, x, y, -(swipeMouseArea.width / 2), 0)
547− tryCompareFunction(function() { mouseDrag(slider, x, y, (swipeMouseArea.width / 2) - slider.width, 0); return actionSpy.signalArguments.length > 0; }, true);
548− compare(actionSpy.signalArguments[0][0], data.actions.data(1, ActionModel.RoleActionId), "got wrong id for positive action")
491+ var buttonCancel = findChild(buttonRow, "notify_button1")
492+ var buttonAccept = findChild(buttonRow, "notify_button0")
493+
494+ // only test the left/cancel-button if two actions have been passed in
495+ if (data.actions.length == 2) {
496+ tryCompareFunction(function() { mouseClick(buttonCancel, buttonCancel.width / 2, buttonCancel.height / 2); return actionSpy.signalArguments.length > 0; }, true);
497+ compare(actionSpy.signalArguments[0][0], data.actions[1]["id"], "got wrong id for negative action")
549498 actionSpy.clear()
550− } else {
551− var buttonCancel = findChild(buttonRow, "notify_button1")
552− var buttonAccept = findChild(buttonRow, "notify_button0")
553−
554− // only test the left/cancel-button if two actions have been passed in
555− if (data.actions.length == 2) {
556− tryCompareFunction(function() { mouseClick(buttonCancel, buttonCancel.width / 2, buttonCancel.height / 2); return actionSpy.signalArguments.length > 0; }, true);
557− compare(actionSpy.signalArguments[0][0], data.actions[1]["id"], "got wrong id for negative action")
558− actionSpy.clear()
559− }
560−
561− // check the tinting of the positive/right button
562− verify(buttonAccept.color === data.buttonTinted ? "#3fb24f" : "#dddddd", "button has the wrong color-tint")
563−
564− // click the positive/right button
565− tryCompareFunction(function() { mouseClick(buttonAccept, buttonAccept.width / 2, buttonAccept.height / 2); return actionSpy.signalArguments.length > 0; }, true);
566− compare(actionSpy.signalArguments[0][0], data.actions[0]["id"], "got wrong id positive action")
499+ }
500+
501+ // check the tinting of the positive/right button
502+ verify(buttonAccept.color === data.buttonTinted ? "#3fb24f" : "#dddddd", "button has the wrong color-tint")
503+
504+ // click the positive/right button
505+ tryCompareFunction(function() { mouseClick(buttonAccept, buttonAccept.width / 2, buttonAccept.height / 2); return actionSpy.signalArguments.length > 0; }, true);
506+ compare(actionSpy.signalArguments[0][0], data.actions[0]["id"], "got wrong id positive action")
507+ actionSpy.clear()
508+ waitForRendering (notification)
509+
510+ // check if there's a ComboButton created due to more actions being passed
511+ if (data.actions.length > 2) {
512+ var comboButton = findChild(notification, "notify_button2")
513+ tryCompareFunction(function() { return comboButton.expanded == false; }, true);
514+
515+ // click to expand
516+ tryCompareFunction(function() { mouseClick(comboButton, comboButton.width - comboButton.__styleInstance.dropDownWidth / 2, comboButton.height / 2); return comboButton.expanded == true; }, true);
517+
518+ // try clicking on choices in expanded comboList
519+ var choiceButton1 = findChild(notification, "notify_button3")
520+ tryCompareFunction(function() { mouseClick(choiceButton1, choiceButton1.width / 2, choiceButton1.height / 2); return actionSpy.signalArguments.length > 0; }, true);
521+ compare(actionSpy.signalArguments[0][0], data.actions[3]["id"], "got wrong id choice action 1")
567522 actionSpy.clear()
568− waitForRendering (notification)
569−
570− // check if there's a ComboButton created due to more actions being passed
571− if (data.actions.length > 2) {
572− var comboButton = findChild(notification, "notify_button2")
573− tryCompareFunction(function() { return comboButton.expanded == false; }, true);
574−
575− // click to expand
576− tryCompareFunction(function() { mouseClick(comboButton, comboButton.width - comboButton.__styleInstance.dropDownWidth / 2, comboButton.height / 2); return comboButton.expanded == true; }, true);
577−
578− // try clicking on choices in expanded comboList
579− var choiceButton1 = findChild(notification, "notify_button3")
580− tryCompareFunction(function() { mouseClick(choiceButton1, choiceButton1.width / 2, choiceButton1.height / 2); return actionSpy.signalArguments.length > 0; }, true);
581− compare(actionSpy.signalArguments[0][0], data.actions[3]["id"], "got wrong id choice action 1")
582− actionSpy.clear()
583−
584− var choiceButton2 = findChild(notification, "notify_button4")
585− tryCompareFunction(function() { mouseClick(choiceButton2, choiceButton2.width / 2, choiceButton2.height / 2); return actionSpy.signalArguments.length > 0; }, true);
586− compare(actionSpy.signalArguments[0][0], data.actions[4]["id"], "got wrong id choice action 2")
587− actionSpy.clear()
588−
589− // click to collapse
590− //tryCompareFunction(function() { mouseClick(comboButton, comboButton.width - comboButton.__styleInstance.dropDownWidth / 2, comboButton.height / 2); return comboButton.expanded == false; }, true);
591− } else {
592− mouseClick(buttonCancel, buttonCancel.width / 2, buttonCancel.height / 2)
593− compare(actionSpy.signalArguments[0][0], data.actions[1]["id"], "got wrong id for negative action")
594− }
523+
524+ var choiceButton2 = findChild(notification, "notify_button4")
525+ tryCompareFunction(function() { mouseClick(choiceButton2, choiceButton2.width / 2, choiceButton2.height / 2); return actionSpy.signalArguments.length > 0; }, true);
526+ compare(actionSpy.signalArguments[0][0], data.actions[4]["id"], "got wrong id choice action 2")
527+ actionSpy.clear()
528+
529+ // click to collapse
530+ //tryCompareFunction(function() { mouseClick(comboButton, comboButton.width - comboButton.__styleInstance.dropDownWidth / 2, comboButton.height / 2); return comboButton.expanded == false; }, true);
531+ } else {
532+ mouseClick(buttonCancel, buttonCancel.width / 2, buttonCancel.height / 2)
533+ compare(actionSpy.signalArguments[0][0], data.actions[1]["id"], "got wrong id for negative action")
595534 }
596535 }
597536 }
tests/qmltests/Notifications/tst_SwipeToAct.qmlnew file+280
@@ -0,0 +1,280 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.0
18+import QtTest 1.0
19+import ".."
20+import "../../../qml/Notifications"
21+import Ubuntu.Components 0.1
22+import Unity.Test 0.1
23+import Unity.Notifications 1.0
24+import QtMultimedia 5.0
25+
26+Item {
27+ width: notificationsRect.width + interactiveControls.width
28+ height: notificationsRect.height
29+
30+ Row {
31+ id: rootRow
32+
33+ Component {
34+ id: mockNotification
35+
36+ QtObject {
37+ function invokeAction(actionId) {
38+ mockModel.actionInvoked(actionId)
39+ }
40+ }
41+ }
42+
43+ ListModel {
44+ id: mockModel
45+ dynamicRoles: true
46+
47+ signal actionInvoked(string actionId)
48+
49+ function getRaw(id) {
50+ return mockNotification.createObject(mockModel)
51+ }
52+
53+ // add the default/PlaceHolder notification to the model
54+ Component.onCompleted: {
55+ var n = {
56+ type: Notification.PlaceHolder,
57+ hints: {},
58+ summary: "",
59+ body: "",
60+ icon: "",
61+ secondaryIcon: "",
62+ actions: []
63+ }
64+
65+ append(n)
66+ }
67+ }
68+
69+ function addSwipeToActNotification() {
70+ var n = {
71+ type: Notification.SnapDecision,
72+ hints: {"x-canonical-snap-decisions-swipe": "true"},
73+ summary: "Incoming call",
74+ body: "Frank Zappa\n+44 (0)7736 027340",
75+ icon: "../graphics/avatars/amanda.png",
76+ secondaryIcon: "incoming-call",
77+ actions: [{ id: "ok_id", label: "Ok"},
78+ { id: "cancel_id", label: "Cancel"}]
79+ }
80+
81+ mockModel.append(n)
82+ }
83+
84+ function clearNotifications() {
85+ mockModel.clear()
86+ }
87+
88+ function remove1stNotification() {
89+ if (mockModel.count > 0)
90+ mockModel.remove(0)
91+ }
92+
93+ Rectangle {
94+ id: notificationsRect
95+
96+ width: units.gu(40)
97+ height: units.gu(71)
98+
99+ MouseArea{
100+ id: clickThroughCatcher
101+
102+ anchors.fill: parent
103+ }
104+
105+ Notifications {
106+ id: notifications
107+
108+ margin: units.gu(1)
109+
110+ anchors.fill: parent
111+ model: mockModel
112+ }
113+ }
114+
115+ Rectangle {
116+ id: interactiveControls
117+
118+ width: units.gu(30)
119+ height: units.gu(81)
120+ color: "grey"
121+
122+ Column {
123+ spacing: units.gu(1)
124+ anchors.fill: parent
125+ anchors.margins: units.gu(1)
126+
127+ Button {
128+ width: parent.width
129+ text: "add a SwipeToAct snap-decision"
130+ onClicked: rootRow.addSwipeToActNotification()
131+ }
132+
133+ Button {
134+ width: parent.width
135+ text: "remove 1st notification"
136+ onClicked: rootRow.remove1stNotification()
137+ }
138+
139+ Button {
140+ width: parent.width
141+ text: "clear model"
142+ onClicked: rootRow.clearNotifications()
143+ }
144+ }
145+ }
146+
147+ ActionModel {
148+ id: myActionModel
149+ }
150+
151+ UnityTestCase {
152+ id: root
153+ name: "NotificationRendererTest"
154+ when: windowShown
155+
156+ function test_NotificationRenderer_data() {
157+ return [
158+ {
159+ tag: "Snap Decision with SwipeToAct-widget (accept)",
160+ type: Notification.SnapDecision,
161+ hints: {"x-canonical-snap-decisions-swipe": "true"},
162+ summary: "Incoming call",
163+ body: "Frank Zappa\n+44 (0)7736 027340",
164+ icon: "../graphics/avatars/amanda.png",
165+ secondaryIcon: "../graphics/applicationIcons/facebook.png",
166+ actions: myActionModel,
167+ summaryVisible: true,
168+ bodyVisible: true,
169+ iconVisible: true,
170+ shapedIcon: true,
171+ nonShapedIcon: false,
172+ secondaryIconVisible: true,
173+ buttonRowVisible: true,
174+ buttonTinted: false,
175+ checkSwipeToActAccept: true,
176+ checkSwipeToActReject: false
177+ },
178+ {
179+ tag: "Snap Decision with SwipeToAct-widget (reject)",
180+ type: Notification.SnapDecision,
181+ hints: {"x-canonical-snap-decisions-swipe": "true"},
182+ summary: "Incoming call",
183+ body: "Bro Coly\n+49 (0)221 426973",
184+ icon: "../graphics/avatars/funky.png",
185+ secondaryIcon: "../graphics/applicationIcons/facebook.png",
186+ actions: myActionModel,
187+ summaryVisible: true,
188+ bodyVisible: true,
189+ iconVisible: true,
190+ shapedIcon: true,
191+ nonShapedIcon: false,
192+ secondaryIconVisible: true,
193+ buttonRowVisible: true,
194+ buttonTinted: false,
195+ checkSwipeToActAccept: false,
196+ checkSwipeToActReject: true
197+ }
198+ ]
199+ }
200+
201+ SignalSpy {
202+ id: clickThroughSpy
203+
204+ target: clickThroughCatcher
205+ signalName: "clicked"
206+ }
207+
208+ SignalSpy {
209+ id: actionSpy
210+
211+ target: mockModel
212+ signalName: "actionInvoked"
213+ }
214+
215+ function cleanup() {
216+ clickThroughSpy.clear()
217+ actionSpy.clear()
218+ }
219+
220+ function test_NotificationRenderer(data) {
221+ // populate model with some mock notifications
222+ mockModel.append(data)
223+
224+ // make sure the view is properly updated before going on
225+ notifications.forceLayout();
226+ waitForRendering(notifications);
227+
228+ var notification = findChild(notifications, "notification" + (mockModel.count - 1))
229+ verify(notification !== undefined, "notification wasn't found");
230+
231+ waitForRendering(notification);
232+
233+ var icon = findChild(notification, "icon")
234+ var shapedIcon = findChild(notification, "shapedIcon")
235+ var nonShapedIcon = findChild(notification, "nonShapedIcon")
236+ var interactiveArea = findChild(notification, "interactiveArea")
237+ var secondaryIcon = findChild(notification, "secondaryIcon")
238+ var summaryLabel = findChild(notification, "summaryLabel")
239+ var bodyLabel = findChild(notification, "bodyLabel")
240+ var buttonRow = findChild(notification, "buttonRow")
241+
242+ compare(icon.visible, data.iconVisible, "avatar-icon visibility is incorrect")
243+ compare(shapedIcon.visible, data.shapedIcon, "shaped-icon visibility is incorrect")
244+ compare(nonShapedIcon.visible, data.nonShapedIcon, "non-shaped-icon visibility is incorrect")
245+
246+ // test input does not fall through
247+ mouseClick(notification, notification.width / 2, notification.height / 2)
248+ if(data.type == Notification.Interactive) {
249+ actionSpy.wait()
250+ compare(actionSpy.signalArguments[0][0], data.actions[0]["id"], "got wrong id for interactive action")
251+ }
252+ compare(clickThroughSpy.count, 0, "click on notification fell through")
253+
254+ compare(secondaryIcon.visible, data.secondaryIconVisible, "secondary-icon visibility is incorrect")
255+ compare(summaryLabel.visible, data.summaryVisible, "summary-text visibility is incorrect")
256+ compare(bodyLabel.visible, data.bodyVisible, "body-text visibility is incorrect")
257+ compare(buttonRow.visible, data.buttonRowVisible, "button visibility is incorrect")
258+
259+ if(data.buttonRowVisible) {
260+ var swipeButton = findChild(buttonRow, "notify_swipe_button")
261+ var slider = findChild(swipeButton, "slider")
262+ var swipeMouseArea = findChild(swipeButton, "swipeMouseArea")
263+ var x = swipeMouseArea.width / 2
264+ var y = swipeMouseArea.height / 2
265+
266+ if(data.checkSwipeToActReject) {
267+ tryCompareFunction(function() { mouseDrag(slider, x, y, -(swipeMouseArea.width / 2), 0); return actionSpy.signalArguments.length > 0; }, true);
268+ compare(actionSpy.signalArguments[0][0], data.actions.data(0, ActionModel.RoleActionId), "got wrong id for negative action")
269+ actionSpy.clear()
270+ }
271+ if(data.checkSwipeToActAccept) {
272+ tryCompareFunction(function() { mouseDrag(slider, x, y, (swipeMouseArea.width / 2) - slider.width, 0); return actionSpy.signalArguments.length > 0; }, true);
273+ compare(actionSpy.signalArguments[0][0], data.actions.data(1, ActionModel.RoleActionId), "got wrong id for positive action")
274+ actionSpy.clear()
275+ }
276+ }
277+ }
278+ }
279+ }
280+}