diff options
Diffstat (limited to 'apps/files/tests/js/filelistSpec.js')
-rw-r--r-- | apps/files/tests/js/filelistSpec.js | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js index a6d72a88efd..c05e7c37214 100644 --- a/apps/files/tests/js/filelistSpec.js +++ b/apps/files/tests/js/filelistSpec.js @@ -2157,6 +2157,93 @@ describe('OCA.Files.FileList tests', function() { expect(fileList.$fileList.find('tr').length).toEqual(5); }); }); + describe('create file', function() { + var deferredCreate; + + beforeEach(function() { + deferredCreate = $.Deferred(); + }); + + it('creates file with given name and adds it to the list', function() { + var deferred = fileList.createFile('test file.txt'); + var successStub = sinon.stub(); + var failureStub = sinon.stub(); + + deferred.done(successStub); + deferred.fail(failureStub); + + expect(fakeServer.requests.length).toEqual(1); + expect(fakeServer.requests[0].url).toEqual(OC.generateUrl('/apps/files/ajax/newfile.php')); + + var query = fakeServer.requests[0].requestBody; + expect(OC.parseQueryString(query)).toEqual({ + dir: '/subdir', + filename: 'test file.txt' + }); + + fakeServer.requests[0].respond( + 200, + { 'Content-Type': 'application/json' }, + JSON.stringify({ + status: 'success', + data: { + path: '/subdir', + name: 'test file.txt', + mimetype: 'text/plain' + } + }) + ); + + var $tr = fileList.findFileEl('test file.txt'); + expect($tr.length).toEqual(1); + expect($tr.attr('data-mime')).toEqual('text/plain'); + + expect(successStub.calledOnce).toEqual(true); + expect(failureStub.notCalled).toEqual(true); + }); + // TODO: error cases + // TODO: unique name cases + }); + describe('create directory', function() { + it('creates directory with given name and adds it to the list', function() { + var deferred = fileList.createDirectory('test directory'); + var successStub = sinon.stub(); + var failureStub = sinon.stub(); + + deferred.done(successStub); + deferred.fail(failureStub); + + expect(fakeServer.requests.length).toEqual(1); + expect(fakeServer.requests[0].url).toEqual(OC.generateUrl('/apps/files/ajax/newfolder.php')); + var query = fakeServer.requests[0].requestBody; + expect(OC.parseQueryString(query)).toEqual({ + dir: '/subdir', + foldername: 'test directory' + }); + + fakeServer.requests[0].respond( + 200, + { 'Content-Type': 'application/json' }, + JSON.stringify({ + status: 'success', + data: { + path: '/subdir', + name: 'test directory', + mimetype: 'httpd/unix-directory' + } + }) + ); + + var $tr = fileList.findFileEl('test directory'); + expect($tr.length).toEqual(1); + expect($tr.attr('data-mime')).toEqual('httpd/unix-directory'); + + expect(successStub.calledOnce).toEqual(true); + expect(failureStub.notCalled).toEqual(true); + }); + // TODO: error cases + // TODO: unique name cases + }); /** * Test upload mostly by testing the code inside the event handlers * that were registered on the magic upload object @@ -2359,4 +2446,36 @@ describe('OCA.Files.FileList tests', function() { expect(fileInfo.type).toEqual('file'); }); }); + describe('new file menu', function() { + var newFileMenuStub; + + beforeEach(function() { + newFileMenuStub = sinon.stub(OCA.Files.NewFileMenu.prototype, 'showAt'); + }); + afterEach(function() { + newFileMenuStub.restore(); + }) + it('renders new button when no legacy upload button exists', function() { + expect(fileList.$el.find('.button.upload').length).toEqual(0); + expect(fileList.$el.find('.button.new').length).toEqual(1); + }); + it('does not render new button when no legacy upload button exists (public page)', function() { + fileList.destroy(); + $('#controls').append('<input type="button" class="button upload" />'); + fileList = new OCA.Files.FileList($('#app-content-files')); + expect(fileList.$el.find('.button.upload').length).toEqual(1); + expect(fileList.$el.find('.button.new').length).toEqual(0); + }); + it('opens the new file menu when clicking on the "New" button', function() { + var $button = fileList.$el.find('.button.new'); + $button.click(); + expect(newFileMenuStub.calledOnce).toEqual(true); + }); + it('does not open the new file menu when button is disabled', function() { + var $button = fileList.$el.find('.button.new'); + $button.addClass('disabled'); + $button.click(); + expect(newFileMenuStub.notCalled).toEqual(true); + }); + }); }); |