diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-04-27 16:31:18 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-04-27 16:31:18 +0200 |
commit | 69f88b38c942e2b33ba1cbac7a9f2895b3380434 (patch) | |
tree | 9831592c81a3b7da443d5e7da897611e879d610e /apps/files/tests | |
parent | eb0e9e56467db90d0a8e828edbef0261c186cf37 (diff) | |
download | nextcloud-server-69f88b38c942e2b33ba1cbac7a9f2895b3380434.tar.gz nextcloud-server-69f88b38c942e2b33ba1cbac7a9f2895b3380434.zip |
Fix file name validation in New menu
Diffstat (limited to 'apps/files/tests')
-rw-r--r-- | apps/files/tests/js/fileUploadSpec.js | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/apps/files/tests/js/fileUploadSpec.js b/apps/files/tests/js/fileUploadSpec.js index 49b7265ced1..817654c4fa9 100644 --- a/apps/files/tests/js/fileUploadSpec.js +++ b/apps/files/tests/js/fileUploadSpec.js @@ -35,7 +35,14 @@ describe('OC.Upload tests', function() { $('#testArea').append( '<input type="file" id="file_upload_start" name="files[]" multiple="multiple">' + '<input type="hidden" id="upload_limit" name="upload_limit" value="10000000">' + // 10 MB - '<input type="hidden" id="free_space" name="free_space" value="50000000">' // 50 MB + '<input type="hidden" id="free_space" name="free_space" value="50000000">' + // 50 MB + // TODO: handlebars! + '<div id="new">' + + '<a>New</a>' + + '<ul>' + + '<li data-type="file" data-newname="New text file.txt"><p>Text file</p></li>' + + '</ul>' + + '</div>' ); $dummyUploader = $('#file_upload_start'); }); @@ -111,4 +118,54 @@ describe('OC.Upload tests', function() { ); }); }); + describe('New file', function() { + var $input; + var currentDirStub; + + beforeEach(function() { + OC.Upload.init(); + $('#new>a').click(); + $('#new li[data-type=file]').click(); + $input = $('#new input[type=text]'); + + currentDirStub = sinon.stub(FileList, 'getCurrentDirectory'); + currentDirStub.returns('testdir'); + }); + afterEach(function() { + currentDirStub.restore(); + }); + it('sets default text in field', function() { + expect($input.length).toEqual(1); + expect($input.val()).toEqual('New text file.txt'); + }); + it('creates file when enter is pressed', function() { + $input.val('somefile.txt'); + $input.trigger(new $.Event('keyup', {keyCode: 13})); + $input.parent('form').submit(); + expect(fakeServer.requests.length).toEqual(2); + + var request = fakeServer.requests[1]; + expect(request.method).toEqual('POST'); + expect(request.url).toEqual(OC.webroot + '/index.php/apps/files/ajax/newfile.php'); + var query = OC.parseQueryString(request.requestBody); + expect(query).toEqual({ + dir: 'testdir', + filename: 'somefile.txt' + }); + }); + it('prevents entering invalid file names', function() { + $input.val('..'); + $input.trigger(new $.Event('keyup', {keyCode: 13})); + $input.parent('form').submit(); + expect(fakeServer.requests.length).toEqual(1); + }); + it('prevents entering file names that already exist', function() { + var inListStub = sinon.stub(FileList, 'inList').returns(true); + $input.val('existing.txt'); + $input.trigger(new $.Event('keyup', {keyCode: 13})); + $input.parent('form').submit(); + expect(fakeServer.requests.length).toEqual(1); + inListStub.restore(); + }); + }); }); |