| 1 |
/* |
| 2 |
* Copyright 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 Lesser 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 Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser 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 TestUtil 0.1 |
| 20 |
import Lomiri.Notifications 0.1 |
| 21 |
import Lomiri.Notifications.Mocks 0.1 as Mocks |
| 22 |
|
| 23 |
Item { |
| 24 |
|
| 25 |
Mocks.MockSource { |
| 26 |
id: mockSource |
| 27 |
} |
| 28 |
|
| 29 |
Verifier { |
| 30 |
id: typeTestCase |
| 31 |
|
| 32 |
property var model: Model |
| 33 |
property var source: Source |
| 34 |
|
| 35 |
function cleanup() { |
| 36 |
clear(); |
| 37 |
Source.model = null; |
| 38 |
Model.confirmationPlaceholder = false; |
| 39 |
} |
| 40 |
|
| 41 |
function test_types_data() { |
| 42 |
return [ |
| 43 |
{ name: "Urgency", tag: "Urgency.Invalid", enum: "Invalid" }, |
| 44 |
{ name: "Urgency", tag: "Urgency.Low", enum: "Low" }, |
| 45 |
{ name: "Urgency", tag: "Urgency.Normal", enum: "Normal" }, |
| 46 |
{ name: "Urgency", tag: "Urgency.Critical", enum: "Critical" }, |
| 47 |
{ name: "Type", tag: "Type.Invalid", enum: "Invalid" }, |
| 48 |
{ name: "Type", tag: "Type.Confirmation", enum: "Confirmation" }, |
| 49 |
{ name: "Type", tag: "Type.Ephemeral", enum: "Ephemeral" }, |
| 50 |
{ name: "Type", tag: "Type.Interactive", enum: "Ephemeral" }, |
| 51 |
{ name: "Type", tag: "Type.SnapDecision", enum: "SnapDecision" }, |
| 52 |
{ name: "Type", tag: "Type.Placeholder", enum: "Placeholder" }, |
| 53 |
{ name: "Hint", tag: "Hint.Invalid", enum: "Invalid" }, |
| 54 |
{ name: "Hint", tag: "Hint.ButtonTint", enum: "ButtonTint" }, |
| 55 |
{ name: "Hint", tag: "Hint.IconOnly", enum: "IconOnly" }, |
| 56 |
{ name: "Notification", tag: "Notification" }, |
| 57 |
]; |
| 58 |
} |
| 59 |
|
| 60 |
function test_types(data) { |
| 61 |
try { |
| 62 |
object = eval(data.name); |
| 63 |
} catch(err) { |
| 64 |
object = undefined; |
| 65 |
} |
| 66 |
name = data.name; |
| 67 |
|
| 68 |
verifyData(data); |
| 69 |
} |
| 70 |
|
| 71 |
/* make sure all the required roles are exposed on the NotificationModel */ |
| 72 |
function test_model_roles_enum_data() { |
| 73 |
return [ |
| 74 |
{ enum: "RoleType" }, |
| 75 |
{ enum: "RoleUrgency" }, |
| 76 |
{ enum: "RoleId" }, |
| 77 |
{ enum: "RoleSummary" }, |
| 78 |
{ enum: "RoleBody" }, |
| 79 |
{ enum: "RoleValue" }, |
| 80 |
{ enum: "RoleIcon" }, |
| 81 |
{ enum: "RoleSecondaryIcon" }, |
| 82 |
{ enum: "RoleActions" }, |
| 83 |
{ enum: "RoleHints" }, |
| 84 |
{ enum: "RoleNotification" }, |
| 85 |
]; |
| 86 |
} |
| 87 |
|
| 88 |
function test_model_roles_enum(data) { |
| 89 |
object = model |
| 90 |
name = "Model" |
| 91 |
|
| 92 |
verifyData(data); |
| 93 |
} |
| 94 |
|
| 95 |
function test_model_data() { |
| 96 |
return [ |
| 97 |
{ tag: "Model[object]", type: "object" }, |
| 98 |
{ tag: "Model[ModelInterface]", type: "lomiri::shell::notifications::ModelInterface" }, |
| 99 |
{ tag: "Model.confirmationPlaceholder", writable: "confirmationPlaceholder", |
| 100 |
type: "boolean", value: !Model.confirmationPlaceholder } |
| 101 |
]; |
| 102 |
} |
| 103 |
|
| 104 |
function test_model(data) { |
| 105 |
object = model; |
| 106 |
name = "Model" |
| 107 |
|
| 108 |
verifyData(data); |
| 109 |
} |
| 110 |
|
| 111 |
function test_source_data() { |
| 112 |
return [ |
| 113 |
{ tag: "Source[object]", type: "object" }, |
| 114 |
{ tag: "Source[SourceInterface]", type: "lomiri::shell::notifications::SourceInterface" }, |
| 115 |
{ tag: "Source.model", writable: "model", type: "object", value: model }, |
| 116 |
]; |
| 117 |
} |
| 118 |
|
| 119 |
function test_source(data) { |
| 120 |
object = source; |
| 121 |
name = "Source" |
| 122 |
|
| 123 |
verifyData(data); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
Verifier { |
| 128 |
when: typeTestCase.completed |
| 129 |
optional: true |
| 130 |
|
| 131 |
Repeater { |
| 132 |
id: repeater |
| 133 |
delegate: Item { |
| 134 |
id: item |
| 135 |
property var roles: model |
| 136 |
property Repeater actionRepeater: actions |
| 137 |
|
| 138 |
Repeater { |
| 139 |
id: actions |
| 140 |
model: parent.roles.actions |
| 141 |
delegate: Item { |
| 142 |
property var roles: model |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
SignalSpy { |
| 149 |
id: dataSpy |
| 150 |
signalName: "dataChanged" |
| 151 |
} |
| 152 |
|
| 153 |
function initTestCase() { |
| 154 |
repeater.model = Model; |
| 155 |
dataSpy.target = Model; |
| 156 |
mockSource.model = Model; |
| 157 |
} |
| 158 |
|
| 159 |
function init() { |
| 160 |
tryCompare(repeater, "count", 0); |
| 161 |
} |
| 162 |
|
| 163 |
function cleanup() { |
| 164 |
Model.confirmationPlaceholder = false; |
| 165 |
// dismiss all Notifications |
| 166 |
for (var i = 0; i < repeater.count; i++) { |
| 167 |
repeater.itemAt(i).roles.notification.dismissed() |
| 168 |
} |
| 169 |
dataSpy.clear() |
| 170 |
tryCompare(repeater, "count", 0); |
| 171 |
} |
| 172 |
|
| 173 |
/* make sure all the required roles are exposed on Model */ |
| 174 |
function test_model_roles_data() { |
| 175 |
return [ |
| 176 |
{ tag: "Model.roles[notification]", role: "notification", type: "object" }, |
| 177 |
{ tag: "Model.roles[type]", role: "type", type: "number" }, |
| 178 |
{ tag: "Model.roles[urgency]", role: "urgency", type: "number" }, |
| 179 |
{ tag: "Model.roles[id]", role: "id", type: "number" }, |
| 180 |
{ tag: "Model.roles[summary]", role: "summary", type: "string" }, |
| 181 |
{ tag: "Model.roles[body]", role: "body", type: "string" }, |
| 182 |
{ tag: "Model.roles[value]", role: "value", type: "number" }, |
| 183 |
{ tag: "Model.roles[icon]", role: "icon", type: "object" }, |
| 184 |
{ tag: "Model.roles[secondaryIcon]", role: "secondaryIcon", type: "object" }, |
| 185 |
{ tag: "Model.roles[actions]", role: "actions", type: "object" }, |
| 186 |
{ tag: "Model.roles[hints]", role: "hints", type: "number" }, |
| 187 |
]; |
| 188 |
} |
| 189 |
|
| 190 |
function test_model_roles(data) { |
| 191 |
mockSource.send({}); |
| 192 |
tryCompare(repeater, "count", 1); |
| 193 |
|
| 194 |
try { |
| 195 |
object = repeater.itemAt(0).roles; |
| 196 |
} catch(err) { |
| 197 |
object = undefined; |
| 198 |
} |
| 199 |
name = "Model"; |
| 200 |
|
| 201 |
verifyData(data); |
| 202 |
} |
| 203 |
|
| 204 |
/* make sure all the members of Notification objects are available */ |
| 205 |
function test_notification_members_data() { |
| 206 |
return [ |
| 207 |
{ tag: "Notification.dismissed", signal: "dismissed" }, |
| 208 |
{ tag: "Notification.hovered", signal: "hovered" }, |
| 209 |
{ tag: "Notification.displayed", signal: "displayed" }, |
| 210 |
{ tag: "Notification.actionInvoked", signal: "actionInvoked" } |
| 211 |
]; |
| 212 |
} |
| 213 |
|
| 214 |
function test_notification_members(data) { |
| 215 |
mockSource.send({}); |
| 216 |
tryCompare(repeater, "count", 1); |
| 217 |
|
| 218 |
try { |
| 219 |
object = repeater.itemAt(0).roles.notification; |
| 220 |
} catch(err) { |
| 221 |
object = undefined; |
| 222 |
} |
| 223 |
name = "Notification"; |
| 224 |
|
| 225 |
verifyData(data); |
| 226 |
} |
| 227 |
|
| 228 |
/* make sure all the required roles for actions are exposed */ |
| 229 |
function test_action_members_data() { |
| 230 |
return [ |
| 231 |
{ tag: "actions.roles[label]", role: "label", type: "string" }, |
| 232 |
{ tag: "actions.roles[id]", role: "id", type: "string" } |
| 233 |
]; |
| 234 |
} |
| 235 |
|
| 236 |
function test_action_members(data) { |
| 237 |
mockSource.send({ |
| 238 |
"actions": [ |
| 239 |
{"label": "test", "id": "test"} |
| 240 |
] |
| 241 |
}); |
| 242 |
tryCompare(repeater, "count", 1); |
| 243 |
tryCompare(repeater.itemAt(0).actionRepeater, "count", 1); |
| 244 |
|
| 245 |
try { |
| 246 |
object = repeater.itemAt(0).actionRepeater.itemAt(0).roles; |
| 247 |
} catch(err) { |
| 248 |
object = undefined; |
| 249 |
} |
| 250 |
name = "actions"; |
| 251 |
|
| 252 |
verifyData(data); |
| 253 |
} |
| 254 |
|
| 255 |
/* make sure the model is empty by default */ |
| 256 |
function test_empty() { |
| 257 |
tryCompare(repeater, "count", 0); |
| 258 |
} |
| 259 |
|
| 260 |
/* make sure there is a placeholder item used as the first one when |
| 261 |
confirmationPlaceholder is true and that any additional notification is added |
| 262 |
after it */ |
| 263 |
function test_placeholder() { |
| 264 |
Model.confirmationPlaceholder = true; |
| 265 |
tryCompare(repeater, "count", 1); |
| 266 |
|
| 267 |
compare(repeater.itemAt(0).roles.type, Type.Placeholder, "the notification should be of Placeholder type"); |
| 268 |
mockSource.send({ |
| 269 |
type: Type.Ephemeral |
| 270 |
}) |
| 271 |
tryCompare(repeater, "count", 2); |
| 272 |
|
| 273 |
compare(repeater.itemAt(0).roles.type, Type.Placeholder, "the first notification should be of Placeholder type"); |
| 274 |
compare(repeater.itemAt(1).roles.type, Type.Ephemeral, "the second notification should be of Ephemeral type"); |
| 275 |
} |
| 276 |
|
| 277 |
/* make sure the placeholder item is updated with roles incoming in a Confirmation |
| 278 |
notification */ |
| 279 |
function test_confirmation() { |
| 280 |
Model.confirmationPlaceholder = true; |
| 281 |
tryCompare(repeater, "count", 1); |
| 282 |
mockSource.send({ |
| 283 |
"type": Type.Confirmation |
| 284 |
}); |
| 285 |
tryCompare(repeater, "count", 1); |
| 286 |
dataSpy.wait(); |
| 287 |
compare(repeater.count, 1, "there should be only one notification"); |
| 288 |
compare(repeater.itemAt(0).roles.type, Type.Confirmation, "the first notification should be of Confirmation type"); |
| 289 |
} |
| 290 |
} |
| 291 |
} |