aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/tests
diff options
context:
space:
mode:
authorJan-Christoph Borchardt <hey@jancborchardt.net>2015-09-07 14:03:57 +0200
committerJan-Christoph Borchardt <hey@jancborchardt.net>2015-09-07 14:03:57 +0200
commit004de1425e23649ca011a8d57d09ec2280583b8a (patch)
tree99e8043118dd73922f152b65da0d1ebc688bd4a9 /apps/files/tests
parenta35bc974bbeb3f037af3dbc0a6acbd56599fa847 (diff)
parent4ba233350746b4287556d96bb9adbae039f93882 (diff)
downloadnextcloud-server-004de1425e23649ca011a8d57d09ec2280583b8a.tar.gz
nextcloud-server-004de1425e23649ca011a8d57d09ec2280583b8a.zip
Merge pull request #18630 from owncloud/files-combineuploadbutton
Combine upload action into the "New" menu
Diffstat (limited to 'apps/files/tests')
-rw-r--r--apps/files/tests/js/fileUploadSpec.js51
-rw-r--r--apps/files/tests/js/filelistSpec.js119
-rw-r--r--apps/files/tests/js/newfilemenuSpec.js119
3 files changed, 238 insertions, 51 deletions
diff --git a/apps/files/tests/js/fileUploadSpec.js b/apps/files/tests/js/fileUploadSpec.js
index 817654c4fa9..cad8468d1c8 100644
--- a/apps/files/tests/js/fileUploadSpec.js
+++ b/apps/files/tests/js/fileUploadSpec.js
@@ -19,7 +19,6 @@
*
*/
-/* global OC */
describe('OC.Upload tests', function() {
var $dummyUploader;
var testFile;
@@ -118,54 +117,4 @@ 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();
- });
- });
});
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);
+ });
+ });
});
diff --git a/apps/files/tests/js/newfilemenuSpec.js b/apps/files/tests/js/newfilemenuSpec.js
new file mode 100644
index 00000000000..3d89a997eb2
--- /dev/null
+++ b/apps/files/tests/js/newfilemenuSpec.js
@@ -0,0 +1,119 @@
+/**
+* ownCloud
+*
+* @author Vincent Petry
+* @copyright 2015 Vincent Petry <pvince81@owncloud.com>
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+describe('OCA.Files.NewFileMenu', function() {
+ var FileList = OCA.Files.FileList;
+ var menu, fileList, $uploadField, $trigger;
+
+ beforeEach(function() {
+ // dummy upload button
+ var $container = $('<div id="app-content-files"></div>');
+ $uploadField = $('<input id="file_upload_start"></input>');
+ $trigger = $('<a href="#">Menu</a>');
+ $container.append($uploadField).append($trigger);
+ $('#testArea').append($container);
+
+ fileList = new FileList($container);
+ menu = new OCA.Files.NewFileMenu({
+ fileList: fileList
+ });
+ menu.showAt($trigger);
+ });
+ afterEach(function() {
+ OC.hideMenus();
+ fileList = null;
+ menu = null;
+ });
+
+ describe('rendering', function() {
+ it('renders menu items', function() {
+ var $items = menu.$el.find('.menuitem');
+ expect($items.length).toEqual(3);
+ // label points to the file_upload_start item
+ var $item = $items.eq(0);
+ expect($item.is('label')).toEqual(true);
+ expect($item.attr('for')).toEqual('file_upload_start');
+ });
+ });
+ describe('New file/folder', function() {
+ var $input;
+ var createFileStub;
+ var createDirectoryStub;
+
+ beforeEach(function() {
+ createFileStub = sinon.stub(FileList.prototype, 'createFile');
+ createDirectoryStub = sinon.stub(FileList.prototype, 'createDirectory');
+ menu.$el.find('.menuitem').eq(1).click();
+ $input = menu.$el.find('form.filenameform input');
+ });
+ afterEach(function() {
+ createFileStub.restore();
+ createDirectoryStub.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(createFileStub.calledOnce).toEqual(true);
+ expect(createFileStub.getCall(0).args[0]).toEqual('somefile.txt');
+ expect(createDirectoryStub.notCalled).toEqual(true);
+ });
+ it('prevents entering invalid file names', function() {
+ $input.val('..');
+ $input.trigger(new $.Event('keyup', {keyCode: 13}));
+ $input.closest('form').submit();
+
+ expect(createFileStub.notCalled).toEqual(true);
+ expect(createDirectoryStub.notCalled).toEqual(true);
+ });
+ 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.closest('form').submit();
+
+ expect(createFileStub.notCalled).toEqual(true);
+ expect(createDirectoryStub.notCalled).toEqual(true);
+ inListStub.restore();
+ });
+ it('switching fields removes the previous form', function() {
+ menu.$el.find('.menuitem').eq(2).click();
+ expect(menu.$el.find('form').length).toEqual(1);
+ });
+ it('creates directory when clicking on create directory field', function() {
+ menu.$el.find('.menuitem').eq(2).click();
+ $input = menu.$el.find('form.filenameform input');
+ $input.val('some folder');
+ $input.trigger(new $.Event('keyup', {keyCode: 13}));
+ $input.closest('form').submit();
+
+ expect(createDirectoryStub.calledOnce).toEqual(true);
+ expect(createDirectoryStub.getCall(0).args[0]).toEqual('some folder');
+ expect(createFileStub.notCalled).toEqual(true);
+ });
+ });
+});