From 69f88b38c942e2b33ba1cbac7a9f2895b3380434 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 27 Apr 2015 16:31:18 +0200 Subject: Fix file name validation in New menu --- apps/files/tests/js/fileUploadSpec.js | 59 ++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'apps/files/tests/js/fileUploadSpec.js') 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( '' + '' + // 10 MB - '' // 50 MB + '' + // 50 MB + // TODO: handlebars! + '
' + + 'New' + + '' + + '
' ); $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(); + }); + }); }); -- cgit v1.2.3