From abd0ba1f2593770833ed6bf886c72b1c24817ecf Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 21 Oct 2015 11:46:51 +0200 Subject: Fix file upload, conflict dialog, also in public link - Use "FileList" instead of "OCA.Files.App.fileList" that doesn't exist in public link page. - Fix public link upload by properly adding the form data using a new utility function "addFormData". That one is needed because IE8 upload and regular upload use a different format... --- apps/files/tests/js/fileUploadSpec.js | 96 +++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) (limited to 'apps/files/tests') diff --git a/apps/files/tests/js/fileUploadSpec.js b/apps/files/tests/js/fileUploadSpec.js index cad8468d1c8..a49a5d4e2e0 100644 --- a/apps/files/tests/js/fileUploadSpec.js +++ b/apps/files/tests/js/fileUploadSpec.js @@ -117,4 +117,100 @@ describe('OC.Upload tests', function() { ); }); }); + describe('Upload conflicts', function() { + var oldFileList; + var conflictDialogStub; + var callbacks; + + beforeEach(function() { + oldFileList = FileList; + $('#testArea').append( + '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
' + + '
' + ); + FileList = new OCA.Files.FileList($('#tableContainer')); + + FileList.add({name: 'conflict.txt', mimetype: 'text/plain'}); + FileList.add({name: 'conflict2.txt', mimetype: 'text/plain'}); + + conflictDialogStub = sinon.stub(OC.dialogs, 'fileexists'); + callbacks = { + onNoConflicts: sinon.stub() + }; + }); + afterEach(function() { + conflictDialogStub.restore(); + + FileList.destroy(); + FileList = oldFileList; + }); + it('does not show conflict dialog when no client side conflict', function() { + var selection = { + // yes, the format of uploads is weird... + uploads: [ + {files: [{name: 'noconflict.txt'}]}, + {files: [{name: 'noconflict2.txt'}]} + ] + }; + + OC.Upload.checkExistingFiles(selection, callbacks); + + expect(conflictDialogStub.notCalled).toEqual(true); + expect(callbacks.onNoConflicts.calledOnce).toEqual(true); + expect(callbacks.onNoConflicts.calledWith(selection)).toEqual(true); + }); + it('shows conflict dialog when no client side conflict', function() { + var selection = { + // yes, the format of uploads is weird... + uploads: [ + {files: [{name: 'conflict.txt'}]}, + {files: [{name: 'conflict2.txt'}]}, + {files: [{name: 'noconflict.txt'}]} + ] + }; + + var deferred = $.Deferred(); + conflictDialogStub.returns(deferred.promise()); + deferred.resolve(); + + OC.Upload.checkExistingFiles(selection, callbacks); + + expect(conflictDialogStub.callCount).toEqual(3); + expect(conflictDialogStub.getCall(1).args[0]) + .toEqual({files: [ { name: 'conflict.txt' } ]}); + expect(conflictDialogStub.getCall(1).args[1]) + .toEqual({ name: 'conflict.txt', mimetype: 'text/plain', directory: '/' }); + expect(conflictDialogStub.getCall(1).args[2]).toEqual({ name: 'conflict.txt' }); + + // yes, the dialog must be called several times... + expect(conflictDialogStub.getCall(2).args[0]).toEqual({ + files: [ { name: 'conflict2.txt' } ] + }); + expect(conflictDialogStub.getCall(2).args[1]) + .toEqual({ name: 'conflict2.txt', mimetype: 'text/plain', directory: '/' }); + expect(conflictDialogStub.getCall(2).args[2]).toEqual({ name: 'conflict2.txt' }); + + expect(callbacks.onNoConflicts.calledOnce).toEqual(true); + expect(callbacks.onNoConflicts.calledWith({ + uploads: [ + {files: [{name: 'noconflict.txt'}]} + ] + })).toEqual(true); + }); + }); }); -- cgit v1.2.3