From bd9a380d53f80264f9be192840ca2473ec0f2982 Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Wed, 20 Apr 2016 16:31:04 +0100 Subject: [PATCH 1/2] Delay reloading the page if an ajax error occurs, show notification --- core/js/js.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/js/js.js b/core/js/js.js index 188c15c5db5..5deb2a23610 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -752,7 +752,8 @@ var OC={ // sometimes "beforeunload" happens later, so need to defer the reload a bit setTimeout(function() { if (!self._userIsNavigatingAway && !self._reloadCalled) { - OC.reload(); + OC.Notification.show(t('core', 'Problem loading page, reloading in 5 seconds')); + setTimeout(OC.reload, 5000); // only call reload once self._reloadCalled = true; } From 62024d74d407514beb7773879cba895b457e87cb Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Wed, 20 Apr 2016 22:09:59 +0100 Subject: [PATCH 2/2] Add test for reload delay --- core/js/tests/specs/coreSpec.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js index 83441104289..ce7f0928626 100644 --- a/core/js/tests/specs/coreSpec.js +++ b/core/js/tests/specs/coreSpec.js @@ -936,10 +936,13 @@ describe('Core base tests', function() { }); describe('global ajax errors', function() { var reloadStub, ajaxErrorStub, clock; + var notificationStub; + var waitTimeMs = 6000; beforeEach(function() { clock = sinon.useFakeTimers(); reloadStub = sinon.stub(OC, 'reload'); + notificationStub = sinon.stub(OC.Notification, 'show'); // unstub the error processing method ajaxErrorStub = OC._processAjaxError; ajaxErrorStub.restore(); @@ -947,6 +950,7 @@ describe('Core base tests', function() { }); afterEach(function() { reloadStub.restore(); + notificationStub.restore(); clock.restore(); }); @@ -971,7 +975,7 @@ describe('Core base tests', function() { $(document).trigger(new $.Event('ajaxError'), xhr); // trigger timers - clock.tick(1000); + clock.tick(waitTimeMs); if (expectedCall) { expect(reloadStub.calledOnce).toEqual(true); @@ -987,7 +991,7 @@ describe('Core base tests', function() { $(document).trigger(new $.Event('ajaxError'), xhr); // trigger timers - clock.tick(1000); + clock.tick(waitTimeMs); expect(reloadStub.calledOnce).toEqual(true); }); @@ -998,9 +1002,17 @@ describe('Core base tests', function() { $(document).trigger(new $.Event('ajaxError'), xhr); - clock.tick(1000); + clock.tick(waitTimeMs); expect(reloadStub.notCalled).toEqual(true); }); + it('displays notification', function() { + var xhr = { status: 401 }; + + $(document).trigger(new $.Event('ajaxError'), xhr); + + clock.tick(waitTimeMs); + expect(notificationStub.calledOnce).toEqual(true); + }); }); });