diff --git a/resources/static/shared/modules/xhr_delay.js b/resources/static/shared/modules/xhr_delay.js index 2e1eb6c10f7291ad5ea9da752a08307873965265..3186f8c9b28b06f4b17e07ea633ae14d2b92e9ca 100644 --- a/resources/static/shared/modules/xhr_delay.js +++ b/resources/static/shared/modules/xhr_delay.js @@ -7,14 +7,32 @@ BrowserID.Modules.XHRDelay = (function() { var bid = BrowserID, wait = bid.Wait, + delayed, sc; + function delayStart() { + delayed = true; + // XXX - This has a flaw in it. If the user is waiting for at the email + // validation screen and an XHR delay occurs, it will overwrite the waiting + // for validation screen. When the xhr delay completes, then it will take + // away all wait screens and show the add email screen. Perhaps we need + // a new screen/layer to avoid this. + this.renderWait("wait", wait.slowXHR); + } + + function delayStop() { + if(delayed) { + delayed = false; + this.hideWait(); + } + } + var Module = bid.Modules.PageModule.extend({ start: function(options) { var self=this; - self.subscribe("xhr_delay", this.renderWait.curry("wait", wait.slowXHR)); - self.subscribe("xhr_complete", this.hideWait); + self.subscribe("xhr_delay", delayStart); + self.subscribe("xhr_complete", delayStop); sc.start.call(self, options); }, diff --git a/resources/static/test/qunit/shared/modules/xhr_delay_unit_test.js b/resources/static/test/qunit/shared/modules/xhr_delay_unit_test.js index e6588d1b53f517fdede6a3ffa75ed5c995486ae5..1b06fa218eef998f45388b500b82745fac594bcf 100644 --- a/resources/static/test/qunit/shared/modules/xhr_delay_unit_test.js +++ b/resources/static/test/qunit/shared/modules/xhr_delay_unit_test.js @@ -10,6 +10,7 @@ Module = bid.Modules.XHRDelay, testHelpers = bid.TestHelpers, mediator = bid.Mediator, + screens = bid.Screens, mod; function createModule(options) { @@ -31,10 +32,18 @@ test("xhr_delay shows the wait screen, xhr_complete hides the wait screen", function() { mediator.publish("xhr_delay"); - ok($("#slowXHR:visible").length, "slowXHR error screen is shown"); - equal($("body").hasClass("waiting"), true, "waiting screen shown"); + ok($("#slowXHR:visible").length, "slowXHR screen is shown"); + testHelpers.testWaitVisible(); mediator.publish("xhr_complete"); - equal($("body").hasClass("waiting"), false, "waiting screen not shown"); + equal(testHelpers.waitVisible(), false, "slowXHR screen no longer visible"); + }); + + test("xhr_complete does not hide wait screen if wait screen not started by xhr_delay", function() { + + screens.wait.show("wait", {title: "test wait", message: "testing"}); + + mediator.publish("xhr_complete"); + testHelpers.testWaitVisible(); }); }()); diff --git a/resources/static/test/qunit/testHelpers/helpers.js b/resources/static/test/qunit/testHelpers/helpers.js index f7703e275999f70d6b2f5c4b5e00a5f064b2d230..70323eb424b4c85c9389d4b20beec1b6ba5daf6b 100644 --- a/resources/static/test/qunit/testHelpers/helpers.js +++ b/resources/static/test/qunit/testHelpers/helpers.js @@ -112,6 +112,14 @@ BrowserID.TestHelpers = (function() { equal(TestHelpers.errorVisible(), true, "error screen is visible"); }, + waitVisible: function() { + return screens.wait.visible; + }, + + testWaitVisible: function() { + equal(TestHelpers.waitVisible(), true, "wait screen is visible"); + }, + checkNetworkError: checkNetworkError, unexpectedSuccess: function() { ok(false, "unexpected success");