3
3
YUI().use('lp.testing.runner', 'test', 'console', 'node', 'lp', 'lp.client',
4
4
'event-focus', 'event-simulate', 'lazr.picker', 'lazr.person-picker',
5
5
'lp.app.picker', 'node-event-simulate', 'escape', 'event',
9
9
var Assert = Y.Assert;
373
373
{yio: this.mock_io});
376
get_oops_headers: function(oops) {
378
headers['X-Lazr-OopsId'] = oops;
376
make_error_response: function(status, oops) {
377
if (oops === undefined) {
382
getResponseHeader: function(header) {
383
if (header === 'X-Lazr-OopsId') {
382
390
test_oops: function() {
383
391
// A 500 (ISE) with an OOPS ID informs the user that we've
384
392
// logged it, and gives them the OOPS ID.
385
this.mock_io.failure(
386
{responseHeaders: this.get_oops_headers('OOPS')});
393
this.mock_io.simulateXhr(this.make_error_response(500, 'OOPS'), true);
388
395
"Sorry, something went wrong with your search. We've recorded " +
389
396
"what happened, and we'll fix it as soon as possible. " +
394
401
test_timeout: function() {
395
402
// A 503 (timeout) or 502/504 (proxy error) informs the user
396
403
// that they should retry, and gives them the OOPS ID.
397
this.mock_io.failure(
398
{status: 503, responseHeaders: this.get_oops_headers('OOPS')});
404
this.mock_io.simulateXhr(this.make_error_response(503, 'OOPS'), true);
400
406
"Sorry, something went wrong with your search. Trying again " +
401
407
"in a couple of minutes might work. (Error ID: OOPS)",
405
411
test_other_error: function() {
406
412
// Any other type of error just displays a generic failure
407
413
// message, with no OOPS ID.
408
this.mock_io.failure({status: 400});
414
this.mock_io.simulateXhr(this.make_error_response(400), true);
410
416
"Sorry, something went wrong with your search.",
411
417
this.picker.get('error'));
445
451
// If an automated search (like loading branch suggestions) returns
446
452
// results and the user has submitted a search, then the results of
447
453
// the automated search are ignored so as not to confuse the user.
448
var mock_io = new Y.lp.testing.mockio.MockIo();
454
var mock_io = new Y.lazr.testing.MockIo();
449
455
var picker = this.create_picker(mock_io);
450
456
// First an automated search is run.
451
457
picker.fire('search', 'guess', undefined, true);
458
// We have to stash away the mock IO's on-success handler because
459
// it'll get clobbered by the second searc if we don't.
460
automated_success = mock_io.cfg.on.success;
452
461
// Then the user initiates their own search.
453
462
picker.fire('search', 'test');
454
// Two requests have been sent out.
455
Y.Assert.areEqual(2, mock_io.requests.length);
456
// Respond to the automated request.
457
mock_io.requests[0].respond({responseText: '{"entries": 1}'});
463
// Now to get ahold of the user-initiated search's on-success.
464
user_success = mock_io.cfg.on.success;
465
// Now, if the automated search returns...
466
mock_io.cfg.on.success = automated_success;
467
mock_io.simulateXhr(this.make_response(200, null, '{"entries": 1}'));
458
468
// ... the results are ignored.
459
469
Assert.areNotEqual(1, picker.get('results'));
460
// Respond to the user request.
461
mock_io.requests[1].respond({responseText: '{"entries": 2}'});
470
// But if the user's search returns, the results are kept.
471
mock_io.cfg.on.success = user_success;
472
mock_io.simulateXhr(this.make_response(200, null, '{"entries": 2}'));
462
473
Assert.areEqual(2, picker.get('results'));
463
474
cleanup_widget(picker);
467
478
// If an automated search (like loading branch suggestions) returns an
468
479
// error and the user has submitted a search, then the error from the
469
480
// automated search is ignored so as not to confuse the user.
470
var mock_io = new Y.lp.testing.mockio.MockIo();
481
var mock_io = new Y.lazr.testing.MockIo();
471
482
var picker = this.create_picker(mock_io);
472
483
picker.fire('search', 'test');
473
484
picker.fire('search', 'guess', undefined, true);
485
mock_io.simulateXhr(this.make_response(500, 'OOPS'), true);
475
486
Assert.areEqual(null, picker.get('error'));
476
487
cleanup_widget(picker);