Add test for reload delay

This commit is contained in:
Robin McCorkell 2016-04-20 22:09:59 +01:00 committed by Vincent Petry
parent 40f066ab6d
commit 3f16ce7403
No known key found for this signature in database
GPG Key ID: AF8F9EFC56562186
1 changed files with 15 additions and 3 deletions

View File

@ -935,10 +935,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();
@ -946,6 +949,7 @@ describe('Core base tests', function() {
});
afterEach(function() {
reloadStub.restore();
notificationStub.restore();
clock.restore();
});
@ -970,7 +974,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);
@ -986,7 +990,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);
});
@ -997,9 +1001,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);
});
});
});