2
* Copyright (C) 2013 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 "../../../Notifications"
21
import Ubuntu.Components 0.1
31
function addSnapDecisionNotification() {
33
type: "Notifications.Type.SnapDecision",
35
body: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.",
36
icon: "../graphics/avatars/funky.png",
37
secondaryIcon: "../graphics/applicationIcons/facebook.png",
38
actions: [{ id: "ok_id", label: "Ok"},
39
{ id: "cancel_id", label: "Cancel"}]
45
function addEphemeralNotification() {
47
type: "Notifications.Type.Ephemeral",
49
body: "I did not expect it to be that late.",
50
icon: "../graphics/avatars/amanda.png",
51
secondaryIcon: "../graphics/applicationIcons/facebook.png",
58
function addEphemeralIconSummaryNotification() {
60
type: "Notifications.Type.Ephemeral",
61
summary: "Photo upload completed",
64
secondaryIcon: "../graphics/applicationIcons/facebook.png",
71
function addInteractiveNotification() {
73
type: "Notifications.Type.Interactive",
74
summary: "Interactive notification",
75
body: "This is a notification that can be clicked",
76
icon: "../graphics/avatars/anna_olsson.png",
78
actions: [{ id: "reply_id", label: "Dummy"}],
84
function clearNotifications() {
88
function remove1stNotification() {
89
if (mockModel.count > 0)
100
id: clickThroughCatcher
109
anchors.margins: units.gu(1)
115
id: interactiveControls
124
anchors.margins: units.gu(1)
128
text: "add a snap-decision"
129
onClicked: addSnapDecisionNotification()
134
text: "add an ephemeral"
135
onClicked: addEphemeralNotification()
140
text: "add an icon-summary"
141
onClicked: addEphemeralIconSummaryNotification()
146
text: "add an interactive"
147
onClicked: addInteractiveNotification()
152
text: "remove 1st notification"
153
onClicked: remove1stNotification()
159
onClicked: clearNotifications()
166
name: "NotificationRendererTest"
169
function test_NotificationRenderer_data() {
172
tag: "Snap Decision with secondary icon",
173
type: "Notifications.Type.SnapDecision",
175
body: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.",
176
icon: "../graphics/avatars/funky.png",
177
secondaryIcon: "../graphics/applicationIcons/facebook.png",
178
actions: [{ id: "ok_id", label: "Ok"},
179
{ id: "cancel_id", label: "Cancel"}],
180
summaryVisible: true,
182
interactiveAreaEnabled: false,
184
secondaryIconVisible: true,
185
buttonRowVisible: true
188
tag: "Ephemeral notification - icon-summary layout",
189
type: "Notifications.Type.Ephemeral",
190
summary: "Photo upload completed",
193
secondaryIcon: "../graphics/applicationIcons/facebook.png",
195
summaryVisible: true,
197
interactiveAreaEnabled: false,
199
secondaryIconVisible: true,
200
buttonRowVisible: false
203
tag: "Ephemeral notification - check suppression of secondary icon for icon-summary layout",
204
type: "Notifications.Type.Ephemeral",
205
summary: "New comment successfully published",
208
secondaryIcon: "../graphics/applicationIcons/facebook.png",
210
summaryVisible: true,
212
interactiveAreaEnabled: false,
214
secondaryIconVisible: true,
215
buttonRowVisible: false
218
tag: "Interactive notification",
219
type: "Notifications.Type.Interactive",
220
summary: "Interactive notification",
221
body: "This is a notification that can be clicked",
222
icon: "../graphics/avatars/amanda.png",
224
actions: [{ id: "reply_id", label: "Dummy"}],
225
summaryVisible: true,
227
interactiveAreaEnabled: true,
229
secondaryIconVisible: false,
230
buttonRowVisible: false
233
tag: "Snap Decision without secondary icon",
234
type: "Notifications.Type.SnapDecision",
236
body: "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.",
237
icon: "../graphics/avatars/anna_olsson.png",
239
actions: [{ id: "accept_id", label: "Accept"},
240
{ id: "reject_id", label: "Reject"}],
241
summaryVisible: true,
243
interactiveAreaEnabled: false,
245
secondaryIconVisible: false,
246
buttonRowVisible: true
249
tag: "Ephemeral notification",
250
type: "Notifications.Type.Ephemeral",
251
summary: "Cole Raby",
252
body: "I did not expect it to be that late.",
253
icon: "../graphics/avatars/funky.png",
254
secondaryIcon: "../graphics/applicationIcons/facebook.png",
256
summaryVisible: true,
258
interactiveAreaEnabled: false,
260
secondaryIconVisible: true,
261
buttonRowVisible: false
269
target: clickThroughCatcher
270
signalName: "clicked"
275
signalName: "actionInvoked"
279
clickThroughSpy.clear()
283
function test_NotificationRenderer(data) {
284
// populate model with some mock notifications
285
mockModel.append(data)
287
// make sure the view is properly updated before going on
288
notifications.forceLayout();
289
waitForRendering(notifications);
291
var notification = findChild(notifications, "notification" + (mockModel.count - 1))
292
verify(notification !== undefined, "notification wasn't found");
294
var icon = findChild(notification, "icon")
295
var interactiveArea = findChild(notification, "interactiveArea")
296
var secondaryIcon = findChild(notification, "secondaryIcon")
297
var summaryLabel = findChild(notification, "summaryLabel")
298
var bodyLabel = findChild(notification, "bodyLabel")
299
var buttonRow = findChild(notification, "buttonRow")
300
waitForRendering(buttonRow)
302
compare(icon.visible, data.iconVisible, "avatar-icon visibility is incorrect")
303
compare(interactiveArea.enabled, data.interactiveAreaEnabled, "check for interactive area")
305
if(data.interactiveAreaEnabled) {
306
actionSpy.target = notification
307
mouseClick(notification, notification.width / 2, notification.height / 2)
309
compare(actionSpy.signalArguments[0][0], data.actions[0]["id"], "got wrong id for interactive action")
310
compare(clickThroughSpy.count, 0, "click on interactive notification fell through")
312
mouseClick(notification, notification.width / 2, notification.height / 2)
313
clickThroughSpy.wait()
316
compare(secondaryIcon.visible, data.secondaryIconVisible, "secondary-icon visibility is incorrect")
317
compare(summaryLabel.visible, data.summaryVisible, "summary-text visibility is incorrect")
318
compare(bodyLabel.visible, data.bodyVisible, "body-text visibility is incorrect")
319
compare(buttonRow.visible, data.buttonRowVisible, "button visibility is incorrect")
321
if(data.buttonRowVisible) {
322
var buttonCancel = findChild(buttonRow, "button1")
323
var buttonAccept = findChild(buttonRow, "button0")
325
waitForRendering(notification)
326
actionSpy.target = notification
327
mouseClick(buttonCancel, buttonCancel.width / 2, buttonCancel.height / 2)
329
compare(actionSpy.signalArguments[0][0], data.actions[1]["id"], "got wrong id for negative action")
332
mouseClick(buttonAccept, buttonAccept.width / 2, buttonAccept.height / 2)
334
compare(actionSpy.signalArguments[0][0], data.actions[0]["id"], "got wrong id positive action")