diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-12-10 18:08:40 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2016-02-15 12:48:47 +0100 |
commit | b8b77709c05df3d820af2bfc83ff9d386bc19990 (patch) | |
tree | 68a6f739b0d9f4af62d2169340d2c3b35e30d27a /core/js/tests/specs | |
parent | 294dcb4efffabc30fb85f50f2e01af2904b476a6 (diff) | |
download | nextcloud-server-b8b77709c05df3d820af2bfc83ff9d386bc19990.tar.gz nextcloud-server-b8b77709c05df3d820af2bfc83ff9d386bc19990.zip |
Add handler for global ajax errors
Diffstat (limited to 'core/js/tests/specs')
-rw-r--r-- | core/js/tests/specs/coreSpec.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js index 2e970f7e707..32eb8df32d1 100644 --- a/core/js/tests/specs/coreSpec.js +++ b/core/js/tests/specs/coreSpec.js @@ -302,6 +302,7 @@ describe('Core base tests', function() { /* jshint camelcase: false */ window.oc_config = oldConfig; routeStub.restore(); + $(document).off('ajaxError'); }); it('sends heartbeat half the session lifetime when heartbeat enabled', function() { /* jshint camelcase: false */ @@ -473,6 +474,7 @@ describe('Core base tests', function() { }); afterEach(function() { clock.restore(); + $(document).off('ajaxError'); }); it('Sets up menu toggle', function() { window.initCore(); @@ -841,5 +843,45 @@ describe('Core base tests', function() { // verification is done in afterEach }); }); + describe('global ajax errors', function() { + var reloadStub, ajaxErrorStub; + + beforeEach(function() { + reloadStub = sinon.stub(OC, 'reload'); + // unstub the error processing method + ajaxErrorStub = OC._processAjaxError; + ajaxErrorStub.restore(); + window.initCore(); + }); + afterEach(function() { + reloadStub.restore(); + $(document).off('ajaxError'); + }); + + it('reloads current page in case of auth error', function () { + var dataProvider = [ + [200, false], + [400, false], + [401, true], + [302, true], + [307, true] + ]; + + for (var i = 0; i < dataProvider.length; i++) { + var xhr = { status: dataProvider[i][0] }; + var expectedCall = dataProvider[i][1]; + + reloadStub.reset(); + + $(document).trigger(new $.Event('ajaxError'), xhr); + + if (expectedCall) { + expect(reloadStub.calledOnce).toEqual(true); + } else { + expect(reloadStub.notCalled).toEqual(true); + } + } + }); + }) }); |