| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 (function() | 1 (function() |
| 2 { | 2 { |
| 3 let testRunner = null; | 3 let testRunner = null; |
| 4 let server = null; | 4 let server = null; |
| 5 let randomResult = 0.5; | 5 let randomResult = 0.5; |
| 6 | 6 |
| 7 let originalInfo; | 7 let originalInfo; |
| 8 let info = require("info"); | 8 let info = require("info"); |
| 9 | 9 |
| 10 module("Notification", | 10 module("Notification handling", |
| 11 { | 11 { |
| 12 setup: function() | 12 setup: function() |
| 13 { | 13 { |
| 14 testRunner = this; | 14 testRunner = this; |
| 15 | 15 |
| 16 preparePrefs.call(this); | 16 preparePrefs.call(this); |
| 17 setupVirtualTime.call(this, function(wrapTimer) | 17 setupVirtualTime.call(this, function(wrapTimer) |
| 18 { | 18 { |
| 19 let NotificationModule = getModuleGlobal("notification"); | 19 let NotificationModule = getModuleGlobal("notification"); |
| 20 NotificationModule.downloader._timer = wrapTimer(NotificationModule.down loader._timer); | 20 NotificationModule.downloader._timer = wrapTimer(NotificationModule.down loader._timer); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 test("No data", function() | 99 test("No data", function() |
| 100 { | 100 { |
| 101 equal(Notification.getNextToShow(), null, "null should be returned if there is no data"); | 101 equal(Notification.getNextToShow(), null, "null should be returned if there is no data"); |
| 102 }); | 102 }); |
| 103 | 103 |
| 104 test("Single notification", function() | 104 test("Single notification", function() |
| 105 { | 105 { |
| 106 let information = fixConstructors({ | 106 let information = fixConstructors({ |
| 107 id: 1, | 107 id: 1, |
| 108 severity: "information", | 108 severity: "information", |
| 109 message: {en: "Information"} | 109 message: {"en-US": "Information"} |
| 110 }); | 110 }); |
| 111 | 111 |
| 112 registerHandler([information]); | 112 registerHandler([information]); |
| 113 testRunner.runScheduledTasks(1); | 113 testRunner.runScheduledTasks(1); |
| 114 | 114 |
| 115 deepEqual(Notification.getNextToShow(), information, "The notification is sh own"); | 115 deepEqual(Notification.getNextToShow(), information, "The notification is sh own"); |
| 116 equal(Notification.getNextToShow(), null, "Informational notifications aren' t shown more than once"); | 116 equal(Notification.getNextToShow(), null, "Informational notifications aren' t shown more than once"); |
| 117 }); | 117 }); |
| 118 | 118 |
| 119 test("Information and critical", function() | 119 test("Information and critical", function() |
| 120 { | 120 { |
| 121 let information = fixConstructors({ | 121 let information = fixConstructors({ |
| 122 id: 1, | 122 id: 1, |
| 123 severity: "information", | 123 severity: "information", |
| 124 message: {en: "Information"} | 124 message: {"en-US": "Information"} |
| 125 }); | 125 }); |
| 126 let critical = fixConstructors({ | 126 let critical = fixConstructors({ |
| 127 id: 2, | 127 id: 2, |
| 128 severity: "critical", | 128 severity: "critical", |
| 129 message: {en: "Critical"} | 129 message: {"en-US": "Critical"} |
| 130 }); | 130 }); |
| 131 | 131 |
| 132 registerHandler([information, critical]); | 132 registerHandler([information, critical]); |
| 133 testRunner.runScheduledTasks(1); | 133 testRunner.runScheduledTasks(1); |
| 134 | 134 |
| 135 deepEqual(Notification.getNextToShow(), critical, "The critical notification is given priority"); | 135 deepEqual(Notification.getNextToShow(), critical, "The critical notification is given priority"); |
| 136 deepEqual(Notification.getNextToShow(), critical, "Critical notifications ca n be shown multiple times"); | 136 deepEqual(Notification.getNextToShow(), critical, "Critical notifications ca n be shown multiple times"); |
| 137 }); | 137 }); |
| 138 | 138 |
| 139 test("No severity", function() | 139 test("No severity", function() |
| 140 { | 140 { |
| 141 let information = fixConstructors({ | 141 let information = fixConstructors({ |
| 142 id: 1, | 142 id: 1, |
| 143 message: {en: "Information"} | 143 message: {"en-US": "Information"} |
| 144 }); | 144 }); |
| 145 | 145 |
| 146 registerHandler([information]); | 146 registerHandler([information]); |
| 147 testRunner.runScheduledTasks(1); | 147 testRunner.runScheduledTasks(1); |
| 148 | 148 |
| 149 deepEqual(Notification.getNextToShow(), information, "The notification is sh own"); | 149 deepEqual(Notification.getNextToShow(), information, "The notification is sh own"); |
| 150 equal(Notification.getNextToShow(), null, "Notification is treated as severi ty information"); | 150 equal(Notification.getNextToShow(), null, "Notification is treated as severi ty information"); |
| 151 }); | 151 }); |
| 152 | 152 |
| 153 test("Target selection", function() | 153 test("Target selection", function() |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 ]; | 188 ]; |
| 189 | 189 |
| 190 for each (let [propName, value, result] in targets) | 190 for each (let [propName, value, result] in targets) |
| 191 { | 191 { |
| 192 let targetInfo = {}; | 192 let targetInfo = {}; |
| 193 targetInfo[propName] = value; | 193 targetInfo[propName] = value; |
| 194 | 194 |
| 195 let information = fixConstructors({ | 195 let information = fixConstructors({ |
| 196 id: 1, | 196 id: 1, |
| 197 severity: "information", | 197 severity: "information", |
| 198 message: {en: "Information"}, | 198 message: {"en-US": "Information"}, |
| 199 targets: [targetInfo] | 199 targets: [targetInfo] |
| 200 }); | 200 }); |
| 201 | 201 |
| 202 Prefs.notificationdata = {}; | 202 Prefs.notificationdata = {}; |
| 203 registerHandler([information]); | 203 registerHandler([information]); |
| 204 testRunner.runScheduledTasks(1); | 204 testRunner.runScheduledTasks(1); |
| 205 | 205 |
| 206 let expected = (result ? information : null); | 206 let expected = (result ? information : null); |
| 207 deepEqual(Notification.getNextToShow(), expected, "Selected notification f or " + JSON.stringify(information.targets)); | 207 deepEqual(Notification.getNextToShow(), expected, "Selected notification f or " + JSON.stringify(information.targets)); |
| 208 deepEqual(Notification.getNextToShow(), null, "No notification on second c all"); | 208 deepEqual(Notification.getNextToShow(), null, "No notification on second c all"); |
| 209 } | 209 } |
| 210 | 210 |
| 211 function allPairs(array) | 211 function pairs(array) |
| 212 { | 212 { |
| 213 var pairs = []; | 213 for each (let element1 in array) |
|
Felix Dahlke
2013/07/25 10:22:04
Why not use let here and below?
Wladimir Palant
2013/07/25 10:58:07
Because that's copy&paste from your code in Chrome
| |
| 214 for (var i = 0; i < array.length - 1; i++) | 214 for each (let element2 in array) |
| 215 for (var j = i + 1; j < array.length; j++) | 215 yield [element1, element2]; |
| 216 pairs.push([array[i], array[j]]); | 216 } |
| 217 return pairs; | 217 for (let [[propName1, value1, result1], [propName2, value2, result2]] in pai rs(targets)) |
| 218 } | |
| 219 for each (let [[propName1, value1, result1], [propName2, value2, result2]] i n allPairs(targets)) | |
| 220 { | 218 { |
| 221 let targetInfo1 = {}; | 219 let targetInfo1 = {}; |
| 222 targetInfo1[propName1] = value1; | 220 targetInfo1[propName1] = value1; |
| 223 let targetInfo2 = {}; | 221 let targetInfo2 = {}; |
| 224 targetInfo2[propName2] = value2; | 222 targetInfo2[propName2] = value2; |
| 225 | 223 |
| 226 let information = fixConstructors({ | 224 let information = fixConstructors({ |
| 227 id: 1, | 225 id: 1, |
| 228 severity: "information", | 226 severity: "information", |
| 229 message: {en: "Information"}, | 227 message: {"en-US": "Information"}, |
| 230 targets: [targetInfo1, targetInfo2] | 228 targets: [targetInfo1, targetInfo2] |
| 231 }); | 229 }); |
| 232 | 230 |
| 233 Prefs.notificationdata = {}; | 231 Prefs.notificationdata = {}; |
| 234 registerHandler([information]); | 232 registerHandler([information]); |
| 235 testRunner.runScheduledTasks(1); | 233 testRunner.runScheduledTasks(1); |
| 236 | 234 |
| 237 let expected = (result1 || result2 ? information : null) | 235 let expected = (result1 || result2 ? information : null) |
| 238 deepEqual(Notification.getNextToShow(), expected, "Selected notification f or " + JSON.stringify(information.targets)); | 236 deepEqual(Notification.getNextToShow(), expected, "Selected notification f or " + JSON.stringify(information.targets)); |
| 239 deepEqual(Notification.getNextToShow(), null, "No notification on second c all"); | 237 deepEqual(Notification.getNextToShow(), null, "No notification on second c all"); |
| 240 | 238 |
| 241 information = fixConstructors({ | 239 information = fixConstructors({ |
| 242 id: 1, | 240 id: 1, |
| 243 severity: "information", | 241 severity: "information", |
| 244 message: {en: "Information"}, | 242 message: {"en-US": "Information"}, |
| 245 targets: [targetInfo1] | 243 targets: [targetInfo1] |
| 246 }); | 244 }); |
| 247 let critical = fixConstructors({ | 245 let critical = fixConstructors({ |
| 248 id: 2, | 246 id: 2, |
| 249 severity: "critical", | 247 severity: "critical", |
| 250 message: {en: "Critical"}, | 248 message: {"en-US": "Critical"}, |
| 251 targets: [targetInfo2] | 249 targets: [targetInfo2] |
| 252 }); | 250 }); |
| 253 | 251 |
| 254 Prefs.notificationdata = {}; | 252 Prefs.notificationdata = {}; |
| 255 registerHandler([information, critical]); | 253 registerHandler([information, critical]); |
| 256 testRunner.runScheduledTasks(1); | 254 testRunner.runScheduledTasks(1); |
| 257 | 255 |
| 258 expected = (result2 ? critical : (result1 ? information : null)); | 256 expected = (result2 ? critical : (result1 ? information : null)); |
| 259 deepEqual(Notification.getNextToShow(), expected, "Selected notification f or information with " + JSON.stringify(information.targets) + " and critical wit h " + JSON.stringify(critical.targets)); | 257 deepEqual(Notification.getNextToShow(), expected, "Selected notification f or information with " + JSON.stringify(information.targets) + " and critical wit h " + JSON.stringify(critical.targets)); |
| 260 } | 258 } |
| 261 }); | 259 }); |
| 260 | |
| 261 module("Notification localization"); | |
| 262 | |
| 263 test("Language only", function() | |
| 264 { | |
| 265 let notification = {message: {fr: "fr"}}; | |
| 266 let texts = Notification.getLocalizedTexts(notification, "fr"); | |
| 267 equal(texts.message, "fr"); | |
| 268 texts = Notification.getLocalizedTexts(notification, "fr-CA"); | |
| 269 equal(texts.message, "fr"); | |
| 270 }); | |
| 271 | |
| 272 test("Language and country", function() | |
| 273 { | |
| 274 let notification = {message: {fr: "fr", "fr-CA": "fr-CA"}}; | |
| 275 let texts = Notification.getLocalizedTexts(notification, "fr-CA"); | |
| 276 equal(texts.message, "fr-CA"); | |
| 277 texts = Notification.getLocalizedTexts(notification, "fr"); | |
| 278 equal(texts.message, "fr"); | |
| 279 }); | |
| 280 | |
| 281 test("Missing translation", function() | |
| 282 { | |
| 283 let notification = {message: {"en-US": "en-US"}}; | |
| 284 let texts = Notification.getLocalizedTexts(notification, "fr"); | |
| 285 equal(texts.message, "en-US"); | |
| 286 }); | |
| 262 })(); | 287 })(); |
| LEFT | RIGHT |