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
24
import QtMultimedia 5.0
33
function invokeAction(actionId) {
34
console.log("Action invoked", actionId);
35
mockModel.actionInvoked(actionId)
43
signal actionInvoked(string actionId)
46
return mockNotification.createObject(mockModel)
49
// add the default/PlaceHolder notification to the model
50
Component.onCompleted: {
52
type: Notification.PlaceHolder,
65
function addSnapDecisionNotification() {
67
type: Notification.SnapDecision,
68
hints: {"x-canonical-private-affirmative-tint": "true"},
69
summary: "Incoming call",
70
body: "Frank Zappa\n+44 (0)7736 027340",
71
icon: "../graphics/avatars/funky.png",
72
secondaryIcon: "image://theme/incoming-call",
73
actions: [{ id: "ok_id", label: "Ok"},
74
{ id: "cancel_id", label: "Cancel"},
75
{ id: "dummy_id", label: "Quick reply"},
76
{ id: "late_id", label: "messages:I'm running late. I'm on my way."},
77
{ id: "later_id", label: "messages:I'm busy at the moment. I'll call later."}]
83
function clearNotifications() {
87
function remove1stNotification() {
88
if (mockModel.count > 0)
100
id: clickThroughCatcher
116
id: interactiveControls
125
anchors.margins: units.gu(1)
129
text: "add a snap-decision"
130
onClicked: addSnapDecisionNotification()
135
text: "remove 1st notification"
136
onClicked: remove1stNotification()
142
onClicked: clearNotifications()
149
name: "NotificationRendererTest"
152
function test_NotificationRenderer_data() {
155
tag: "Snap Decision with secondary icon, button-tint and OptionToggle",
156
type: Notification.SnapDecision,
157
hints: {"x-canonical-private-affirmative-tint": "true"},
158
summary: "Incoming call",
159
body: "Frank Zappa\n+44 (0)7736 027340",
160
icon: "../graphics/avatars/funky.png",
161
secondaryIcon: "image://theme/incoming-call",
162
actions: [{ id: "ok_id", label: "Ok"},
163
{ id: "cancel_id", label: "Cancel"},
164
{ id: "dummy_id", label: "Quick reply"},
165
{ id: "late_id", label: "messages:I'm running late. I'm on my way."},
166
{ id: "later_id", label: "messages:I'm busy at the moment. I'll call later."}],
167
summaryVisible: true,
171
secondaryIconVisible: true,
172
buttonRowVisible: true,
182
target: clickThroughCatcher
183
signalName: "clicked"
190
signalName: "actionInvoked"
194
clickThroughSpy.clear()
198
function test_NotificationRenderer(data) {
199
// populate model with some mock notifications
200
mockModel.append(data)
202
// make sure the view is properly updated before going on
203
notifications.forceLayout();
204
waitForRendering(notifications);
206
var notification = findChild(notifications, "notification" + (mockModel.count - 1))
207
verify(notification !== undefined, "notification wasn't found");
209
waitForRendering(notification);
211
var icon = findChild(notification, "icon")
212
var shapedIcon = findChild(notification, "shapedIcon")
213
var nonShapedIcon = findChild(notification, "nonShapedIcon")
214
var interactiveArea = findChild(notification, "interactiveArea")
215
var secondaryIcon = findChild(notification, "secondaryIcon")
216
var summaryLabel = findChild(notification, "summaryLabel")
217
var bodyLabel = findChild(notification, "bodyLabel")
218
var buttonRow = findChild(notification, "buttonRow")
220
compare(icon.visible, data.iconVisible, "avatar-icon visibility is incorrect")
222
compare(icon.shaped, data.shaped, "shaped-status is incorrect")
225
// test input does not fall through
226
mouseClick(notification, notification.width / 2, notification.height / 2)
227
if(data.type == Notification.Interactive) {
229
compare(actionSpy.signalArguments[0][0], data.actions[0]["id"], "got wrong id for interactive action")
231
compare(clickThroughSpy.count, 0, "click on notification fell through")
233
compare(secondaryIcon.visible, data.secondaryIconVisible, "secondary-icon visibility is incorrect")
234
compare(summaryLabel.visible, data.summaryVisible, "summary-text visibility is incorrect")
235
compare(bodyLabel.visible, data.bodyVisible, "body-text visibility is incorrect")
236
compare(buttonRow.visible, data.buttonRowVisible, "button visibility is incorrect")
238
var audioItem = findInvisibleChild(notification, "sound")
239
compare(audioItem.playbackState, data.hasSound ? Audio.PlayingState : Audio.StoppedState, "Audio has wrong state")
241
if(data.buttonRowVisible) {
242
var buttonCancel = findChild(buttonRow, "notify_button1")
243
var buttonAccept = findChild(buttonRow, "notify_button0")
245
// only test the left/cancel-button if two actions have been passed in
246
if (data.actions.length == 2) {
247
tryCompareFunction(function() { mouseClick(buttonCancel, buttonCancel.width / 2, buttonCancel.height / 2); return actionSpy.signalArguments.length > 0; }, true);
248
compare(actionSpy.signalArguments[0][0], data.actions[1]["id"], "got wrong id for negative action")
252
// check the tinting of the positive/right button
253
verify(buttonAccept.color === data.buttonTinted ? "#3fb24f" : "#dddddd", "button has the wrong color-tint")
255
// click the positive/right button
256
tryCompareFunction(function() { mouseClick(buttonAccept, buttonAccept.width / 2, buttonAccept.height / 2); return actionSpy.signalArguments.length > 0; }, true);
257
compare(actionSpy.signalArguments[0][0], data.actions[0]["id"], "got wrong id positive action")
259
waitForRendering(notification)
261
// check if there's a OptionToggle created due to more actions being passed
262
if (data.actions.length > 2) {
263
var optionToggle = findChild(notification, "notify_button2")
264
tryCompareFunction(function() { return optionToggle.expanded == false; }, true);
267
tryCompareFunction(function() { mouseClick(optionToggle, optionToggle.width / 2, optionToggle.height / 2); return optionToggle.expanded == true; }, true);
269
// try clicking on choices in expanded comboList
270
var choiceButton1 = findChild(notification, "notify_button3")
271
tryCompareFunction(function() { mouseClick(choiceButton1, choiceButton1.width / 2, choiceButton1.height / 2); return actionSpy.signalArguments.length > 0; }, true);
272
compare(actionSpy.signalArguments[0][0], data.actions[3]["id"], "got wrong id choice action 1")
275
var choiceButton2 = findChild(notification, "notify_button4")
276
tryCompareFunction(function() { mouseClick(choiceButton2, choiceButton2.width / 2, choiceButton2.height / 2); return actionSpy.signalArguments.length > 0; }, true);
277
compare(actionSpy.signalArguments[0][0], data.actions[4]["id"], "got wrong id choice action 2")
280
mouseClick(buttonCancel, buttonCancel.width / 2, buttonCancel.height / 2)
281
compare(actionSpy.signalArguments[0][0], data.actions[1]["id"], "got wrong id for negative action")