aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/tests/js/filesSpec.js
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-10-30 14:37:19 +0100
committerVincent Petry <pvince81@owncloud.com>2015-10-30 14:58:53 +0100
commit80cf4e84e32f09838e9f9e362568f02642ef7658 (patch)
tree3bcb07d844f1002b8027aa37f79db5f16ccf1643 /apps/files/tests/js/filesSpec.js
parent73d9699be9d2a343b0573dc6a5bcc65f5f9c7303 (diff)
downloadnextcloud-server-80cf4e84e32f09838e9f9e362568f02642ef7658.tar.gz
nextcloud-server-80cf4e84e32f09838e9f9e362568f02642ef7658.zip
Fix file action download spinner
Diffstat (limited to 'apps/files/tests/js/filesSpec.js')
-rw-r--r--apps/files/tests/js/filesSpec.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/apps/files/tests/js/filesSpec.js b/apps/files/tests/js/filesSpec.js
index f20ba03e2f1..30e6675c155 100644
--- a/apps/files/tests/js/filesSpec.js
+++ b/apps/files/tests/js/filesSpec.js
@@ -87,4 +87,56 @@ describe('OCA.Files.Files tests', function() {
expect(url).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=%5B%22test%20file.txt%22%2C%22abc.txt%22%5D');
});
});
+ describe('handleDownload', function() {
+ var redirectStub;
+ var cookieStub;
+ var clock;
+ var testUrl;
+
+ beforeEach(function() {
+ testUrl = 'http://example.com/owncloud/path/download.php';
+ redirectStub = sinon.stub(OC, 'redirect');
+ cookieStub = sinon.stub(OC.Util, 'isCookieSetToValue');
+ clock = sinon.useFakeTimers();
+ });
+ afterEach(function() {
+ redirectStub.restore();
+ cookieStub.restore();
+ clock.restore();
+ });
+
+ it('appends secret to url when no existing parameters', function() {
+ Files.handleDownload(testUrl);
+ expect(redirectStub.calledOnce).toEqual(true);
+ expect(redirectStub.getCall(0).args[0]).toContain(testUrl + '?downloadStartSecret=');
+ });
+ it('appends secret to url with existing parameters', function() {
+ Files.handleDownload(testUrl + '?test=1');
+ expect(redirectStub.calledOnce).toEqual(true);
+ expect(redirectStub.getCall(0).args[0]).toContain(testUrl + '?test=1&downloadStartSecret=');
+ });
+ it('sets cookie and calls callback when cookie appears', function() {
+ var callbackStub = sinon.stub();
+ var token;
+ Files.handleDownload(testUrl, callbackStub);
+ expect(redirectStub.calledOnce).toEqual(true);
+ token = OC.parseQueryString(redirectStub.getCall(0).args[0]).downloadStartSecret;
+ expect(token).toBeDefined();
+
+ expect(cookieStub.calledOnce).toEqual(true);
+ cookieStub.returns(false);
+ clock.tick(600);
+
+ expect(cookieStub.calledTwice).toEqual(true);
+ expect(cookieStub.getCall(1).args[0]).toEqual('ocDownloadStarted');
+ expect(cookieStub.getCall(1).args[1]).toEqual(token);
+ expect(callbackStub.notCalled).toEqual(true);
+
+ cookieStub.returns(true);
+ clock.tick(2000);
+
+ expect(cookieStub.callCount).toEqual(3);
+ expect(callbackStub.calledOnce).toEqual(true);
+ });
+ });
});