~unity-team/+junk/dashboard-playground

« back to all changes in this revision

Viewing changes to tests/qmltests/Notifications/tst_Notifications.qml

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "../../../Notifications"
 
21
import Ubuntu.Components 0.1
 
22
import Unity.Test 0.1
 
23
 
 
24
Row {
 
25
    id: rootRow
 
26
 
 
27
    ListModel {
 
28
        id: mockModel
 
29
    }
 
30
 
 
31
    function addSnapDecisionNotification() {
 
32
        var n = {
 
33
            type: "Notifications.Type.SnapDecision",
 
34
            summary: "Tom Ato",
 
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"}]
 
40
        }
 
41
 
 
42
        mockModel.append(n)
 
43
    }
 
44
 
 
45
    function addEphemeralNotification() {
 
46
        var n = {
 
47
            type: "Notifications.Type.Ephemeral",
 
48
            summary: "Cole Raby",
 
49
            body: "I did not expect it to be that late.",
 
50
            icon: "../graphics/avatars/amanda.png",
 
51
            secondaryIcon: "../graphics/applicationIcons/facebook.png",
 
52
            actions: []
 
53
        }
 
54
 
 
55
        mockModel.append(n)
 
56
    }
 
57
 
 
58
    function addEphemeralIconSummaryNotification() {
 
59
        var n = {
 
60
            type: "Notifications.Type.Ephemeral",
 
61
            summary: "Photo upload completed",
 
62
            body: "",
 
63
            icon: "",
 
64
            secondaryIcon: "../graphics/applicationIcons/facebook.png",
 
65
            actions: []
 
66
        }
 
67
 
 
68
        mockModel.append(n)
 
69
    }
 
70
 
 
71
    function addInteractiveNotification() {
 
72
        var n = {
 
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",
 
77
            secondaryIcon: "",
 
78
            actions: [{ id: "reply_id", label: "Dummy"}],
 
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
            anchors.fill: parent
 
109
            anchors.margins: units.gu(1)
 
110
            model: mockModel
 
111
        }
 
112
    }
 
113
 
 
114
    Rectangle {
 
115
        id: interactiveControls
 
116
 
 
117
        width: units.gu(30)
 
118
        height: units.gu(71)
 
119
        color: "grey"
 
120
 
 
121
        Column {
 
122
            spacing: units.gu(1)
 
123
            anchors.fill: parent
 
124
            anchors.margins: units.gu(1)
 
125
 
 
126
            Button {
 
127
                width: parent.width
 
128
                text: "add a snap-decision"
 
129
                onClicked: addSnapDecisionNotification()
 
130
            }
 
131
 
 
132
            Button {
 
133
                width: parent.width
 
134
                text: "add an ephemeral"
 
135
                onClicked: addEphemeralNotification()
 
136
            }
 
137
 
 
138
            Button {
 
139
                width: parent.width
 
140
                text: "add an icon-summary"
 
141
                onClicked: addEphemeralIconSummaryNotification()
 
142
            }
 
143
 
 
144
            Button {
 
145
                width: parent.width
 
146
                text: "add an interactive"
 
147
                onClicked: addInteractiveNotification()
 
148
            }
 
149
 
 
150
            Button {
 
151
                width: parent.width
 
152
                text: "remove 1st notification"
 
153
                onClicked: remove1stNotification()
 
154
            }
 
155
 
 
156
            Button {
 
157
                width: parent.width
 
158
                text: "clear model"
 
159
                onClicked: clearNotifications()
 
160
            }
 
161
        }
 
162
    }
 
163
 
 
164
    UnityTestCase {
 
165
        id: root
 
166
        name: "NotificationRendererTest"
 
167
        when: windowShown
 
168
 
 
169
        function test_NotificationRenderer_data() {
 
170
            return [
 
171
            {
 
172
                tag: "Snap Decision with secondary icon",
 
173
                type: "Notifications.Type.SnapDecision",
 
174
                summary: "Tom Ato",
 
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,
 
181
                bodyVisible: true,
 
182
                interactiveAreaEnabled: false,
 
183
                iconVisible: true,
 
184
                secondaryIconVisible: true,
 
185
                buttonRowVisible: true
 
186
            },
 
187
            {
 
188
                tag: "Ephemeral notification - icon-summary layout",
 
189
                type: "Notifications.Type.Ephemeral",
 
190
                summary: "Photo upload completed",
 
191
                body: "",
 
192
                icon: "",
 
193
                secondaryIcon: "../graphics/applicationIcons/facebook.png",
 
194
                actions: [],
 
195
                summaryVisible: true,
 
196
                bodyVisible: false,
 
197
                interactiveAreaEnabled: false,
 
198
                iconVisible: false,
 
199
                secondaryIconVisible: true,
 
200
                buttonRowVisible: false
 
201
            },
 
202
            {
 
203
                tag: "Ephemeral notification - check suppression of secondary icon for icon-summary layout",
 
204
                type: "Notifications.Type.Ephemeral",
 
205
                summary: "New comment successfully published",
 
206
                body: "",
 
207
                icon: "",
 
208
                secondaryIcon: "../graphics/applicationIcons/facebook.png",
 
209
                actions: [],
 
210
                summaryVisible: true,
 
211
                bodyVisible: false,
 
212
                interactiveAreaEnabled: false,
 
213
                iconVisible: false,
 
214
                secondaryIconVisible: true,
 
215
                buttonRowVisible: false
 
216
            },
 
217
            {
 
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",
 
223
                secondaryIcon: "",
 
224
                actions: [{ id: "reply_id", label: "Dummy"}],
 
225
                summaryVisible: true,
 
226
                bodyVisible: true,
 
227
                interactiveAreaEnabled: true,
 
228
                iconVisible: true,
 
229
                secondaryIconVisible: false,
 
230
                buttonRowVisible: false
 
231
            },
 
232
            {
 
233
                tag: "Snap Decision without secondary icon",
 
234
                type: "Notifications.Type.SnapDecision",
 
235
                summary: "Bro Coly",
 
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",
 
238
                secondaryIcon: "",
 
239
                actions: [{ id: "accept_id", label: "Accept"},
 
240
                          { id: "reject_id", label: "Reject"}],
 
241
                summaryVisible: true,
 
242
                bodyVisible: true,
 
243
                interactiveAreaEnabled: false,
 
244
                iconVisible: true,
 
245
                secondaryIconVisible: false,
 
246
                buttonRowVisible: true
 
247
            },
 
248
            {
 
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",
 
255
                actions: [],
 
256
                summaryVisible: true,
 
257
                bodyVisible: true,
 
258
                interactiveAreaEnabled: false,
 
259
                iconVisible: true,
 
260
                secondaryIconVisible: true,
 
261
                buttonRowVisible: false
 
262
            }
 
263
            ]
 
264
        }
 
265
 
 
266
        SignalSpy {
 
267
            id: clickThroughSpy
 
268
 
 
269
            target: clickThroughCatcher
 
270
            signalName: "clicked"
 
271
        }
 
272
 
 
273
        SignalSpy {
 
274
            id: actionSpy
 
275
            signalName: "actionInvoked"
 
276
        }
 
277
 
 
278
        function cleanup() {
 
279
            clickThroughSpy.clear()
 
280
            actionSpy.clear()
 
281
        }
 
282
 
 
283
        function test_NotificationRenderer(data) {
 
284
            // populate model with some mock notifications
 
285
            mockModel.append(data)
 
286
 
 
287
            // make sure the view is properly updated before going on
 
288
            notifications.forceLayout();
 
289
            waitForRendering(notifications);
 
290
 
 
291
            var notification = findChild(notifications, "notification" + (mockModel.count - 1))
 
292
            verify(notification !== undefined, "notification wasn't found");
 
293
 
 
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)
 
301
 
 
302
            compare(icon.visible, data.iconVisible, "avatar-icon visibility is incorrect")
 
303
            compare(interactiveArea.enabled, data.interactiveAreaEnabled, "check for interactive area")
 
304
 
 
305
            if(data.interactiveAreaEnabled) {
 
306
                actionSpy.target = notification
 
307
                mouseClick(notification, notification.width / 2, notification.height / 2)
 
308
                actionSpy.wait()
 
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")
 
311
            } else {
 
312
                mouseClick(notification, notification.width / 2, notification.height / 2)
 
313
                clickThroughSpy.wait()
 
314
            }
 
315
 
 
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")
 
320
 
 
321
            if(data.buttonRowVisible) {
 
322
                var buttonCancel = findChild(buttonRow, "button1")
 
323
                var buttonAccept = findChild(buttonRow, "button0")
 
324
 
 
325
                waitForRendering(notification)
 
326
                actionSpy.target = notification
 
327
                mouseClick(buttonCancel, buttonCancel.width / 2, buttonCancel.height / 2)
 
328
                actionSpy.wait()
 
329
                compare(actionSpy.signalArguments[0][0], data.actions[1]["id"], "got wrong id for negative action")
 
330
                actionSpy.clear()
 
331
 
 
332
                mouseClick(buttonAccept, buttonAccept.width / 2, buttonAccept.height / 2)
 
333
                actionSpy.wait()
 
334
                compare(actionSpy.signalArguments[0][0], data.actions[0]["id"], "got wrong id positive action")
 
335
            }
 
336
        }
 
337
    }
 
338
}