├── .editorconfig ├── .gitignore ├── Procfile ├── app ├── browser │ └── bootstrap.jsx ├── common │ ├── data.js │ └── utils.js ├── component │ ├── network.jsx │ ├── predictions.jsx │ └── tube-tracker.jsx ├── server │ ├── api.js │ ├── bootstrap.jsx │ └── template.js └── view │ └── index.html ├── config.example.json ├── package.json ├── public ├── scripts │ ├── bundle.dev.js │ └── bundle.min.js └── styles │ ├── styles.css │ └── webfont.css ├── readme.md ├── server.js └── test ├── SpecRunner.html ├── lib ├── jasmine-2.0.0 │ ├── boot.js │ ├── console.js │ ├── jasmine-html.js │ ├── jasmine.css │ ├── jasmine.js │ ├── jasmine_favicon.png │ └── mock-ajax.js └── stub │ ├── component.js │ └── prediction.json └── spec ├── common └── utils.spec.js ├── component ├── network.spec.jsx ├── predictions.spec.jsx └── tube-tracker.spec.jsx └── suite.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | indent_style = space 7 | indent_size = 2 8 | trim_trailing_whitespace = true 9 | 10 | [*.md] 11 | trim_trailing_whitespace = false 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.bak 2 | *.log 3 | *.dat 4 | 5 | .DS_Store 6 | Thumbs.db 7 | 8 | .grunt 9 | .module-cache 10 | node_modules 11 | bower_components 12 | 13 | heroku 14 | heroku.pub 15 | 16 | config.json 17 | test/spec/bundle.js 18 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: NODE_ENV=production node server.js 2 | -------------------------------------------------------------------------------- /app/browser/bootstrap.jsx: -------------------------------------------------------------------------------- 1 | var React = require("react"); 2 | var networkData = require("../common/data"); 3 | var TubeTracker = require("../component/tube-tracker.jsx"); 4 | 5 | window.app = (function() { 6 | var requiredFeatures = { 7 | "JSON decoding": window.JSON, 8 | "the selectors API": document.querySelector, 9 | "ES5 array methods": Array.prototype.forEach, 10 | "DOM level 2 events": window.addEventListener, 11 | "the HTML5 history API": window.history.pushState 12 | }; 13 | 14 | for (var feature in requiredFeatures) { 15 | if (!requiredFeatures[feature]) { 16 | return alert("Sorry, but your browser does not support " + feature + " so this app won't work properly."); 17 | } 18 | } 19 | 20 | var initialData = JSON.parse(document.getElementById("initial-data").innerHTML); 21 | return React.render(, document.getElementById("app")); 22 | })(); 23 | -------------------------------------------------------------------------------- /app/common/data.js: -------------------------------------------------------------------------------- 1 | module.exports.lines = { 2 | "bakerloo": "Bakerloo", 3 | "central": "Central", 4 | "circle": "Circle", 5 | "district": "District", 6 | "hammersmith-city": "Hammersmith & City", 7 | "jubilee": "Jubilee", 8 | "metropolitan": "Metropolitan", 9 | "northern": "Northern", 10 | "piccadilly": "Piccadilly", 11 | "victoria": "Victoria", 12 | "waterloo-city": "Waterloo & City" 13 | }; 14 | 15 | module.exports.stations = { 16 | "940GZZLUBST": "Baker Street", 17 | "940GZZLUCHX": "Charing Cross", 18 | "940GZZLUEAC": "Elephant & Castle", 19 | "940GZZLUEMB": "Embankment", 20 | "940GZZLUERB": "Edgware Road (Bakerloo)", 21 | "940GZZLUHAW": "Harrow & Wealdstone", 22 | "940GZZLUHSN": "Harlesden", 23 | "940GZZLUKEN": "Kenton", 24 | "940GZZLUKPK": "Kilburn Park", 25 | "940GZZLUKSL": "Kensal Green", 26 | "940GZZLULBN": "Lambeth North", 27 | "940GZZLUMVL": "Maida Vale", 28 | "940GZZLUMYB": "Marylebone", 29 | "940GZZLUNWY": "North Wembley", 30 | "940GZZLUOXC": "Oxford Circus", 31 | "940GZZLUPAC": "Paddington", 32 | "940GZZLUPCC": "Piccadilly Circus", 33 | "940GZZLUQPS": "Queen's Park", 34 | "940GZZLURGP": "Regent's Park", 35 | "940GZZLUSGP": "Stonebridge Park", 36 | "940GZZLUSKT": "South Kenton", 37 | "940GZZLUWJN": "Willesden Junction", 38 | "940GZZLUWKA": "Warwick Avenue", 39 | "940GZZLUWLO": "Waterloo", 40 | "940GZZLUWYC": "Wembley Central", 41 | "940GZZLUADE": "Aldgate East", 42 | "940GZZLUBBB": "Bromley-by-Bow", 43 | "940GZZLUBBN": "Barbican", 44 | "940GZZLUBKG": "Barking", 45 | "940GZZLUBWR": "Bow Road", 46 | "940GZZLUEHM": "East Ham", 47 | "940GZZLUERC": "Edgware Road (Circle Line)", 48 | "940GZZLUESQ": "Euston Square", 49 | "940GZZLUFCN": "Farringdon", 50 | "940GZZLUGHK": "Goldhawk Road", 51 | "940GZZLUGPS": "Great Portland Street", 52 | "940GZZLUHSC": "Hammersmith (H&C Line)", 53 | "940GZZLUKSX": "King's Cross St. Pancras", 54 | "940GZZLULAD": "Ladbroke Grove", 55 | "940GZZLULRD": "Latimer Road", 56 | "940GZZLULVT": "Liverpool Street", 57 | "940GZZLUMED": "Mile End", 58 | "940GZZLUMGT": "Moorgate", 59 | "940GZZLUPAH": "Paddington (H&C Line)-Underground", 60 | "940GZZLUPLW": "Plaistow", 61 | "940GZZLURYO": "Royal Oak", 62 | "940GZZLUSBM": "Shepherd's Bush Market", 63 | "940GZZLUSGN": "Stepney Green", 64 | "940GZZLUUPK": "Upton Park", 65 | "940GZZLUWHM": "West Ham", 66 | "940GZZLUWLA": "Wood Lane", 67 | "940GZZLUWPL": "Whitechapel", 68 | "940GZZLUWSP": "Westbourne Park", 69 | "940GZZLUBMY": "Bermondsey", 70 | "940GZZLUBND": "Bond Street", 71 | "940GZZLUCGT": "Canning Town", 72 | "940GZZLUCPK": "Canons Park", 73 | "940GZZLUCWR": "Canada Water", 74 | "940GZZLUCYF": "Canary Wharf", 75 | "940GZZLUDOH": "Dollis Hill", 76 | "940GZZLUFYR": "Finchley Road", 77 | "940GZZLUGPK": "Green Park", 78 | "940GZZLUKBN": "Kilburn", 79 | "940GZZLUKBY": "Kingsbury", 80 | "940GZZLULNB": "London Bridge", 81 | "940GZZLUNDN": "Neasden", 82 | "940GZZLUNGW": "North Greenwich", 83 | "940GZZLUQBY": "Queensbury", 84 | "940GZZLUSJW": "St. John's Wood", 85 | "940GZZLUSTD": "Stratford", 86 | "940GZZLUSTM": "Stanmore", 87 | "940GZZLUSWC": "Swiss Cottage", 88 | "940GZZLUSWK": "Southwark", 89 | "940GZZLUWHP": "West Hampstead", 90 | "940GZZLUWIG": "Willesden Green", 91 | "940GZZLUWSM": "Westminster", 92 | "940GZZLUWYP": "Wembley Park", 93 | "940GZZLUBKE": "Barkingside", 94 | "940GZZLUBKH": "Buckhurst Hill", 95 | "940GZZLUBLG": "Bethnal Green", 96 | "940GZZLUBNK": "Bank", 97 | "940GZZLUCHL": "Chancery Lane", 98 | "940GZZLUCWL": "Chigwell", 99 | "940GZZLUDBN": "Debden", 100 | "940GZZLUEAN": "East Acton", 101 | "940GZZLUEBY": "Ealing Broadway", 102 | "940GZZLUEPG": "Epping", 103 | "940GZZLUFLP": "Fairlop", 104 | "940GZZLUGFD": "Greenford", 105 | "940GZZLUGGH": "Grange Hill", 106 | "940GZZLUGTH": "Gants Hill", 107 | "940GZZLUHBN": "Holborn", 108 | "940GZZLUHGR": "Hanger Lane", 109 | "940GZZLUHLT": "Hainault", 110 | "940GZZLUHPK": "Holland Park", 111 | "940GZZLULGN": "Loughton", 112 | "940GZZLULGT": "Lancaster Gate", 113 | "940GZZLULYN": "Leyton", 114 | "940GZZLULYS": "Leytonstone", 115 | "940GZZLUMBA": "Marble Arch", 116 | "940GZZLUNAN": "North Acton", 117 | "940GZZLUNBP": "Newbury Park", 118 | "940GZZLUNHG": "Notting Hill Gate", 119 | "940GZZLUNHT": "Northolt", 120 | "940GZZLUPVL": "Perivale", 121 | "940GZZLUQWY": "Queensway", 122 | "940GZZLURBG": "Redbridge", 123 | "940GZZLURSG": "Ruislip Gardens", 124 | "940GZZLURVY": "Roding Valley", 125 | "940GZZLUSBC": "Shepherd's Bush (Central)", 126 | "940GZZLUSNB": "Snaresbrook", 127 | "940GZZLUSPU": "St. Paul's", 128 | "940GZZLUSRP": "South Ruislip", 129 | "940GZZLUSWF": "South Woodford", 130 | "940GZZLUTCR": "Tottenham Court Road", 131 | "940GZZLUTHB": "Theydon Bois", 132 | "940GZZLUWCY": "White City", 133 | "940GZZLUWOF": "Woodford", 134 | "940GZZLUWRP": "West Ruislip", 135 | "940GZZLUWSD": "Wanstead", 136 | "940GZZLUWTA": "West Acton", 137 | "940GZZLUALD": "Aldgate", 138 | "940GZZLUBKF": "Blackfriars", 139 | "940GZZLUBWT": "Bayswater", 140 | "940GZZLUCST": "Cannon Street", 141 | "940GZZLUECT": "Earl's Court", 142 | "940GZZLUGTR": "Gloucester Road", 143 | "940GZZLUHSK": "High Street Kensington", 144 | "940GZZLUMMT": "Monument", 145 | "940GZZLUMSH": "Mansion House", 146 | "940GZZLUSJP": "St. James's Park", 147 | "940GZZLUSKS": "South Kensington", 148 | "940GZZLUSSQ": "Sloane Square", 149 | "940GZZLUTMP": "Temple", 150 | "940GZZLUTWH": "Tower Hill", 151 | "940GZZLUVIC": "Victoria", 152 | "940GZZLUACT": "Acton Town", 153 | "940GZZLUBEC": "Becontree", 154 | "940GZZLUBSC": "Barons Court", 155 | "940GZZLUCWP": "Chiswick Park", 156 | "940GZZLUDGE": "Dagenham East", 157 | "940GZZLUDGY": "Dagenham Heathway", 158 | "940GZZLUECM": "Ealing Common", 159 | "940GZZLUEPK": "Elm Park", 160 | "940GZZLUEPY": "East Putney", 161 | "940GZZLUFBY": "Fulham Broadway", 162 | "940GZZLUGBY": "Gunnersbury", 163 | "940GZZLUHCH": "Hornchurch", 164 | "940GZZLUHSD": "Hammersmith (Dist&Picc Line)", 165 | "940GZZLUKOY": "Kensington (Olympia)", 166 | "940GZZLUKWG": "Kew Gardens", 167 | "940GZZLUPSG": "Parsons Green", 168 | "940GZZLUPYB": "Putney Bridge", 169 | "940GZZLURMD": "Richmond", 170 | "940GZZLURVP": "Ravenscourt Park", 171 | "940GZZLUSFB": "Stamford Brook", 172 | "940GZZLUSFS": "Southfields", 173 | "940GZZLUTNG": "Turnham Green", 174 | "940GZZLUUPB": "Upminster Bridge", 175 | "940GZZLUUPM": "Upminster", 176 | "940GZZLUUPY": "Upney", 177 | "940GZZLUWBN": "West Brompton", 178 | "940GZZLUWIM": "Wimbledon", 179 | "940GZZLUWIP": "Wimbledon Park", 180 | "940GZZLUWKN": "West Kensington", 181 | "940GZZLUAMS": "Amersham", 182 | "940GZZLUCAL": "Chalfont & Latimer", 183 | "940GZZLUCSM": "Chesham", 184 | "940GZZLUCXY": "Croxley", 185 | "940GZZLUCYD": "Chorleywood", 186 | "940GZZLUEAE": "Eastcote", 187 | "940GZZLUHGD": "Hillingdon", 188 | "940GZZLUHOH": "Harrow-on-the-Hill", 189 | "940GZZLUICK": "Ickenham", 190 | "940GZZLUMPK": "Moor Park", 191 | "940GZZLUNHA": "North Harrow", 192 | "940GZZLUNKP": "Northwick Park", 193 | "940GZZLUNOW": "Northwood", 194 | "940GZZLUNWH": "Northwood Hills", 195 | "940GZZLUPNR": "Pinner", 196 | "940GZZLUPRD": "Preston Road", 197 | "940GZZLURKW": "Rickmansworth", 198 | "940GZZLURSM": "Ruislip Manor", 199 | "940GZZLURSP": "Ruislip", 200 | "940GZZLURYL": "Rayners Lane", 201 | "940GZZLUUXB": "Uxbridge", 202 | "940GZZLUWAF": "Watford", 203 | "940GZZLUWHW": "West Harrow", 204 | "940GZZLUBLR": "Blackhorse Road", 205 | "940GZZLUBXN": "Brixton", 206 | "940GZZLUEUS": "Euston", 207 | "940GZZLUFPK": "Finsbury Park", 208 | "940GZZLUHAI": "Highbury & Islington", 209 | "940GZZLUPCO": "Pimlico", 210 | "940GZZLUSKW": "Stockwell", 211 | "940GZZLUSVS": "Seven Sisters", 212 | "940GZZLUTMH": "Tottenham Hale", 213 | "940GZZLUVXL": "Vauxhall", 214 | "940GZZLUWRR": "Warren Street", 215 | "940GZZLUWWL": "Walthamstow Central", 216 | "940GZZLUACY": "Archway", 217 | "940GZZLUAGL": "Angel", 218 | "940GZZLUBLM": "Balham", 219 | "940GZZLUBOR": "Borough", 220 | "940GZZLUBTK": "Burnt Oak", 221 | "940GZZLUBTX": "Brent Cross", 222 | "940GZZLUBZP": "Belsize Park", 223 | "940GZZLUCFM": "Chalk Farm", 224 | "940GZZLUCND": "Colindale", 225 | "940GZZLUCPC": "Clapham Common", 226 | "940GZZLUCPN": "Clapham North", 227 | "940GZZLUCPS": "Clapham South", 228 | "940GZZLUCSD": "Colliers Wood", 229 | "940GZZLUCTN": "Camden Town", 230 | "940GZZLUEFY": "East Finchley", 231 | "940GZZLUEGW": "Edgware", 232 | "940GZZLUFYC": "Finchley Central", 233 | "940GZZLUGDG": "Goodge Street", 234 | "940GZZLUGGN": "Golders Green", 235 | "940GZZLUHBT": "High Barnet", 236 | "940GZZLUHCL": "Hendon Central", 237 | "940GZZLUHGT": "Highgate", 238 | "940GZZLUHTD": "Hampstead", 239 | "940GZZLUKNG": "Kennington", 240 | "940GZZLUKSH": "Kentish Town", 241 | "940GZZLULSQ": "Leicester Square", 242 | "940GZZLUMDN": "Morden", 243 | "940GZZLUMHL": "Mill Hill East", 244 | "940GZZLUMTC": "Mornington Crescent", 245 | "940GZZLUODS": "Old Street", 246 | "940GZZLUOVL": "Oval", 247 | "940GZZLUSWN": "South Wimbledon", 248 | "940GZZLUTAW": "Totteridge & Whetstone", 249 | "940GZZLUTBC": "Tooting Bec", 250 | "940GZZLUTBY": "Tooting Broadway", 251 | "940GZZLUTFP": "Tufnell Park", 252 | "940GZZLUWFN": "West Finchley", 253 | "940GZZLUWOP": "Woodside Park", 254 | "910GENFCOAK": "Oakwood Station", 255 | "940GZZLUALP": "Alperton", 256 | "940GZZLUASG": "Arnos Grove", 257 | "940GZZLUASL": "Arsenal", 258 | "940GZZLUBDS": "Bounds Green", 259 | "940GZZLUBOS": "Boston Manor", 260 | "940GZZLUCAR": "Caledonian Road", 261 | "940GZZLUCGN": "Covent Garden", 262 | "940GZZLUCKS": "Cockfosters", 263 | "940GZZLUHNX": "Hatton Cross", 264 | "940GZZLUHPC": "Hyde Park Corner", 265 | "940GZZLUHR4": "Heathrow Terminal 4", 266 | "940GZZLUHR5": "Heathrow Terminal 5", 267 | "940GZZLUHRC": "Heathrow Terminals 1-2-3 ", 268 | "940GZZLUHWC": "Hounslow Central", 269 | "940GZZLUHWE": "Hounslow East", 270 | "940GZZLUHWT": "Hounslow West", 271 | "940GZZLUHWY": "Holloway Road", 272 | "940GZZLUKNB": "Knightsbridge", 273 | "940GZZLUMRH": "Manor House", 274 | "940GZZLUNEN": "North Ealing", 275 | "940GZZLUNFD": "Northfields", 276 | "940GZZLUOAK": "Oakwood", 277 | "940GZZLUOSY": "Osterley", 278 | "940GZZLUPKR": "Park Royal", 279 | "940GZZLURSQ": "Russell Square", 280 | "940GZZLUSEA": "South Ealing", 281 | "940GZZLUSGT": "Southgate", 282 | "940GZZLUSHH": "South Harrow", 283 | "940GZZLUSUH": "Sudbury Hill", 284 | "940GZZLUSUT": "Sudbury Town", 285 | "940GZZLUTPN": "Turnpike Lane", 286 | "940GZZLUWOG": "Wood Green" 287 | }; 288 | 289 | module.exports.stationsOnLines = { 290 | "bakerloo": [ 291 | "940GZZLUBST", 292 | "940GZZLUCHX", 293 | "940GZZLUEAC", 294 | "940GZZLUEMB", 295 | "940GZZLUERB", 296 | "940GZZLUHAW", 297 | "940GZZLUHSN", 298 | "940GZZLUKEN", 299 | "940GZZLUKPK", 300 | "940GZZLUKSL", 301 | "940GZZLULBN", 302 | "940GZZLUMVL", 303 | "940GZZLUMYB", 304 | "940GZZLUNWY", 305 | "940GZZLUOXC", 306 | "940GZZLUPAC", 307 | "940GZZLUPCC", 308 | "940GZZLUQPS", 309 | "940GZZLURGP", 310 | "940GZZLUSGP", 311 | "940GZZLUSKT", 312 | "940GZZLUWJN", 313 | "940GZZLUWKA", 314 | "940GZZLUWLO", 315 | "940GZZLUWYC" 316 | ], 317 | "central": [ 318 | "940GZZLUBKE", 319 | "940GZZLUBKH", 320 | "940GZZLUBLG", 321 | "940GZZLUBND", 322 | "940GZZLUBNK", 323 | "940GZZLUCHL", 324 | "940GZZLUCWL", 325 | "940GZZLUDBN", 326 | "940GZZLUEAN", 327 | "940GZZLUEBY", 328 | "940GZZLUEPG", 329 | "940GZZLUFLP", 330 | "940GZZLUGFD", 331 | "940GZZLUGGH", 332 | "940GZZLUGTH", 333 | "940GZZLUHBN", 334 | "940GZZLUHGR", 335 | "940GZZLUHLT", 336 | "940GZZLUHPK", 337 | "940GZZLULGN", 338 | "940GZZLULGT", 339 | "940GZZLULVT", 340 | "940GZZLULYN", 341 | "940GZZLULYS", 342 | "940GZZLUMBA", 343 | "940GZZLUMED", 344 | "940GZZLUNAN", 345 | "940GZZLUNBP", 346 | "940GZZLUNHG", 347 | "940GZZLUNHT", 348 | "940GZZLUOXC", 349 | "940GZZLUPVL", 350 | "940GZZLUQWY", 351 | "940GZZLURBG", 352 | "940GZZLURSG", 353 | "940GZZLURVY", 354 | "940GZZLUSBC", 355 | "940GZZLUSNB", 356 | "940GZZLUSPU", 357 | "940GZZLUSRP", 358 | "940GZZLUSTD", 359 | "940GZZLUSWF", 360 | "940GZZLUTCR", 361 | "940GZZLUTHB", 362 | "940GZZLUWCY", 363 | "940GZZLUWOF", 364 | "940GZZLUWRP", 365 | "940GZZLUWSD", 366 | "940GZZLUWTA" 367 | ], 368 | "circle": [ 369 | "940GZZLUALD", 370 | "940GZZLUBBN", 371 | "940GZZLUBKF", 372 | "940GZZLUBST", 373 | "940GZZLUBWT", 374 | "940GZZLUCST", 375 | "940GZZLUEMB", 376 | "940GZZLUERC", 377 | "940GZZLUESQ", 378 | "940GZZLUFCN", 379 | "940GZZLUGHK", 380 | "940GZZLUGPS", 381 | "940GZZLUGTR", 382 | "940GZZLUHSC", 383 | "940GZZLUHSK", 384 | "940GZZLUKSX", 385 | "940GZZLULAD", 386 | "940GZZLULRD", 387 | "940GZZLULVT", 388 | "940GZZLUMGT", 389 | "940GZZLUMMT", 390 | "940GZZLUMSH", 391 | "940GZZLUNHG", 392 | "940GZZLUPAC", 393 | "940GZZLUPAH", 394 | "940GZZLURYO", 395 | "940GZZLUSBM", 396 | "940GZZLUSJP", 397 | "940GZZLUSKS", 398 | "940GZZLUSSQ", 399 | "940GZZLUTMP", 400 | "940GZZLUTWH", 401 | "940GZZLUVIC", 402 | "940GZZLUWLA", 403 | "940GZZLUWSM", 404 | "940GZZLUWSP" 405 | ], 406 | "district": [ 407 | "940GZZLUACT", 408 | "940GZZLUADE", 409 | "940GZZLUBBB", 410 | "940GZZLUBEC", 411 | "940GZZLUBKF", 412 | "940GZZLUBKG", 413 | "940GZZLUBSC", 414 | "940GZZLUBWR", 415 | "940GZZLUBWT", 416 | "940GZZLUCST", 417 | "940GZZLUCWP", 418 | "940GZZLUDGE", 419 | "940GZZLUDGY", 420 | "940GZZLUEBY", 421 | "940GZZLUECM", 422 | "940GZZLUECT", 423 | "940GZZLUEHM", 424 | "940GZZLUEMB", 425 | "940GZZLUEPK", 426 | "940GZZLUEPY", 427 | "940GZZLUERC", 428 | "940GZZLUFBY", 429 | "940GZZLUGBY", 430 | "940GZZLUGHK", 431 | "940GZZLUGTR", 432 | "940GZZLUHCH", 433 | "940GZZLUHSC", 434 | "940GZZLUHSD", 435 | "940GZZLUHSK", 436 | "940GZZLUKOY", 437 | "940GZZLUKWG", 438 | "940GZZLULAD", 439 | "940GZZLULRD", 440 | "940GZZLUMED", 441 | "940GZZLUMMT", 442 | "940GZZLUMSH", 443 | "940GZZLUNHG", 444 | "940GZZLUPAC", 445 | "940GZZLUPAH", 446 | "940GZZLUPLW", 447 | "940GZZLUPSG", 448 | "940GZZLUPYB", 449 | "940GZZLURMD", 450 | "940GZZLURVP", 451 | "940GZZLURYO", 452 | "940GZZLUSBM", 453 | "940GZZLUSFB", 454 | "940GZZLUSFS", 455 | "940GZZLUSGN", 456 | "940GZZLUSJP", 457 | "940GZZLUSKS", 458 | "940GZZLUSSQ", 459 | "940GZZLUTMP", 460 | "940GZZLUTNG", 461 | "940GZZLUTWH", 462 | "940GZZLUUPB", 463 | "940GZZLUUPK", 464 | "940GZZLUUPM", 465 | "940GZZLUUPY", 466 | "940GZZLUVIC", 467 | "940GZZLUWBN", 468 | "940GZZLUWHM", 469 | "940GZZLUWIM", 470 | "940GZZLUWIP", 471 | "940GZZLUWKN", 472 | "940GZZLUWLA", 473 | "940GZZLUWPL", 474 | "940GZZLUWSM", 475 | "940GZZLUWSP" 476 | ], 477 | "hammersmith-city": [ 478 | "940GZZLUADE", 479 | "940GZZLUBBB", 480 | "940GZZLUBBN", 481 | "940GZZLUBKG", 482 | "940GZZLUBST", 483 | "940GZZLUBWR", 484 | "940GZZLUEHM", 485 | "940GZZLUERC", 486 | "940GZZLUESQ", 487 | "940GZZLUFCN", 488 | "940GZZLUGHK", 489 | "940GZZLUGPS", 490 | "940GZZLUHSC", 491 | "940GZZLUKSX", 492 | "940GZZLULAD", 493 | "940GZZLULRD", 494 | "940GZZLULVT", 495 | "940GZZLUMED", 496 | "940GZZLUMGT", 497 | "940GZZLUPAH", 498 | "940GZZLUPLW", 499 | "940GZZLURYO", 500 | "940GZZLUSBM", 501 | "940GZZLUSGN", 502 | "940GZZLUUPK", 503 | "940GZZLUWHM", 504 | "940GZZLUWLA", 505 | "940GZZLUWPL", 506 | "940GZZLUWSP" 507 | ], 508 | "jubilee": [ 509 | "940GZZLUBMY", 510 | "940GZZLUBND", 511 | "940GZZLUBST", 512 | "940GZZLUCGT", 513 | "940GZZLUCPK", 514 | "940GZZLUCWR", 515 | "940GZZLUCYF", 516 | "940GZZLUDOH", 517 | "940GZZLUFYR", 518 | "940GZZLUGPK", 519 | "940GZZLUKBN", 520 | "940GZZLUKBY", 521 | "940GZZLULNB", 522 | "940GZZLUNDN", 523 | "940GZZLUNGW", 524 | "940GZZLUQBY", 525 | "940GZZLUSJW", 526 | "940GZZLUSTD", 527 | "940GZZLUSTM", 528 | "940GZZLUSWC", 529 | "940GZZLUSWK", 530 | "940GZZLUWHM", 531 | "940GZZLUWHP", 532 | "940GZZLUWIG", 533 | "940GZZLUWLO", 534 | "940GZZLUWSM", 535 | "940GZZLUWYP" 536 | ], 537 | "metropolitan": [ 538 | "940GZZLUALD", 539 | "940GZZLUAMS", 540 | "940GZZLUBBN", 541 | "940GZZLUBST", 542 | "940GZZLUCAL", 543 | "940GZZLUCSM", 544 | "940GZZLUCXY", 545 | "940GZZLUCYD", 546 | "940GZZLUEAE", 547 | "940GZZLUESQ", 548 | "940GZZLUFCN", 549 | "940GZZLUFYR", 550 | "940GZZLUGPS", 551 | "940GZZLUHGD", 552 | "940GZZLUHOH", 553 | "940GZZLUICK", 554 | "940GZZLUKSX", 555 | "940GZZLULVT", 556 | "940GZZLUMGT", 557 | "940GZZLUMPK", 558 | "940GZZLUNHA", 559 | "940GZZLUNKP", 560 | "940GZZLUNOW", 561 | "940GZZLUNWH", 562 | "940GZZLUPNR", 563 | "940GZZLUPRD", 564 | "940GZZLURKW", 565 | "940GZZLURSM", 566 | "940GZZLURSP", 567 | "940GZZLURYL", 568 | "940GZZLUUXB", 569 | "940GZZLUWAF", 570 | "940GZZLUWHW", 571 | "940GZZLUWYP" 572 | ], 573 | "northern": [ 574 | "940GZZLUACY", 575 | "940GZZLUAGL", 576 | "940GZZLUBLM", 577 | "940GZZLUBNK", 578 | "940GZZLUBOR", 579 | "940GZZLUBTK", 580 | "940GZZLUBTX", 581 | "940GZZLUBZP", 582 | "940GZZLUCFM", 583 | "940GZZLUCHX", 584 | "940GZZLUCND", 585 | "940GZZLUCPC", 586 | "940GZZLUCPN", 587 | "940GZZLUCPS", 588 | "940GZZLUCSD", 589 | "940GZZLUCTN", 590 | "940GZZLUEAC", 591 | "940GZZLUEFY", 592 | "940GZZLUEGW", 593 | "940GZZLUEMB", 594 | "940GZZLUEUS", 595 | "940GZZLUFYC", 596 | "940GZZLUGDG", 597 | "940GZZLUGGN", 598 | "940GZZLUHBT", 599 | "940GZZLUHCL", 600 | "940GZZLUHGT", 601 | "940GZZLUHTD", 602 | "940GZZLUKNG", 603 | "940GZZLUKSH", 604 | "940GZZLUKSX", 605 | "940GZZLULNB", 606 | "940GZZLULSQ", 607 | "940GZZLUMDN", 608 | "940GZZLUMGT", 609 | "940GZZLUMHL", 610 | "940GZZLUMTC", 611 | "940GZZLUODS", 612 | "940GZZLUOVL", 613 | "940GZZLUSKW", 614 | "940GZZLUSWN", 615 | "940GZZLUTAW", 616 | "940GZZLUTBC", 617 | "940GZZLUTBY", 618 | "940GZZLUTCR", 619 | "940GZZLUTFP", 620 | "940GZZLUWFN", 621 | "940GZZLUWLO", 622 | "940GZZLUWOP", 623 | "940GZZLUWRR" 624 | ], 625 | "piccadilly": [ 626 | "910GENFCOAK", 627 | "940GZZLUACT", 628 | "940GZZLUALP", 629 | "940GZZLUASG", 630 | "940GZZLUASL", 631 | "940GZZLUBDS", 632 | "940GZZLUBOS", 633 | "940GZZLUBSC", 634 | "940GZZLUCAR", 635 | "940GZZLUCGN", 636 | "940GZZLUCKS", 637 | "940GZZLUCWP", 638 | "940GZZLUEAE", 639 | "940GZZLUECM", 640 | "940GZZLUECT", 641 | "940GZZLUFPK", 642 | "940GZZLUGPK", 643 | "940GZZLUGTR", 644 | "940GZZLUHBN", 645 | "940GZZLUHGD", 646 | "940GZZLUHNX", 647 | "940GZZLUHPC", 648 | "940GZZLUHR4", 649 | "940GZZLUHR5", 650 | "940GZZLUHRC", 651 | "940GZZLUHSD", 652 | "940GZZLUHWC", 653 | "940GZZLUHWE", 654 | "940GZZLUHWT", 655 | "940GZZLUHWY", 656 | "940GZZLUICK", 657 | "940GZZLUKNB", 658 | "940GZZLUKSX", 659 | "940GZZLULSQ", 660 | "940GZZLUMRH", 661 | "940GZZLUNEN", 662 | "940GZZLUNFD", 663 | "940GZZLUOAK", 664 | "940GZZLUOSY", 665 | "940GZZLUPCC", 666 | "940GZZLUPKR", 667 | "940GZZLURSM", 668 | "940GZZLURSP", 669 | "940GZZLURSQ", 670 | "940GZZLURVP", 671 | "940GZZLURYL", 672 | "940GZZLUSEA", 673 | "940GZZLUSFB", 674 | "940GZZLUSGT", 675 | "940GZZLUSHH", 676 | "940GZZLUSKS", 677 | "940GZZLUSUH", 678 | "940GZZLUSUT", 679 | "940GZZLUTNG", 680 | "940GZZLUTPN", 681 | "940GZZLUUXB", 682 | "940GZZLUWOG" 683 | ], 684 | "victoria": [ 685 | "940GZZLUBLR", 686 | "940GZZLUBXN", 687 | "940GZZLUEUS", 688 | "940GZZLUFPK", 689 | "940GZZLUGPK", 690 | "940GZZLUHAI", 691 | "940GZZLUKSX", 692 | "940GZZLUOXC", 693 | "940GZZLUPCO", 694 | "940GZZLUSKW", 695 | "940GZZLUSVS", 696 | "940GZZLUTMH", 697 | "940GZZLUVIC", 698 | "940GZZLUVXL", 699 | "940GZZLUWRR", 700 | "940GZZLUWWL" 701 | ], 702 | "waterloo-city": [ 703 | "940GZZLUBNK", 704 | "940GZZLUWLO" 705 | ] 706 | }; 707 | 708 | module.exports.sharedPlatforms = { 709 | "940GZZLUEMB": [ 710 | [ 711 | "circle", 712 | "district" 713 | ] 714 | ], 715 | "940GZZLUADE": [ 716 | [ 717 | "district", 718 | "hammersmith-city" 719 | ] 720 | ], 721 | "940GZZLUBBB": [ 722 | [ 723 | "district", 724 | "hammersmith-city" 725 | ] 726 | ], 727 | "940GZZLUBBN": [ 728 | [ 729 | "circle", 730 | "hammersmith-city", 731 | "metropolitan" 732 | ] 733 | ], 734 | "940GZZLUBWR": [ 735 | [ 736 | "district", 737 | "hammersmith-city" 738 | ] 739 | ], 740 | "940GZZLUEHM": [ 741 | [ 742 | "district", 743 | "hammersmith-city" 744 | ] 745 | ], 746 | "940GZZLUERC": [ 747 | [ 748 | "circle", 749 | "hammersmith-city" 750 | ], 751 | [ 752 | "circle", 753 | "district" 754 | ] 755 | ], 756 | "940GZZLUESQ": [ 757 | [ 758 | "circle", 759 | "hammersmith-city", 760 | "metropolitan" 761 | ] 762 | ], 763 | "940GZZLUGHK": [ 764 | [ 765 | "circle", 766 | "hammersmith-city" 767 | ] 768 | ], 769 | "940GZZLUGPS": [ 770 | [ 771 | "circle", 772 | "hammersmith-city", 773 | "metropolitan" 774 | ] 775 | ], 776 | "940GZZLULAD": [ 777 | [ 778 | "circle", 779 | "hammersmith-city" 780 | ] 781 | ], 782 | "940GZZLULRD": [ 783 | [ 784 | "circle", 785 | "hammersmith-city" 786 | ] 787 | ], 788 | "940GZZLUPLW": [ 789 | [ 790 | "district", 791 | "hammersmith-city" 792 | ] 793 | ], 794 | "940GZZLUMED": [ 795 | [ 796 | "district", 797 | "hammersmith-city" 798 | ] 799 | ], 800 | "940GZZLURYO": [ 801 | [ 802 | "circle", 803 | "hammersmith-city" 804 | ] 805 | ], 806 | "940GZZLUSBM": [ 807 | [ 808 | "circle", 809 | "hammersmith-city" 810 | ] 811 | ], 812 | "940GZZLUWLA": [ 813 | [ 814 | "circle", 815 | "hammersmith-city" 816 | ] 817 | ], 818 | "940GZZLUSGN": [ 819 | [ 820 | "district", 821 | "hammersmith-city" 822 | ] 823 | ], 824 | "940GZZLUUPK": [ 825 | [ 826 | "district", 827 | "hammersmith-city" 828 | ] 829 | ], 830 | "940GZZLUWSP": [ 831 | [ 832 | "circle", 833 | "hammersmith-city" 834 | ] 835 | ], 836 | "940GZZLUEAE": [ 837 | [ 838 | "metropolitan", 839 | "piccadilly" 840 | ] 841 | ], 842 | "940GZZLUHGD": [ 843 | [ 844 | "metropolitan", 845 | "piccadilly" 846 | ] 847 | ], 848 | "940GZZLUICK": [ 849 | [ 850 | "metropolitan", 851 | "piccadilly" 852 | ] 853 | ], 854 | "940GZZLURSM": [ 855 | [ 856 | "metropolitan", 857 | "piccadilly" 858 | ] 859 | ], 860 | "940GZZLURYL": [ 861 | [ 862 | "metropolitan", 863 | "piccadilly" 864 | ] 865 | ], 866 | "940GZZLURSP": [ 867 | [ 868 | "metropolitan", 869 | "piccadilly" 870 | ] 871 | ], 872 | "940GZZLUBST": [ 873 | [ 874 | "circle", 875 | "hammersmith-city" 876 | ] 877 | ], 878 | "940GZZLUUXB": [ 879 | [ 880 | "metropolitan", 881 | "piccadilly" 882 | ] 883 | ], 884 | "940GZZLUBWT": [ 885 | [ 886 | "circle", 887 | "district" 888 | ] 889 | ], 890 | "940GZZLUGTR": [ 891 | [ 892 | "circle", 893 | "district" 894 | ] 895 | ], 896 | "940GZZLUHSK": [ 897 | [ 898 | "circle", 899 | "district" 900 | ] 901 | ], 902 | "940GZZLUMMT": [ 903 | [ 904 | "circle", 905 | "district" 906 | ] 907 | ], 908 | "940GZZLUSJP": [ 909 | [ 910 | "circle", 911 | "district" 912 | ] 913 | ], 914 | "940GZZLUMSH": [ 915 | [ 916 | "circle", 917 | "district" 918 | ] 919 | ], 920 | "940GZZLUNHG": [ 921 | [ 922 | "circle", 923 | "district" 924 | ] 925 | ], 926 | "940GZZLUSKS": [ 927 | [ 928 | "circle", 929 | "district" 930 | ] 931 | ], 932 | "940GZZLUTMP": [ 933 | [ 934 | "circle", 935 | "district" 936 | ] 937 | ], 938 | "940GZZLUSSQ": [ 939 | [ 940 | "circle", 941 | "district" 942 | ] 943 | ], 944 | "940GZZLUECM": [ 945 | [ 946 | "district", 947 | "piccadilly" 948 | ] 949 | ], 950 | "940GZZLUTNG": [ 951 | [ 952 | "district", 953 | "piccadilly" 954 | ] 955 | ] 956 | }; 957 | -------------------------------------------------------------------------------- /app/common/utils.js: -------------------------------------------------------------------------------- 1 | module.exports.debounceEvent = function(callback, wait) { 2 | var timeout; 3 | 4 | return function() { 5 | clearTimeout(timeout); 6 | timeout = setTimeout(callback, wait); 7 | }; 8 | }; 9 | 10 | module.exports.httpRequest = function(url, success, error) { 11 | var request = new XMLHttpRequest; 12 | 13 | request.open("GET", url); 14 | 15 | request.onload = function() { 16 | if (this.status === 200) { 17 | success(this.responseText); 18 | } 19 | else { 20 | error(new Error(this.status)); 21 | } 22 | }; 23 | 24 | request.onerror = function() { 25 | error(new Error(this.status)); 26 | }; 27 | 28 | request.send(); 29 | }; 30 | 31 | module.exports.apiRequestURL = function(line, station) { 32 | return "/api/" + line + "/" + station; 33 | }; 34 | 35 | module.exports.formattedTimeUntil = function(timeTo) { 36 | var minutes = Math.round(timeTo / 60); 37 | var seconds = Math.round((timeTo - (minutes * 60)) / 30) * 30; 38 | return "" + minutes + ":" + (seconds < 10 ? "0" : "") + (seconds > 0 ? seconds : "0"); 39 | }; 40 | 41 | module.exports.getQueryString = function() { 42 | return window.location.search; 43 | }; 44 | 45 | module.exports.formatQueryString = function(properties) { 46 | var property; 47 | var queryString = []; 48 | 49 | for (property in properties) { 50 | if (properties.hasOwnProperty(property)) { 51 | queryString.push("" + property + "=" + properties[property]); 52 | } 53 | } 54 | 55 | return "?" + queryString.join("&"); 56 | }; 57 | 58 | module.exports.queryStringProperty = function(queryString, prop) { 59 | var pairs = queryString.replace(/^\?/, "").replace(/\/$/, "").split("&"); 60 | var properties = {}; 61 | 62 | pairs.forEach(function(pair) { 63 | pair = pair.split("="); 64 | properties[ pair[0] ] = pair[1]; 65 | }); 66 | 67 | return properties[prop]; 68 | }; 69 | 70 | module.exports.isLine = function(line, data) { 71 | return line in data.lines; 72 | }; 73 | 74 | module.exports.isStation = function(station, data) { 75 | return station in data.stations; 76 | }; 77 | 78 | module.exports.isStationOnLine = function(line, station, data) { 79 | return this.isLine(line, data) && this.isStation(station, data) && 80 | data.stationsOnLines[line].indexOf(station) >= 0; 81 | }; 82 | 83 | module.exports.mergeGroupedLines = function(station, line, data) { 84 | var lines = [line]; 85 | 86 | if (station in data.sharedPlatforms) { 87 | var lineGroups = data.sharedPlatforms[station].filter(function(lineGroup) { 88 | return lineGroup.indexOf(line) > -1; 89 | }); 90 | 91 | // Flatten array of arrays 92 | lines = lines.concat.apply(lines, lineGroups); 93 | 94 | // Remove duplicates 95 | lines = lines.filter(function(line, i) { 96 | return lines.indexOf(line) == i; 97 | }); 98 | } 99 | 100 | return lines; 101 | }; 102 | -------------------------------------------------------------------------------- /app/component/network.jsx: -------------------------------------------------------------------------------- 1 | var React = require("react"); 2 | var utils = require("../common/utils"); 3 | 4 | var Network = React.createClass({ 5 | 6 | getInitialState: function() { 7 | return { 8 | collapsible: global ? false : window.innerWidth <= 800, 9 | open: false 10 | }; 11 | }, 12 | 13 | handleToggle: function() { 14 | this.setState({ open: !this.state.open }); 15 | }, 16 | 17 | handleResize: function() { 18 | this.setState({ collapsible: window.innerWidth <= 800 }); 19 | }, 20 | 21 | componentDidMount: function() { 22 | // Simple event debouncing to avoid multiple recalculations 23 | this.debounce = utils.debounceEvent(this.handleResize, 250); 24 | window.addEventListener("resize", this.debounce, false); 25 | }, 26 | 27 | componentWillUnmount: function() { 28 | window.removeEventListener("resize", this.debounce, false); 29 | }, 30 | 31 | render: function() { 32 | var networkData = this.props.networkData; 33 | var networkLineCodes = Object.keys(networkData.lines); 34 | 35 | var toggleText = this.state.open ? "Close" : "Open"; 36 | var toggleClass = this.state.collapsible ? (this.state.open ? "is-open" : "is-closed") : "is-static"; 37 | 38 | var generatedForms = networkLineCodes.map(function(lineCode, i) { 39 | return ; 40 | }, this); 41 | 42 | return ( 43 |
44 | {generatedForms} 45 | 46 |
47 | ); 48 | } 49 | 50 | }); 51 | 52 | var Line = React.createClass({ 53 | 54 | handleSubmit: function(event) { 55 | event.preventDefault(); 56 | 57 | // Dispatch an event for other components to capture 58 | var updateEvent = new CustomEvent("tt:update", { 59 | detail: { 60 | station: React.findDOMNode(this.refs.station).value, 61 | line: this.props.lineCode 62 | }, 63 | bubbles: true 64 | }); 65 | 66 | React.findDOMNode(this.refs.form).dispatchEvent(updateEvent); 67 | }, 68 | 69 | render: function() { 70 | var lineCode = this.props.lineCode; 71 | var networkData = this.props.networkData; 72 | var stationsOnThisLine = networkData.stationsOnLines[lineCode]; 73 | 74 | var generatedOptions = stationsOnThisLine.map(function(stationCode, i) { 75 | return ; 76 | }); 77 | 78 | return ( 79 |
80 |
81 | {networkData.lines[lineCode]} 82 | 83 | 84 | 85 |
86 |
87 | ); 88 | } 89 | 90 | }); 91 | 92 | module.exports = Network; 93 | -------------------------------------------------------------------------------- /app/component/predictions.jsx: -------------------------------------------------------------------------------- 1 | var React = require("react"); 2 | var utils = require("../common/utils"); 3 | 4 | var Predictions = React.createClass({ 5 | 6 | getInitialState: function() { 7 | return { 8 | status: this.props.initialData ? "success" : "welcome", 9 | predictionData: this.props.initialData 10 | }; 11 | }, 12 | 13 | fetchPredictions: function(line, station) { 14 | this.setState({ status: "loading" }); 15 | utils.httpRequest(utils.apiRequestURL(line, station), this.predictionsSuccess, this.predictionsError); 16 | }, 17 | 18 | predictionsError: function(error) { 19 | this.setState({ 20 | status: "error", 21 | predictionData: null 22 | }); 23 | 24 | // Pipe the error into your error logging setup 25 | // Airbrake.push({ error: error }); 26 | }, 27 | 28 | predictionsSuccess: function(responseData) { 29 | if (!responseData.length) { 30 | return this.predictionsError(new Error("Invalid API response")); 31 | } 32 | 33 | this.setState({ 34 | status: "success", 35 | predictionData: JSON.parse(responseData) 36 | }); 37 | }, 38 | 39 | resetPoll: function(line, station) { 40 | this.fetchPredictions(line, station); 41 | 42 | if (this.poll) { 43 | clearInterval(this.poll); 44 | } 45 | 46 | this.poll = setInterval(this.fetchPredictions.bind(this, line, station), 1000 * 30); 47 | }, 48 | 49 | componentDidMount: function() { 50 | if (this.props.line && this.props.station) { 51 | this.resetPoll(this.props.line, this.props.station); 52 | } 53 | }, 54 | 55 | componentWillUnmount: function() { 56 | clearInterval(this.poll); 57 | }, 58 | 59 | componentWillReceiveProps: function(newProps) { 60 | this.resetPoll(newProps.line, newProps.station); 61 | }, 62 | 63 | shouldComponentUpdate: function(newProps, newState) { 64 | // Only update when line/station changes or new predictions load otherwise the 65 | // loading notice will be displayed when refreshing current predictions. 66 | return this.props !== newProps || this.state.predictionData !== newState.predictionData; 67 | }, 68 | 69 | render: function() { 70 | if (this.state.status === "success") { 71 | return ; 72 | } 73 | 74 | return ; 75 | } 76 | 77 | }); 78 | 79 | var DepartureBoard = React.createClass({ 80 | 81 | render: function() { 82 | var station = this.props.predictionData.station; 83 | var platforms = this.props.predictionData.platforms; 84 | 85 | var generatedPlatforms = Object.keys(platforms).map(function(platform, i) { 86 | return ( 87 |
88 |

{platform}

89 | 90 |
91 | ); 92 | }); 93 | 94 | return ( 95 |
96 |

{station.stationName + " Station, " + station.lineName + " Line"}

97 | {generatedPlatforms} 98 |
99 | ); 100 | } 101 | 102 | }); 103 | 104 | var Trains = React.createClass({ 105 | 106 | render: function() { 107 | var generatedTrains = this.props.trains.map(function(train) { 108 | var timeTo = utils.formattedTimeUntil(train.timeToStation); 109 | 110 | return ( 111 | 112 | {timeTo === "0:00" ? "-" : timeTo} 113 | {train.towards} 114 | {train.lineName} 115 | {train.currentLocation} 116 | 117 | ); 118 | }); 119 | 120 | return ( 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | {generatedTrains} 132 | 133 |
TimeDestinationLineCurrent location
134 | ); 135 | } 136 | 137 | }); 138 | 139 | var Notice = React.createClass({ 140 | 141 | statusText: function(status) { 142 | var text; 143 | 144 | switch (status) { 145 | case "error": 146 | text = "Sorry an error occurred, please try again."; 147 | break; 148 | case "loading": 149 | text = "Loading predictions…" 150 | break; 151 | case "welcome": 152 | text = "Please choose a station."; 153 | break; 154 | } 155 | 156 | return text; 157 | }, 158 | 159 | render: function() { 160 | return ( 161 |
162 |

{this.statusText(this.props.type)}

163 |
164 | ); 165 | } 166 | 167 | }); 168 | 169 | module.exports = Predictions; 170 | -------------------------------------------------------------------------------- /app/component/tube-tracker.jsx: -------------------------------------------------------------------------------- 1 | var React = require("react"); 2 | var utils = require("../common/utils"); 3 | var Network = require("./network.jsx"); 4 | var Predictions = require("./predictions.jsx"); 5 | 6 | var TubeTracker = React.createClass({ 7 | 8 | formatAndValidateUserInput: function(userLine, userStation) { 9 | var line = null; 10 | var station = null; 11 | 12 | // We could have added extra states for invalid data 13 | // but it's easier simply to ignore it. 14 | if (utils.isStationOnLine(userLine, userStation, this.props.networkData)) { 15 | line = userLine; 16 | station = userStation; 17 | } 18 | 19 | return { 20 | line: line, 21 | station: station 22 | }; 23 | }, 24 | 25 | getInitialState: function() { 26 | var initialData = this.props.initialData; 27 | 28 | return this.formatAndValidateUserInput( 29 | initialData ? initialData.request.lineCode : null, 30 | initialData ? initialData.request.stationCode : null 31 | ); 32 | }, 33 | 34 | handleUpdate: function(e) { 35 | var input = this.formatAndValidateUserInput(e.detail.line, e.detail.station); 36 | 37 | if (input.line && input.station) { 38 | this.setState(input); 39 | } 40 | }, 41 | 42 | componentWillUpdate: function(newProps, newState) { 43 | // When the state changes push a query string so users can bookmark 44 | // or share the link to a chosen departure board. 45 | window.history.pushState(null, null, utils.formatQueryString(newState)); 46 | }, 47 | 48 | componentDidMount: function() { 49 | window.addEventListener("tt:update", this.handleUpdate, false); 50 | }, 51 | 52 | componentWillUnmount: function() { 53 | window.removeEventListener("tt:update", this.handleUpdate, false); 54 | }, 55 | 56 | render: function() { 57 | return ( 58 |
59 |
60 | 61 |
62 |
63 | 64 |
65 |
66 | ); 67 | } 68 | 69 | }); 70 | 71 | module.exports = TubeTracker; 72 | -------------------------------------------------------------------------------- /app/server/api.js: -------------------------------------------------------------------------------- 1 | var https = require("https"); 2 | var utils = require("../common/utils"); 3 | var networkData = require("../common/data"); 4 | 5 | function APIRequest(config) { 6 | this.config = config; 7 | } 8 | 9 | APIRequest.prototype.for = function(line, station) { 10 | this.line = line; 11 | this.station = station; 12 | return this; 13 | }; 14 | 15 | APIRequest.prototype.get = function(callback) { 16 | if (!utils.isStationOnLine(this.line, this.station, networkData)) { 17 | return callback(null, ""); 18 | } 19 | 20 | var formatCallback = this.format.bind(this); 21 | var groupedLines = utils.mergeGroupedLines(this.station, this.line, networkData); 22 | var path = "/Line/" + groupedLines.join(',') + "/Arrivals?stopPointId=" + this.station; 23 | var auth = "&app_id=" + this.config.APP_ID + "&app_key=" + this.config.APP_KEY; 24 | 25 | var options = { 26 | path: path + auth, 27 | hostname: "api.tfl.gov.uk" 28 | }; 29 | 30 | var request = https.request(options, function(response) { 31 | var str = ""; 32 | 33 | response.setEncoding("utf8"); 34 | 35 | response.on("data", function(chunk) { 36 | str+= chunk; 37 | }); 38 | 39 | response.on("end", function() { 40 | var responseJSON = formatCallback(str); 41 | 42 | if (responseJSON instanceof Error) { 43 | callback(responseJSON, null); 44 | } 45 | else { 46 | callback(null, responseJSON); 47 | } 48 | }); 49 | }); 50 | 51 | request.on("error", function(err) { 52 | callback(err); 53 | console.log(options.hostname + options.path); 54 | }); 55 | 56 | request.end(); 57 | }; 58 | 59 | APIRequest.prototype.format = function(responseText, callback) { 60 | var parsedResponse = parseResponse(responseText); 61 | 62 | if (parsedResponse instanceof Error) { 63 | return parsedResponse; 64 | } 65 | 66 | return { 67 | request: { 68 | lineCode: this.line, 69 | stationCode: this.station 70 | }, 71 | station: { 72 | lineName: networkData.lines[this.line], 73 | stationName: networkData.stations[this.station] 74 | }, 75 | platforms: formatData(parsedResponse) 76 | }; 77 | }; 78 | 79 | function parseResponse(responseText) { 80 | var jsonData; 81 | 82 | try { 83 | jsonData = JSON.parse(responseText); 84 | } 85 | catch(e) { 86 | return new Error("Data could not be parsed"); 87 | } 88 | 89 | return jsonData; 90 | }; 91 | 92 | function formatData(responseData) { 93 | var formattedData = {}; 94 | 95 | console.log(responseData) 96 | 97 | var sortedData = responseData.sort(function(a, b) { 98 | return a.timeToStation - b.timeToStation; 99 | }); 100 | 101 | sortedData.forEach(function(record) { 102 | formattedData[record.platformName] = formattedData[record.platformName] || []; 103 | formattedData[record.platformName].push(record); 104 | }); 105 | 106 | return formattedData; 107 | }; 108 | 109 | module.exports = APIRequest; 110 | -------------------------------------------------------------------------------- /app/server/bootstrap.jsx: -------------------------------------------------------------------------------- 1 | var React = require("react"); 2 | var networkData = require("../common/data"); 3 | var Template = require("../server/template"); 4 | var TubeTracker = require("../component/tube-tracker.jsx"); 5 | 6 | function Bootstrap(data) { 7 | this.data = data; 8 | } 9 | 10 | Bootstrap.prototype.load = function(callback) { 11 | var staticHTML = React.renderToString(); 12 | new Template("../view/index.html").render({ app: staticHTML, data: JSON.stringify(this.data) }, callback); 13 | }; 14 | 15 | module.exports = Bootstrap; 16 | -------------------------------------------------------------------------------- /app/server/template.js: -------------------------------------------------------------------------------- 1 | var fs = require("fs"); 2 | var path = require("path"); 3 | 4 | function Template(target) { 5 | this.target = target; 6 | } 7 | 8 | Template.prototype.render = function(data, callback) { 9 | var fullPath = path.resolve(__dirname, this.target); 10 | 11 | fs.readFile(fullPath, { encoding: "utf8" }, function(err, template) { 12 | if (err) { 13 | return callback(err); 14 | } 15 | 16 | var rendered = template.replace(/\{\{yield:([a-z0-9_]+)\}\}/g, function(match, property) { 17 | return data[property]; 18 | }); 19 | 20 | callback(null, rendered); 21 | }); 22 | }; 23 | 24 | module.exports = Template; 25 | -------------------------------------------------------------------------------- /app/view/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | TfL London Underground 10 | 11 | 12 | 13 | 14 | 15 | 16 |
{{yield:app}}
17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /config.example.json: -------------------------------------------------------------------------------- 1 | { 2 | "APP_ID": "", 3 | "APP_KEY": "" 4 | } 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tube-tracker", 3 | "version": "0.4.0", 4 | "devDependencies": { 5 | "browserify": "~10.0.0", 6 | "reactify": "~1.1.0", 7 | "uglifyify": "~3.0.0", 8 | "rewireify": "~0.2.2" 9 | }, 10 | "dependencies": { 11 | "express": "4.x", 12 | "react": "~0.13.3", 13 | "node-jsx": "~0.13.3" 14 | }, 15 | "engines": { 16 | "node": ">=0.12.0" 17 | }, 18 | "scripts": { 19 | "build-dev": "browserify -e app/browser/bootstrap.jsx -t reactify -o public/scripts/bundle.dev.js --debug", 20 | "build-min": "browserify -e app/browser/bootstrap.jsx -t reactify -g uglifyify -o public/scripts/bundle.min.js", 21 | "build-tdd": "browserify -e test/spec/suite.js -t [ rewireify --ignore test/**,node_modules/** ] -t reactify -o test/spec/bundle.js --debug" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /public/styles/styles.css: -------------------------------------------------------------------------------- 1 | @import url(webfont.css); 2 | 3 | /* Normalise elements */ 4 | html, 5 | body { 6 | margin: 0; 7 | } 8 | 9 | legend, 10 | fieldset { 11 | border: 0; 12 | margin: 0; 13 | padding: 0; 14 | } 15 | 16 | select, 17 | button { 18 | -moz-box-sizing: border-box; 19 | box-sizing: border-box; 20 | margin: 0; 21 | border-radius: 0; 22 | font: inherit; 23 | vertical-align: middle; 24 | } 25 | 26 | button::-moz-focus-inner { 27 | border: 0; 28 | padding: 0; 29 | } 30 | 31 | 32 | /* Typography */ 33 | body { 34 | font: normal 16px/1.5 Karla, Helvetica, Arial, sans-serif; 35 | color: #333; 36 | } 37 | 38 | h1 { 39 | margin: 0 0 16px; 40 | font-weight: normal; 41 | font-size: 36px; 42 | line-height: 48px; 43 | } 44 | 45 | h2 { 46 | margin: 0 0 8px; 47 | font-weight: normal; 48 | font-size: 24px; 49 | line-height: 32px; 50 | } 51 | 52 | p { 53 | margin: 0 0 16px; 54 | } 55 | 56 | 57 | /* Form elements */ 58 | select, 59 | button { 60 | display: inline-block; 61 | height: 48px; 62 | padding: 12px 16px; 63 | border: 1px solid #999; 64 | line-height: 22px; 65 | color: #555; 66 | } 67 | 68 | select:focus, 69 | button:focus { 70 | outline: 2px solid #2070B0; 71 | } 72 | 73 | select { 74 | -webkit-appearance: none; 75 | -moz-appearance: none; 76 | appearance: none; 77 | 78 | /* Remove the dropdown arrow from FF. Dirty. */ 79 | text-indent: .01px; 80 | text-overflow: ' '; 81 | 82 | background-color: #FFF; 83 | box-shadow: inset 0 2px rgba(0, 0, 0, .15); 84 | } 85 | 86 | select:focus { 87 | color: #333; 88 | border-color: #0036FF; 89 | } 90 | 91 | button { 92 | background-color: #E5E9E8; 93 | text-shadow: 0 1px #FFF; 94 | box-shadow: inset 0 1px #FFF; 95 | } 96 | 97 | button:hover, 98 | button:focus { 99 | background-color: #EFF1F1; 100 | } 101 | 102 | button:active { 103 | border-color: #999; 104 | background-color: #D2D6D6; 105 | box-shadow: inset 0 2px rgba(0, 0, 0, .15); 106 | } 107 | 108 | 109 | /* App layout */ 110 | .layout { 111 | overflow: hidden; 112 | } 113 | 114 | .layout__sidebar { 115 | position: absolute; 116 | top: 0; 117 | bottom: 0; 118 | left: 0; 119 | width: 35%; 120 | } 121 | 122 | .layout__content { 123 | margin-left: 35%; 124 | } 125 | 126 | @media screen and (max-width: 800px) { 127 | 128 | .layout__sidebar { 129 | width: auto; 130 | } 131 | 132 | .layout__content { 133 | margin-left: 0; 134 | } 135 | 136 | } 137 | 138 | @media screen and (min-width: 1200px) { 139 | 140 | .layout__sidebar { 141 | width: 25%; 142 | } 143 | 144 | .layout__content { 145 | margin-left: 25%; 146 | } 147 | 148 | } 149 | 150 | 151 | /* Network panel */ 152 | .network { 153 | position: relative; 154 | -webkit-box-sizing: border-box; 155 | -moz-box-sizing: border-box; 156 | box-sizing: border-box; 157 | min-height: 100%; 158 | padding: 20px; 159 | border-right: 1px solid #9daca9; 160 | background: #FFF; 161 | } 162 | 163 | .network__line { 164 | position: relative; 165 | margin-bottom: 12px; 166 | padding: 30px 10px 10px 20px; 167 | border-left: 6px solid; 168 | } 169 | 170 | .network__line--bakerloo { 171 | border-left-color: #894E24; 172 | } 173 | 174 | .network__line--central { 175 | border-left-color: #DC241F; 176 | } 177 | 178 | .network__line--circle { 179 | border-left-color: #FFCE00; 180 | } 181 | 182 | .network__line--district { 183 | border-left-color: #007229; 184 | } 185 | 186 | .network__line--hammersmith-city { 187 | border-left-color: #D799AF; 188 | } 189 | 190 | .network__line--jubilee { 191 | border-left-color: #6A7278; 192 | } 193 | 194 | .network__line--metropolitan { 195 | border-left-color: #751056; 196 | } 197 | 198 | .network__line--northern { 199 | border-left-color: #111; 200 | } 201 | 202 | .network__line--piccadilly { 203 | border-left-color: #0019A8; 204 | } 205 | 206 | .network__line--victoria { 207 | border-left-color: #00A0E2; 208 | } 209 | 210 | .network__line--waterloo-city { 211 | border-left-color: #76D0BD; 212 | } 213 | 214 | .network__line legend { 215 | position: absolute; 216 | top: 0; 217 | } 218 | 219 | .network__line select, 220 | .network__line button { 221 | float: left; 222 | } 223 | 224 | .network__line select { 225 | width: 75%; 226 | border-right: 0; 227 | } 228 | 229 | .network__line button { 230 | width: 25%; 231 | } 232 | 233 | .network__toggle { 234 | display: none; 235 | } 236 | 237 | @media screen and (max-width: 800px) { 238 | 239 | .network { 240 | box-shadow: 0 0 5px rgba(0, 0, 0, .25); 241 | } 242 | 243 | .network.is-closed { 244 | -webkit-transform: translate3d(-97.5%, 0, 0); 245 | transform: translate3d(-97.5%, 0, 0); 246 | } 247 | 248 | .network.is-open { 249 | -webkit-transform: translate3d(0, 0, 0); 250 | transform: translate3d(0, 0, 0); 251 | } 252 | 253 | .network__toggle { 254 | position: absolute; 255 | top: 21px; 256 | left: 100%; 257 | display: inline-block; 258 | 259 | /* Hide the text... */ 260 | overflow: hidden; 261 | text-indent: -999px; 262 | } 263 | 264 | .network__toggle:after { 265 | /* ... but display the generated content */ 266 | position: absolute; 267 | left: 0; 268 | width: 100%; 269 | text-indent: 0; 270 | text-align: center; 271 | } 272 | 273 | .is-closed .network__toggle:after { 274 | content: " →"; 275 | } 276 | 277 | .is-open .network__toggle:after { 278 | content: " ←"; 279 | } 280 | 281 | } 282 | 283 | 284 | /* Departures */ 285 | .departures { 286 | padding: 20px; 287 | } 288 | 289 | .departures__heading { 290 | overflow: hidden; 291 | border-bottom: 1px solid #E0E0E0; 292 | white-space: nowrap; 293 | text-overflow: ellipsis; 294 | color: #2070B0; 295 | background: #FFF; 296 | } 297 | 298 | @media screen and (max-width: 800px) { 299 | 300 | .departures { 301 | /* Allow for network panel overlay */ 302 | padding-left: -webkit-calc(2.5% + 20px); 303 | padding-left: calc(2.5% + 20px); 304 | } 305 | 306 | .departures__heading { 307 | text-indent: 20px; 308 | } 309 | 310 | } 311 | 312 | 313 | /* Trains */ 314 | .trains { 315 | width: 100%; 316 | margin: 0 0 32px; 317 | border: 1px solid #151717; 318 | border-collapse: collapse; 319 | color: #FFF; 320 | } 321 | 322 | .trains th, 323 | .trains td { 324 | padding: 12px 16px; 325 | text-align: left; 326 | } 327 | 328 | .trains th { 329 | border-bottom: 1px solid #151717; 330 | color: #FCFCBD; 331 | background: #2D3232; 332 | box-shadow: inset 0 2px rgba(255, 255, 255, .5); 333 | } 334 | 335 | .trains td { 336 | border-bottom: 1px solid #2D3232; 337 | background: #393F3F; 338 | box-shadow: inset 0 2px rgba(255, 255, 255, .15); 339 | } 340 | 341 | @media screen and (max-width: 800px) { 342 | 343 | .trains th:last-child, 344 | .trains td:last-child { 345 | display: none; 346 | } 347 | 348 | } 349 | 350 | 351 | /* Notices */ 352 | .notice { 353 | margin: 20px; 354 | padding: 20px; 355 | border: 1px solid; 356 | box-shadow: inset 0 2px #FFF; 357 | } 358 | 359 | .notice--welcome { 360 | background: #F2F8FD; 361 | border-color: #2B8BD8; 362 | } 363 | 364 | .notice--loading { 365 | background: #FAFBFB; 366 | border-color: #AEBDBD; 367 | } 368 | 369 | .notice--error { 370 | background: #FDF2F2; 371 | border-color: #D82B34; 372 | } 373 | 374 | .notice p { 375 | margin-bottom: 0; 376 | } 377 | -------------------------------------------------------------------------------- /public/styles/webfont.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Karla'; 3 | src: url(data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAADXEABMAAAAAT1QAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABqAAAABwAAAAcZXL9/kdERUYAAAHEAAAAIgAAACgArQAkR1BPUwAAAegAAAKWAAAEABWn+UhHU1VCAAAEgAAAACAAAAAgbJF0j09TLzIAAASgAAAAUAAAAGCTh0tnY21hcAAABPAAAAD+AAABugsSWAFjdnQgAAAF8AAAADQAAAA0C5oPR2ZwZ20AAAYkAAABsQAAAmVTtC+nZ2FzcAAAB9gAAAAIAAAACAAAABBnbHlmAAAH4AAAJ3EAADr8S2z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9/e29MuW/9aiQR5rDJ0v+YYc2n17f/pKgI2nmKlD7mlq3vPkkW1C7Em/p6i3Ea7T+su5Te58dyRPnpn869w1E243JAHjabczHTkJhFIXR71ClCEiz997vpdoVQey9d0mUkhhjNAycOHOoD6OJvoo+jRrvP3RPVvY5ycbEX74L5PkvjyAmMWPGghUbdipw4MSFm0o8ePFRhZ8AQUKEqaaGWuqop4FGmmimhVbaaKeDTrropode+uhngEGGGEZDJ0KUGHESJBlhlDHGmWCSKaaZIcUsaTLMkWWeBRZZYpkVVlljnQ022WKbHXbZY58DDjnimBNOOeOcC3Ji4YkXsfLMJ19iE7tUiEOc4hK3VIpHvOKTKvFLgFfeeOdDghKSsK1w/XBb1O3lm5KmaRnDlKb865Hfh1JXRpRRZUwZVyaUSeWIclSZMtTVrq4786VC+e7qMndfNE6RrGHcMJ5N/wA66ksLAHjaRcw9DoJAFARglpXlHxakJcH4F7OtRxAaGmLFJhaews7ExlIrD/Kw8kDeQ5+6eXbzzSTzYK8zsIvVgtf1A2NXPTRC9ROQuoVii+GkSxBq11vAqxq42oBT1Xe+t9UXI4SzNhCf5WngIsTRwEO43Q8MfPMUYOuXthp4c0CGyODPCBmuiDEyWhITZLwgpshkTpTIdEbMkHJKzJHZjThG5rRqKNQbq2NPZQABUvqNfgAA) format('woff'); 4 | font-weight: normal; 5 | font-style: normal; 6 | } 7 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Tube Tracker 2 | 3 | This is a simple application to check the predicted arrival times of trains at stations on the London Underground network. It is built using [React][1], [Browserify][3] and [Jasmine][4] with data from [unified TfL API][2]. The application was built in conjunction with my series "Building robust web apps with React": 4 | 5 | 1. [In-browser prototype][part1] ([Download source code][tag1]) 6 | 2. [Optimising for the browser][part2] ([Download source code][tag2]) 7 | 3. [Testing with Jasmine][part3] ([Download source code][tag3]) 8 | 4. [Server-side rendering][part4] ([Download source code][tag4]) 9 | 10 | The project was originally built with React 0.12 but has since been updated to 0.13. I have no plans to continue updating the project but there is a separate [ES6, Babel and Webpack port available][preact] for reference. 11 | 12 | ## Dependencies 13 | 14 | - [Node.js and NPM](http://nodejs.org/) 15 | 16 | ## Installation and usage 17 | 18 | 1. Clone or download this repository 19 | 2. Install dependencies with `npm install` 20 | 3. Copy the example config and enter your API credentials `cp config.example.json config.json` 21 | 4. Run `npm start` or `node server.js` 22 | 5. Open your browser and navigate to `http://localhost:8080` 23 | 24 | ## Demo 25 | 26 | You can test [the demo][demo] in the your browser now. Please note this is running on a free service tier and is not always available. 27 | 28 | [1]: http://facebook.github.io/react/ 29 | [2]: https://api.tfl.gov.uk 30 | [3]: http://browserify.org 31 | [4]: http://jasmine.github.io 32 | [part1]: http://maketea.co.uk/2014/03/05/building-robust-web-apps-with-react-part-1.html 33 | [part2]: http://maketea.co.uk/2014/04/07/building-robust-web-apps-with-react-part-2.html 34 | [part3]: http://maketea.co.uk/2014/05/22/building-robust-web-apps-with-react-part-3.html 35 | [part4]: http://maketea.co.uk/2014/06/30/building-robust-web-apps-with-react-part-4.html 36 | [tag1]: https://github.com/i-like-robots/react-tube-tracker/releases/tag/prototype 37 | [tag2]: https://github.com/i-like-robots/react-tube-tracker/releases/tag/optimise 38 | [tag3]: https://github.com/i-like-robots/react-tube-tracker/releases/tag/testing 39 | [tag4]: https://github.com/i-like-robots/react-tube-tracker/releases/tag/isomorphic 40 | [demo]: http://react-tube-tracker.herokuapp.com/ 41 | [preact]: https://github.com/i-like-robots/preact-tube-tracker 42 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | require("node-jsx").install({ extension: ".jsx" }); 2 | 3 | var express = require("express"); 4 | var API = require("./app/server/api"); 5 | var Bootstrap = require("./app/server/bootstrap.jsx"); 6 | var config = process.env.APP_ID && process.env.APP_KEY ? process.env : require("./config"); 7 | 8 | // Start a new app 9 | var app = express(); 10 | 11 | // API Proxy 12 | app.get("/api/:line/:station", function(req, res) { 13 | new API(config).for(req.params.line, req.params.station).get(function(err, data) { 14 | if (err) { 15 | return res.status(500).send("Internal error"); 16 | } 17 | 18 | res.json(data); 19 | }); 20 | }); 21 | 22 | // Serve initial HTML 23 | app.get("/", function(req, res) { 24 | new API(config).for(req.query.line, req.query.station).get(function(err, data) { 25 | if (err) { 26 | return res.status(500).send("API error"); 27 | } 28 | 29 | new Bootstrap(data).load(function(err, responseHTML) { 30 | if (err) { 31 | return res.status(500).send("Template error"); 32 | } 33 | 34 | res.send(responseHTML); 35 | }); 36 | }); 37 | }); 38 | 39 | // Static assets 40 | app.use(function(req, res, next) { 41 | if (req.url === "/scripts/bundle.js") { 42 | var pkg = app.get("env") === "development" ? "dev" : "min"; 43 | req.url = "/scripts/bundle." + pkg + ".js"; 44 | } 45 | 46 | next(); 47 | }); 48 | 49 | app.use(express.static("./public")); 50 | 51 | var port = process.env.PORT || 8080; 52 | 53 | app.listen(port); 54 | 55 | console.log("Running server on port " + port + ", press ctrl + c to stop."); 56 | -------------------------------------------------------------------------------- /test/SpecRunner.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Jasmine Spec Runner v2.0.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /test/lib/jasmine-2.0.0/boot.js: -------------------------------------------------------------------------------- 1 | /** 2 | Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project. 3 | 4 | If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms. 5 | 6 | The location of `boot.js` can be specified and/or overridden in `jasmine.yml`. 7 | 8 | [jasmine-gem]: http://github.com/pivotal/jasmine-gem 9 | */ 10 | 11 | (function() { 12 | 13 | /** 14 | * ## Require & Instantiate 15 | * 16 | * Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference. 17 | */ 18 | window.jasmine = jasmineRequire.core(jasmineRequire); 19 | 20 | /** 21 | * Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference. 22 | */ 23 | jasmineRequire.html(jasmine); 24 | 25 | /** 26 | * Create the Jasmine environment. This is used to run all specs in a project. 27 | */ 28 | var env = jasmine.getEnv(); 29 | 30 | /** 31 | * ## The Global Interface 32 | * 33 | * Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged. 34 | */ 35 | var jasmineInterface = { 36 | describe: function(description, specDefinitions) { 37 | return env.describe(description, specDefinitions); 38 | }, 39 | 40 | xdescribe: function(description, specDefinitions) { 41 | return env.xdescribe(description, specDefinitions); 42 | }, 43 | 44 | it: function(desc, func) { 45 | return env.it(desc, func); 46 | }, 47 | 48 | xit: function(desc, func) { 49 | return env.xit(desc, func); 50 | }, 51 | 52 | beforeEach: function(beforeEachFunction) { 53 | return env.beforeEach(beforeEachFunction); 54 | }, 55 | 56 | afterEach: function(afterEachFunction) { 57 | return env.afterEach(afterEachFunction); 58 | }, 59 | 60 | expect: function(actual) { 61 | return env.expect(actual); 62 | }, 63 | 64 | pending: function() { 65 | return env.pending(); 66 | }, 67 | 68 | spyOn: function(obj, methodName) { 69 | return env.spyOn(obj, methodName); 70 | }, 71 | 72 | jsApiReporter: new jasmine.JsApiReporter({ 73 | timer: new jasmine.Timer() 74 | }) 75 | }; 76 | 77 | /** 78 | * Add all of the Jasmine global/public interface to the proper global, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`. 79 | */ 80 | if (typeof window == "undefined" && typeof exports == "object") { 81 | extend(exports, jasmineInterface); 82 | } else { 83 | extend(window, jasmineInterface); 84 | } 85 | 86 | /** 87 | * Expose the interface for adding custom equality testers. 88 | */ 89 | jasmine.addCustomEqualityTester = function(tester) { 90 | env.addCustomEqualityTester(tester); 91 | }; 92 | 93 | /** 94 | * Expose the interface for adding custom expectation matchers 95 | */ 96 | jasmine.addMatchers = function(matchers) { 97 | return env.addMatchers(matchers); 98 | }; 99 | 100 | /** 101 | * Expose the mock interface for the JavaScript timeout functions 102 | */ 103 | jasmine.clock = function() { 104 | return env.clock; 105 | }; 106 | 107 | /** 108 | * ## Runner Parameters 109 | * 110 | * More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface. 111 | */ 112 | 113 | var queryString = new jasmine.QueryString({ 114 | getWindowLocation: function() { return window.location; } 115 | }); 116 | 117 | var catchingExceptions = queryString.getParam("catch"); 118 | env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions); 119 | 120 | /** 121 | * ## Reporters 122 | * The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any). 123 | */ 124 | var htmlReporter = new jasmine.HtmlReporter({ 125 | env: env, 126 | onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); }, 127 | getContainer: function() { return document.body; }, 128 | createElement: function() { return document.createElement.apply(document, arguments); }, 129 | createTextNode: function() { return document.createTextNode.apply(document, arguments); }, 130 | timer: new jasmine.Timer() 131 | }); 132 | 133 | /** 134 | * The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript. 135 | */ 136 | env.addReporter(jasmineInterface.jsApiReporter); 137 | env.addReporter(htmlReporter); 138 | 139 | /** 140 | * Filter which specs will be run by matching the start of the full name against the `spec` query param. 141 | */ 142 | var specFilter = new jasmine.HtmlSpecFilter({ 143 | filterString: function() { return queryString.getParam("spec"); } 144 | }); 145 | 146 | env.specFilter = function(spec) { 147 | return specFilter.matches(spec.getFullName()); 148 | }; 149 | 150 | /** 151 | * Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack. 152 | */ 153 | window.setTimeout = window.setTimeout; 154 | window.setInterval = window.setInterval; 155 | window.clearTimeout = window.clearTimeout; 156 | window.clearInterval = window.clearInterval; 157 | 158 | /** 159 | * ## Execution 160 | * 161 | * Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded. 162 | */ 163 | var currentWindowOnload = window.onload; 164 | 165 | window.onload = function() { 166 | if (currentWindowOnload) { 167 | currentWindowOnload(); 168 | } 169 | htmlReporter.initialize(); 170 | env.execute(); 171 | }; 172 | 173 | /** 174 | * Helper function for readability above. 175 | */ 176 | function extend(destination, source) { 177 | for (var property in source) destination[property] = source[property]; 178 | return destination; 179 | } 180 | 181 | }()); 182 | -------------------------------------------------------------------------------- /test/lib/jasmine-2.0.0/console.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2013 Pivotal Labs 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | function getJasmineRequireObj() { 24 | if (typeof module !== "undefined" && module.exports) { 25 | return exports; 26 | } else { 27 | window.jasmineRequire = window.jasmineRequire || {}; 28 | return window.jasmineRequire; 29 | } 30 | } 31 | 32 | getJasmineRequireObj().console = function(jRequire, j$) { 33 | j$.ConsoleReporter = jRequire.ConsoleReporter(); 34 | }; 35 | 36 | getJasmineRequireObj().ConsoleReporter = function() { 37 | 38 | var noopTimer = { 39 | start: function(){}, 40 | elapsed: function(){ return 0; } 41 | }; 42 | 43 | function ConsoleReporter(options) { 44 | var print = options.print, 45 | showColors = options.showColors || false, 46 | onComplete = options.onComplete || function() {}, 47 | timer = options.timer || noopTimer, 48 | specCount, 49 | failureCount, 50 | failedSpecs = [], 51 | pendingCount, 52 | ansi = { 53 | green: '\x1B[32m', 54 | red: '\x1B[31m', 55 | yellow: '\x1B[33m', 56 | none: '\x1B[0m' 57 | }; 58 | 59 | this.jasmineStarted = function() { 60 | specCount = 0; 61 | failureCount = 0; 62 | pendingCount = 0; 63 | print("Started"); 64 | printNewline(); 65 | timer.start(); 66 | }; 67 | 68 | this.jasmineDone = function() { 69 | printNewline(); 70 | for (var i = 0; i < failedSpecs.length; i++) { 71 | specFailureDetails(failedSpecs[i]); 72 | } 73 | 74 | printNewline(); 75 | var specCounts = specCount + " " + plural("spec", specCount) + ", " + 76 | failureCount + " " + plural("failure", failureCount); 77 | 78 | if (pendingCount) { 79 | specCounts += ", " + pendingCount + " pending " + plural("spec", pendingCount); 80 | } 81 | 82 | print(specCounts); 83 | 84 | printNewline(); 85 | var seconds = timer.elapsed() / 1000; 86 | print("Finished in " + seconds + " " + plural("second", seconds)); 87 | 88 | printNewline(); 89 | 90 | onComplete(failureCount === 0); 91 | }; 92 | 93 | this.specDone = function(result) { 94 | specCount++; 95 | 96 | if (result.status == "pending") { 97 | pendingCount++; 98 | print(colored("yellow", "*")); 99 | return; 100 | } 101 | 102 | if (result.status == "passed") { 103 | print(colored("green", '.')); 104 | return; 105 | } 106 | 107 | if (result.status == "failed") { 108 | failureCount++; 109 | failedSpecs.push(result); 110 | print(colored("red", 'F')); 111 | } 112 | }; 113 | 114 | return this; 115 | 116 | function printNewline() { 117 | print("\n"); 118 | } 119 | 120 | function colored(color, str) { 121 | return showColors ? (ansi[color] + str + ansi.none) : str; 122 | } 123 | 124 | function plural(str, count) { 125 | return count == 1 ? str : str + "s"; 126 | } 127 | 128 | function repeat(thing, times) { 129 | var arr = []; 130 | for (var i = 0; i < times; i++) { 131 | arr.push(thing); 132 | } 133 | return arr; 134 | } 135 | 136 | function indent(str, spaces) { 137 | var lines = (str || '').split("\n"); 138 | var newArr = []; 139 | for (var i = 0; i < lines.length; i++) { 140 | newArr.push(repeat(" ", spaces).join("") + lines[i]); 141 | } 142 | return newArr.join("\n"); 143 | } 144 | 145 | function specFailureDetails(result) { 146 | printNewline(); 147 | print(result.fullName); 148 | 149 | for (var i = 0; i < result.failedExpectations.length; i++) { 150 | var failedExpectation = result.failedExpectations[i]; 151 | printNewline(); 152 | print(indent(failedExpectation.stack, 2)); 153 | } 154 | 155 | printNewline(); 156 | } 157 | } 158 | 159 | return ConsoleReporter; 160 | }; 161 | -------------------------------------------------------------------------------- /test/lib/jasmine-2.0.0/jasmine-html.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2013 Pivotal Labs 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | jasmineRequire.html = function(j$) { 24 | j$.ResultsNode = jasmineRequire.ResultsNode(); 25 | j$.HtmlReporter = jasmineRequire.HtmlReporter(j$); 26 | j$.QueryString = jasmineRequire.QueryString(); 27 | j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter(); 28 | }; 29 | 30 | jasmineRequire.HtmlReporter = function(j$) { 31 | 32 | var noopTimer = { 33 | start: function() {}, 34 | elapsed: function() { return 0; } 35 | }; 36 | 37 | function HtmlReporter(options) { 38 | var env = options.env || {}, 39 | getContainer = options.getContainer, 40 | createElement = options.createElement, 41 | createTextNode = options.createTextNode, 42 | onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {}, 43 | timer = options.timer || noopTimer, 44 | results = [], 45 | specsExecuted = 0, 46 | failureCount = 0, 47 | pendingSpecCount = 0, 48 | htmlReporterMain, 49 | symbols; 50 | 51 | this.initialize = function() { 52 | htmlReporterMain = createDom("div", {className: "html-reporter"}, 53 | createDom("div", {className: "banner"}, 54 | createDom("span", {className: "title"}, "Jasmine"), 55 | createDom("span", {className: "version"}, j$.version) 56 | ), 57 | createDom("ul", {className: "symbol-summary"}), 58 | createDom("div", {className: "alert"}), 59 | createDom("div", {className: "results"}, 60 | createDom("div", {className: "failures"}) 61 | ) 62 | ); 63 | getContainer().appendChild(htmlReporterMain); 64 | 65 | symbols = find(".symbol-summary"); 66 | }; 67 | 68 | var totalSpecsDefined; 69 | this.jasmineStarted = function(options) { 70 | totalSpecsDefined = options.totalSpecsDefined || 0; 71 | timer.start(); 72 | }; 73 | 74 | var summary = createDom("div", {className: "summary"}); 75 | 76 | var topResults = new j$.ResultsNode({}, "", null), 77 | currentParent = topResults; 78 | 79 | this.suiteStarted = function(result) { 80 | currentParent.addChild(result, "suite"); 81 | currentParent = currentParent.last(); 82 | }; 83 | 84 | this.suiteDone = function(result) { 85 | if (currentParent == topResults) { 86 | return; 87 | } 88 | 89 | currentParent = currentParent.parent; 90 | }; 91 | 92 | this.specStarted = function(result) { 93 | currentParent.addChild(result, "spec"); 94 | }; 95 | 96 | var failures = []; 97 | this.specDone = function(result) { 98 | if (result.status != "disabled") { 99 | specsExecuted++; 100 | } 101 | 102 | symbols.appendChild(createDom("li", { 103 | className: result.status, 104 | id: "spec_" + result.id, 105 | title: result.fullName 106 | } 107 | )); 108 | 109 | if (result.status == "failed") { 110 | failureCount++; 111 | 112 | var failure = 113 | createDom("div", {className: "spec-detail failed"}, 114 | createDom("div", {className: "description"}, 115 | createDom("a", {title: result.fullName, href: specHref(result)}, result.fullName) 116 | ), 117 | createDom("div", {className: "messages"}) 118 | ); 119 | var messages = failure.childNodes[1]; 120 | 121 | for (var i = 0; i < result.failedExpectations.length; i++) { 122 | var expectation = result.failedExpectations[i]; 123 | messages.appendChild(createDom("div", {className: "result-message"}, expectation.message)); 124 | messages.appendChild(createDom("div", {className: "stack-trace"}, expectation.stack)); 125 | } 126 | 127 | failures.push(failure); 128 | } 129 | 130 | if (result.status == "pending") { 131 | pendingSpecCount++; 132 | } 133 | }; 134 | 135 | this.jasmineDone = function() { 136 | var banner = find(".banner"); 137 | banner.appendChild(createDom("span", {className: "duration"}, "finished in " + timer.elapsed() / 1000 + "s")); 138 | 139 | var alert = find(".alert"); 140 | 141 | alert.appendChild(createDom("span", { className: "exceptions" }, 142 | createDom("label", { className: "label", 'for': "raise-exceptions" }, "raise exceptions"), 143 | createDom("input", { 144 | className: "raise", 145 | id: "raise-exceptions", 146 | type: "checkbox" 147 | }) 148 | )); 149 | var checkbox = find("input"); 150 | 151 | checkbox.checked = !env.catchingExceptions(); 152 | checkbox.onclick = onRaiseExceptionsClick; 153 | 154 | if (specsExecuted < totalSpecsDefined) { 155 | var skippedMessage = "Ran " + specsExecuted + " of " + totalSpecsDefined + " specs - run all"; 156 | alert.appendChild( 157 | createDom("span", {className: "bar skipped"}, 158 | createDom("a", {href: "?", title: "Run all specs"}, skippedMessage) 159 | ) 160 | ); 161 | } 162 | var statusBarMessage = "" + pluralize("spec", specsExecuted) + ", " + pluralize("failure", failureCount); 163 | if (pendingSpecCount) { statusBarMessage += ", " + pluralize("pending spec", pendingSpecCount); } 164 | 165 | var statusBarClassName = "bar " + ((failureCount > 0) ? "failed" : "passed"); 166 | alert.appendChild(createDom("span", {className: statusBarClassName}, statusBarMessage)); 167 | 168 | var results = find(".results"); 169 | results.appendChild(summary); 170 | 171 | summaryList(topResults, summary); 172 | 173 | function summaryList(resultsTree, domParent) { 174 | var specListNode; 175 | for (var i = 0; i < resultsTree.children.length; i++) { 176 | var resultNode = resultsTree.children[i]; 177 | if (resultNode.type == "suite") { 178 | var suiteListNode = createDom("ul", {className: "suite", id: "suite-" + resultNode.result.id}, 179 | createDom("li", {className: "suite-detail"}, 180 | createDom("a", {href: specHref(resultNode.result)}, resultNode.result.description) 181 | ) 182 | ); 183 | 184 | summaryList(resultNode, suiteListNode); 185 | domParent.appendChild(suiteListNode); 186 | } 187 | if (resultNode.type == "spec") { 188 | if (domParent.getAttribute("class") != "specs") { 189 | specListNode = createDom("ul", {className: "specs"}); 190 | domParent.appendChild(specListNode); 191 | } 192 | specListNode.appendChild( 193 | createDom("li", { 194 | className: resultNode.result.status, 195 | id: "spec-" + resultNode.result.id 196 | }, 197 | createDom("a", {href: specHref(resultNode.result)}, resultNode.result.description) 198 | ) 199 | ); 200 | } 201 | } 202 | } 203 | 204 | if (failures.length) { 205 | alert.appendChild( 206 | createDom('span', {className: "menu bar spec-list"}, 207 | createDom("span", {}, "Spec List | "), 208 | createDom('a', {className: "failures-menu", href: "#"}, "Failures"))); 209 | alert.appendChild( 210 | createDom('span', {className: "menu bar failure-list"}, 211 | createDom('a', {className: "spec-list-menu", href: "#"}, "Spec List"), 212 | createDom("span", {}, " | Failures "))); 213 | 214 | find(".failures-menu").onclick = function() { 215 | setMenuModeTo('failure-list'); 216 | }; 217 | find(".spec-list-menu").onclick = function() { 218 | setMenuModeTo('spec-list'); 219 | }; 220 | 221 | setMenuModeTo('failure-list'); 222 | 223 | var failureNode = find(".failures"); 224 | for (var i = 0; i < failures.length; i++) { 225 | failureNode.appendChild(failures[i]); 226 | } 227 | } 228 | }; 229 | 230 | return this; 231 | 232 | function find(selector) { 233 | return getContainer().querySelector(selector); 234 | } 235 | 236 | function createDom(type, attrs, childrenVarArgs) { 237 | var el = createElement(type); 238 | 239 | for (var i = 2; i < arguments.length; i++) { 240 | var child = arguments[i]; 241 | 242 | if (typeof child === 'string') { 243 | el.appendChild(createTextNode(child)); 244 | } else { 245 | if (child) { 246 | el.appendChild(child); 247 | } 248 | } 249 | } 250 | 251 | for (var attr in attrs) { 252 | if (attr == "className") { 253 | el[attr] = attrs[attr]; 254 | } else { 255 | el.setAttribute(attr, attrs[attr]); 256 | } 257 | } 258 | 259 | return el; 260 | } 261 | 262 | function pluralize(singular, count) { 263 | var word = (count == 1 ? singular : singular + "s"); 264 | 265 | return "" + count + " " + word; 266 | } 267 | 268 | function specHref(result) { 269 | return "?spec=" + encodeURIComponent(result.fullName); 270 | } 271 | 272 | function setMenuModeTo(mode) { 273 | htmlReporterMain.setAttribute("class", "html-reporter " + mode); 274 | } 275 | } 276 | 277 | return HtmlReporter; 278 | }; 279 | 280 | jasmineRequire.HtmlSpecFilter = function() { 281 | function HtmlSpecFilter(options) { 282 | var filterString = options && options.filterString() && options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); 283 | var filterPattern = new RegExp(filterString); 284 | 285 | this.matches = function(specName) { 286 | return filterPattern.test(specName); 287 | }; 288 | } 289 | 290 | return HtmlSpecFilter; 291 | }; 292 | 293 | jasmineRequire.ResultsNode = function() { 294 | function ResultsNode(result, type, parent) { 295 | this.result = result; 296 | this.type = type; 297 | this.parent = parent; 298 | 299 | this.children = []; 300 | 301 | this.addChild = function(result, type) { 302 | this.children.push(new ResultsNode(result, type, this)); 303 | }; 304 | 305 | this.last = function() { 306 | return this.children[this.children.length - 1]; 307 | }; 308 | } 309 | 310 | return ResultsNode; 311 | }; 312 | 313 | jasmineRequire.QueryString = function() { 314 | function QueryString(options) { 315 | 316 | this.setParam = function(key, value) { 317 | var paramMap = queryStringToParamMap(); 318 | paramMap[key] = value; 319 | options.getWindowLocation().search = toQueryString(paramMap); 320 | }; 321 | 322 | this.getParam = function(key) { 323 | return queryStringToParamMap()[key]; 324 | }; 325 | 326 | return this; 327 | 328 | function toQueryString(paramMap) { 329 | var qStrPairs = []; 330 | for (var prop in paramMap) { 331 | qStrPairs.push(encodeURIComponent(prop) + "=" + encodeURIComponent(paramMap[prop])); 332 | } 333 | return "?" + qStrPairs.join('&'); 334 | } 335 | 336 | function queryStringToParamMap() { 337 | var paramStr = options.getWindowLocation().search.substring(1), 338 | params = [], 339 | paramMap = {}; 340 | 341 | if (paramStr.length > 0) { 342 | params = paramStr.split('&'); 343 | for (var i = 0; i < params.length; i++) { 344 | var p = params[i].split('='); 345 | var value = decodeURIComponent(p[1]); 346 | if (value === "true" || value === "false") { 347 | value = JSON.parse(value); 348 | } 349 | paramMap[decodeURIComponent(p[0])] = value; 350 | } 351 | } 352 | 353 | return paramMap; 354 | } 355 | 356 | } 357 | 358 | return QueryString; 359 | }; 360 | -------------------------------------------------------------------------------- /test/lib/jasmine-2.0.0/jasmine.css: -------------------------------------------------------------------------------- 1 | body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; } 2 | 3 | .html-reporter { font-size: 11px; font-family: Monaco, "Lucida Console", monospace; line-height: 14px; color: #333333; } 4 | .html-reporter a { text-decoration: none; } 5 | .html-reporter a:hover { text-decoration: underline; } 6 | .html-reporter p, .html-reporter h1, .html-reporter h2, .html-reporter h3, .html-reporter h4, .html-reporter h5, .html-reporter h6 { margin: 0; line-height: 14px; } 7 | .html-reporter .banner, .html-reporter .symbol-summary, .html-reporter .summary, .html-reporter .result-message, .html-reporter .spec .description, .html-reporter .spec-detail .description, .html-reporter .alert .bar, .html-reporter .stack-trace { padding-left: 9px; padding-right: 9px; } 8 | .html-reporter .banner .version { margin-left: 14px; } 9 | .html-reporter #jasmine_content { position: fixed; right: 100%; } 10 | .html-reporter .version { color: #aaaaaa; } 11 | .html-reporter .banner { margin-top: 14px; } 12 | .html-reporter .duration { color: #aaaaaa; float: right; } 13 | .html-reporter .symbol-summary { overflow: hidden; *zoom: 1; margin: 14px 0; } 14 | .html-reporter .symbol-summary li { display: inline-block; height: 8px; width: 14px; font-size: 16px; } 15 | .html-reporter .symbol-summary li.passed { font-size: 14px; } 16 | .html-reporter .symbol-summary li.passed:before { color: #5e7d00; content: "\02022"; } 17 | .html-reporter .symbol-summary li.failed { line-height: 9px; } 18 | .html-reporter .symbol-summary li.failed:before { color: #b03911; content: "x"; font-weight: bold; margin-left: -1px; } 19 | .html-reporter .symbol-summary li.disabled { font-size: 14px; } 20 | .html-reporter .symbol-summary li.disabled:before { color: #bababa; content: "\02022"; } 21 | .html-reporter .symbol-summary li.pending { line-height: 17px; } 22 | .html-reporter .symbol-summary li.pending:before { color: #ba9d37; content: "*"; } 23 | .html-reporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; } 24 | .html-reporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; } 25 | .html-reporter .bar.failed { background-color: #b03911; } 26 | .html-reporter .bar.passed { background-color: #a6b779; } 27 | .html-reporter .bar.skipped { background-color: #bababa; } 28 | .html-reporter .bar.menu { background-color: #fff; color: #aaaaaa; } 29 | .html-reporter .bar.menu a { color: #333333; } 30 | .html-reporter .bar a { color: white; } 31 | .html-reporter.spec-list .bar.menu.failure-list, .html-reporter.spec-list .results .failures { display: none; } 32 | .html-reporter.failure-list .bar.menu.spec-list, .html-reporter.failure-list .summary { display: none; } 33 | .html-reporter .running-alert { background-color: #666666; } 34 | .html-reporter .results { margin-top: 14px; } 35 | .html-reporter.showDetails .summaryMenuItem { font-weight: normal; text-decoration: inherit; } 36 | .html-reporter.showDetails .summaryMenuItem:hover { text-decoration: underline; } 37 | .html-reporter.showDetails .detailsMenuItem { font-weight: bold; text-decoration: underline; } 38 | .html-reporter.showDetails .summary { display: none; } 39 | .html-reporter.showDetails #details { display: block; } 40 | .html-reporter .summaryMenuItem { font-weight: bold; text-decoration: underline; } 41 | .html-reporter .summary { margin-top: 14px; } 42 | .html-reporter .summary ul { list-style-type: none; margin-left: 14px; padding-top: 0; padding-left: 0; } 43 | .html-reporter .summary ul.suite { margin-top: 7px; margin-bottom: 7px; } 44 | .html-reporter .summary li.passed a { color: #5e7d00; } 45 | .html-reporter .summary li.failed a { color: #b03911; } 46 | .html-reporter .summary li.pending a { color: #ba9d37; } 47 | .html-reporter .description + .suite { margin-top: 0; } 48 | .html-reporter .suite { margin-top: 14px; } 49 | .html-reporter .suite a { color: #333333; } 50 | .html-reporter .failures .spec-detail { margin-bottom: 28px; } 51 | .html-reporter .failures .spec-detail .description { background-color: #b03911; } 52 | .html-reporter .failures .spec-detail .description a { color: white; } 53 | .html-reporter .result-message { padding-top: 14px; color: #333333; white-space: pre; } 54 | .html-reporter .result-message span.result { display: block; } 55 | .html-reporter .stack-trace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #ddd; background: white; white-space: pre; } 56 | -------------------------------------------------------------------------------- /test/lib/jasmine-2.0.0/jasmine.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2013 Pivotal Labs 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | function getJasmineRequireObj() { 24 | if (typeof module !== "undefined" && module.exports) { 25 | return exports; 26 | } else { 27 | window.jasmineRequire = window.jasmineRequire || {}; 28 | return window.jasmineRequire; 29 | } 30 | } 31 | 32 | getJasmineRequireObj().core = function(jRequire) { 33 | var j$ = {}; 34 | 35 | jRequire.base(j$); 36 | j$.util = jRequire.util(); 37 | j$.Any = jRequire.Any(); 38 | j$.CallTracker = jRequire.CallTracker(); 39 | j$.Clock = jRequire.Clock(); 40 | j$.DelayedFunctionScheduler = jRequire.DelayedFunctionScheduler(); 41 | j$.Env = jRequire.Env(j$); 42 | j$.ExceptionFormatter = jRequire.ExceptionFormatter(); 43 | j$.Expectation = jRequire.Expectation(); 44 | j$.buildExpectationResult = jRequire.buildExpectationResult(); 45 | j$.JsApiReporter = jRequire.JsApiReporter(); 46 | j$.matchersUtil = jRequire.matchersUtil(j$); 47 | j$.ObjectContaining = jRequire.ObjectContaining(j$); 48 | j$.pp = jRequire.pp(j$); 49 | j$.QueueRunner = jRequire.QueueRunner(); 50 | j$.ReportDispatcher = jRequire.ReportDispatcher(); 51 | j$.Spec = jRequire.Spec(j$); 52 | j$.SpyStrategy = jRequire.SpyStrategy(); 53 | j$.Suite = jRequire.Suite(); 54 | j$.Timer = jRequire.Timer(); 55 | j$.version = jRequire.version(); 56 | 57 | j$.matchers = jRequire.requireMatchers(jRequire, j$); 58 | 59 | return j$; 60 | }; 61 | 62 | getJasmineRequireObj().requireMatchers = function(jRequire, j$) { 63 | var availableMatchers = [ 64 | "toBe", 65 | "toBeCloseTo", 66 | "toBeDefined", 67 | "toBeFalsy", 68 | "toBeGreaterThan", 69 | "toBeLessThan", 70 | "toBeNaN", 71 | "toBeNull", 72 | "toBeTruthy", 73 | "toBeUndefined", 74 | "toContain", 75 | "toEqual", 76 | "toHaveBeenCalled", 77 | "toHaveBeenCalledWith", 78 | "toMatch", 79 | "toThrow", 80 | "toThrowError" 81 | ], 82 | matchers = {}; 83 | 84 | for (var i = 0; i < availableMatchers.length; i++) { 85 | var name = availableMatchers[i]; 86 | matchers[name] = jRequire[name](j$); 87 | } 88 | 89 | return matchers; 90 | }; 91 | 92 | getJasmineRequireObj().base = function(j$) { 93 | j$.unimplementedMethod_ = function() { 94 | throw new Error("unimplemented method"); 95 | }; 96 | 97 | j$.MAX_PRETTY_PRINT_DEPTH = 40; 98 | j$.DEFAULT_TIMEOUT_INTERVAL = 5000; 99 | 100 | j$.getGlobal = (function() { 101 | var jasmineGlobal = eval.call(null, "this"); 102 | return function() { 103 | return jasmineGlobal; 104 | }; 105 | })(); 106 | 107 | j$.getEnv = function(options) { 108 | var env = j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options); 109 | //jasmine. singletons in here (setTimeout blah blah). 110 | return env; 111 | }; 112 | 113 | j$.isArray_ = function(value) { 114 | return j$.isA_("Array", value); 115 | }; 116 | 117 | j$.isString_ = function(value) { 118 | return j$.isA_("String", value); 119 | }; 120 | 121 | j$.isNumber_ = function(value) { 122 | return j$.isA_("Number", value); 123 | }; 124 | 125 | j$.isA_ = function(typeName, value) { 126 | return Object.prototype.toString.apply(value) === '[object ' + typeName + ']'; 127 | }; 128 | 129 | j$.isDomNode = function(obj) { 130 | return obj.nodeType > 0; 131 | }; 132 | 133 | j$.any = function(clazz) { 134 | return new j$.Any(clazz); 135 | }; 136 | 137 | j$.objectContaining = function(sample) { 138 | return new j$.ObjectContaining(sample); 139 | }; 140 | 141 | j$.createSpy = function(name, originalFn) { 142 | 143 | var spyStrategy = new j$.SpyStrategy({ 144 | name: name, 145 | fn: originalFn, 146 | getSpy: function() { return spy; } 147 | }), 148 | callTracker = new j$.CallTracker(), 149 | spy = function() { 150 | callTracker.track({ 151 | object: this, 152 | args: Array.prototype.slice.apply(arguments) 153 | }); 154 | return spyStrategy.exec.apply(this, arguments); 155 | }; 156 | 157 | for (var prop in originalFn) { 158 | if (prop === 'and' || prop === 'calls') { 159 | throw new Error("Jasmine spies would overwrite the 'and' and 'calls' properties on the object being spied upon"); 160 | } 161 | 162 | spy[prop] = originalFn[prop]; 163 | } 164 | 165 | spy.and = spyStrategy; 166 | spy.calls = callTracker; 167 | 168 | return spy; 169 | }; 170 | 171 | j$.isSpy = function(putativeSpy) { 172 | if (!putativeSpy) { 173 | return false; 174 | } 175 | return putativeSpy.and instanceof j$.SpyStrategy && 176 | putativeSpy.calls instanceof j$.CallTracker; 177 | }; 178 | 179 | j$.createSpyObj = function(baseName, methodNames) { 180 | if (!j$.isArray_(methodNames) || methodNames.length === 0) { 181 | throw "createSpyObj requires a non-empty array of method names to create spies for"; 182 | } 183 | var obj = {}; 184 | for (var i = 0; i < methodNames.length; i++) { 185 | obj[methodNames[i]] = j$.createSpy(baseName + '.' + methodNames[i]); 186 | } 187 | return obj; 188 | }; 189 | }; 190 | 191 | getJasmineRequireObj().util = function() { 192 | 193 | var util = {}; 194 | 195 | util.inherit = function(childClass, parentClass) { 196 | var Subclass = function() { 197 | }; 198 | Subclass.prototype = parentClass.prototype; 199 | childClass.prototype = new Subclass(); 200 | }; 201 | 202 | util.htmlEscape = function(str) { 203 | if (!str) { 204 | return str; 205 | } 206 | return str.replace(/&/g, '&') 207 | .replace(//g, '>'); 209 | }; 210 | 211 | util.argsToArray = function(args) { 212 | var arrayOfArgs = []; 213 | for (var i = 0; i < args.length; i++) { 214 | arrayOfArgs.push(args[i]); 215 | } 216 | return arrayOfArgs; 217 | }; 218 | 219 | util.isUndefined = function(obj) { 220 | return obj === void 0; 221 | }; 222 | 223 | return util; 224 | }; 225 | 226 | getJasmineRequireObj().Spec = function(j$) { 227 | function Spec(attrs) { 228 | this.expectationFactory = attrs.expectationFactory; 229 | this.resultCallback = attrs.resultCallback || function() {}; 230 | this.id = attrs.id; 231 | this.description = attrs.description || ''; 232 | this.fn = attrs.fn; 233 | this.beforeFns = attrs.beforeFns || function() { return []; }; 234 | this.afterFns = attrs.afterFns || function() { return []; }; 235 | this.onStart = attrs.onStart || function() {}; 236 | this.exceptionFormatter = attrs.exceptionFormatter || function() {}; 237 | this.getSpecName = attrs.getSpecName || function() { return ''; }; 238 | this.expectationResultFactory = attrs.expectationResultFactory || function() { }; 239 | this.queueRunnerFactory = attrs.queueRunnerFactory || function() {}; 240 | this.catchingExceptions = attrs.catchingExceptions || function() { return true; }; 241 | 242 | this.timer = attrs.timer || {setTimeout: setTimeout, clearTimeout: clearTimeout}; 243 | 244 | if (!this.fn) { 245 | this.pend(); 246 | } 247 | 248 | this.result = { 249 | id: this.id, 250 | description: this.description, 251 | fullName: this.getFullName(), 252 | failedExpectations: [] 253 | }; 254 | } 255 | 256 | Spec.prototype.addExpectationResult = function(passed, data) { 257 | if (passed) { 258 | return; 259 | } 260 | this.result.failedExpectations.push(this.expectationResultFactory(data)); 261 | }; 262 | 263 | Spec.prototype.expect = function(actual) { 264 | return this.expectationFactory(actual, this); 265 | }; 266 | 267 | Spec.prototype.execute = function(onComplete) { 268 | var self = this, 269 | timeout; 270 | 271 | this.onStart(this); 272 | 273 | if (this.markedPending || this.disabled) { 274 | complete(); 275 | return; 276 | } 277 | 278 | function timeoutable(fn) { 279 | return function(done) { 280 | timeout = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() { 281 | onException(new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.')); 282 | done(); 283 | }, j$.DEFAULT_TIMEOUT_INTERVAL]]); 284 | 285 | var callDone = function() { 286 | clearTimeoutable(); 287 | done(); 288 | }; 289 | 290 | fn.call(this, callDone); //TODO: do we care about more than 1 arg? 291 | }; 292 | } 293 | 294 | function clearTimeoutable() { 295 | Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeout]]); 296 | timeout = void 0; 297 | } 298 | 299 | var allFns = this.beforeFns().concat(this.fn).concat(this.afterFns()), 300 | allTimeoutableFns = []; 301 | for (var i = 0; i < allFns.length; i++) { 302 | var fn = allFns[i]; 303 | allTimeoutableFns.push(fn.length > 0 ? timeoutable(fn) : fn); 304 | } 305 | 306 | this.queueRunnerFactory({ 307 | fns: allTimeoutableFns, 308 | onException: onException, 309 | onComplete: complete 310 | }); 311 | 312 | function onException(e) { 313 | clearTimeoutable(); 314 | if (Spec.isPendingSpecException(e)) { 315 | self.pend(); 316 | return; 317 | } 318 | 319 | self.addExpectationResult(false, { 320 | matcherName: "", 321 | passed: false, 322 | expected: "", 323 | actual: "", 324 | error: e 325 | }); 326 | } 327 | 328 | function complete() { 329 | self.result.status = self.status(); 330 | self.resultCallback(self.result); 331 | 332 | if (onComplete) { 333 | onComplete(); 334 | } 335 | } 336 | }; 337 | 338 | Spec.prototype.disable = function() { 339 | this.disabled = true; 340 | }; 341 | 342 | Spec.prototype.pend = function() { 343 | this.markedPending = true; 344 | }; 345 | 346 | Spec.prototype.status = function() { 347 | if (this.disabled) { 348 | return 'disabled'; 349 | } 350 | 351 | if (this.markedPending) { 352 | return 'pending'; 353 | } 354 | 355 | if (this.result.failedExpectations.length > 0) { 356 | return 'failed'; 357 | } else { 358 | return 'passed'; 359 | } 360 | }; 361 | 362 | Spec.prototype.getFullName = function() { 363 | return this.getSpecName(this); 364 | }; 365 | 366 | Spec.pendingSpecExceptionMessage = "=> marked Pending"; 367 | 368 | Spec.isPendingSpecException = function(e) { 369 | return e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1; 370 | }; 371 | 372 | return Spec; 373 | }; 374 | 375 | if (typeof window == void 0 && typeof exports == "object") { 376 | exports.Spec = jasmineRequire.Spec; 377 | } 378 | 379 | getJasmineRequireObj().Env = function(j$) { 380 | function Env(options) { 381 | options = options || {}; 382 | 383 | var self = this; 384 | var global = options.global || j$.getGlobal(); 385 | 386 | var totalSpecsDefined = 0; 387 | 388 | var catchExceptions = true; 389 | 390 | var realSetTimeout = j$.getGlobal().setTimeout; 391 | var realClearTimeout = j$.getGlobal().clearTimeout; 392 | this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler()); 393 | 394 | var runnableLookupTable = {}; 395 | 396 | var spies = []; 397 | 398 | var currentSpec = null; 399 | var currentSuite = null; 400 | 401 | var reporter = new j$.ReportDispatcher([ 402 | "jasmineStarted", 403 | "jasmineDone", 404 | "suiteStarted", 405 | "suiteDone", 406 | "specStarted", 407 | "specDone" 408 | ]); 409 | 410 | this.specFilter = function() { 411 | return true; 412 | }; 413 | 414 | var equalityTesters = []; 415 | 416 | var customEqualityTesters = []; 417 | this.addCustomEqualityTester = function(tester) { 418 | customEqualityTesters.push(tester); 419 | }; 420 | 421 | j$.Expectation.addCoreMatchers(j$.matchers); 422 | 423 | var nextSpecId = 0; 424 | var getNextSpecId = function() { 425 | return 'spec' + nextSpecId++; 426 | }; 427 | 428 | var nextSuiteId = 0; 429 | var getNextSuiteId = function() { 430 | return 'suite' + nextSuiteId++; 431 | }; 432 | 433 | var expectationFactory = function(actual, spec) { 434 | return j$.Expectation.Factory({ 435 | util: j$.matchersUtil, 436 | customEqualityTesters: customEqualityTesters, 437 | actual: actual, 438 | addExpectationResult: addExpectationResult 439 | }); 440 | 441 | function addExpectationResult(passed, result) { 442 | return spec.addExpectationResult(passed, result); 443 | } 444 | }; 445 | 446 | var specStarted = function(spec) { 447 | currentSpec = spec; 448 | reporter.specStarted(spec.result); 449 | }; 450 | 451 | var beforeFns = function(suite) { 452 | return function() { 453 | var befores = []; 454 | while(suite) { 455 | befores = befores.concat(suite.beforeFns); 456 | suite = suite.parentSuite; 457 | } 458 | return befores.reverse(); 459 | }; 460 | }; 461 | 462 | var afterFns = function(suite) { 463 | return function() { 464 | var afters = []; 465 | while(suite) { 466 | afters = afters.concat(suite.afterFns); 467 | suite = suite.parentSuite; 468 | } 469 | return afters; 470 | }; 471 | }; 472 | 473 | var getSpecName = function(spec, suite) { 474 | return suite.getFullName() + ' ' + spec.description; 475 | }; 476 | 477 | // TODO: we may just be able to pass in the fn instead of wrapping here 478 | var buildExpectationResult = j$.buildExpectationResult, 479 | exceptionFormatter = new j$.ExceptionFormatter(), 480 | expectationResultFactory = function(attrs) { 481 | attrs.messageFormatter = exceptionFormatter.message; 482 | attrs.stackFormatter = exceptionFormatter.stack; 483 | 484 | return buildExpectationResult(attrs); 485 | }; 486 | 487 | // TODO: fix this naming, and here's where the value comes in 488 | this.catchExceptions = function(value) { 489 | catchExceptions = !!value; 490 | return catchExceptions; 491 | }; 492 | 493 | this.catchingExceptions = function() { 494 | return catchExceptions; 495 | }; 496 | 497 | var maximumSpecCallbackDepth = 20; 498 | var currentSpecCallbackDepth = 0; 499 | 500 | function clearStack(fn) { 501 | currentSpecCallbackDepth++; 502 | if (currentSpecCallbackDepth >= maximumSpecCallbackDepth) { 503 | currentSpecCallbackDepth = 0; 504 | realSetTimeout(fn, 0); 505 | } else { 506 | fn(); 507 | } 508 | } 509 | 510 | var catchException = function(e) { 511 | return j$.Spec.isPendingSpecException(e) || catchExceptions; 512 | }; 513 | 514 | var queueRunnerFactory = function(options) { 515 | options.catchException = catchException; 516 | options.clearStack = options.clearStack || clearStack; 517 | 518 | new j$.QueueRunner(options).execute(); 519 | }; 520 | 521 | var topSuite = new j$.Suite({ 522 | env: this, 523 | id: getNextSuiteId(), 524 | description: 'Jasmine__TopLevel__Suite', 525 | queueRunner: queueRunnerFactory, 526 | resultCallback: function() {} // TODO - hook this up 527 | }); 528 | runnableLookupTable[topSuite.id] = topSuite; 529 | currentSuite = topSuite; 530 | 531 | this.topSuite = function() { 532 | return topSuite; 533 | }; 534 | 535 | this.execute = function(runnablesToRun) { 536 | runnablesToRun = runnablesToRun || [topSuite.id]; 537 | 538 | var allFns = []; 539 | for(var i = 0; i < runnablesToRun.length; i++) { 540 | var runnable = runnableLookupTable[runnablesToRun[i]]; 541 | allFns.push((function(runnable) { return function(done) { runnable.execute(done); }; })(runnable)); 542 | } 543 | 544 | reporter.jasmineStarted({ 545 | totalSpecsDefined: totalSpecsDefined 546 | }); 547 | 548 | queueRunnerFactory({fns: allFns, onComplete: reporter.jasmineDone}); 549 | }; 550 | 551 | this.addReporter = function(reporterToAdd) { 552 | reporter.addReporter(reporterToAdd); 553 | }; 554 | 555 | this.addMatchers = function(matchersToAdd) { 556 | j$.Expectation.addMatchers(matchersToAdd); 557 | }; 558 | 559 | this.spyOn = function(obj, methodName) { 560 | if (j$.util.isUndefined(obj)) { 561 | throw new Error("spyOn could not find an object to spy upon for " + methodName + "()"); 562 | } 563 | 564 | if (j$.util.isUndefined(obj[methodName])) { 565 | throw new Error(methodName + '() method does not exist'); 566 | } 567 | 568 | if (obj[methodName] && j$.isSpy(obj[methodName])) { 569 | //TODO?: should this return the current spy? Downside: may cause user confusion about spy state 570 | throw new Error(methodName + ' has already been spied upon'); 571 | } 572 | 573 | var spy = j$.createSpy(methodName, obj[methodName]); 574 | 575 | spies.push({ 576 | spy: spy, 577 | baseObj: obj, 578 | methodName: methodName, 579 | originalValue: obj[methodName] 580 | }); 581 | 582 | obj[methodName] = spy; 583 | 584 | return spy; 585 | }; 586 | 587 | var suiteFactory = function(description) { 588 | var suite = new j$.Suite({ 589 | env: self, 590 | id: getNextSuiteId(), 591 | description: description, 592 | parentSuite: currentSuite, 593 | queueRunner: queueRunnerFactory, 594 | onStart: suiteStarted, 595 | resultCallback: function(attrs) { 596 | reporter.suiteDone(attrs); 597 | } 598 | }); 599 | 600 | runnableLookupTable[suite.id] = suite; 601 | return suite; 602 | }; 603 | 604 | this.describe = function(description, specDefinitions) { 605 | var suite = suiteFactory(description); 606 | 607 | var parentSuite = currentSuite; 608 | parentSuite.addChild(suite); 609 | currentSuite = suite; 610 | 611 | var declarationError = null; 612 | try { 613 | specDefinitions.call(suite); 614 | } catch (e) { 615 | declarationError = e; 616 | } 617 | 618 | if (declarationError) { 619 | this.it("encountered a declaration exception", function() { 620 | throw declarationError; 621 | }); 622 | } 623 | 624 | currentSuite = parentSuite; 625 | 626 | return suite; 627 | }; 628 | 629 | this.xdescribe = function(description, specDefinitions) { 630 | var suite = this.describe(description, specDefinitions); 631 | suite.disable(); 632 | return suite; 633 | }; 634 | 635 | var specFactory = function(description, fn, suite) { 636 | totalSpecsDefined++; 637 | 638 | var spec = new j$.Spec({ 639 | id: getNextSpecId(), 640 | beforeFns: beforeFns(suite), 641 | afterFns: afterFns(suite), 642 | expectationFactory: expectationFactory, 643 | exceptionFormatter: exceptionFormatter, 644 | resultCallback: specResultCallback, 645 | getSpecName: function(spec) { 646 | return getSpecName(spec, suite); 647 | }, 648 | onStart: specStarted, 649 | description: description, 650 | expectationResultFactory: expectationResultFactory, 651 | queueRunnerFactory: queueRunnerFactory, 652 | fn: fn, 653 | timer: {setTimeout: realSetTimeout, clearTimeout: realClearTimeout} 654 | }); 655 | 656 | runnableLookupTable[spec.id] = spec; 657 | 658 | if (!self.specFilter(spec)) { 659 | spec.disable(); 660 | } 661 | 662 | return spec; 663 | 664 | function removeAllSpies() { 665 | for (var i = 0; i < spies.length; i++) { 666 | var spyEntry = spies[i]; 667 | spyEntry.baseObj[spyEntry.methodName] = spyEntry.originalValue; 668 | } 669 | spies = []; 670 | } 671 | 672 | function specResultCallback(result) { 673 | removeAllSpies(); 674 | j$.Expectation.resetMatchers(); 675 | customEqualityTesters = []; 676 | currentSpec = null; 677 | reporter.specDone(result); 678 | } 679 | }; 680 | 681 | var suiteStarted = function(suite) { 682 | reporter.suiteStarted(suite.result); 683 | }; 684 | 685 | this.it = function(description, fn) { 686 | var spec = specFactory(description, fn, currentSuite); 687 | currentSuite.addChild(spec); 688 | return spec; 689 | }; 690 | 691 | this.xit = function(description, fn) { 692 | var spec = this.it(description, fn); 693 | spec.pend(); 694 | return spec; 695 | }; 696 | 697 | this.expect = function(actual) { 698 | return currentSpec.expect(actual); 699 | }; 700 | 701 | this.beforeEach = function(beforeEachFunction) { 702 | currentSuite.beforeEach(beforeEachFunction); 703 | }; 704 | 705 | this.afterEach = function(afterEachFunction) { 706 | currentSuite.afterEach(afterEachFunction); 707 | }; 708 | 709 | this.pending = function() { 710 | throw j$.Spec.pendingSpecExceptionMessage; 711 | }; 712 | } 713 | 714 | return Env; 715 | }; 716 | 717 | getJasmineRequireObj().JsApiReporter = function() { 718 | 719 | var noopTimer = { 720 | start: function(){}, 721 | elapsed: function(){ return 0; } 722 | }; 723 | 724 | function JsApiReporter(options) { 725 | var timer = options.timer || noopTimer, 726 | status = "loaded"; 727 | 728 | this.started = false; 729 | this.finished = false; 730 | 731 | this.jasmineStarted = function() { 732 | this.started = true; 733 | status = 'started'; 734 | timer.start(); 735 | }; 736 | 737 | var executionTime; 738 | 739 | this.jasmineDone = function() { 740 | this.finished = true; 741 | executionTime = timer.elapsed(); 742 | status = 'done'; 743 | }; 744 | 745 | this.status = function() { 746 | return status; 747 | }; 748 | 749 | var suites = {}; 750 | 751 | this.suiteStarted = function(result) { 752 | storeSuite(result); 753 | }; 754 | 755 | this.suiteDone = function(result) { 756 | storeSuite(result); 757 | }; 758 | 759 | function storeSuite(result) { 760 | suites[result.id] = result; 761 | } 762 | 763 | this.suites = function() { 764 | return suites; 765 | }; 766 | 767 | var specs = []; 768 | this.specStarted = function(result) { }; 769 | 770 | this.specDone = function(result) { 771 | specs.push(result); 772 | }; 773 | 774 | this.specResults = function(index, length) { 775 | return specs.slice(index, index + length); 776 | }; 777 | 778 | this.specs = function() { 779 | return specs; 780 | }; 781 | 782 | this.executionTime = function() { 783 | return executionTime; 784 | }; 785 | 786 | } 787 | 788 | return JsApiReporter; 789 | }; 790 | 791 | getJasmineRequireObj().Any = function() { 792 | 793 | function Any(expectedObject) { 794 | this.expectedObject = expectedObject; 795 | } 796 | 797 | Any.prototype.jasmineMatches = function(other) { 798 | if (this.expectedObject == String) { 799 | return typeof other == 'string' || other instanceof String; 800 | } 801 | 802 | if (this.expectedObject == Number) { 803 | return typeof other == 'number' || other instanceof Number; 804 | } 805 | 806 | if (this.expectedObject == Function) { 807 | return typeof other == 'function' || other instanceof Function; 808 | } 809 | 810 | if (this.expectedObject == Object) { 811 | return typeof other == 'object'; 812 | } 813 | 814 | if (this.expectedObject == Boolean) { 815 | return typeof other == 'boolean'; 816 | } 817 | 818 | return other instanceof this.expectedObject; 819 | }; 820 | 821 | Any.prototype.jasmineToString = function() { 822 | return ''; 823 | }; 824 | 825 | return Any; 826 | }; 827 | 828 | getJasmineRequireObj().CallTracker = function() { 829 | 830 | function CallTracker() { 831 | var calls = []; 832 | 833 | this.track = function(context) { 834 | calls.push(context); 835 | }; 836 | 837 | this.any = function() { 838 | return !!calls.length; 839 | }; 840 | 841 | this.count = function() { 842 | return calls.length; 843 | }; 844 | 845 | this.argsFor = function(index) { 846 | var call = calls[index]; 847 | return call ? call.args : []; 848 | }; 849 | 850 | this.all = function() { 851 | return calls; 852 | }; 853 | 854 | this.allArgs = function() { 855 | var callArgs = []; 856 | for(var i = 0; i < calls.length; i++){ 857 | callArgs.push(calls[i].args); 858 | } 859 | 860 | return callArgs; 861 | }; 862 | 863 | this.first = function() { 864 | return calls[0]; 865 | }; 866 | 867 | this.mostRecent = function() { 868 | return calls[calls.length - 1]; 869 | }; 870 | 871 | this.reset = function() { 872 | calls = []; 873 | }; 874 | } 875 | 876 | return CallTracker; 877 | }; 878 | 879 | getJasmineRequireObj().Clock = function() { 880 | function Clock(global, delayedFunctionScheduler) { 881 | var self = this, 882 | realTimingFunctions = { 883 | setTimeout: global.setTimeout, 884 | clearTimeout: global.clearTimeout, 885 | setInterval: global.setInterval, 886 | clearInterval: global.clearInterval 887 | }, 888 | fakeTimingFunctions = { 889 | setTimeout: setTimeout, 890 | clearTimeout: clearTimeout, 891 | setInterval: setInterval, 892 | clearInterval: clearInterval 893 | }, 894 | installed = false, 895 | timer; 896 | 897 | self.install = function() { 898 | replace(global, fakeTimingFunctions); 899 | timer = fakeTimingFunctions; 900 | installed = true; 901 | }; 902 | 903 | self.uninstall = function() { 904 | delayedFunctionScheduler.reset(); 905 | replace(global, realTimingFunctions); 906 | timer = realTimingFunctions; 907 | installed = false; 908 | }; 909 | 910 | self.setTimeout = function(fn, delay, params) { 911 | if (legacyIE()) { 912 | if (arguments.length > 2) { 913 | throw new Error("IE < 9 cannot support extra params to setTimeout without a polyfill"); 914 | } 915 | return timer.setTimeout(fn, delay); 916 | } 917 | return Function.prototype.apply.apply(timer.setTimeout, [global, arguments]); 918 | }; 919 | 920 | self.setInterval = function(fn, delay, params) { 921 | if (legacyIE()) { 922 | if (arguments.length > 2) { 923 | throw new Error("IE < 9 cannot support extra params to setInterval without a polyfill"); 924 | } 925 | return timer.setInterval(fn, delay); 926 | } 927 | return Function.prototype.apply.apply(timer.setInterval, [global, arguments]); 928 | }; 929 | 930 | self.clearTimeout = function(id) { 931 | return Function.prototype.call.apply(timer.clearTimeout, [global, id]); 932 | }; 933 | 934 | self.clearInterval = function(id) { 935 | return Function.prototype.call.apply(timer.clearInterval, [global, id]); 936 | }; 937 | 938 | self.tick = function(millis) { 939 | if (installed) { 940 | delayedFunctionScheduler.tick(millis); 941 | } else { 942 | throw new Error("Mock clock is not installed, use jasmine.clock().install()"); 943 | } 944 | }; 945 | 946 | return self; 947 | 948 | function legacyIE() { 949 | //if these methods are polyfilled, apply will be present 950 | return !(realTimingFunctions.setTimeout || realTimingFunctions.setInterval).apply; 951 | } 952 | 953 | function replace(dest, source) { 954 | for (var prop in source) { 955 | dest[prop] = source[prop]; 956 | } 957 | } 958 | 959 | function setTimeout(fn, delay) { 960 | return delayedFunctionScheduler.scheduleFunction(fn, delay, argSlice(arguments, 2)); 961 | } 962 | 963 | function clearTimeout(id) { 964 | return delayedFunctionScheduler.removeFunctionWithId(id); 965 | } 966 | 967 | function setInterval(fn, interval) { 968 | return delayedFunctionScheduler.scheduleFunction(fn, interval, argSlice(arguments, 2), true); 969 | } 970 | 971 | function clearInterval(id) { 972 | return delayedFunctionScheduler.removeFunctionWithId(id); 973 | } 974 | 975 | function argSlice(argsObj, n) { 976 | return Array.prototype.slice.call(argsObj, 2); 977 | } 978 | } 979 | 980 | return Clock; 981 | }; 982 | 983 | getJasmineRequireObj().DelayedFunctionScheduler = function() { 984 | function DelayedFunctionScheduler() { 985 | var self = this; 986 | var scheduledLookup = []; 987 | var scheduledFunctions = {}; 988 | var currentTime = 0; 989 | var delayedFnCount = 0; 990 | 991 | self.tick = function(millis) { 992 | millis = millis || 0; 993 | var endTime = currentTime + millis; 994 | 995 | runScheduledFunctions(endTime); 996 | currentTime = endTime; 997 | }; 998 | 999 | self.scheduleFunction = function(funcToCall, millis, params, recurring, timeoutKey, runAtMillis) { 1000 | var f; 1001 | if (typeof(funcToCall) === 'string') { 1002 | /* jshint evil: true */ 1003 | f = function() { return eval(funcToCall); }; 1004 | /* jshint evil: false */ 1005 | } else { 1006 | f = funcToCall; 1007 | } 1008 | 1009 | millis = millis || 0; 1010 | timeoutKey = timeoutKey || ++delayedFnCount; 1011 | runAtMillis = runAtMillis || (currentTime + millis); 1012 | 1013 | var funcToSchedule = { 1014 | runAtMillis: runAtMillis, 1015 | funcToCall: f, 1016 | recurring: recurring, 1017 | params: params, 1018 | timeoutKey: timeoutKey, 1019 | millis: millis 1020 | }; 1021 | 1022 | if (runAtMillis in scheduledFunctions) { 1023 | scheduledFunctions[runAtMillis].push(funcToSchedule); 1024 | } else { 1025 | scheduledFunctions[runAtMillis] = [funcToSchedule]; 1026 | scheduledLookup.push(runAtMillis); 1027 | scheduledLookup.sort(function (a, b) { 1028 | return a - b; 1029 | }); 1030 | } 1031 | 1032 | return timeoutKey; 1033 | }; 1034 | 1035 | self.removeFunctionWithId = function(timeoutKey) { 1036 | for (var runAtMillis in scheduledFunctions) { 1037 | var funcs = scheduledFunctions[runAtMillis]; 1038 | var i = indexOfFirstToPass(funcs, function (func) { 1039 | return func.timeoutKey === timeoutKey; 1040 | }); 1041 | 1042 | if (i > -1) { 1043 | if (funcs.length === 1) { 1044 | delete scheduledFunctions[runAtMillis]; 1045 | deleteFromLookup(runAtMillis); 1046 | } else { 1047 | funcs.splice(i, 1); 1048 | } 1049 | 1050 | // intervals get rescheduled when executed, so there's never more 1051 | // than a single scheduled function with a given timeoutKey 1052 | break; 1053 | } 1054 | } 1055 | }; 1056 | 1057 | self.reset = function() { 1058 | currentTime = 0; 1059 | scheduledLookup = []; 1060 | scheduledFunctions = {}; 1061 | delayedFnCount = 0; 1062 | }; 1063 | 1064 | return self; 1065 | 1066 | function indexOfFirstToPass(array, testFn) { 1067 | var index = -1; 1068 | 1069 | for (var i = 0; i < array.length; ++i) { 1070 | if (testFn(array[i])) { 1071 | index = i; 1072 | break; 1073 | } 1074 | } 1075 | 1076 | return index; 1077 | } 1078 | 1079 | function deleteFromLookup(key) { 1080 | var value = Number(key); 1081 | var i = indexOfFirstToPass(scheduledLookup, function (millis) { 1082 | return millis === value; 1083 | }); 1084 | 1085 | if (i > -1) { 1086 | scheduledLookup.splice(i, 1); 1087 | } 1088 | } 1089 | 1090 | function reschedule(scheduledFn) { 1091 | self.scheduleFunction(scheduledFn.funcToCall, 1092 | scheduledFn.millis, 1093 | scheduledFn.params, 1094 | true, 1095 | scheduledFn.timeoutKey, 1096 | scheduledFn.runAtMillis + scheduledFn.millis); 1097 | } 1098 | 1099 | function runScheduledFunctions(endTime) { 1100 | if (scheduledLookup.length === 0 || scheduledLookup[0] > endTime) { 1101 | return; 1102 | } 1103 | 1104 | do { 1105 | currentTime = scheduledLookup.shift(); 1106 | 1107 | var funcsToRun = scheduledFunctions[currentTime]; 1108 | delete scheduledFunctions[currentTime]; 1109 | 1110 | for (var i = 0; i < funcsToRun.length; ++i) { 1111 | var funcToRun = funcsToRun[i]; 1112 | funcToRun.funcToCall.apply(null, funcToRun.params || []); 1113 | 1114 | if (funcToRun.recurring) { 1115 | reschedule(funcToRun); 1116 | } 1117 | } 1118 | } while (scheduledLookup.length > 0 && 1119 | // checking first if we're out of time prevents setTimeout(0) 1120 | // scheduled in a funcToRun from forcing an extra iteration 1121 | currentTime !== endTime && 1122 | scheduledLookup[0] <= endTime); 1123 | } 1124 | } 1125 | 1126 | return DelayedFunctionScheduler; 1127 | }; 1128 | 1129 | getJasmineRequireObj().ExceptionFormatter = function() { 1130 | function ExceptionFormatter() { 1131 | this.message = function(error) { 1132 | var message = error.name + 1133 | ': ' + 1134 | error.message; 1135 | 1136 | if (error.fileName || error.sourceURL) { 1137 | message += " in " + (error.fileName || error.sourceURL); 1138 | } 1139 | 1140 | if (error.line || error.lineNumber) { 1141 | message += " (line " + (error.line || error.lineNumber) + ")"; 1142 | } 1143 | 1144 | return message; 1145 | }; 1146 | 1147 | this.stack = function(error) { 1148 | return error ? error.stack : null; 1149 | }; 1150 | } 1151 | 1152 | return ExceptionFormatter; 1153 | }; 1154 | 1155 | getJasmineRequireObj().Expectation = function() { 1156 | 1157 | var matchers = {}; 1158 | 1159 | function Expectation(options) { 1160 | this.util = options.util || { buildFailureMessage: function() {} }; 1161 | this.customEqualityTesters = options.customEqualityTesters || []; 1162 | this.actual = options.actual; 1163 | this.addExpectationResult = options.addExpectationResult || function(){}; 1164 | this.isNot = options.isNot; 1165 | 1166 | for (var matcherName in matchers) { 1167 | this[matcherName] = matchers[matcherName]; 1168 | } 1169 | } 1170 | 1171 | Expectation.prototype.wrapCompare = function(name, matcherFactory) { 1172 | return function() { 1173 | var args = Array.prototype.slice.call(arguments, 0), 1174 | expected = args.slice(0), 1175 | message = ""; 1176 | 1177 | args.unshift(this.actual); 1178 | 1179 | var matcher = matcherFactory(this.util, this.customEqualityTesters), 1180 | matcherCompare = matcher.compare; 1181 | 1182 | function defaultNegativeCompare() { 1183 | var result = matcher.compare.apply(null, args); 1184 | result.pass = !result.pass; 1185 | return result; 1186 | } 1187 | 1188 | if (this.isNot) { 1189 | matcherCompare = matcher.negativeCompare || defaultNegativeCompare; 1190 | } 1191 | 1192 | var result = matcherCompare.apply(null, args); 1193 | 1194 | if (!result.pass) { 1195 | if (!result.message) { 1196 | args.unshift(this.isNot); 1197 | args.unshift(name); 1198 | message = this.util.buildFailureMessage.apply(null, args); 1199 | } else { 1200 | message = result.message; 1201 | } 1202 | } 1203 | 1204 | if (expected.length == 1) { 1205 | expected = expected[0]; 1206 | } 1207 | 1208 | // TODO: how many of these params are needed? 1209 | this.addExpectationResult( 1210 | result.pass, 1211 | { 1212 | matcherName: name, 1213 | passed: result.pass, 1214 | message: message, 1215 | actual: this.actual, 1216 | expected: expected // TODO: this may need to be arrayified/sliced 1217 | } 1218 | ); 1219 | }; 1220 | }; 1221 | 1222 | Expectation.addCoreMatchers = function(matchers) { 1223 | var prototype = Expectation.prototype; 1224 | for (var matcherName in matchers) { 1225 | var matcher = matchers[matcherName]; 1226 | prototype[matcherName] = prototype.wrapCompare(matcherName, matcher); 1227 | } 1228 | }; 1229 | 1230 | Expectation.addMatchers = function(matchersToAdd) { 1231 | for (var name in matchersToAdd) { 1232 | var matcher = matchersToAdd[name]; 1233 | matchers[name] = Expectation.prototype.wrapCompare(name, matcher); 1234 | } 1235 | }; 1236 | 1237 | Expectation.resetMatchers = function() { 1238 | for (var name in matchers) { 1239 | delete matchers[name]; 1240 | } 1241 | }; 1242 | 1243 | Expectation.Factory = function(options) { 1244 | options = options || {}; 1245 | 1246 | var expect = new Expectation(options); 1247 | 1248 | // TODO: this would be nice as its own Object - NegativeExpectation 1249 | // TODO: copy instead of mutate options 1250 | options.isNot = true; 1251 | expect.not = new Expectation(options); 1252 | 1253 | return expect; 1254 | }; 1255 | 1256 | return Expectation; 1257 | }; 1258 | 1259 | //TODO: expectation result may make more sense as a presentation of an expectation. 1260 | getJasmineRequireObj().buildExpectationResult = function() { 1261 | function buildExpectationResult(options) { 1262 | var messageFormatter = options.messageFormatter || function() {}, 1263 | stackFormatter = options.stackFormatter || function() {}; 1264 | 1265 | return { 1266 | matcherName: options.matcherName, 1267 | expected: options.expected, 1268 | actual: options.actual, 1269 | message: message(), 1270 | stack: stack(), 1271 | passed: options.passed 1272 | }; 1273 | 1274 | function message() { 1275 | if (options.passed) { 1276 | return "Passed."; 1277 | } else if (options.message) { 1278 | return options.message; 1279 | } else if (options.error) { 1280 | return messageFormatter(options.error); 1281 | } 1282 | return ""; 1283 | } 1284 | 1285 | function stack() { 1286 | if (options.passed) { 1287 | return ""; 1288 | } 1289 | 1290 | var error = options.error; 1291 | if (!error) { 1292 | try { 1293 | throw new Error(message()); 1294 | } catch (e) { 1295 | error = e; 1296 | } 1297 | } 1298 | return stackFormatter(error); 1299 | } 1300 | } 1301 | 1302 | return buildExpectationResult; 1303 | }; 1304 | 1305 | getJasmineRequireObj().ObjectContaining = function(j$) { 1306 | 1307 | function ObjectContaining(sample) { 1308 | this.sample = sample; 1309 | } 1310 | 1311 | ObjectContaining.prototype.jasmineMatches = function(other, mismatchKeys, mismatchValues) { 1312 | if (typeof(this.sample) !== "object") { throw new Error("You must provide an object to objectContaining, not '"+this.sample+"'."); } 1313 | 1314 | mismatchKeys = mismatchKeys || []; 1315 | mismatchValues = mismatchValues || []; 1316 | 1317 | var hasKey = function(obj, keyName) { 1318 | return obj !== null && !j$.util.isUndefined(obj[keyName]); 1319 | }; 1320 | 1321 | for (var property in this.sample) { 1322 | if (!hasKey(other, property) && hasKey(this.sample, property)) { 1323 | mismatchKeys.push("expected has key '" + property + "', but missing from actual."); 1324 | } 1325 | else if (!j$.matchersUtil.equals(this.sample[property], other[property])) { 1326 | mismatchValues.push("'" + property + "' was '" + (other[property] ? j$.util.htmlEscape(other[property].toString()) : other[property]) + "' in actual, but was '" + (this.sample[property] ? j$.util.htmlEscape(this.sample[property].toString()) : this.sample[property]) + "' in expected."); 1327 | } 1328 | } 1329 | 1330 | return (mismatchKeys.length === 0 && mismatchValues.length === 0); 1331 | }; 1332 | 1333 | ObjectContaining.prototype.jasmineToString = function() { 1334 | return ""; 1335 | }; 1336 | 1337 | return ObjectContaining; 1338 | }; 1339 | 1340 | getJasmineRequireObj().pp = function(j$) { 1341 | 1342 | function PrettyPrinter() { 1343 | this.ppNestLevel_ = 0; 1344 | } 1345 | 1346 | PrettyPrinter.prototype.format = function(value) { 1347 | this.ppNestLevel_++; 1348 | try { 1349 | if (j$.util.isUndefined(value)) { 1350 | this.emitScalar('undefined'); 1351 | } else if (value === null) { 1352 | this.emitScalar('null'); 1353 | } else if (value === j$.getGlobal()) { 1354 | this.emitScalar(''); 1355 | } else if (value.jasmineToString) { 1356 | this.emitScalar(value.jasmineToString()); 1357 | } else if (typeof value === 'string') { 1358 | this.emitString(value); 1359 | } else if (j$.isSpy(value)) { 1360 | this.emitScalar("spy on " + value.and.identity()); 1361 | } else if (value instanceof RegExp) { 1362 | this.emitScalar(value.toString()); 1363 | } else if (typeof value === 'function') { 1364 | this.emitScalar('Function'); 1365 | } else if (typeof value.nodeType === 'number') { 1366 | this.emitScalar('HTMLNode'); 1367 | } else if (value instanceof Date) { 1368 | this.emitScalar('Date(' + value + ')'); 1369 | } else if (value.__Jasmine_been_here_before__) { 1370 | this.emitScalar(''); 1371 | } else if (j$.isArray_(value) || j$.isA_('Object', value)) { 1372 | value.__Jasmine_been_here_before__ = true; 1373 | if (j$.isArray_(value)) { 1374 | this.emitArray(value); 1375 | } else { 1376 | this.emitObject(value); 1377 | } 1378 | delete value.__Jasmine_been_here_before__; 1379 | } else { 1380 | this.emitScalar(value.toString()); 1381 | } 1382 | } finally { 1383 | this.ppNestLevel_--; 1384 | } 1385 | }; 1386 | 1387 | PrettyPrinter.prototype.iterateObject = function(obj, fn) { 1388 | for (var property in obj) { 1389 | if (!obj.hasOwnProperty(property)) { continue; } 1390 | if (property == '__Jasmine_been_here_before__') { continue; } 1391 | fn(property, obj.__lookupGetter__ ? (!j$.util.isUndefined(obj.__lookupGetter__(property)) && 1392 | obj.__lookupGetter__(property) !== null) : false); 1393 | } 1394 | }; 1395 | 1396 | PrettyPrinter.prototype.emitArray = j$.unimplementedMethod_; 1397 | PrettyPrinter.prototype.emitObject = j$.unimplementedMethod_; 1398 | PrettyPrinter.prototype.emitScalar = j$.unimplementedMethod_; 1399 | PrettyPrinter.prototype.emitString = j$.unimplementedMethod_; 1400 | 1401 | function StringPrettyPrinter() { 1402 | PrettyPrinter.call(this); 1403 | 1404 | this.string = ''; 1405 | } 1406 | 1407 | j$.util.inherit(StringPrettyPrinter, PrettyPrinter); 1408 | 1409 | StringPrettyPrinter.prototype.emitScalar = function(value) { 1410 | this.append(value); 1411 | }; 1412 | 1413 | StringPrettyPrinter.prototype.emitString = function(value) { 1414 | this.append("'" + value + "'"); 1415 | }; 1416 | 1417 | StringPrettyPrinter.prototype.emitArray = function(array) { 1418 | if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) { 1419 | this.append("Array"); 1420 | return; 1421 | } 1422 | 1423 | this.append('[ '); 1424 | for (var i = 0; i < array.length; i++) { 1425 | if (i > 0) { 1426 | this.append(', '); 1427 | } 1428 | this.format(array[i]); 1429 | } 1430 | this.append(' ]'); 1431 | }; 1432 | 1433 | StringPrettyPrinter.prototype.emitObject = function(obj) { 1434 | if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) { 1435 | this.append("Object"); 1436 | return; 1437 | } 1438 | 1439 | var self = this; 1440 | this.append('{ '); 1441 | var first = true; 1442 | 1443 | this.iterateObject(obj, function(property, isGetter) { 1444 | if (first) { 1445 | first = false; 1446 | } else { 1447 | self.append(', '); 1448 | } 1449 | 1450 | self.append(property); 1451 | self.append(' : '); 1452 | if (isGetter) { 1453 | self.append(''); 1454 | } else { 1455 | self.format(obj[property]); 1456 | } 1457 | }); 1458 | 1459 | this.append(' }'); 1460 | }; 1461 | 1462 | StringPrettyPrinter.prototype.append = function(value) { 1463 | this.string += value; 1464 | }; 1465 | 1466 | return function(value) { 1467 | var stringPrettyPrinter = new StringPrettyPrinter(); 1468 | stringPrettyPrinter.format(value); 1469 | return stringPrettyPrinter.string; 1470 | }; 1471 | }; 1472 | 1473 | getJasmineRequireObj().QueueRunner = function() { 1474 | 1475 | function QueueRunner(attrs) { 1476 | this.fns = attrs.fns || []; 1477 | this.onComplete = attrs.onComplete || function() {}; 1478 | this.clearStack = attrs.clearStack || function(fn) {fn();}; 1479 | this.onException = attrs.onException || function() {}; 1480 | this.catchException = attrs.catchException || function() { return true; }; 1481 | this.userContext = {}; 1482 | } 1483 | 1484 | QueueRunner.prototype.execute = function() { 1485 | this.run(this.fns, 0); 1486 | }; 1487 | 1488 | QueueRunner.prototype.run = function(fns, recursiveIndex) { 1489 | var length = fns.length, 1490 | self = this, 1491 | iterativeIndex; 1492 | 1493 | for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) { 1494 | var fn = fns[iterativeIndex]; 1495 | if (fn.length > 0) { 1496 | return attemptAsync(fn); 1497 | } else { 1498 | attemptSync(fn); 1499 | } 1500 | } 1501 | 1502 | var runnerDone = iterativeIndex >= length; 1503 | 1504 | if (runnerDone) { 1505 | this.clearStack(this.onComplete); 1506 | } 1507 | 1508 | function attemptSync(fn) { 1509 | try { 1510 | fn.call(self.userContext); 1511 | } catch (e) { 1512 | handleException(e); 1513 | } 1514 | } 1515 | 1516 | function attemptAsync(fn) { 1517 | var next = function () { self.run(fns, iterativeIndex + 1); }; 1518 | 1519 | try { 1520 | fn.call(self.userContext, next); 1521 | } catch (e) { 1522 | handleException(e); 1523 | next(); 1524 | } 1525 | } 1526 | 1527 | function handleException(e) { 1528 | self.onException(e); 1529 | if (!self.catchException(e)) { 1530 | //TODO: set a var when we catch an exception and 1531 | //use a finally block to close the loop in a nice way.. 1532 | throw e; 1533 | } 1534 | } 1535 | }; 1536 | 1537 | return QueueRunner; 1538 | }; 1539 | 1540 | getJasmineRequireObj().ReportDispatcher = function() { 1541 | function ReportDispatcher(methods) { 1542 | 1543 | var dispatchedMethods = methods || []; 1544 | 1545 | for (var i = 0; i < dispatchedMethods.length; i++) { 1546 | var method = dispatchedMethods[i]; 1547 | this[method] = (function(m) { 1548 | return function() { 1549 | dispatch(m, arguments); 1550 | }; 1551 | }(method)); 1552 | } 1553 | 1554 | var reporters = []; 1555 | 1556 | this.addReporter = function(reporter) { 1557 | reporters.push(reporter); 1558 | }; 1559 | 1560 | return this; 1561 | 1562 | function dispatch(method, args) { 1563 | for (var i = 0; i < reporters.length; i++) { 1564 | var reporter = reporters[i]; 1565 | if (reporter[method]) { 1566 | reporter[method].apply(reporter, args); 1567 | } 1568 | } 1569 | } 1570 | } 1571 | 1572 | return ReportDispatcher; 1573 | }; 1574 | 1575 | 1576 | getJasmineRequireObj().SpyStrategy = function() { 1577 | 1578 | function SpyStrategy(options) { 1579 | options = options || {}; 1580 | 1581 | var identity = options.name || "unknown", 1582 | originalFn = options.fn || function() {}, 1583 | getSpy = options.getSpy || function() {}, 1584 | plan = function() {}; 1585 | 1586 | this.identity = function() { 1587 | return identity; 1588 | }; 1589 | 1590 | this.exec = function() { 1591 | return plan.apply(this, arguments); 1592 | }; 1593 | 1594 | this.callThrough = function() { 1595 | plan = originalFn; 1596 | return getSpy(); 1597 | }; 1598 | 1599 | this.returnValue = function(value) { 1600 | plan = function() { 1601 | return value; 1602 | }; 1603 | return getSpy(); 1604 | }; 1605 | 1606 | this.throwError = function(something) { 1607 | var error = (something instanceof Error) ? something : new Error(something); 1608 | plan = function() { 1609 | throw error; 1610 | }; 1611 | return getSpy(); 1612 | }; 1613 | 1614 | this.callFake = function(fn) { 1615 | plan = fn; 1616 | return getSpy(); 1617 | }; 1618 | 1619 | this.stub = function(fn) { 1620 | plan = function() {}; 1621 | return getSpy(); 1622 | }; 1623 | } 1624 | 1625 | return SpyStrategy; 1626 | }; 1627 | 1628 | getJasmineRequireObj().Suite = function() { 1629 | function Suite(attrs) { 1630 | this.env = attrs.env; 1631 | this.id = attrs.id; 1632 | this.parentSuite = attrs.parentSuite; 1633 | this.description = attrs.description; 1634 | this.onStart = attrs.onStart || function() {}; 1635 | this.resultCallback = attrs.resultCallback || function() {}; 1636 | this.clearStack = attrs.clearStack || function(fn) {fn();}; 1637 | 1638 | this.beforeFns = []; 1639 | this.afterFns = []; 1640 | this.queueRunner = attrs.queueRunner || function() {}; 1641 | this.disabled = false; 1642 | 1643 | this.children = []; 1644 | 1645 | this.result = { 1646 | id: this.id, 1647 | status: this.disabled ? 'disabled' : '', 1648 | description: this.description, 1649 | fullName: this.getFullName() 1650 | }; 1651 | } 1652 | 1653 | Suite.prototype.getFullName = function() { 1654 | var fullName = this.description; 1655 | for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { 1656 | if (parentSuite.parentSuite) { 1657 | fullName = parentSuite.description + ' ' + fullName; 1658 | } 1659 | } 1660 | return fullName; 1661 | }; 1662 | 1663 | Suite.prototype.disable = function() { 1664 | this.disabled = true; 1665 | }; 1666 | 1667 | Suite.prototype.beforeEach = function(fn) { 1668 | this.beforeFns.unshift(fn); 1669 | }; 1670 | 1671 | Suite.prototype.afterEach = function(fn) { 1672 | this.afterFns.unshift(fn); 1673 | }; 1674 | 1675 | Suite.prototype.addChild = function(child) { 1676 | this.children.push(child); 1677 | }; 1678 | 1679 | Suite.prototype.execute = function(onComplete) { 1680 | var self = this; 1681 | if (this.disabled) { 1682 | complete(); 1683 | return; 1684 | } 1685 | 1686 | var allFns = []; 1687 | 1688 | for (var i = 0; i < this.children.length; i++) { 1689 | allFns.push(wrapChildAsAsync(this.children[i])); 1690 | } 1691 | 1692 | this.onStart(this); 1693 | 1694 | this.queueRunner({ 1695 | fns: allFns, 1696 | onComplete: complete 1697 | }); 1698 | 1699 | function complete() { 1700 | self.resultCallback(self.result); 1701 | 1702 | if (onComplete) { 1703 | onComplete(); 1704 | } 1705 | } 1706 | 1707 | function wrapChildAsAsync(child) { 1708 | return function(done) { child.execute(done); }; 1709 | } 1710 | }; 1711 | 1712 | return Suite; 1713 | }; 1714 | 1715 | if (typeof window == void 0 && typeof exports == "object") { 1716 | exports.Suite = jasmineRequire.Suite; 1717 | } 1718 | 1719 | getJasmineRequireObj().Timer = function() { 1720 | function Timer(options) { 1721 | options = options || {}; 1722 | 1723 | var now = options.now || function() { return new Date().getTime(); }, 1724 | startTime; 1725 | 1726 | this.start = function() { 1727 | startTime = now(); 1728 | }; 1729 | 1730 | this.elapsed = function() { 1731 | return now() - startTime; 1732 | }; 1733 | } 1734 | 1735 | return Timer; 1736 | }; 1737 | 1738 | getJasmineRequireObj().matchersUtil = function(j$) { 1739 | // TODO: what to do about jasmine.pp not being inject? move to JSON.stringify? gut PrettyPrinter? 1740 | 1741 | return { 1742 | equals: function(a, b, customTesters) { 1743 | customTesters = customTesters || []; 1744 | 1745 | return eq(a, b, [], [], customTesters); 1746 | }, 1747 | 1748 | contains: function(haystack, needle, customTesters) { 1749 | customTesters = customTesters || []; 1750 | 1751 | if (Object.prototype.toString.apply(haystack) === "[object Array]") { 1752 | for (var i = 0; i < haystack.length; i++) { 1753 | if (eq(haystack[i], needle, [], [], customTesters)) { 1754 | return true; 1755 | } 1756 | } 1757 | return false; 1758 | } 1759 | return haystack.indexOf(needle) >= 0; 1760 | }, 1761 | 1762 | buildFailureMessage: function() { 1763 | var args = Array.prototype.slice.call(arguments, 0), 1764 | matcherName = args[0], 1765 | isNot = args[1], 1766 | actual = args[2], 1767 | expected = args.slice(3), 1768 | englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); }); 1769 | 1770 | var message = "Expected " + 1771 | j$.pp(actual) + 1772 | (isNot ? " not " : " ") + 1773 | englishyPredicate; 1774 | 1775 | if (expected.length > 0) { 1776 | for (var i = 0; i < expected.length; i++) { 1777 | if (i > 0) { 1778 | message += ","; 1779 | } 1780 | message += " " + j$.pp(expected[i]); 1781 | } 1782 | } 1783 | 1784 | return message + "."; 1785 | } 1786 | }; 1787 | 1788 | // Equality function lovingly adapted from isEqual in 1789 | // [Underscore](http://underscorejs.org) 1790 | function eq(a, b, aStack, bStack, customTesters) { 1791 | var result = true; 1792 | 1793 | for (var i = 0; i < customTesters.length; i++) { 1794 | var customTesterResult = customTesters[i](a, b); 1795 | if (!j$.util.isUndefined(customTesterResult)) { 1796 | return customTesterResult; 1797 | } 1798 | } 1799 | 1800 | if (a instanceof j$.Any) { 1801 | result = a.jasmineMatches(b); 1802 | if (result) { 1803 | return true; 1804 | } 1805 | } 1806 | 1807 | if (b instanceof j$.Any) { 1808 | result = b.jasmineMatches(a); 1809 | if (result) { 1810 | return true; 1811 | } 1812 | } 1813 | 1814 | if (b instanceof j$.ObjectContaining) { 1815 | result = b.jasmineMatches(a); 1816 | if (result) { 1817 | return true; 1818 | } 1819 | } 1820 | 1821 | if (a instanceof Error && b instanceof Error) { 1822 | return a.message == b.message; 1823 | } 1824 | 1825 | // Identical objects are equal. `0 === -0`, but they aren't identical. 1826 | // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal). 1827 | if (a === b) { return a !== 0 || 1 / a == 1 / b; } 1828 | // A strict comparison is necessary because `null == undefined`. 1829 | if (a === null || b === null) { return a === b; } 1830 | var className = Object.prototype.toString.call(a); 1831 | if (className != Object.prototype.toString.call(b)) { return false; } 1832 | switch (className) { 1833 | // Strings, numbers, dates, and booleans are compared by value. 1834 | case '[object String]': 1835 | // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is 1836 | // equivalent to `new String("5")`. 1837 | return a == String(b); 1838 | case '[object Number]': 1839 | // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for 1840 | // other numeric values. 1841 | return a != +a ? b != +b : (a === 0 ? 1 / a == 1 / b : a == +b); 1842 | case '[object Date]': 1843 | case '[object Boolean]': 1844 | // Coerce dates and booleans to numeric primitive values. Dates are compared by their 1845 | // millisecond representations. Note that invalid dates with millisecond representations 1846 | // of `NaN` are not equivalent. 1847 | return +a == +b; 1848 | // RegExps are compared by their source patterns and flags. 1849 | case '[object RegExp]': 1850 | return a.source == b.source && 1851 | a.global == b.global && 1852 | a.multiline == b.multiline && 1853 | a.ignoreCase == b.ignoreCase; 1854 | } 1855 | if (typeof a != 'object' || typeof b != 'object') { return false; } 1856 | // Assume equality for cyclic structures. The algorithm for detecting cyclic 1857 | // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`. 1858 | var length = aStack.length; 1859 | while (length--) { 1860 | // Linear search. Performance is inversely proportional to the number of 1861 | // unique nested structures. 1862 | if (aStack[length] == a) { return bStack[length] == b; } 1863 | } 1864 | // Add the first object to the stack of traversed objects. 1865 | aStack.push(a); 1866 | bStack.push(b); 1867 | var size = 0; 1868 | // Recursively compare objects and arrays. 1869 | if (className == '[object Array]') { 1870 | // Compare array lengths to determine if a deep comparison is necessary. 1871 | size = a.length; 1872 | result = size == b.length; 1873 | if (result) { 1874 | // Deep compare the contents, ignoring non-numeric properties. 1875 | while (size--) { 1876 | if (!(result = eq(a[size], b[size], aStack, bStack, customTesters))) { break; } 1877 | } 1878 | } 1879 | } else { 1880 | // Objects with different constructors are not equivalent, but `Object`s 1881 | // from different frames are. 1882 | var aCtor = a.constructor, bCtor = b.constructor; 1883 | if (aCtor !== bCtor && !(isFunction(aCtor) && (aCtor instanceof aCtor) && 1884 | isFunction(bCtor) && (bCtor instanceof bCtor))) { 1885 | return false; 1886 | } 1887 | // Deep compare objects. 1888 | for (var key in a) { 1889 | if (has(a, key)) { 1890 | // Count the expected number of properties. 1891 | size++; 1892 | // Deep compare each member. 1893 | if (!(result = has(b, key) && eq(a[key], b[key], aStack, bStack, customTesters))) { break; } 1894 | } 1895 | } 1896 | // Ensure that both objects contain the same number of properties. 1897 | if (result) { 1898 | for (key in b) { 1899 | if (has(b, key) && !(size--)) { break; } 1900 | } 1901 | result = !size; 1902 | } 1903 | } 1904 | // Remove the first object from the stack of traversed objects. 1905 | aStack.pop(); 1906 | bStack.pop(); 1907 | 1908 | return result; 1909 | 1910 | function has(obj, key) { 1911 | return obj.hasOwnProperty(key); 1912 | } 1913 | 1914 | function isFunction(obj) { 1915 | return typeof obj === 'function'; 1916 | } 1917 | } 1918 | }; 1919 | 1920 | getJasmineRequireObj().toBe = function() { 1921 | function toBe() { 1922 | return { 1923 | compare: function(actual, expected) { 1924 | return { 1925 | pass: actual === expected 1926 | }; 1927 | } 1928 | }; 1929 | } 1930 | 1931 | return toBe; 1932 | }; 1933 | 1934 | getJasmineRequireObj().toBeCloseTo = function() { 1935 | 1936 | function toBeCloseTo() { 1937 | return { 1938 | compare: function(actual, expected, precision) { 1939 | if (precision !== 0) { 1940 | precision = precision || 2; 1941 | } 1942 | 1943 | return { 1944 | pass: Math.abs(expected - actual) < (Math.pow(10, -precision) / 2) 1945 | }; 1946 | } 1947 | }; 1948 | } 1949 | 1950 | return toBeCloseTo; 1951 | }; 1952 | 1953 | getJasmineRequireObj().toBeDefined = function() { 1954 | function toBeDefined() { 1955 | return { 1956 | compare: function(actual) { 1957 | return { 1958 | pass: (void 0 !== actual) 1959 | }; 1960 | } 1961 | }; 1962 | } 1963 | 1964 | return toBeDefined; 1965 | }; 1966 | 1967 | getJasmineRequireObj().toBeFalsy = function() { 1968 | function toBeFalsy() { 1969 | return { 1970 | compare: function(actual) { 1971 | return { 1972 | pass: !!!actual 1973 | }; 1974 | } 1975 | }; 1976 | } 1977 | 1978 | return toBeFalsy; 1979 | }; 1980 | 1981 | getJasmineRequireObj().toBeGreaterThan = function() { 1982 | 1983 | function toBeGreaterThan() { 1984 | return { 1985 | compare: function(actual, expected) { 1986 | return { 1987 | pass: actual > expected 1988 | }; 1989 | } 1990 | }; 1991 | } 1992 | 1993 | return toBeGreaterThan; 1994 | }; 1995 | 1996 | 1997 | getJasmineRequireObj().toBeLessThan = function() { 1998 | function toBeLessThan() { 1999 | return { 2000 | 2001 | compare: function(actual, expected) { 2002 | return { 2003 | pass: actual < expected 2004 | }; 2005 | } 2006 | }; 2007 | } 2008 | 2009 | return toBeLessThan; 2010 | }; 2011 | getJasmineRequireObj().toBeNaN = function(j$) { 2012 | 2013 | function toBeNaN() { 2014 | return { 2015 | compare: function(actual) { 2016 | var result = { 2017 | pass: (actual !== actual) 2018 | }; 2019 | 2020 | if (result.pass) { 2021 | result.message = "Expected actual not to be NaN."; 2022 | } else { 2023 | result.message = "Expected " + j$.pp(actual) + " to be NaN."; 2024 | } 2025 | 2026 | return result; 2027 | } 2028 | }; 2029 | } 2030 | 2031 | return toBeNaN; 2032 | }; 2033 | 2034 | getJasmineRequireObj().toBeNull = function() { 2035 | 2036 | function toBeNull() { 2037 | return { 2038 | compare: function(actual) { 2039 | return { 2040 | pass: actual === null 2041 | }; 2042 | } 2043 | }; 2044 | } 2045 | 2046 | return toBeNull; 2047 | }; 2048 | 2049 | getJasmineRequireObj().toBeTruthy = function() { 2050 | 2051 | function toBeTruthy() { 2052 | return { 2053 | compare: function(actual) { 2054 | return { 2055 | pass: !!actual 2056 | }; 2057 | } 2058 | }; 2059 | } 2060 | 2061 | return toBeTruthy; 2062 | }; 2063 | 2064 | getJasmineRequireObj().toBeUndefined = function() { 2065 | 2066 | function toBeUndefined() { 2067 | return { 2068 | compare: function(actual) { 2069 | return { 2070 | pass: void 0 === actual 2071 | }; 2072 | } 2073 | }; 2074 | } 2075 | 2076 | return toBeUndefined; 2077 | }; 2078 | 2079 | getJasmineRequireObj().toContain = function() { 2080 | function toContain(util, customEqualityTesters) { 2081 | customEqualityTesters = customEqualityTesters || []; 2082 | 2083 | return { 2084 | compare: function(actual, expected) { 2085 | 2086 | return { 2087 | pass: util.contains(actual, expected, customEqualityTesters) 2088 | }; 2089 | } 2090 | }; 2091 | } 2092 | 2093 | return toContain; 2094 | }; 2095 | 2096 | getJasmineRequireObj().toEqual = function() { 2097 | 2098 | function toEqual(util, customEqualityTesters) { 2099 | customEqualityTesters = customEqualityTesters || []; 2100 | 2101 | return { 2102 | compare: function(actual, expected) { 2103 | var result = { 2104 | pass: false 2105 | }; 2106 | 2107 | result.pass = util.equals(actual, expected, customEqualityTesters); 2108 | 2109 | return result; 2110 | } 2111 | }; 2112 | } 2113 | 2114 | return toEqual; 2115 | }; 2116 | 2117 | getJasmineRequireObj().toHaveBeenCalled = function(j$) { 2118 | 2119 | function toHaveBeenCalled() { 2120 | return { 2121 | compare: function(actual) { 2122 | var result = {}; 2123 | 2124 | if (!j$.isSpy(actual)) { 2125 | throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.'); 2126 | } 2127 | 2128 | if (arguments.length > 1) { 2129 | throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith'); 2130 | } 2131 | 2132 | result.pass = actual.calls.any(); 2133 | 2134 | result.message = result.pass ? 2135 | "Expected spy " + actual.and.identity() + " not to have been called." : 2136 | "Expected spy " + actual.and.identity() + " to have been called."; 2137 | 2138 | return result; 2139 | } 2140 | }; 2141 | } 2142 | 2143 | return toHaveBeenCalled; 2144 | }; 2145 | 2146 | getJasmineRequireObj().toHaveBeenCalledWith = function(j$) { 2147 | 2148 | function toHaveBeenCalledWith(util) { 2149 | return { 2150 | compare: function() { 2151 | var args = Array.prototype.slice.call(arguments, 0), 2152 | actual = args[0], 2153 | expectedArgs = args.slice(1), 2154 | result = { pass: false }; 2155 | 2156 | if (!j$.isSpy(actual)) { 2157 | throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.'); 2158 | } 2159 | 2160 | if (!actual.calls.any()) { 2161 | result.message = "Expected spy " + actual.and.identity() + " to have been called with " + j$.pp(expectedArgs) + " but it was never called."; 2162 | return result; 2163 | } 2164 | 2165 | if (util.contains(actual.calls.allArgs(), expectedArgs)) { 2166 | result.pass = true; 2167 | result.message = "Expected spy " + actual.and.identity() + " not to have been called with " + j$.pp(expectedArgs) + " but it was."; 2168 | } else { 2169 | result.message = "Expected spy " + actual.and.identity() + " to have been called with " + j$.pp(expectedArgs) + " but actual calls were " + j$.pp(actual.calls.allArgs()).replace(/^\[ | \]$/g, '') + "."; 2170 | } 2171 | 2172 | return result; 2173 | } 2174 | }; 2175 | } 2176 | 2177 | return toHaveBeenCalledWith; 2178 | }; 2179 | 2180 | getJasmineRequireObj().toMatch = function() { 2181 | 2182 | function toMatch() { 2183 | return { 2184 | compare: function(actual, expected) { 2185 | var regexp = new RegExp(expected); 2186 | 2187 | return { 2188 | pass: regexp.test(actual) 2189 | }; 2190 | } 2191 | }; 2192 | } 2193 | 2194 | return toMatch; 2195 | }; 2196 | 2197 | getJasmineRequireObj().toThrow = function(j$) { 2198 | 2199 | function toThrow(util) { 2200 | return { 2201 | compare: function(actual, expected) { 2202 | var result = { pass: false }, 2203 | threw = false, 2204 | thrown; 2205 | 2206 | if (typeof actual != "function") { 2207 | throw new Error("Actual is not a Function"); 2208 | } 2209 | 2210 | try { 2211 | actual(); 2212 | } catch (e) { 2213 | threw = true; 2214 | thrown = e; 2215 | } 2216 | 2217 | if (!threw) { 2218 | result.message = "Expected function to throw an exception."; 2219 | return result; 2220 | } 2221 | 2222 | if (arguments.length == 1) { 2223 | result.pass = true; 2224 | result.message = "Expected function not to throw, but it threw " + j$.pp(thrown) + "."; 2225 | 2226 | return result; 2227 | } 2228 | 2229 | if (util.equals(thrown, expected)) { 2230 | result.pass = true; 2231 | result.message = "Expected function not to throw " + j$.pp(expected) + "."; 2232 | } else { 2233 | result.message = "Expected function to throw " + j$.pp(expected) + ", but it threw " + j$.pp(thrown) + "."; 2234 | } 2235 | 2236 | return result; 2237 | } 2238 | }; 2239 | } 2240 | 2241 | return toThrow; 2242 | }; 2243 | 2244 | getJasmineRequireObj().toThrowError = function(j$) { 2245 | function toThrowError (util) { 2246 | return { 2247 | compare: function(actual) { 2248 | var threw = false, 2249 | thrown, 2250 | errorType, 2251 | message, 2252 | regexp, 2253 | name, 2254 | constructorName; 2255 | 2256 | if (typeof actual != "function") { 2257 | throw new Error("Actual is not a Function"); 2258 | } 2259 | 2260 | extractExpectedParams.apply(null, arguments); 2261 | 2262 | try { 2263 | actual(); 2264 | } catch (e) { 2265 | threw = true; 2266 | thrown = e; 2267 | } 2268 | 2269 | if (!threw) { 2270 | return fail("Expected function to throw an Error."); 2271 | } 2272 | 2273 | if (!(thrown instanceof Error)) { 2274 | return fail("Expected function to throw an Error, but it threw " + thrown + "."); 2275 | } 2276 | 2277 | if (arguments.length == 1) { 2278 | return pass("Expected function not to throw an Error, but it threw " + fnNameFor(thrown) + "."); 2279 | } 2280 | 2281 | if (errorType) { 2282 | name = fnNameFor(errorType); 2283 | constructorName = fnNameFor(thrown.constructor); 2284 | } 2285 | 2286 | if (errorType && message) { 2287 | if (thrown.constructor == errorType && util.equals(thrown.message, message)) { 2288 | return pass("Expected function not to throw " + name + " with message \"" + message + "\"."); 2289 | } else { 2290 | return fail("Expected function to throw " + name + " with message \"" + message + 2291 | "\", but it threw " + constructorName + " with message \"" + thrown.message + "\"."); 2292 | } 2293 | } 2294 | 2295 | if (errorType && regexp) { 2296 | if (thrown.constructor == errorType && regexp.test(thrown.message)) { 2297 | return pass("Expected function not to throw " + name + " with message matching " + regexp + "."); 2298 | } else { 2299 | return fail("Expected function to throw " + name + " with message matching " + regexp + 2300 | ", but it threw " + constructorName + " with message \"" + thrown.message + "\"."); 2301 | } 2302 | } 2303 | 2304 | if (errorType) { 2305 | if (thrown.constructor == errorType) { 2306 | return pass("Expected function not to throw " + name + "."); 2307 | } else { 2308 | return fail("Expected function to throw " + name + ", but it threw " + constructorName + "."); 2309 | } 2310 | } 2311 | 2312 | if (message) { 2313 | if (thrown.message == message) { 2314 | return pass("Expected function not to throw an exception with message " + j$.pp(message) + "."); 2315 | } else { 2316 | return fail("Expected function to throw an exception with message " + j$.pp(message) + 2317 | ", but it threw an exception with message " + j$.pp(thrown.message) + "."); 2318 | } 2319 | } 2320 | 2321 | if (regexp) { 2322 | if (regexp.test(thrown.message)) { 2323 | return pass("Expected function not to throw an exception with a message matching " + j$.pp(regexp) + "."); 2324 | } else { 2325 | return fail("Expected function to throw an exception with a message matching " + j$.pp(regexp) + 2326 | ", but it threw an exception with message " + j$.pp(thrown.message) + "."); 2327 | } 2328 | } 2329 | 2330 | function fnNameFor(func) { 2331 | return func.name || func.toString().match(/^\s*function\s*(\w*)\s*\(/)[1]; 2332 | } 2333 | 2334 | function pass(notMessage) { 2335 | return { 2336 | pass: true, 2337 | message: notMessage 2338 | }; 2339 | } 2340 | 2341 | function fail(message) { 2342 | return { 2343 | pass: false, 2344 | message: message 2345 | }; 2346 | } 2347 | 2348 | function extractExpectedParams() { 2349 | if (arguments.length == 1) { 2350 | return; 2351 | } 2352 | 2353 | if (arguments.length == 2) { 2354 | var expected = arguments[1]; 2355 | 2356 | if (expected instanceof RegExp) { 2357 | regexp = expected; 2358 | } else if (typeof expected == "string") { 2359 | message = expected; 2360 | } else if (checkForAnErrorType(expected)) { 2361 | errorType = expected; 2362 | } 2363 | 2364 | if (!(errorType || message || regexp)) { 2365 | throw new Error("Expected is not an Error, string, or RegExp."); 2366 | } 2367 | } else { 2368 | if (checkForAnErrorType(arguments[1])) { 2369 | errorType = arguments[1]; 2370 | } else { 2371 | throw new Error("Expected error type is not an Error."); 2372 | } 2373 | 2374 | if (arguments[2] instanceof RegExp) { 2375 | regexp = arguments[2]; 2376 | } else if (typeof arguments[2] == "string") { 2377 | message = arguments[2]; 2378 | } else { 2379 | throw new Error("Expected error message is not a string or RegExp."); 2380 | } 2381 | } 2382 | } 2383 | 2384 | function checkForAnErrorType(type) { 2385 | if (typeof type !== "function") { 2386 | return false; 2387 | } 2388 | 2389 | var Surrogate = function() {}; 2390 | Surrogate.prototype = type.prototype; 2391 | return (new Surrogate()) instanceof Error; 2392 | } 2393 | } 2394 | }; 2395 | } 2396 | 2397 | return toThrowError; 2398 | }; 2399 | 2400 | getJasmineRequireObj().version = function() { 2401 | return "2.0.0"; 2402 | }; 2403 | -------------------------------------------------------------------------------- /test/lib/jasmine-2.0.0/jasmine_favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/i-like-robots/react-tube-tracker/69df778ded1b4dca50e7e6022797284deb16ef33/test/lib/jasmine-2.0.0/jasmine_favicon.png -------------------------------------------------------------------------------- /test/lib/jasmine-2.0.0/mock-ajax.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Jasmine-Ajax : a set of helpers for testing AJAX requests under the Jasmine 4 | BDD framework for JavaScript. 5 | 6 | http://github.com/pivotal/jasmine-ajax 7 | 8 | Jasmine Home page: http://pivotal.github.com/jasmine 9 | 10 | Copyright (c) 2008-2013 Pivotal Labs 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining 13 | a copy of this software and associated documentation files (the 14 | "Software"), to deal in the Software without restriction, including 15 | without limitation the rights to use, copy, modify, merge, publish, 16 | distribute, sublicense, and/or sell copies of the Software, and to 17 | permit persons to whom the Software is furnished to do so, subject to 18 | the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be 21 | included in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 27 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 28 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 29 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | (function() { 34 | function extend(destination, source) { 35 | for (var property in source) { 36 | destination[property] = source[property]; 37 | } 38 | return destination; 39 | } 40 | 41 | function MockAjax(global) { 42 | var requestTracker = new RequestTracker(), 43 | stubTracker = new StubTracker(), 44 | realAjaxFunction = global.XMLHttpRequest, 45 | mockAjaxFunction = fakeRequest(requestTracker, stubTracker); 46 | 47 | this.install = function() { 48 | global.XMLHttpRequest = mockAjaxFunction; 49 | }; 50 | 51 | this.uninstall = function() { 52 | global.XMLHttpRequest = realAjaxFunction; 53 | 54 | this.stubs.reset(); 55 | this.requests.reset(); 56 | }; 57 | 58 | this.stubRequest = function(url, data) { 59 | var stub = new RequestStub(url, data); 60 | stubTracker.addStub(stub); 61 | return stub; 62 | }; 63 | 64 | this.withMock = function(closure) { 65 | this.install(); 66 | try { 67 | closure(); 68 | } finally { 69 | this.uninstall(); 70 | } 71 | }; 72 | 73 | this.requests = requestTracker; 74 | this.stubs = stubTracker; 75 | } 76 | 77 | function StubTracker() { 78 | var stubs = []; 79 | 80 | this.addStub = function(stub) { 81 | stubs.push(stub); 82 | }; 83 | 84 | this.reset = function() { 85 | stubs = []; 86 | }; 87 | 88 | this.findStub = function(url, data) { 89 | for (var i = stubs.length - 1; i >= 0; i--) { 90 | var stub = stubs[i]; 91 | if (stub.matches(url, data)) { 92 | return stub; 93 | } 94 | } 95 | }; 96 | } 97 | 98 | function fakeRequest(requestTracker, stubTracker) { 99 | function FakeXMLHttpRequest() { 100 | requestTracker.track(this); 101 | this.requestHeaders = {}; 102 | } 103 | 104 | extend(FakeXMLHttpRequest.prototype, new window.XMLHttpRequest()); 105 | extend(FakeXMLHttpRequest.prototype, { 106 | open: function() { 107 | this.method = arguments[0]; 108 | this.url = arguments[1]; 109 | this.username = arguments[3]; 110 | this.password = arguments[4]; 111 | this.readyState = 1; 112 | this.onreadystatechange(); 113 | }, 114 | 115 | setRequestHeader: function(header, value) { 116 | this.requestHeaders[header] = value; 117 | }, 118 | 119 | abort: function() { 120 | this.readyState = 0; 121 | this.status = 0; 122 | this.statusText = "abort"; 123 | this.onreadystatechange(); 124 | }, 125 | 126 | readyState: 0, 127 | 128 | onload: function() { 129 | }, 130 | 131 | onreadystatechange: function(isTimeout) { 132 | }, 133 | 134 | status: null, 135 | 136 | send: function(data) { 137 | this.params = data; 138 | this.readyState = 2; 139 | this.onreadystatechange(); 140 | 141 | var stub = stubTracker.findStub(this.url, data); 142 | if (stub) { 143 | this.response(stub); 144 | } 145 | }, 146 | 147 | data: function() { 148 | var data = {}; 149 | if (typeof this.params !== 'string') { return data; } 150 | var params = this.params.split('&'); 151 | 152 | for (var i = 0; i < params.length; ++i) { 153 | var kv = params[i].replace(/\+/g, ' ').split('='); 154 | var key = decodeURIComponent(kv[0]); 155 | data[key] = data[key] || []; 156 | data[key].push(decodeURIComponent(kv[1])); 157 | } 158 | return data; 159 | }, 160 | 161 | getResponseHeader: function(name) { 162 | return this.responseHeaders[name]; 163 | }, 164 | 165 | getAllResponseHeaders: function() { 166 | var responseHeaders = []; 167 | for (var i in this.responseHeaders) { 168 | if (this.responseHeaders.hasOwnProperty(i)) { 169 | responseHeaders.push(i + ': ' + this.responseHeaders[i]); 170 | } 171 | } 172 | return responseHeaders.join('\r\n'); 173 | }, 174 | 175 | responseText: null, 176 | 177 | response: function(response) { 178 | this.status = response.status; 179 | this.statusText = response.statusText || ""; 180 | this.responseXML = response.responseXML || ""; 181 | this.responseText = response.responseText || ""; 182 | this.readyState = 4; 183 | this.responseHeaders = response.responseHeaders || 184 | { "Content-type": response.contentType || (response.responseXML ? "text/xml" : "application/json") }; 185 | 186 | this.onload(); 187 | this.onreadystatechange(); 188 | }, 189 | 190 | responseTimeout: function() { 191 | this.readyState = 4; 192 | jasmine.clock().tick(30000); 193 | this.onreadystatechange('timeout'); 194 | } 195 | }); 196 | 197 | return FakeXMLHttpRequest; 198 | } 199 | 200 | function RequestTracker() { 201 | var requests = []; 202 | 203 | this.track = function(request) { 204 | requests.push(request); 205 | }; 206 | 207 | this.first = function() { 208 | return requests[0]; 209 | }; 210 | 211 | this.count = function() { 212 | return requests.length; 213 | }; 214 | 215 | this.reset = function() { 216 | requests = []; 217 | }; 218 | 219 | this.mostRecent = function() { 220 | return requests[requests.length - 1]; 221 | }; 222 | 223 | this.at = function(index) { 224 | return requests[index]; 225 | }; 226 | 227 | this.filter = function(url_to_match) { 228 | if (requests.length == 0) return []; 229 | var matching_requests = []; 230 | 231 | for (var i = 0; i < requests.length; i++) { 232 | if (url_to_match instanceof RegExp && 233 | url_to_match.test(requests[i].url)) { 234 | matching_requests.push(requests[i]); 235 | } else if (url_to_match instanceof Function && 236 | url_to_match(requests[i])) { 237 | matching_requests.push(requests[i]); 238 | } else { 239 | if (requests[i].url == url_to_match) { 240 | matching_requests.push(requests[i]); 241 | } 242 | } 243 | } 244 | 245 | return matching_requests; 246 | }; 247 | } 248 | 249 | function RequestStub(url, stubData) { 250 | var split = url.split('?'); 251 | this.url = split[0]; 252 | 253 | var normalizeQuery = function(query) { 254 | return query ? query.split('&').sort().join('&') : undefined; 255 | }; 256 | 257 | this.query = normalizeQuery(split[1]); 258 | this.data = normalizeQuery(stubData); 259 | 260 | this.andReturn = function(options) { 261 | this.status = options.status || 200; 262 | 263 | this.contentType = options.contentType; 264 | this.responseXML = options.responseXML; 265 | this.responseText = options.responseText; 266 | }; 267 | 268 | this.matches = function(fullUrl, data) { 269 | var urlSplit = fullUrl.split('?'), 270 | url = urlSplit[0], 271 | query = urlSplit[1]; 272 | return this.url === url && this.query === normalizeQuery(query) && (!this.data || this.data === normalizeQuery(data)); 273 | }; 274 | } 275 | 276 | if (typeof window === "undefined" && typeof exports === "object") { 277 | exports.MockAjax = MockAjax; 278 | jasmine.Ajax = new MockAjax(exports); 279 | } else { 280 | window.MockAjax = MockAjax; 281 | jasmine.Ajax = new MockAjax(window); 282 | } 283 | }()); 284 | -------------------------------------------------------------------------------- /test/lib/stub/component.js: -------------------------------------------------------------------------------- 1 | var React = require("react"); 2 | 3 | module.exports = function stub(mount, unmount) { 4 | var mixins = []; 5 | 6 | if (mount) { 7 | mixins.push({ 8 | componentDidMount: function() { 9 | mount.call(this); 10 | } 11 | }); 12 | } 13 | 14 | if (unmount) { 15 | mixins.push({ 16 | componentWillUnmount: function() { 17 | unmount.call(this); 18 | } 19 | }); 20 | } 21 | 22 | return React.createClass({ 23 | mixins: mixins, 24 | render: function() { 25 | return React.DOM.div(); 26 | } 27 | }); 28 | }; 29 | -------------------------------------------------------------------------------- /test/lib/stub/prediction.json: -------------------------------------------------------------------------------- 1 | { 2 | "request":{ 3 | "lineCode":"district", 4 | "stationCode":"940GZZLUEMB" 5 | }, 6 | "station":{ 7 | "lineName":"District", 8 | "stationName":"Embankment" 9 | }, 10 | "platforms":{ 11 | "Eastbound - Platform 2":[ 12 | { 13 | "$type":"Tfl.Api.Presentation.Entities.Prediction, Tfl.Api.Presentation.Entities", 14 | "id":"-3127690", 15 | "operationType":1, 16 | "vehicleId":"007", 17 | "naptanId":"940GZZLUEMB", 18 | "stationName":"Embankment Underground Station", 19 | "lineId":"district", 20 | "lineName":"District", 21 | "platformName":"Eastbound - Platform 2", 22 | "direction":"outbound", 23 | "destinationNaptanId":"940GZZLUUPM", 24 | "destinationName":"Upminster Underground Station", 25 | "timestamp":"2014-06-20T14:58:53.467Z", 26 | "timeToStation":106, 27 | "currentLocation":"Approaching Westminster", 28 | "towards":"Upminster", 29 | "expectedArrival":"2014-06-20T15:00:39.467Z", 30 | "timeToLive":"2014-06-20T15:00:39.467Z", 31 | "modeName":"tube" 32 | }, 33 | { 34 | "$type":"Tfl.Api.Presentation.Entities.Prediction, Tfl.Api.Presentation.Entities", 35 | "id":"-1703294318", 36 | "operationType":1, 37 | "vehicleId":"034", 38 | "naptanId":"940GZZLUEMB", 39 | "stationName":"Embankment Underground Station", 40 | "lineId":"district", 41 | "lineName":"District", 42 | "platformName":"Eastbound - Platform 2", 43 | "direction":"outbound", 44 | "destinationNaptanId":"940GZZLUUPM", 45 | "destinationName":"Upminster Underground Station", 46 | "timestamp":"2014-06-20T14:58:53.483Z", 47 | "timeToStation":346, 48 | "currentLocation":"Between Sloane Square and Victoria", 49 | "towards":"Upminster", 50 | "expectedArrival":"2014-06-20T15:04:39.483Z", 51 | "timeToLive":"2014-06-20T15:04:39.483Z", 52 | "modeName":"tube" 53 | }, 54 | { 55 | "$type":"Tfl.Api.Presentation.Entities.Prediction, Tfl.Api.Presentation.Entities", 56 | "id":"-898986643", 57 | "operationType":1, 58 | "vehicleId":"055", 59 | "naptanId":"940GZZLUEMB", 60 | "stationName":"Embankment Underground Station", 61 | "lineId":"district", 62 | "lineName":"District", 63 | "platformName":"Eastbound - Platform 2", 64 | "direction":"outbound", 65 | "destinationNaptanId":"940GZZLUTWH", 66 | "destinationName":"Tower Hill Underground Station", 67 | "timestamp":"2014-06-20T14:58:53.498Z", 68 | "timeToStation":406, 69 | "currentLocation":"At Sloane Square Platform 2", 70 | "towards":"Tower Hill", 71 | "expectedArrival":"2014-06-20T15:05:39.498Z", 72 | "timeToLive":"2014-06-20T15:05:39.498Z", 73 | "modeName":"tube" 74 | } 75 | ], 76 | "Westbound - Platform 1":[ 77 | { 78 | "$type":"Tfl.Api.Presentation.Entities.Prediction, Tfl.Api.Presentation.Entities", 79 | "id":"1764913547", 80 | "operationType":1, 81 | "vehicleId":"044", 82 | "naptanId":"940GZZLUEMB", 83 | "stationName":"Embankment Underground Station", 84 | "lineId":"district", 85 | "lineName":"District", 86 | "platformName":"Westbound - Platform 1", 87 | "direction":"inbound", 88 | "destinationNaptanId":"940GZZLUEBY", 89 | "destinationName":"Ealing Broadway Underground Station", 90 | "timestamp":"2014-06-20T14:58:53.436Z", 91 | "timeToStation":136, 92 | "currentLocation":"Between Blackfriars and Temple", 93 | "towards":"Ealing Broadway", 94 | "expectedArrival":"2014-06-20T15:01:09.436Z", 95 | "timeToLive":"2014-06-20T15:01:09.436Z", 96 | "modeName":"tube" 97 | }, 98 | { 99 | "$type":"Tfl.Api.Presentation.Entities.Prediction, Tfl.Api.Presentation.Entities", 100 | "id":"-1302106302", 101 | "operationType":1, 102 | "vehicleId":"065", 103 | "naptanId":"940GZZLUEMB", 104 | "stationName":"Embankment Underground Station", 105 | "lineId":"district", 106 | "lineName":"District", 107 | "platformName":"Westbound - Platform 1", 108 | "direction":"inbound", 109 | "destinationNaptanId":"940GZZLUWIM", 110 | "destinationName":"Wimbledon Underground Station", 111 | "timestamp":"2014-06-20T14:58:53.467Z", 112 | "timeToStation":286, 113 | "currentLocation":"Left Mansion House", 114 | "towards":"Wimbledon", 115 | "expectedArrival":"2014-06-20T15:03:39.467Z", 116 | "timeToLive":"2014-06-20T15:03:39.467Z", 117 | "modeName":"tube" 118 | }, 119 | { 120 | "$type":"Tfl.Api.Presentation.Entities.Prediction, Tfl.Api.Presentation.Entities", 121 | "id":"-3127725", 122 | "operationType":1, 123 | "vehicleId":"101", 124 | "naptanId":"940GZZLUEMB", 125 | "stationName":"Embankment Underground Station", 126 | "lineId":"district", 127 | "lineName":"District", 128 | "platformName":"Westbound - Platform 1", 129 | "direction":"inbound", 130 | "destinationNaptanId":"940GZZLUEBY", 131 | "destinationName":"Ealing Broadway Underground Station", 132 | "timestamp":"2014-06-20T14:58:53.467Z", 133 | "timeToStation":346, 134 | "currentLocation":"At Cannon Street Platform 1", 135 | "towards":"Ealing Broadway", 136 | "expectedArrival":"2014-06-20T15:04:39.467Z", 137 | "timeToLive":"2014-06-20T15:04:39.467Z", 138 | "modeName":"tube" 139 | }, 140 | { 141 | "$type":"Tfl.Api.Presentation.Entities.Prediction, Tfl.Api.Presentation.Entities", 142 | "id":"956742949", 143 | "operationType":1, 144 | "vehicleId":"020", 145 | "naptanId":"940GZZLUEMB", 146 | "stationName":"Embankment Underground Station", 147 | "lineId":"district", 148 | "lineName":"District", 149 | "platformName":"Westbound - Platform 1", 150 | "direction":"inbound", 151 | "destinationNaptanId":"940GZZLUWIM", 152 | "destinationName":"Wimbledon Underground Station", 153 | "timestamp":"2014-06-20T14:58:53.467Z", 154 | "timeToStation":466, 155 | "currentLocation":"Between Tower Hill and Monument", 156 | "towards":"Wimbledon", 157 | "expectedArrival":"2014-06-20T15:06:39.467Z", 158 | "timeToLive":"2014-06-20T15:06:39.467Z", 159 | "modeName":"tube" 160 | } 161 | ] 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /test/spec/common/utils.spec.js: -------------------------------------------------------------------------------- 1 | var utils = require("../../../app/common/utils"); 2 | var data = require("../../../app/common/data"); 3 | 4 | describe("Utils", function() { 5 | 6 | describe("Async", function() { 7 | 8 | describe(".debounceEvent()", function() { 9 | var instance; 10 | var interval; 11 | var bounceInc = 0; 12 | var callbackInc = 0; 13 | 14 | beforeEach(function(done) { 15 | instance = utils.debounceEvent(function() { 16 | callbackInc++; 17 | done(); 18 | }, 20); 19 | 20 | interval = setInterval(function() { 21 | if (bounceInc < 4) { 22 | bounceInc++; 23 | instance(); 24 | } 25 | }, 10); 26 | }); 27 | 28 | afterEach(function() { 29 | clearInterval(interval); 30 | }); 31 | 32 | it("should execute the given callback after being bounced 4 times", function(done) { 33 | expect(bounceInc).toBe(4); 34 | expect(callbackInc).toBe(1); 35 | done(); 36 | }); 37 | 38 | }); 39 | 40 | describe(".httpRequest()", function() { 41 | 42 | beforeEach(function() { 43 | jasmine.Ajax.install(); 44 | }); 45 | 46 | afterEach(function() { 47 | jasmine.Ajax.uninstall(); 48 | }); 49 | 50 | it("should provide the XML response to the given callback", function() { 51 | var success = jasmine.createSpy("success"); 52 | var error = jasmine.createSpy("error"); 53 | 54 | var mockDoc = "{[{\"fake\":\"data\"}]}"; 55 | 56 | jasmine.Ajax.stubRequest("a/fake/api").andReturn({ 57 | contentType: "text/xml", 58 | responseText: mockDoc, 59 | }); 60 | 61 | utils.httpRequest("a/fake/api", success, error); 62 | 63 | expect(success).toHaveBeenCalledWith(mockDoc); 64 | expect(error).not.toHaveBeenCalled(); 65 | }); 66 | 67 | }); 68 | 69 | }); 70 | 71 | describe("TfL API", function() { 72 | 73 | describe(".apiRequestURL()", function() { 74 | 75 | it("should return the request URL for the given line and station", function() { 76 | expect(utils.apiRequestURL("district", "940GZZLUEMB")).toBe("/api/district/940GZZLUEMB"); 77 | }); 78 | 79 | }); 80 | 81 | describe(".formattedTimeUntil()", function() { 82 | 83 | it("should round the number of seconds to the nearest 30 seconds", function() { 84 | expect(utils.formattedTimeUntil(120)).toBe("2:00"); 85 | expect(utils.formattedTimeUntil(145)).toBe("2:30"); 86 | expect(utils.formattedTimeUntil(165)).toBe("3:00"); 87 | }); 88 | 89 | }); 90 | 91 | }); 92 | 93 | describe("Location", function() { 94 | 95 | describe(".formatQueryString()", function() { 96 | 97 | it("should create a query string from the given map", function() { 98 | var map = { 99 | cat: "meow", 100 | dog: "woof" 101 | }; 102 | 103 | expect(utils.formatQueryString(map), "?cat=meow&dog=woof"); 104 | }); 105 | 106 | }); 107 | 108 | describe(".queryStringProperty()", function() { 109 | 110 | it("should return the value of the requested property from the given string", function() { 111 | var qs = "cat=meow&dog=woof"; 112 | expect(utils.queryStringProperty(qs, "cat")).toBe("meow"); 113 | expect(utils.queryStringProperty(qs, "dog")).toBe("woof"); 114 | }); 115 | 116 | }); 117 | 118 | }); 119 | 120 | describe("Data utils", function() { 121 | 122 | describe(".isLine()", function() { 123 | 124 | it("should return true for a correct line", function() { 125 | expect(utils.isLine("district", data)).toBe(true); 126 | }); 127 | 128 | it("should return false for an incorrect line", function() { 129 | expect(utils.isLine("distract", data)).toBe(false); 130 | }); 131 | 132 | }); 133 | 134 | describe(".isStation()", function() { 135 | 136 | it("should return true for a correct station", function() { 137 | expect(utils.isStation("940GZZLUEMB", data)).toBe(true); 138 | }); 139 | 140 | it("should return false for an incorrect station", function() { 141 | expect(utils.isStation("940GZZLUXYZ", data)).toBe(false); 142 | }); 143 | 144 | }); 145 | 146 | describe(".isStationOnLine()", function() { 147 | 148 | it("should return true for a correct line and station", function() { 149 | expect(utils.isStationOnLine("district", "940GZZLUEMB", data)).toBe(true); 150 | }); 151 | 152 | it("should return false for an incorrect line and station", function() { 153 | expect(utils.isStationOnLine("distract", "940GZZLUXYZ", data)).toBe(false); 154 | }); 155 | 156 | }); 157 | 158 | describe(".mergeGroupedLines()", function() { 159 | 160 | it("should return only the given line when it does not share platforms with others at the station", function() { 161 | var result = utils.mergeGroupedLines("940GZZLUOVL", "victoria", data); 162 | 163 | expect(result.length).toBe(1); 164 | expect(result).toContain("victoria"); 165 | }); 166 | 167 | it("should return all lines that share a platform with the given line at the station", function() { 168 | var result = utils.mergeGroupedLines("940GZZLUEMB", "circle", data); 169 | 170 | expect(result.length).toBe(2); 171 | expect(result).toContain("circle"); 172 | expect(result).toContain("district"); 173 | }); 174 | 175 | }); 176 | 177 | }); 178 | 179 | }); 180 | -------------------------------------------------------------------------------- /test/spec/component/network.spec.jsx: -------------------------------------------------------------------------------- 1 | var React = require("react/addons"); 2 | var networkData = require("../../../app/common/data"); 3 | var Network = require("../../../app/component/network.jsx"); 4 | 5 | var stubComponent = require("../../lib/stub/component"); 6 | var stubPrediction = require("../../lib/stub/prediction"); 7 | 8 | describe("Network", function() { 9 | 10 | var instance; 11 | var TestUtils = React.addons.TestUtils; 12 | 13 | afterEach(function() { 14 | if (instance && instance.isMounted()) { 15 | React.unmountComponentAtNode(React.findDOMNode(instance).parentNode); 16 | } 17 | }); 18 | 19 | describe("Network", function() { 20 | 21 | beforeEach(function() { 22 | this.stubbed = stubComponent(); 23 | this.original = Network.__get__("Line"); 24 | Network.__set__("Line", this.stubbed); 25 | 26 | instance = TestUtils.renderIntoDocument(); 27 | }); 28 | 29 | afterEach(function() { 30 | Network.__set__("Line", this.original); 31 | }); 32 | 33 | it("should render a form for each line available from TrackerNet", function() { 34 | var lines = TestUtils.scryRenderedComponentsWithType(instance, this.stubbed); 35 | expect(lines.length).toBe(11); 36 | }); 37 | 38 | it("should toggle open/closed status when clicking the toggle button", function() { 39 | var button = TestUtils.findRenderedDOMComponentWithTag(instance, "button"); 40 | var initialState = instance.state.open; 41 | 42 | TestUtils.Simulate.click(React.findDOMNode(button)); 43 | 44 | expect(instance.state.open).toBe(!initialState); 45 | }); 46 | 47 | }); 48 | 49 | describe("Line", function() { 50 | var Line = Network.__get__("Line"); 51 | 52 | beforeEach(function() { 53 | instance = TestUtils.renderIntoDocument(); 54 | }); 55 | 56 | it("should display the line name for the given line code", function() { 57 | var legend = TestUtils.findRenderedDOMComponentWithTag(instance, "legend"); 58 | expect(React.findDOMNode(legend).textContent).toBe("District"); 59 | }); 60 | 61 | it("should trigger a custom event with selected line and station", function() { 62 | var stubbedEvent = new CustomEvent("stub"); 63 | spyOn(window, "CustomEvent").and.returnValue(stubbedEvent); 64 | 65 | React.findDOMNode(instance.refs.station).value = "940GZZLUEMB"; 66 | TestUtils.Simulate.submit(React.findDOMNode(instance)); 67 | 68 | expect(window.CustomEvent).toHaveBeenCalled(); 69 | expect(window.CustomEvent.calls.argsFor(0).pop().detail).toEqual(jasmine.objectContaining({ 70 | station: "940GZZLUEMB", 71 | line: "district" 72 | })); 73 | }); 74 | 75 | }); 76 | 77 | }); 78 | -------------------------------------------------------------------------------- /test/spec/component/predictions.spec.jsx: -------------------------------------------------------------------------------- 1 | var React = require("react/addons"); 2 | var Predictions = require("../../../app/component/predictions.jsx"); 3 | 4 | var stubComponent = require("../../lib/stub/component"); 5 | var stubPrediction = require("../../lib/stub/prediction"); 6 | 7 | describe("Predictions", function() { 8 | 9 | var instance; 10 | var TestUtils = React.addons.TestUtils; 11 | 12 | beforeEach(function() { 13 | // Stub out AJAX requests with Jasmine's AJAX util 14 | jasmine.Ajax.install(); 15 | 16 | jasmine.Ajax.stubRequest("api/success").andReturn({ 17 | status: 200, 18 | contentType: "text/json", 19 | responseText: "{\"request\":{},\"station\":{},\"platforms\":{}}" 20 | }); 21 | 22 | jasmine.Ajax.stubRequest("api/failure").andReturn({ status: 500 }); 23 | }); 24 | 25 | afterEach(function() { 26 | jasmine.Ajax.uninstall(); 27 | 28 | // Teardown any fixtures that have been rendered into the container 29 | if (instance && instance.isMounted()) { 30 | React.unmountComponentAtNode(React.findDOMNode(instance).parentNode); 31 | } 32 | }); 33 | 34 | describe("Predictions", function() { 35 | 36 | describe("initial state", function() { 37 | var Notice = Predictions.__get__("Notice"); 38 | 39 | beforeEach(function() { 40 | // Prevent any HTTP requests, just test the initial state 41 | spyOn(Predictions.__get__("utils"), "httpRequest").and.stub(); 42 | }); 43 | 44 | it("should display the welcome message when a line/station is not set", function() { 45 | instance = TestUtils.renderIntoDocument(); 46 | 47 | // expect(TestUtils.isComponentOfType(instance.refs.content, Notice)).toBe(true); 48 | expect(instance.state.status).toBe("welcome"); 49 | }); 50 | 51 | it("should display the loading message when a line/station is set and valid", function() { 52 | instance = TestUtils.renderIntoDocument(); 53 | 54 | // expect(TestUtils.isComponentOfType(instance.refs.content, Notice)).toBe(true); 55 | expect(instance.state.status).toBe("loading"); 56 | }); 57 | 58 | }); 59 | 60 | describe("with valid departure data", function() { 61 | 62 | beforeEach(function() { 63 | spyOn(Predictions.__get__("utils"), "apiRequestURL").and.returnValue("api/success"); 64 | 65 | // The entire component stack should not be tested and must be stubbed. My mock 66 | // component also permits testing async component rendering. 67 | this.stubbed = stubComponent(); 68 | this.original = Predictions.__get__("DepartureBoard"); 69 | Predictions.__set__("DepartureBoard", this.stubbed); 70 | 71 | instance = TestUtils.renderIntoDocument(); 72 | }); 73 | 74 | afterEach(function() { 75 | Predictions.__set__("DepartureBoard", this.original); 76 | }); 77 | 78 | it("should display the departure board when valid data is received", function(done) { 79 | // expect(TestUtils.isComponentOfType(instance.refs.content, this.stubbed)).toBe(true); 80 | expect(instance.state.status).toBe("success"); 81 | done(); 82 | }); 83 | 84 | }); 85 | 86 | describe("on a data error", function() { 87 | 88 | beforeEach(function() { 89 | spyOn(Predictions.__get__("utils"), "apiRequestURL").and.returnValue("api/failure"); 90 | 91 | this.stubbed = stubComponent(); 92 | this.original = Predictions.__get__("Notice"); 93 | Predictions.__set__("Notice", this.stubbed); 94 | 95 | instance = TestUtils.renderIntoDocument(); 96 | }); 97 | 98 | afterEach(function() { 99 | Predictions.__set__("Notice", this.original); 100 | }); 101 | 102 | it("should display an error message", function(done) { 103 | // expect(TestUtils.isComponentOfType(instance.refs.content, this.stubbed)).toBe(true); 104 | expect(instance.state.status).toBe("error"); 105 | done(); 106 | }); 107 | 108 | }); 109 | 110 | }); 111 | 112 | describe("DepartureBoard", function() { 113 | var DepartureBoard = Predictions.__get__("DepartureBoard"); 114 | 115 | beforeEach(function() { 116 | instance = TestUtils.renderIntoDocument(); 117 | }); 118 | 119 | it("should display the selected line and station", function() { 120 | // the 'find' methods will return the first match found 121 | var heading = TestUtils.findRenderedDOMComponentWithTag(instance, "h1"); 122 | expect(heading.props.children).toBe("Embankment Station, District Line"); 123 | }); 124 | 125 | it("should display each platform at the station on the line", function() { 126 | // the 'scry' methods will return an array of all matches 127 | var platforms = TestUtils.scryRenderedDOMComponentsWithClass(instance, "platform"); 128 | expect(platforms.length).toBe(2); 129 | 130 | var headings = TestUtils.scryRenderedDOMComponentsWithClass(instance, "platform__heading"); 131 | expect(headings[0].props.children).toBe("Eastbound - Platform 2"); 132 | expect(headings[1].props.children).toBe("Westbound - Platform 1"); 133 | }); 134 | 135 | }); 136 | 137 | describe("Trains", function() { 138 | var Trains = Predictions.__get__("Trains"); 139 | 140 | beforeEach(function() { 141 | var trains = stubPrediction.platforms["Eastbound - Platform 2"]; 142 | instance = TestUtils.renderIntoDocument(); 143 | }); 144 | 145 | it("should render a table row for each train", function() { 146 | var arrivals = TestUtils.scryRenderedDOMComponentsWithClass(instance, "trains__arrival"); 147 | expect(arrivals.length).toBe(3); 148 | }); 149 | 150 | it("should display the train time until, destination and current location", function() { 151 | var arrivals = TestUtils.scryRenderedDOMComponentsWithClass(instance, "trains__arrival"); 152 | var columns = TestUtils.scryRenderedDOMComponentsWithTag(arrivals.shift(), "td"); 153 | 154 | // The rendered DOM nodes can be accessed and inspected 155 | expect(columns[0].props.children).toBe("2:00"); 156 | expect(columns[1].props.children).toBe("Upminster"); 157 | expect(columns[2].props.children).toBe("District"); 158 | expect(columns[3].props.children).toBe("Approaching Westminster"); 159 | }); 160 | 161 | }); 162 | 163 | describe("Notice", function() { 164 | var Notice = Predictions.__get__("Notice"); 165 | 166 | beforeEach(function() { 167 | instance = TestUtils.renderIntoDocument(); 168 | }); 169 | 170 | it("should display the error message when given type is 'error'", function() { 171 | expect(instance.statusText("error")).toBe("Sorry an error occurred, please try again."); 172 | }); 173 | 174 | it("should display the loading message when given type is 'loading'", function() { 175 | expect(instance.statusText("loading")).toBe("Loading predictions…"); 176 | }); 177 | 178 | it("should display the welcome message when given type is 'welcome'", function() { 179 | expect(instance.statusText("welcome")).toBe("Please choose a station."); 180 | }); 181 | 182 | }); 183 | 184 | }); 185 | -------------------------------------------------------------------------------- /test/spec/component/tube-tracker.spec.jsx: -------------------------------------------------------------------------------- 1 | var React = require("react/addons"); 2 | var networkData = require("../../../app/common/data"); 3 | var TubeTracker = require("../../../app/component/tube-tracker.jsx"); 4 | 5 | var stubComponent = require("../../lib/stub/component"); 6 | var stubPrediction = require("../../lib/stub/prediction"); 7 | 8 | describe("Tube Tracker", function() { 9 | 10 | var instance; 11 | var TestUtils = React.addons.TestUtils; 12 | 13 | beforeEach(function() { 14 | this.original = { 15 | network: TubeTracker.__get__("Network"), 16 | predictions: TubeTracker.__get__("Predictions") 17 | }; 18 | 19 | this.stubbed ={ 20 | network: stubComponent(), 21 | predictions: stubComponent() 22 | }; 23 | 24 | TubeTracker.__set__({ 25 | Network: this.stubbed.network, 26 | Predictions: this.stubbed.predictions 27 | }); 28 | }); 29 | 30 | afterEach(function() { 31 | TubeTracker.__set__({ 32 | Network: this.original.network, 33 | Predictions: this.original.predictions 34 | }); 35 | }); 36 | 37 | describe("initial state", function() { 38 | var stubs = [ 39 | { 40 | request: { 41 | lineCode: "distract", 42 | stationCode: "940GZZLUXYZ" 43 | } 44 | }, 45 | { 46 | request: { 47 | lineCode: "district", 48 | stationCode: "940GZZLUEMB" 49 | } 50 | } 51 | ]; 52 | 53 | beforeEach(function() { 54 | // A convenient way to test multiple stubs 55 | instance = TestUtils.renderIntoDocument(); 56 | }); 57 | 58 | it("should not set the line/station when the provided data is invalid", function() { 59 | expect(instance.state.line).toBe(null); 60 | expect(instance.state.station).toBe(null); 61 | }); 62 | 63 | it("should set the line/station when the provided data is valid", function() { 64 | expect(instance.state.line).toBe("district"); 65 | expect(instance.state.station).toBe("940GZZLUEMB"); 66 | }); 67 | 68 | }); 69 | 70 | describe("on user input", function() { 71 | 72 | beforeEach(function() { 73 | spyOn(window.history, "pushState").and.stub(); 74 | instance = TestUtils.renderIntoDocument(); 75 | }); 76 | 77 | it("should not set the line/station when received data is invalid", function() { 78 | // There is no easy way to simulate custom events but component methods can be called directly 79 | instance.handleUpdate({ detail: { line: "distract", station: "940GZZLUXYZ" } }); 80 | expect(window.history.pushState).not.toHaveBeenCalled(); 81 | }); 82 | 83 | it("should set the line/station when received data is valid", function() { 84 | instance.handleUpdate({ detail: { line: "district", station: "940GZZLUEMB" } }); 85 | expect(window.history.pushState).toHaveBeenCalledWith(null, null, "?line=district&station=940GZZLUEMB"); 86 | }); 87 | 88 | }); 89 | 90 | }); 91 | -------------------------------------------------------------------------------- /test/spec/suite.js: -------------------------------------------------------------------------------- 1 | // Include all specs here, this should be dynamic 2 | require("./common/utils.spec"); 3 | require("./component/network.spec.jsx"); 4 | require("./component/predictions.spec.jsx"); 5 | require("./component/tube-tracker.spec.jsx"); 6 | --------------------------------------------------------------------------------