2
* Copyright (C) 2014 Canonical, Ltd.
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.
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.
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/>.
20
import "../../../qml/Notifications"
21
import Ubuntu.Components 0.1
23
import Unity.Notifications 1.0
26
width: notificationsRect.width + interactiveControls.width
27
height: notificationsRect.height
36
function invokeAction(actionId) {
37
mockModel.actionInvoked(actionId)
46
signal actionInvoked(string actionId)
49
return mockNotification.createObject(mockModel)
52
// add the default/PlaceHolder notification to the model
53
Component.onCompleted: {
55
type: Notification.PlaceHolder,
68
function addSwipeToActNotification() {
70
type: Notification.SnapDecision,
71
hints: {"x-canonical-snap-decisions-swipe": "true"},
72
summary: "Incoming call",
73
body: "Frank Zappa\n+44 (0)7736 027340",
74
icon: "../graphics/avatars/amanda.png",
75
secondaryIcon: "incoming-call",
76
actions: [{ id: "ok_id", label: "Ok"},
77
{ id: "cancel_id", label: "Cancel"}]
83
function clearNotifications() {
87
function remove1stNotification() {
88
if (mockModel.count > 0)
99
id: clickThroughCatcher
115
id: interactiveControls
124
anchors.margins: units.gu(1)
128
text: "add a SwipeToAct snap-decision"
129
onClicked: rootRow.addSwipeToActNotification()
134
text: "remove 1st notification"
135
onClicked: rootRow.remove1stNotification()
141
onClicked: rootRow.clearNotifications()
152
name: "NotificationRendererTest"
155
function test_NotificationRenderer_data() {
158
tag: "Snap Decision with SwipeToAct-widget (accept)",
159
type: Notification.SnapDecision,
160
hints: {"x-canonical-snap-decisions-swipe": "true"},
161
summary: "Incoming call",
162
body: "Frank Zappa\n+44 (0)7736 027340",
163
icon: "../graphics/avatars/amanda.png",
164
secondaryIcon: "../graphics/applicationIcons/facebook.png",
165
actions: myActionModel,
166
summaryVisible: true,
170
secondaryIconVisible: true,
171
buttonRowVisible: true,
173
checkSwipeToActAccept: true,
174
checkSwipeToActReject: false
177
tag: "Snap Decision with SwipeToAct-widget (reject)",
178
type: Notification.SnapDecision,
179
hints: {"x-canonical-snap-decisions-swipe": "true"},
180
summary: "Incoming call",
181
body: "Bro Coly\n+49 (0)221 426973",
182
icon: "../graphics/avatars/funky.png",
183
secondaryIcon: "../graphics/applicationIcons/facebook.png",
184
actions: myActionModel,
185
summaryVisible: true,
189
secondaryIconVisible: true,
190
buttonRowVisible: true,
192
checkSwipeToActAccept: false,
193
checkSwipeToActReject: true
201
target: clickThroughCatcher
202
signalName: "clicked"
209
signalName: "actionInvoked"
213
clickThroughSpy.clear()
217
function test_NotificationRenderer(data) {
218
// populate model with some mock notifications
219
mockModel.append(data)
221
// make sure the view is properly updated before going on
222
notifications.forceLayout();
223
waitForRendering(notifications);
225
var notification = findChild(notifications, "notification" + (mockModel.count - 1))
226
verify(notification !== undefined, "notification wasn't found");
228
waitForRendering(notification);
230
var icon = findChild(notification, "icon")
231
var interactiveArea = findChild(notification, "interactiveArea")
232
var secondaryIcon = findChild(notification, "secondaryIcon")
233
var summaryLabel = findChild(notification, "summaryLabel")
234
var bodyLabel = findChild(notification, "bodyLabel")
235
var buttonRow = findChild(notification, "buttonRow")
237
compare(icon.visible, data.iconVisible, "avatar-icon visibility is incorrect")
239
compare(icon.shaped, data.shaped, "shaped-status is incorrect")
242
// test input does not fall through
243
mouseClick(notification, notification.width / 2, notification.height / 2)
244
if(data.type == Notification.Interactive) {
246
compare(actionSpy.signalArguments[0][0], data.actions[0]["id"], "got wrong id for interactive action")
248
compare(clickThroughSpy.count, 0, "click on notification fell through")
250
compare(secondaryIcon.visible, data.secondaryIconVisible, "secondary-icon visibility is incorrect")
251
compare(summaryLabel.visible, data.summaryVisible, "summary-text visibility is incorrect")
252
compare(bodyLabel.visible, data.bodyVisible, "body-text visibility is incorrect")
253
compare(buttonRow.visible, data.buttonRowVisible, "button visibility is incorrect")
255
if(data.buttonRowVisible) {
256
var swipeButton = findChild(buttonRow, "notify_swipe_button")
257
var slider = findChild(swipeButton, "slider")
258
var swipeMouseArea = findChild(swipeButton, "swipeMouseArea")
259
var x = swipeMouseArea.width / 2
260
var y = swipeMouseArea.height / 2
262
if(data.checkSwipeToActAccept) {
263
tryCompareFunction(function() { mouseDrag(slider, x, y, (swipeMouseArea.width / 2) - slider.width, 0); return actionSpy.signalArguments.length > 0; }, true);
264
compare(actionSpy.signalArguments[0][0], data.actions.data(0, ActionModel.RoleActionId), "got wrong id for positive action")
267
if(data.checkSwipeToActReject) {
268
tryCompareFunction(function() { mouseDrag(slider, x, y, -(swipeMouseArea.width / 2), 0); return actionSpy.signalArguments.length > 0; }, true);
269
compare(actionSpy.signalArguments[0][0], data.actions.data(1, ActionModel.RoleActionId), "got wrong id for negative action")