diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-05-08 22:06:30 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-05-15 17:51:04 +0200 |
commit | 9d38e3602b2faf37d861729c52690ce51b8fee97 (patch) | |
tree | 5da63d26db4a4e8ec356dee45fc8f7804c6fe38a /apps/files/tests | |
parent | fb10bf4048aaf5b2a9665fc9dff217c790efe005 (diff) | |
download | nextcloud-server-9d38e3602b2faf37d861729c52690ce51b8fee97.tar.gz nextcloud-server-9d38e3602b2faf37d861729c52690ce51b8fee97.zip |
Namespacing for FileList, FileActions and trashbin app
- FileList is now an instantiable class
- FileActions is now in namespace
- added App class for trashbin app
- moved trashbin overrides into classes extending FileList
- replaced many static calls with "this." or "self." to make the classes
reusable/extendable
- new URL parameter "view" to specify which view is shown, for example
"files" or "trashbin"
- added OC.Util.History utility class in core for handling history
- moved URL handling/routing to OCA.Files.App
- popstate will correctly update the current view and notify the view of
the URL change so it can update the current dir
- added JS unitt tests for the trashbin app
- fixed public app to work with the new namespaces
Diffstat (limited to 'apps/files/tests')
-rw-r--r-- | apps/files/tests/js/appSpec.js | 169 | ||||
-rw-r--r-- | apps/files/tests/js/breadcrumbSpec.js | 4 | ||||
-rw-r--r-- | apps/files/tests/js/fileactionsSpec.js | 23 | ||||
-rw-r--r-- | apps/files/tests/js/filelistSpec.js | 601 | ||||
-rw-r--r-- | apps/files/tests/js/filesSpec.js | 17 | ||||
-rw-r--r-- | apps/files/tests/js/filesummarySpec.js | 3 |
6 files changed, 495 insertions, 322 deletions
diff --git a/apps/files/tests/js/appSpec.js b/apps/files/tests/js/appSpec.js new file mode 100644 index 00000000000..315f11f4b5b --- /dev/null +++ b/apps/files/tests/js/appSpec.js @@ -0,0 +1,169 @@ +/** +* ownCloud +* +* @author Vincent Petry +* @copyright 2014 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.App tests', function() { + var App = OCA.Files.App; + var pushStateStub; + var parseUrlQueryStub; + + beforeEach(function() { + $('#testArea').append( + '<div id="app-navigation">' + + '<ul><li data-id="files"><a>Files</a></li>' + + '<li data-id="other"><a>Other</a></li>' + + '</div>' + + '<div id="app-content">' + + '<div id="app-content-files" class="hidden">' + + '</div>' + + '<div id="app-content-other" class="hidden">' + + '</div>' + + '</div>' + + '</div>' + ); + + pushStateStub = sinon.stub(OC.Util.History, 'pushState'); + parseUrlQueryStub = sinon.stub(OC.Util.History, 'parseUrlQuery'); + parseUrlQueryStub.returns({}); + + App.initialize(); + }); + afterEach(function() { + App.navigation = null; + App.fileList = null; + App.files = null; + App.fileActions.clear(); + App.fileActions = null; + + pushStateStub.restore(); + parseUrlQueryStub.restore(); + }); + + describe('initialization', function() { + it('initializes the default file list with the default file actions', function() { + expect(App.fileList).toBeDefined(); + expect(App.fileList.fileActions.actions.all).toBeDefined(); + expect(App.fileList.$el.is('#app-content-files')).toEqual(true); + }); + }); + + describe('URL handling', function() { + it('pushes the state to the URL when current app changed directory', function() { + $('#app-content-files').trigger(new $.Event('changeDirectory', {dir: 'subdir'})); + expect(pushStateStub.calledOnce).toEqual(true); + expect(pushStateStub.getCall(0).args[0].dir).toEqual('subdir'); + expect(pushStateStub.getCall(0).args[0].view).not.toBeDefined(); + + $('li[data-id=other]>a').click(); + pushStateStub.reset(); + + $('#app-content-other').trigger(new $.Event('changeDirectory', {dir: 'subdir'})); + expect(pushStateStub.calledOnce).toEqual(true); + expect(pushStateStub.getCall(0).args[0].dir).toEqual('subdir'); + expect(pushStateStub.getCall(0).args[0].view).toEqual('other'); + }); + describe('onpopstate', function() { + it('sends "urlChanged" event to current app', function() { + var handler = sinon.stub(); + $('#app-content-files').on('urlChanged', handler); + App._onPopState({view: 'files', dir: '/somedir'}); + expect(handler.calledOnce).toEqual(true); + expect(handler.getCall(0).args[0].view).toEqual('files'); + expect(handler.getCall(0).args[0].dir).toEqual('/somedir'); + }); + it('sends "show" event to current app and sets navigation', function() { + var handlerFiles = sinon.stub(); + var handlerOther = sinon.stub(); + $('#app-content-files').on('show', handlerFiles); + $('#app-content-other').on('show', handlerOther); + App._onPopState({view: 'other', dir: '/somedir'}); + expect(handlerFiles.notCalled).toEqual(true); + expect(handlerOther.calledOnce).toEqual(true); + + handlerFiles.reset(); + handlerOther.reset(); + + App._onPopState({view: 'files', dir: '/somedir'}); + expect(handlerFiles.calledOnce).toEqual(true); + expect(handlerOther.notCalled).toEqual(true); + + expect(App.navigation.getActiveItem()).toEqual('files'); + expect($('#app-content-files').hasClass('hidden')).toEqual(false); + expect($('#app-content-other').hasClass('hidden')).toEqual(true); + }); + it('does not send "show" event to current app when already visible', function() { + var handler = sinon.stub(); + $('#app-content-files').on('show', handler); + App._onPopState({view: 'files', dir: '/somedir'}); + expect(handler.notCalled).toEqual(true); + }); + it('state defaults to files app with root dir', function() { + var handler = sinon.stub(); + parseUrlQueryStub.returns({}); + $('#app-content-files').on('urlChanged', handler); + App._onPopState(); + expect(handler.calledOnce).toEqual(true); + expect(handler.getCall(0).args[0].view).toEqual('files'); + expect(handler.getCall(0).args[0].dir).toEqual('/'); + }); + }); + describe('navigation', function() { + it('switches the navigation item and panel visibility when onpopstate', function() { + App._onPopState({view: 'other', dir: '/somedir'}); + expect(App.navigation.getActiveItem()).toEqual('other'); + expect($('#app-content-files').hasClass('hidden')).toEqual(true); + expect($('#app-content-other').hasClass('hidden')).toEqual(false); + expect($('li[data-id=files]').hasClass('selected')).toEqual(false); + expect($('li[data-id=other]').hasClass('selected')).toEqual(true); + + App._onPopState({view: 'files', dir: '/somedir'}); + + expect(App.navigation.getActiveItem()).toEqual('files'); + expect($('#app-content-files').hasClass('hidden')).toEqual(false); + expect($('#app-content-other').hasClass('hidden')).toEqual(true); + expect($('li[data-id=files]').hasClass('selected')).toEqual(true); + expect($('li[data-id=other]').hasClass('selected')).toEqual(false); + }); + it('clicking on navigation switches the panel visibility', function() { + $('li[data-id=other]>a').click(); + expect(App.navigation.getActiveItem()).toEqual('other'); + expect($('#app-content-files').hasClass('hidden')).toEqual(true); + expect($('#app-content-other').hasClass('hidden')).toEqual(false); + expect($('li[data-id=files]').hasClass('selected')).toEqual(false); + expect($('li[data-id=other]').hasClass('selected')).toEqual(true); + + $('li[data-id=files]>a').click(); + expect(App.navigation.getActiveItem()).toEqual('files'); + expect($('#app-content-files').hasClass('hidden')).toEqual(false); + expect($('#app-content-other').hasClass('hidden')).toEqual(true); + expect($('li[data-id=files]').hasClass('selected')).toEqual(true); + expect($('li[data-id=other]').hasClass('selected')).toEqual(false); + }); + it('clicking on navigation sends "urlChanged" event', function() { + var handler = sinon.stub(); + $('#app-content-other').on('urlChanged', handler); + $('li[data-id=other]>a').click(); + expect(handler.calledOnce).toEqual(true); + expect(handler.getCall(0).args[0].view).toEqual('other'); + expect(handler.getCall(0).args[0].dir).toEqual('/'); + }); + }); + }); +}); diff --git a/apps/files/tests/js/breadcrumbSpec.js b/apps/files/tests/js/breadcrumbSpec.js index 1bfe5308a27..e3d9c757a7c 100644 --- a/apps/files/tests/js/breadcrumbSpec.js +++ b/apps/files/tests/js/breadcrumbSpec.js @@ -20,7 +20,9 @@ */ /* global BreadCrumb */ -describe('BreadCrumb tests', function() { +describe('OCA.Files.BreadCrumb tests', function() { + var BreadCrumb = OCA.Files.BreadCrumb; + describe('Rendering', function() { var bc; beforeEach(function() { diff --git a/apps/files/tests/js/fileactionsSpec.js b/apps/files/tests/js/fileactionsSpec.js index f5eafba509f..23a13be45d4 100644 --- a/apps/files/tests/js/fileactionsSpec.js +++ b/apps/files/tests/js/fileactionsSpec.js @@ -19,20 +19,23 @@ * */ -/* global OC, FileActions, FileList */ -describe('FileActions tests', function() { - var $filesTable; +describe('OCA.Files.FileActions tests', function() { + var $filesTable, fileList; + var FileActions = OCA.Files.FileActions; beforeEach(function() { // init horrible parameters - var $body = $('body'); + var $body = $('#testArea'); $body.append('<input type="hidden" id="dir" value="/subdir"></input>'); $body.append('<input type="hidden" id="permissions" value="31"></input>'); // dummy files table $filesTable = $body.append('<table id="filestable"></table>'); - FileList.files = []; + fileList = new OCA.Files.FileList($('#testArea')); + FileActions.registerDefaultActions(fileList); }); afterEach(function() { + FileActions.clear(); + fileList = undefined; $('#dir, #permissions, #filestable').remove(); }); it('calling display() sets file actions', function() { @@ -47,7 +50,7 @@ describe('FileActions tests', function() { }; // note: FileActions.display() is called implicitly - var $tr = FileList.add(fileData); + var $tr = fileList.add(fileData); // actions defined after call expect($tr.find('.action.action-download').length).toEqual(1); @@ -66,7 +69,7 @@ describe('FileActions tests', function() { etag: 'a01234c', mtime: '123456' }; - var $tr = FileList.add(fileData); + var $tr = fileList.add(fileData); FileActions.display($tr.find('td.filename'), true); FileActions.display($tr.find('td.filename'), true); @@ -87,7 +90,7 @@ describe('FileActions tests', function() { etag: 'a01234c', mtime: '123456' }; - var $tr = FileList.add(fileData); + var $tr = fileList.add(fileData); FileActions.display($tr.find('td.filename'), true); $tr.find('.action-download').click(); @@ -97,7 +100,7 @@ describe('FileActions tests', function() { redirectStub.restore(); }); it('deletes file when clicking delete', function() { - var deleteStub = sinon.stub(FileList, 'do_delete'); + var deleteStub = sinon.stub(fileList, 'do_delete'); var fileData = { id: 18, type: 'file', @@ -107,7 +110,7 @@ describe('FileActions tests', function() { etag: 'a01234c', mtime: '123456' }; - var $tr = FileList.add(fileData); + var $tr = fileList.add(fileData); FileActions.display($tr.find('td.filename'), true); $tr.find('.action.delete').click(); diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js index edb9e15e9bc..a0d8870f33c 100644 --- a/apps/files/tests/js/filelistSpec.js +++ b/apps/files/tests/js/filelistSpec.js @@ -19,10 +19,9 @@ * */ -/* global OC, FileList */ -describe('FileList tests', function() { - var testFiles, alertStub, notificationStub, - pushStateStub; +describe('OCA.Files.FileList tests', function() { + var testFiles, alertStub, notificationStub, fileList; + var FileActions = OCA.Files.FileActions; /** * Generate test file data @@ -59,14 +58,12 @@ describe('FileList tests', function() { // dummy files table $body.append('<table id="filestable"></table>'); - // prevents URL changes during tests - pushStateStub = sinon.stub(window.history, 'pushState'); - alertStub = sinon.stub(OC.dialogs, 'alert'); notificationStub = sinon.stub(OC.Notification, 'show'); // init parameters and test table elements $('#testArea').append( + '<div id="app-content-files">' + '<input type="hidden" id="dir" value="/subdir"></input>' + '<input type="hidden" id="permissions" value="31"></input>' + // dummy controls @@ -75,7 +72,7 @@ describe('FileList tests', function() { ' <div class="notCreatable"></div>' + '</div>' + // dummy table - // TODO: at some point this will be rendered by the FileList class itself! + // TODO: at some point this will be rendered by the fileList class itself! '<table id="filestable">' + '<thead><tr>' + '<th id="headerName" class="hidden column-name">' + @@ -91,7 +88,8 @@ describe('FileList tests', function() { '<tbody id="fileList"></tbody>' + '<tfoot></tfoot>' + '</table>' + - '<div id="emptycontent">Empty content message</div>' + '<div id="emptycontent">Empty content message</div>' + + '</div>' ); testFiles = [{ @@ -124,27 +122,27 @@ describe('FileList tests', function() { etag: '456' }]; - FileList.initialize(); + fileList = new OCA.Files.FileList($('#app-content-files')); + FileActions.registerDefaultActions(fileList); + fileList.setFileActions(FileActions); }); afterEach(function() { testFiles = undefined; - FileList.initialized = false; - FileList.isEmpty = true; - delete FileList._reloadCall; + fileList = undefined; + FileActions.clear(); $('#dir, #permissions, #filestable').remove(); notificationStub.restore(); alertStub.restore(); - pushStateStub.restore(); }); describe('Getters', function() { it('Returns the current directory', function() { $('#dir').val('/one/two/three'); - expect(FileList.getCurrentDirectory()).toEqual('/one/two/three'); + expect(fileList.getCurrentDirectory()).toEqual('/one/two/three'); }); it('Returns the directory permissions as int', function() { $('#permissions').val('23'); - expect(FileList.getDirectoryPermissions()).toEqual(23); + expect(fileList.getDirectoryPermissions()).toEqual(23); }); }); describe('Adding files', function() { @@ -167,7 +165,7 @@ describe('FileList tests', function() { etag: 'a01234c', mtime: '123456' }; - var $tr = FileList.add(fileData); + var $tr = fileList.add(fileData); expect($tr).toBeDefined(); expect($tr[0].tagName.toLowerCase()).toEqual('tr'); @@ -182,7 +180,7 @@ describe('FileList tests', function() { expect($tr.find('a.name').attr('href')).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=testName.txt'); expect($tr.find('.filesize').text()).toEqual('1 kB'); - expect(FileList.findFileEl('testName.txt')[0]).toEqual($tr[0]); + expect(fileList.findFileEl('testName.txt')[0]).toEqual($tr[0]); }); it('generates dir element with correct attributes when calling add() with dir data', function() { var fileData = { @@ -194,7 +192,7 @@ describe('FileList tests', function() { etag: 'a01234c', mtime: '123456' }; - var $tr = FileList.add(fileData); + var $tr = fileList.add(fileData); expect($tr).toBeDefined(); expect($tr[0].tagName.toLowerCase()).toEqual('tr'); @@ -209,7 +207,7 @@ describe('FileList tests', function() { expect($tr.find('.filesize').text()).toEqual('1 kB'); - expect(FileList.findFileEl('testFolder')[0]).toEqual($tr[0]); + expect(fileList.findFileEl('testFolder')[0]).toEqual($tr[0]); }); it('generates file element with default attributes when calling add() with minimal data', function() { var fileData = { @@ -217,8 +215,8 @@ describe('FileList tests', function() { name: 'testFile.txt' }; - clock.tick(123456); - var $tr = FileList.add(fileData); + clock.tick(123456); + var $tr = fileList.add(fileData); expect($tr).toBeDefined(); expect($tr[0].tagName.toLowerCase()).toEqual('tr'); @@ -238,8 +236,8 @@ describe('FileList tests', function() { type: 'dir', name: 'testFolder' }; - clock.tick(123456); - var $tr = FileList.add(fileData); + clock.tick(123456); + var $tr = fileList.add(fileData); expect($tr).toBeDefined(); expect($tr[0].tagName.toLowerCase()).toEqual('tr'); @@ -260,7 +258,7 @@ describe('FileList tests', function() { name: 'testFolder', size: '0' }; - var $tr = FileList.add(fileData); + var $tr = fileList.add(fileData); expect($tr.find('.filesize').text()).toEqual('0 B'); }); it('adds new file to the end of the list', function() { @@ -269,19 +267,19 @@ describe('FileList tests', function() { type: 'file', name: 'ZZZ.txt' }; - FileList.setFiles(testFiles); - $tr = FileList.add(fileData); + fileList.setFiles(testFiles); + $tr = fileList.add(fileData); expect($tr.index()).toEqual(4); }); it('inserts files in a sorted manner when insert option is enabled', function() { var $tr; for (var i = 0; i < testFiles.length; i++) { - FileList.add(testFiles[i]); + fileList.add(testFiles[i]); } - expect(FileList.files[0].name).toEqual('somedir'); - expect(FileList.files[1].name).toEqual('One.txt'); - expect(FileList.files[2].name).toEqual('Three.pdf'); - expect(FileList.files[3].name).toEqual('Two.jpg'); + expect(fileList.files[0].name).toEqual('somedir'); + expect(fileList.files[1].name).toEqual('One.txt'); + expect(fileList.files[2].name).toEqual('Three.pdf'); + expect(fileList.files[3].name).toEqual('Two.jpg'); }); it('inserts new file at correct position', function() { var $tr; @@ -290,12 +288,12 @@ describe('FileList tests', function() { name: 'P comes after O.txt' }; for (var i = 0; i < testFiles.length; i++) { - FileList.add(testFiles[i]); + fileList.add(testFiles[i]); } - $tr = FileList.add(fileData); + $tr = fileList.add(fileData); // after "One.txt" expect($tr.index()).toEqual(2); - expect(FileList.files[2]).toEqual(fileData); + expect(fileList.files[2]).toEqual(fileData); }); it('inserts new folder at correct position in insert mode', function() { var $tr; @@ -304,11 +302,11 @@ describe('FileList tests', function() { name: 'somedir2 comes after somedir' }; for (var i = 0; i < testFiles.length; i++) { - FileList.add(testFiles[i]); + fileList.add(testFiles[i]); } - $tr = FileList.add(fileData); + $tr = fileList.add(fileData); expect($tr.index()).toEqual(1); - expect(FileList.files[1]).toEqual(fileData); + expect(fileList.files[1]).toEqual(fileData); }); it('inserts new file at the end correctly', function() { var $tr; @@ -317,21 +315,22 @@ describe('FileList tests', function() { name: 'zzz.txt' }; for (var i = 0; i < testFiles.length; i++) { - FileList.add(testFiles[i]); + fileList.add(testFiles[i]); } - $tr = FileList.add(fileData); + $tr = fileList.add(fileData); expect($tr.index()).toEqual(4); - expect(FileList.files[4]).toEqual(fileData); + expect(fileList.files[4]).toEqual(fileData); }); it('removes empty content message and shows summary when adding first file', function() { + var $summary; var fileData = { type: 'file', name: 'first file.txt', size: 12 }; - FileList.setFiles([]); - expect(FileList.isEmpty).toEqual(true); - FileList.add(fileData); + fileList.setFiles([]); + expect(fileList.isEmpty).toEqual(true); + fileList.add(fileData); $summary = $('#filestable .summary'); expect($summary.hasClass('hidden')).toEqual(false); // yes, ugly... @@ -341,19 +340,20 @@ describe('FileList tests', function() { expect($summary.find('.filesize').text()).toEqual('12 B'); expect($('#filestable thead th').hasClass('hidden')).toEqual(false); expect($('#emptycontent').hasClass('hidden')).toEqual(true); - expect(FileList.isEmpty).toEqual(false); + expect(fileList.isEmpty).toEqual(false); }); }); describe('Removing files from the list', function() { it('Removes file from list when calling remove() and updates summary', function() { + var $summary; var $removedEl; - FileList.setFiles(testFiles); - $removedEl = FileList.remove('One.txt'); + fileList.setFiles(testFiles); + $removedEl = fileList.remove('One.txt'); expect($removedEl).toBeDefined(); expect($removedEl.attr('data-file')).toEqual('One.txt'); expect($('#fileList tr').length).toEqual(3); - expect(FileList.files.length).toEqual(3); - expect(FileList.findFileEl('One.txt').length).toEqual(0); + expect(fileList.files.length).toEqual(3); + expect(fileList.findFileEl('One.txt').length).toEqual(0); $summary = $('#filestable .summary'); expect($summary.hasClass('hidden')).toEqual(false); @@ -361,27 +361,28 @@ describe('FileList tests', function() { expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(false); expect($summary.find('.fileinfo').hasClass('hidden')).toEqual(false); expect($summary.find('.filesize').text()).toEqual('69 kB'); - expect(FileList.isEmpty).toEqual(false); + expect(fileList.isEmpty).toEqual(false); }); it('Shows empty content when removing last file', function() { - FileList.setFiles([testFiles[0]]); - FileList.remove('One.txt'); + var $summary; + fileList.setFiles([testFiles[0]]); + fileList.remove('One.txt'); expect($('#fileList tr').length).toEqual(0); - expect(FileList.files.length).toEqual(0); - expect(FileList.findFileEl('One.txt').length).toEqual(0); + expect(fileList.files.length).toEqual(0); + expect(fileList.findFileEl('One.txt').length).toEqual(0); $summary = $('#filestable .summary'); expect($summary.hasClass('hidden')).toEqual(true); expect($('#filestable thead th').hasClass('hidden')).toEqual(true); expect($('#emptycontent').hasClass('hidden')).toEqual(false); - expect(FileList.isEmpty).toEqual(true); + expect(fileList.isEmpty).toEqual(true); }); }); describe('Deleting files', function() { function doDelete() { var request, query; // note: normally called from FileActions - FileList.do_delete(['One.txt', 'Two.jpg']); + fileList.do_delete(['One.txt', 'Two.jpg']); expect(fakeServer.requests.length).toEqual(1); request = fakeServer.requests[0]; @@ -391,7 +392,8 @@ describe('FileList tests', function() { expect(OC.parseQueryString(query)).toEqual({'dir': '/subdir', files: '["One.txt","Two.jpg"]'}); } it('calls delete.php, removes the deleted entries and updates summary', function() { - FileList.setFiles(testFiles); + var $summary; + fileList.setFiles(testFiles); doDelete(); fakeServer.requests[0].respond( @@ -400,10 +402,10 @@ describe('FileList tests', function() { JSON.stringify({status: 'success'}) ); - expect(FileList.findFileEl('One.txt').length).toEqual(0); - expect(FileList.findFileEl('Two.jpg').length).toEqual(0); - expect(FileList.findFileEl('Three.pdf').length).toEqual(1); - expect(FileList.$fileList.find('tr').length).toEqual(2); + expect(fileList.findFileEl('One.txt').length).toEqual(0); + expect(fileList.findFileEl('Two.jpg').length).toEqual(0); + expect(fileList.findFileEl('Three.pdf').length).toEqual(1); + expect(fileList.$fileList.find('tr').length).toEqual(2); $summary = $('#filestable .summary'); expect($summary.hasClass('hidden')).toEqual(false); @@ -411,28 +413,29 @@ describe('FileList tests', function() { expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(false); expect($summary.find('.fileinfo').hasClass('hidden')).toEqual(false); expect($summary.find('.filesize').text()).toEqual('57 kB'); - expect(FileList.isEmpty).toEqual(false); + expect(fileList.isEmpty).toEqual(false); expect($('#filestable thead th').hasClass('hidden')).toEqual(false); expect($('#emptycontent').hasClass('hidden')).toEqual(true); expect(notificationStub.notCalled).toEqual(true); }); it('shows spinner on files to be deleted', function() { - FileList.setFiles(testFiles); + fileList.setFiles(testFiles); doDelete(); - expect(FileList.findFileEl('One.txt').find('.progress-icon:not(.delete-icon)').length).toEqual(1); - expect(FileList.findFileEl('Three.pdf').find('.delete-icon:not(.progress-icon)').length).toEqual(1); + expect(fileList.findFileEl('One.txt').find('.progress-icon:not(.delete-icon)').length).toEqual(1); + expect(fileList.findFileEl('Three.pdf').find('.delete-icon:not(.progress-icon)').length).toEqual(1); }); it('shows spinner on all files when deleting all', function() { - FileList.setFiles(testFiles); + fileList.setFiles(testFiles); - FileList.do_delete(); + fileList.do_delete(); - expect(FileList.$fileList.find('tr .progress-icon:not(.delete-icon)').length).toEqual(4); + expect(fileList.$fileList.find('tr .progress-icon:not(.delete-icon)').length).toEqual(4); }); it('updates summary when deleting last file', function() { - FileList.setFiles([testFiles[0], testFiles[1]]); + var $summary; + fileList.setFiles([testFiles[0], testFiles[1]]); doDelete(); fakeServer.requests[0].respond( @@ -441,17 +444,17 @@ describe('FileList tests', function() { JSON.stringify({status: 'success'}) ); - expect(FileList.$fileList.find('tr').length).toEqual(0); + expect(fileList.$fileList.find('tr').length).toEqual(0); $summary = $('#filestable .summary'); expect($summary.hasClass('hidden')).toEqual(true); - expect(FileList.isEmpty).toEqual(true); - expect(FileList.files.length).toEqual(0); + expect(fileList.isEmpty).toEqual(true); + expect(fileList.files.length).toEqual(0); expect($('#filestable thead th').hasClass('hidden')).toEqual(true); expect($('#emptycontent').hasClass('hidden')).toEqual(false); }); it('bring back deleted item when delete call failed', function() { - FileList.setFiles(testFiles); + fileList.setFiles(testFiles); doDelete(); fakeServer.requests[0].respond( @@ -461,9 +464,9 @@ describe('FileList tests', function() { ); // files are still in the list - expect(FileList.findFileEl('One.txt').length).toEqual(1); - expect(FileList.findFileEl('Two.jpg').length).toEqual(1); - expect(FileList.$fileList.find('tr').length).toEqual(4); + expect(fileList.findFileEl('One.txt').length).toEqual(1); + expect(fileList.findFileEl('Two.jpg').length).toEqual(1); + expect(fileList.$fileList.find('tr').length).toEqual(4); expect(notificationStub.calledOnce).toEqual(true); }); @@ -473,12 +476,12 @@ describe('FileList tests', function() { var $input, request; for (var i = 0; i < testFiles.length; i++) { - FileList.add(testFiles[i]); + fileList.add(testFiles[i]); } // trigger rename prompt - FileList.rename('One.txt'); - $input = FileList.$fileList.find('input.filename'); + fileList.rename('One.txt'); + $input = fileList.$fileList.find('input.filename'); $input.val('Tu_after_three.txt').blur(); expect(fakeServer.requests.length).toEqual(1); @@ -487,10 +490,10 @@ describe('FileList tests', function() { expect(OC.parseQueryString(request.url)).toEqual({'dir': '/subdir', newname: 'Tu_after_three.txt', file: 'One.txt'}); // element is renamed before the request finishes - expect(FileList.findFileEl('One.txt').length).toEqual(0); - expect(FileList.findFileEl('Tu_after_three.txt').length).toEqual(1); + expect(fileList.findFileEl('One.txt').length).toEqual(0); + expect(fileList.findFileEl('Tu_after_three.txt').length).toEqual(1); // input is gone - expect(FileList.$fileList.find('input.filename').length).toEqual(0); + expect(fileList.$fileList.find('input.filename').length).toEqual(0); } it('Inserts renamed file entry at correct position if rename ajax call suceeded', function() { doRename(); @@ -504,9 +507,9 @@ describe('FileList tests', function() { })); // element stays renamed - expect(FileList.findFileEl('One.txt').length).toEqual(0); - expect(FileList.findFileEl('Tu_after_three.txt').length).toEqual(1); - expect(FileList.findFileEl('Tu_after_three.txt').index()).toEqual(2); // after Two.txt + expect(fileList.findFileEl('One.txt').length).toEqual(0); + expect(fileList.findFileEl('Tu_after_three.txt').length).toEqual(1); + expect(fileList.findFileEl('Tu_after_three.txt').index()).toEqual(2); // after Two.txt expect(alertStub.notCalled).toEqual(true); }); @@ -521,9 +524,9 @@ describe('FileList tests', function() { })); // element was reverted - expect(FileList.findFileEl('One.txt').length).toEqual(1); - expect(FileList.findFileEl('One.txt').index()).toEqual(1); // after somedir - expect(FileList.findFileEl('Tu_after_three.txt').length).toEqual(0); + expect(fileList.findFileEl('One.txt').length).toEqual(1); + expect(fileList.findFileEl('One.txt').index()).toEqual(1); // after somedir + expect(fileList.findFileEl('Tu_after_three.txt').length).toEqual(0); expect(alertStub.calledOnce).toEqual(true); }); @@ -538,7 +541,7 @@ describe('FileList tests', function() { } })); - $tr = FileList.findFileEl('Tu_after_three.txt'); + $tr = fileList.findFileEl('Tu_after_three.txt'); expect($tr.find('a.name').attr('href')).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=Tu_after_three.txt'); }); // FIXME: fix this in the source code! @@ -555,17 +558,17 @@ describe('FileList tests', function() { } })); - $tr = FileList.findFileEl('Tu_after_three.txt'); + $tr = fileList.findFileEl('Tu_after_three.txt'); expect($tr.find('a.name').attr('href')).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=One.txt'); }); }); describe('Moving files', function() { beforeEach(function() { - FileList.setFiles(testFiles); + fileList.setFiles(testFiles); }); it('Moves single file to target folder', function() { var request; - FileList.move('One.txt', '/somedir'); + fileList.move('One.txt', '/somedir'); expect(fakeServer.requests.length).toEqual(1); request = fakeServer.requests[0]; @@ -580,17 +583,17 @@ describe('FileList tests', function() { } })); - expect(FileList.findFileEl('One.txt').length).toEqual(0); + expect(fileList.findFileEl('One.txt').length).toEqual(0); // folder size has increased - expect(FileList.findFileEl('somedir').data('size')).toEqual(262); - expect(FileList.findFileEl('somedir').find('.filesize').text()).toEqual('262 B'); + expect(fileList.findFileEl('somedir').data('size')).toEqual(262); + expect(fileList.findFileEl('somedir').find('.filesize').text()).toEqual('262 B'); expect(notificationStub.notCalled).toEqual(true); }); it('Moves list of files to target folder', function() { var request; - FileList.move(['One.txt', 'Two.jpg'], '/somedir'); + fileList.move(['One.txt', 'Two.jpg'], '/somedir'); expect(fakeServer.requests.length).toEqual(2); request = fakeServer.requests[0]; @@ -609,11 +612,11 @@ describe('FileList tests', function() { } })); - expect(FileList.findFileEl('One.txt').length).toEqual(0); + expect(fileList.findFileEl('One.txt').length).toEqual(0); // folder size has increased - expect(FileList.findFileEl('somedir').data('size')).toEqual(262); - expect(FileList.findFileEl('somedir').find('.filesize').text()).toEqual('262 B'); + expect(fileList.findFileEl('somedir').data('size')).toEqual(262); + expect(fileList.findFileEl('somedir').find('.filesize').text()).toEqual('262 B'); fakeServer.requests[1].respond(200, {'Content-Type': 'application/json'}, JSON.stringify({ status: 'success', @@ -623,17 +626,17 @@ describe('FileList tests', function() { } })); - expect(FileList.findFileEl('Two.jpg').length).toEqual(0); + expect(fileList.findFileEl('Two.jpg').length).toEqual(0); // folder size has increased - expect(FileList.findFileEl('somedir').data('size')).toEqual(12311); - expect(FileList.findFileEl('somedir').find('.filesize').text()).toEqual('12 kB'); + expect(fileList.findFileEl('somedir').data('size')).toEqual(12311); + expect(fileList.findFileEl('somedir').find('.filesize').text()).toEqual('12 kB'); expect(notificationStub.notCalled).toEqual(true); }); it('Shows notification if a file could not be moved', function() { var request; - FileList.move('One.txt', '/somedir'); + fileList.move('One.txt', '/somedir'); expect(fakeServer.requests.length).toEqual(1); request = fakeServer.requests[0]; @@ -647,7 +650,7 @@ describe('FileList tests', function() { } })); - expect(FileList.findFileEl('One.txt').length).toEqual(1); + expect(fileList.findFileEl('One.txt').length).toEqual(1); expect(notificationStub.calledOnce).toEqual(true); expect(notificationStub.getCall(0).args[0]).toEqual('Error while moving file'); @@ -655,47 +658,47 @@ describe('FileList tests', function() { }); describe('List rendering', function() { it('renders a list of files using add()', function() { - expect(FileList.files.length).toEqual(0); - expect(FileList.files).toEqual([]); - FileList.setFiles(testFiles); + expect(fileList.files.length).toEqual(0); + expect(fileList.files).toEqual([]); + fileList.setFiles(testFiles); expect($('#fileList tr').length).toEqual(4); - expect(FileList.files.length).toEqual(4); - expect(FileList.files).toEqual(testFiles); + expect(fileList.files.length).toEqual(4); + expect(fileList.files).toEqual(testFiles); }); it('updates summary using the file sizes', function() { var $summary; - FileList.setFiles(testFiles); + fileList.setFiles(testFiles); $summary = $('#filestable .summary'); expect($summary.hasClass('hidden')).toEqual(false); expect($summary.find('.info').text()).toEqual('1 folder and 3 files'); expect($summary.find('.filesize').text()).toEqual('69 kB'); }); it('shows headers, summary and hide empty content message after setting files', function(){ - FileList.setFiles(testFiles); + fileList.setFiles(testFiles); expect($('#filestable thead th').hasClass('hidden')).toEqual(false); expect($('#emptycontent').hasClass('hidden')).toEqual(true); - expect(FileList.$el.find('.summary').hasClass('hidden')).toEqual(false); + expect(fileList.$el.find('.summary').hasClass('hidden')).toEqual(false); }); it('hides headers, summary and show empty content message after setting empty file list', function(){ - FileList.setFiles([]); + fileList.setFiles([]); expect($('#filestable thead th').hasClass('hidden')).toEqual(true); expect($('#emptycontent').hasClass('hidden')).toEqual(false); - expect(FileList.$el.find('.summary').hasClass('hidden')).toEqual(true); + expect(fileList.$el.find('.summary').hasClass('hidden')).toEqual(true); }); it('hides headers, empty content message, and summary when list is empty and user has no creation permission', function(){ $('#permissions').val(0); - FileList.setFiles([]); + fileList.setFiles([]); expect($('#filestable thead th').hasClass('hidden')).toEqual(true); expect($('#emptycontent').hasClass('hidden')).toEqual(true); - expect(FileList.$el.find('.summary').hasClass('hidden')).toEqual(true); + expect(fileList.$el.find('.summary').hasClass('hidden')).toEqual(true); }); it('calling findFileEl() can find existing file element', function() { - FileList.setFiles(testFiles); - expect(FileList.findFileEl('Two.jpg').length).toEqual(1); + fileList.setFiles(testFiles); + expect(fileList.findFileEl('Two.jpg').length).toEqual(1); }); it('calling findFileEl() returns empty when file not found in file', function() { - FileList.setFiles(testFiles); - expect(FileList.findFileEl('unexist.dat').length).toEqual(0); + fileList.setFiles(testFiles); + expect(fileList.findFileEl('unexist.dat').length).toEqual(0); }); it('only add file if in same current directory', function() { $('#dir').val('/current dir'); @@ -704,121 +707,122 @@ describe('FileList tests', function() { name: 'testFile.txt', directory: '/current dir' }; - var $tr = FileList.add(fileData); - expect(FileList.findFileEl('testFile.txt').length).toEqual(1); + var $tr = fileList.add(fileData); + expect(fileList.findFileEl('testFile.txt').length).toEqual(1); }); it('triggers "fileActionsReady" event after update', function() { var handler = sinon.stub(); - FileList.$fileList.on('fileActionsReady', handler); - FileList.setFiles(testFiles); + fileList.$fileList.on('fileActionsReady', handler); + fileList.setFiles(testFiles); expect(handler.calledOnce).toEqual(true); }); it('triggers "updated" event after update', function() { var handler = sinon.stub(); - FileList.$fileList.on('updated', handler); - FileList.setFiles(testFiles); + fileList.$fileList.on('updated', handler); + fileList.setFiles(testFiles); expect(handler.calledOnce).toEqual(true); }); it('does not update summary when removing non-existing files', function() { + var $summary; // single file - FileList.setFiles([testFiles[0]]); + fileList.setFiles([testFiles[0]]); $summary = $('#filestable .summary'); expect($summary.hasClass('hidden')).toEqual(false); expect($summary.find('.info').text()).toEqual('0 folders and 1 file'); - FileList.remove('unexist.txt'); + fileList.remove('unexist.txt'); expect($summary.hasClass('hidden')).toEqual(false); expect($summary.find('.info').text()).toEqual('0 folders and 1 file'); }); }); describe('Rendering next page on scroll', function() { beforeEach(function() { - FileList.setFiles(generateFiles(0, 64)); + fileList.setFiles(generateFiles(0, 64)); }); it('renders only the first page', function() { - expect(FileList.files.length).toEqual(65); + expect(fileList.files.length).toEqual(65); expect($('#fileList tr').length).toEqual(20); }); it('renders the second page when scrolling down (trigger nextPage)', function() { // TODO: can't simulate scrolling here, so calling nextPage directly - FileList._nextPage(true); + fileList._nextPage(true); expect($('#fileList tr').length).toEqual(40); - FileList._nextPage(true); + fileList._nextPage(true); expect($('#fileList tr').length).toEqual(60); - FileList._nextPage(true); + fileList._nextPage(true); expect($('#fileList tr').length).toEqual(65); - FileList._nextPage(true); + fileList._nextPage(true); // stays at 65 expect($('#fileList tr').length).toEqual(65); }); it('inserts into the DOM if insertion point is in the visible page ', function() { - FileList.add({ + fileList.add({ id: 2000, type: 'file', name: 'File with index 15b.txt' }); expect($('#fileList tr').length).toEqual(21); - expect(FileList.findFileEl('File with index 15b.txt').index()).toEqual(16); + expect(fileList.findFileEl('File with index 15b.txt').index()).toEqual(16); }); it('does not inserts into the DOM if insertion point is not the visible page ', function() { - FileList.add({ + fileList.add({ id: 2000, type: 'file', name: 'File with index 28b.txt' }); expect($('#fileList tr').length).toEqual(20); - expect(FileList.findFileEl('File with index 28b.txt').length).toEqual(0); - FileList._nextPage(true); + expect(fileList.findFileEl('File with index 28b.txt').length).toEqual(0); + fileList._nextPage(true); expect($('#fileList tr').length).toEqual(40); - expect(FileList.findFileEl('File with index 28b.txt').index()).toEqual(29); + expect(fileList.findFileEl('File with index 28b.txt').index()).toEqual(29); }); it('appends into the DOM when inserting a file after the last visible element', function() { - FileList.add({ + fileList.add({ id: 2000, type: 'file', name: 'File with index 19b.txt' }); expect($('#fileList tr').length).toEqual(21); - FileList._nextPage(true); + fileList._nextPage(true); expect($('#fileList tr').length).toEqual(41); }); it('appends into the DOM when inserting a file on the last page when visible', function() { - FileList._nextPage(true); + fileList._nextPage(true); expect($('#fileList tr').length).toEqual(40); - FileList._nextPage(true); + fileList._nextPage(true); expect($('#fileList tr').length).toEqual(60); - FileList._nextPage(true); + fileList._nextPage(true); expect($('#fileList tr').length).toEqual(65); - FileList._nextPage(true); - FileList.add({ + fileList._nextPage(true); + fileList.add({ id: 2000, type: 'file', name: 'File with index 88.txt' }); expect($('#fileList tr').length).toEqual(66); - FileList._nextPage(true); + fileList._nextPage(true); expect($('#fileList tr').length).toEqual(66); }); it('shows additional page when appending a page of files and scrolling down', function() { var newFiles = generateFiles(66, 81); for (var i = 0; i < newFiles.length; i++) { - FileList.add(newFiles[i]); + fileList.add(newFiles[i]); } expect($('#fileList tr').length).toEqual(20); - FileList._nextPage(true); + fileList._nextPage(true); expect($('#fileList tr').length).toEqual(40); - FileList._nextPage(true); + fileList._nextPage(true); expect($('#fileList tr').length).toEqual(60); - FileList._nextPage(true); + fileList._nextPage(true); expect($('#fileList tr').length).toEqual(80); - FileList._nextPage(true); + fileList._nextPage(true); expect($('#fileList tr').length).toEqual(81); - FileList._nextPage(true); + fileList._nextPage(true); expect($('#fileList tr').length).toEqual(81); }); it('automatically renders next page when there are not enough elements visible', function() { // delete the 15 first elements for (var i = 0; i < 15; i++) { - FileList.remove(FileList.files[0].name); + fileList.remove(fileList.files[0].name); } // still makes sure that there are 20 elements visible, if any expect($('#fileList tr').length).toEqual(25); @@ -838,7 +842,7 @@ describe('FileList tests', function() { } beforeEach(function() { - previewLoadStub = sinon.stub(Files, 'lazyLoadPreview'); + previewLoadStub = sinon.stub(OCA.Files.FileList.prototype, 'lazyLoadPreview'); }); afterEach(function() { previewLoadStub.restore(); @@ -848,7 +852,7 @@ describe('FileList tests', function() { type: 'file', name: 'testFile.txt' }; - var $tr = FileList.add(fileData); + var $tr = fileList.add(fileData); var $td = $tr.find('td.filename'); expect(getImageUrl($td)).toEqual(OC.webroot + '/core/img/filetypes/file.svg'); expect(previewLoadStub.notCalled).toEqual(true); @@ -858,7 +862,7 @@ describe('FileList tests', function() { type: 'dir', name: 'test dir' }; - var $tr = FileList.add(fileData); + var $tr = fileList.add(fileData); var $td = $tr.find('td.filename'); expect(getImageUrl($td)).toEqual(OC.webroot + '/core/img/filetypes/folder.svg'); expect(previewLoadStub.notCalled).toEqual(true); @@ -869,7 +873,7 @@ describe('FileList tests', function() { name: 'test dir', icon: OC.webroot + '/core/img/filetypes/application-pdf.svg' }; - var $tr = FileList.add(fileData); + var $tr = fileList.add(fileData); var $td = $tr.find('td.filename'); expect(getImageUrl($td)).toEqual(OC.webroot + '/core/img/filetypes/application-pdf.svg'); expect(previewLoadStub.notCalled).toEqual(true); @@ -880,12 +884,12 @@ describe('FileList tests', function() { name: 'test dir', isPreviewAvailable: true }; - var $tr = FileList.add(fileData); + var $tr = fileList.add(fileData); var $td = $tr.find('td.filename'); expect(getImageUrl($td)).toEqual(OC.webroot + '/core/img/filetypes/file.svg'); expect(previewLoadStub.calledOnce).toEqual(true); // third argument is callback - previewLoadStub.getCall(0).args[2](OC.webroot + '/somepath.png'); + previewLoadStub.getCall(0).args[0].callback(OC.webroot + '/somepath.png'); expect(getImageUrl($td)).toEqual(OC.webroot + '/somepath.png'); }); it('renders default file type icon when no icon was provided and no preview is available', function() { @@ -894,7 +898,7 @@ describe('FileList tests', function() { name: 'test dir', isPreviewAvailable: false }; - var $tr = FileList.add(fileData); + var $tr = fileList.add(fileData); var $td = $tr.find('td.filename'); expect(getImageUrl($td)).toEqual(OC.webroot + '/core/img/filetypes/file.svg'); expect(previewLoadStub.notCalled).toEqual(true); @@ -902,22 +906,22 @@ describe('FileList tests', function() { }); describe('viewer mode', function() { it('enabling viewer mode hides files table and action buttons', function() { - FileList.setViewerMode(true); + fileList.setViewerMode(true); expect($('#filestable').hasClass('hidden')).toEqual(true); expect($('.actions').hasClass('hidden')).toEqual(true); expect($('.notCreatable').hasClass('hidden')).toEqual(true); }); it('disabling viewer mode restores files table and action buttons', function() { - FileList.setViewerMode(true); - FileList.setViewerMode(false); + fileList.setViewerMode(true); + fileList.setViewerMode(false); expect($('#filestable').hasClass('hidden')).toEqual(false); expect($('.actions').hasClass('hidden')).toEqual(false); expect($('.notCreatable').hasClass('hidden')).toEqual(true); }); it('disabling viewer mode restores files table and action buttons with correct permissions', function() { $('#permissions').val(0); - FileList.setViewerMode(true); - FileList.setViewerMode(false); + fileList.setViewerMode(true); + fileList.setViewerMode(false); expect($('#filestable').hasClass('hidden')).toEqual(false); expect($('.actions').hasClass('hidden')).toEqual(true); expect($('.notCreatable').hasClass('hidden')).toEqual(false); @@ -940,18 +944,18 @@ describe('FileList tests', function() { ]); }); it('fetches file list from server and renders it when reload() is called', function() { - FileList.reload(); + fileList.reload(); expect(fakeServer.requests.length).toEqual(1); var url = fakeServer.requests[0].url; var query = url.substr(url.indexOf('?') + 1); expect(OC.parseQueryString(query)).toEqual({'dir': '/subdir', sort: 'name', sortdirection: 'asc'}); fakeServer.respond(); expect($('#fileList tr').length).toEqual(4); - expect(FileList.findFileEl('One.txt').length).toEqual(1); + expect(fileList.findFileEl('One.txt').length).toEqual(1); }); it('switches dir and fetches file list when calling changeDirectory()', function() { - FileList.changeDirectory('/anothersubdir'); - expect(FileList.getCurrentDirectory()).toEqual('/anothersubdir'); + fileList.changeDirectory('/anothersubdir'); + expect(fileList.getCurrentDirectory()).toEqual('/anothersubdir'); expect(fakeServer.requests.length).toEqual(1); var url = fakeServer.requests[0].url; var query = url.substr(url.indexOf('?') + 1); @@ -965,14 +969,14 @@ describe('FileList tests', function() { }, '' ]); - FileList.changeDirectory('/unexist'); + fileList.changeDirectory('/unexist'); fakeServer.respond(); - expect(FileList.getCurrentDirectory()).toEqual('/'); + expect(fileList.getCurrentDirectory()).toEqual('/'); }); it('shows mask before loading file list then hides it at the end', function() { - var showMaskStub = sinon.stub(FileList, 'showMask'); - var hideMaskStub = sinon.stub(FileList, 'hideMask'); - FileList.changeDirectory('/anothersubdir'); + var showMaskStub = sinon.stub(fileList, 'showMask'); + var hideMaskStub = sinon.stub(fileList, 'hideMask'); + fileList.changeDirectory('/anothersubdir'); expect(showMaskStub.calledOnce).toEqual(true); expect(hideMaskStub.calledOnce).toEqual(false); fakeServer.respond(); @@ -981,18 +985,23 @@ describe('FileList tests', function() { showMaskStub.restore(); hideMaskStub.restore(); }); - it('changes URL to target dir', function() { - FileList.changeDirectory('/somedir'); - expect(pushStateStub.calledOnce).toEqual(true); - expect(pushStateStub.getCall(0).args[0]).toEqual({dir: '/somedir'}); - expect(pushStateStub.getCall(0).args[2]).toEqual(OC.webroot + '/index.php/apps/files?dir=/somedir'); + it('triggers "changeDirectory" event when changing directory', function() { + var handler = sinon.stub(); + $('#app-content-files').on('changeDirectory', handler); + fileList.changeDirectory('/somedir'); + expect(handler.calledOnce).toEqual(true); + expect(handler.getCall(0).args[0].dir).toEqual('/somedir'); + }); + it('changes the directory when receiving "urlChanged" event', function() { + $('#app-content-files').trigger(new $.Event('urlChanged', {view: 'files', dir: '/somedir'})); + expect(fileList.getCurrentDirectory()).toEqual('/somedir'); }); it('refreshes breadcrumb after update', function() { - var setDirSpy = sinon.spy(FileList.breadcrumb, 'setDirectory'); - FileList.changeDirectory('/anothersubdir'); + var setDirSpy = sinon.spy(fileList.breadcrumb, 'setDirectory'); + fileList.changeDirectory('/anothersubdir'); fakeServer.respond(); - expect(FileList.breadcrumb.setDirectory.calledOnce).toEqual(true); - expect(FileList.breadcrumb.setDirectory.calledWith('/anothersubdir')).toEqual(true); + expect(fileList.breadcrumb.setDirectory.calledOnce).toEqual(true); + expect(fileList.breadcrumb.setDirectory.calledWith('/anothersubdir')).toEqual(true); setDirSpy.restore(); }); }); @@ -1013,20 +1022,20 @@ describe('FileList tests', function() { ]); }); it('clicking on root breadcrumb changes directory to root', function() { - FileList.changeDirectory('/subdir/two/three with space/four/five'); + fileList.changeDirectory('/subdir/two/three with space/four/five'); fakeServer.respond(); - var changeDirStub = sinon.stub(FileList, 'changeDirectory'); - FileList.breadcrumb.$el.find('.crumb:eq(0)').click(); + var changeDirStub = sinon.stub(fileList, 'changeDirectory'); + fileList.breadcrumb.$el.find('.crumb:eq(0)').click(); expect(changeDirStub.calledOnce).toEqual(true); expect(changeDirStub.getCall(0).args[0]).toEqual('/'); changeDirStub.restore(); }); it('clicking on breadcrumb changes directory', function() { - FileList.changeDirectory('/subdir/two/three with space/four/five'); + fileList.changeDirectory('/subdir/two/three with space/four/five'); fakeServer.respond(); - var changeDirStub = sinon.stub(FileList, 'changeDirectory'); - FileList.breadcrumb.$el.find('.crumb:eq(3)').click(); + var changeDirStub = sinon.stub(fileList, 'changeDirectory'); + fileList.breadcrumb.$el.find('.crumb:eq(3)').click(); expect(changeDirStub.calledOnce).toEqual(true); expect(changeDirStub.getCall(0).args[0]).toEqual('/subdir/two/three with space'); @@ -1034,9 +1043,9 @@ describe('FileList tests', function() { }); it('dropping files on breadcrumb calls move operation', function() { var request, query, testDir = '/subdir/two/three with space/four/five'; - FileList.changeDirectory(testDir); + fileList.changeDirectory(testDir); fakeServer.respond(); - var $crumb = FileList.breadcrumb.$el.find('.crumb:eq(3)'); + var $crumb = fileList.breadcrumb.$el.find('.crumb:eq(3)'); // no idea what this is but is required by the handler var ui = { helper: { @@ -1049,7 +1058,7 @@ describe('FileList tests', function() { $('<tr data-file="Two.jpg" data-dir="' + testDir + '"></tr>') ]); // simulate drop event - FileList._onDropOnBreadCrumb(new $.Event('drop', {target: $crumb}), ui); + fileList._onDropOnBreadCrumb(new $.Event('drop', {target: $crumb}), ui); // will trigger two calls to move.php (first one was previous list.php) expect(fakeServer.requests.length).toEqual(3); @@ -1075,10 +1084,10 @@ describe('FileList tests', function() { }); }); it('dropping files on same dir breadcrumb does nothing', function() { - var request, query, testDir = '/subdir/two/three with space/four/five'; - FileList.changeDirectory(testDir); + var testDir = '/subdir/two/three with space/four/five'; + fileList.changeDirectory(testDir); fakeServer.respond(); - var $crumb = FileList.breadcrumb.$el.find('.crumb:last'); + var $crumb = fileList.breadcrumb.$el.find('.crumb:last'); // no idea what this is but is required by the handler var ui = { helper: { @@ -1091,7 +1100,7 @@ describe('FileList tests', function() { $('<tr data-file="Two.jpg" data-dir="' + testDir + '"></tr>') ]); // simulate drop event - FileList._onDropOnBreadCrumb(new $.Event('drop', {target: $crumb}), ui); + fileList._onDropOnBreadCrumb(new $.Event('drop', {target: $crumb}), ui); // no extra server request expect(fakeServer.requests.length).toEqual(1); @@ -1099,32 +1108,32 @@ describe('FileList tests', function() { }); describe('Download Url', function() { it('returns correct download URL for single files', function() { - expect(Files.getDownloadUrl('some file.txt')).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=some%20file.txt'); - expect(Files.getDownloadUrl('some file.txt', '/anotherpath/abc')).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fanotherpath%2Fabc&files=some%20file.txt'); + expect(fileList.getDownloadUrl('some file.txt')).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=some%20file.txt'); + expect(fileList.getDownloadUrl('some file.txt', '/anotherpath/abc')).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fanotherpath%2Fabc&files=some%20file.txt'); $('#dir').val('/'); - expect(Files.getDownloadUrl('some file.txt')).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2F&files=some%20file.txt'); + expect(fileList.getDownloadUrl('some file.txt')).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2F&files=some%20file.txt'); }); it('returns correct download URL for multiple files', function() { - expect(Files.getDownloadUrl(['a b c.txt', 'd e f.txt'])).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=%5B%22a%20b%20c.txt%22%2C%22d%20e%20f.txt%22%5D'); + expect(fileList.getDownloadUrl(['a b c.txt', 'd e f.txt'])).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=%5B%22a%20b%20c.txt%22%2C%22d%20e%20f.txt%22%5D'); }); it('returns the correct ajax URL', function() { - expect(Files.getAjaxUrl('test', {a:1, b:'x y'})).toEqual(OC.webroot + '/index.php/apps/files/ajax/test.php?a=1&b=x%20y'); + expect(fileList.getAjaxUrl('test', {a:1, b:'x y'})).toEqual(OC.webroot + '/index.php/apps/files/ajax/test.php?a=1&b=x%20y'); }); }); describe('File selection', function() { beforeEach(function() { - FileList.setFiles(testFiles); + fileList.setFiles(testFiles); }); it('Selects a file when clicking its checkbox', function() { - var $tr = FileList.findFileEl('One.txt'); + var $tr = fileList.findFileEl('One.txt'); expect($tr.find('input:checkbox').prop('checked')).toEqual(false); $tr.find('td.filename input:checkbox').click(); expect($tr.find('input:checkbox').prop('checked')).toEqual(true); }); it('Selects/deselect a file when clicking on the name while holding Ctrl', function() { - var $tr = FileList.findFileEl('One.txt'); - var $tr2 = FileList.findFileEl('Three.pdf'); + var $tr = fileList.findFileEl('One.txt'); + var $tr2 = fileList.findFileEl('Three.pdf'); var e; expect($tr.find('input:checkbox').prop('checked')).toEqual(false); expect($tr2.find('input:checkbox').prop('checked')).toEqual(false); @@ -1142,7 +1151,7 @@ describe('FileList tests', function() { expect($tr.find('input:checkbox').prop('checked')).toEqual(true); expect($tr2.find('input:checkbox').prop('checked')).toEqual(true); - expect(_.pluck(FileList.getSelectedFiles(), 'name')).toEqual(['One.txt', 'Three.pdf']); + expect(_.pluck(fileList.getSelectedFiles(), 'name')).toEqual(['One.txt', 'Three.pdf']); // deselect now e = new $.Event('click'); @@ -1150,11 +1159,11 @@ describe('FileList tests', function() { $tr2.find('td.filename .name').trigger(e); expect($tr.find('input:checkbox').prop('checked')).toEqual(true); expect($tr2.find('input:checkbox').prop('checked')).toEqual(false); - expect(_.pluck(FileList.getSelectedFiles(), 'name')).toEqual(['One.txt']); + expect(_.pluck(fileList.getSelectedFiles(), 'name')).toEqual(['One.txt']); }); it('Selects a range when clicking on one file then Shift clicking on another one', function() { - var $tr = FileList.findFileEl('One.txt'); - var $tr2 = FileList.findFileEl('Three.pdf'); + var $tr = fileList.findFileEl('One.txt'); + var $tr2 = fileList.findFileEl('Three.pdf'); var e; $tr.find('td.filename input:checkbox').click(); e = new $.Event('click'); @@ -1163,16 +1172,16 @@ describe('FileList tests', function() { expect($tr.find('input:checkbox').prop('checked')).toEqual(true); expect($tr2.find('input:checkbox').prop('checked')).toEqual(true); - expect(FileList.findFileEl('Two.jpg').find('input:checkbox').prop('checked')).toEqual(true); - var selection = _.pluck(FileList.getSelectedFiles(), 'name'); + expect(fileList.findFileEl('Two.jpg').find('input:checkbox').prop('checked')).toEqual(true); + var selection = _.pluck(fileList.getSelectedFiles(), 'name'); expect(selection.length).toEqual(3); expect(selection).toContain('One.txt'); expect(selection).toContain('Two.jpg'); expect(selection).toContain('Three.pdf'); }); it('Selects a range when clicking on one file then Shift clicking on another one that is above the first one', function() { - var $tr = FileList.findFileEl('One.txt'); - var $tr2 = FileList.findFileEl('Three.pdf'); + var $tr = fileList.findFileEl('One.txt'); + var $tr2 = fileList.findFileEl('Three.pdf'); var e; $tr2.find('td.filename input:checkbox').click(); e = new $.Event('click'); @@ -1181,8 +1190,8 @@ describe('FileList tests', function() { expect($tr.find('input:checkbox').prop('checked')).toEqual(true); expect($tr2.find('input:checkbox').prop('checked')).toEqual(true); - expect(FileList.findFileEl('Two.jpg').find('input:checkbox').prop('checked')).toEqual(true); - var selection = _.pluck(FileList.getSelectedFiles(), 'name'); + expect(fileList.findFileEl('Two.jpg').find('input:checkbox').prop('checked')).toEqual(true); + var selection = _.pluck(fileList.getSelectedFiles(), 'name'); expect(selection.length).toEqual(3); expect(selection).toContain('One.txt'); expect(selection).toContain('Two.jpg'); @@ -1194,19 +1203,19 @@ describe('FileList tests', function() { expect($('#select_all').prop('checked')).toEqual(true); }); it('Selecting all files on the first visible page will not automatically check "select all" checkbox', function() { - FileList.setFiles(generateFiles(0, 41)); + fileList.setFiles(generateFiles(0, 41)); expect($('#select_all').prop('checked')).toEqual(false); $('#fileList tr td.filename input:checkbox').click(); expect($('#select_all').prop('checked')).toEqual(false); }); it('Clicking "select all" will select/deselect all files', function() { - FileList.setFiles(generateFiles(0, 41)); + fileList.setFiles(generateFiles(0, 41)); $('#select_all').click(); expect($('#select_all').prop('checked')).toEqual(true); $('#fileList tr input:checkbox').each(function() { expect($(this).prop('checked')).toEqual(true); }); - expect(_.pluck(FileList.getSelectedFiles(), 'name').length).toEqual(42); + expect(_.pluck(fileList.getSelectedFiles(), 'name').length).toEqual(42); $('#select_all').click(); expect($('#select_all').prop('checked')).toEqual(false); @@ -1214,71 +1223,71 @@ describe('FileList tests', function() { $('#fileList tr input:checkbox').each(function() { expect($(this).prop('checked')).toEqual(false); }); - expect(_.pluck(FileList.getSelectedFiles(), 'name').length).toEqual(0); + expect(_.pluck(fileList.getSelectedFiles(), 'name').length).toEqual(0); }); it('Clicking "select all" then deselecting a file will uncheck "select all"', function() { $('#select_all').click(); expect($('#select_all').prop('checked')).toEqual(true); - var $tr = FileList.findFileEl('One.txt'); + var $tr = fileList.findFileEl('One.txt'); $tr.find('input:checkbox').click(); expect($('#select_all').prop('checked')).toEqual(false); - expect(_.pluck(FileList.getSelectedFiles(), 'name').length).toEqual(3); + expect(_.pluck(fileList.getSelectedFiles(), 'name').length).toEqual(3); }); it('Updates the selection summary when doing a few manipulations with "Select all"', function() { $('#select_all').click(); expect($('#select_all').prop('checked')).toEqual(true); - var $tr = FileList.findFileEl('One.txt'); + var $tr = fileList.findFileEl('One.txt'); // unselect one $tr.find('input:checkbox').click(); expect($('#select_all').prop('checked')).toEqual(false); - expect(_.pluck(FileList.getSelectedFiles(), 'name').length).toEqual(3); + expect(_.pluck(fileList.getSelectedFiles(), 'name').length).toEqual(3); // select all $('#select_all').click(); expect($('#select_all').prop('checked')).toEqual(true); - expect(_.pluck(FileList.getSelectedFiles(), 'name').length).toEqual(4); + expect(_.pluck(fileList.getSelectedFiles(), 'name').length).toEqual(4); // unselect one $tr.find('input:checkbox').click(); expect($('#select_all').prop('checked')).toEqual(false); - expect(_.pluck(FileList.getSelectedFiles(), 'name').length).toEqual(3); + expect(_.pluck(fileList.getSelectedFiles(), 'name').length).toEqual(3); // re-select it $tr.find('input:checkbox').click(); expect($('#select_all').prop('checked')).toEqual(true); - expect(_.pluck(FileList.getSelectedFiles(), 'name').length).toEqual(4); + expect(_.pluck(fileList.getSelectedFiles(), 'name').length).toEqual(4); }); it('Auto-selects files on next page when "select all" is checked', function() { - FileList.setFiles(generateFiles(0, 41)); + fileList.setFiles(generateFiles(0, 41)); $('#select_all').click(); - expect(FileList.$fileList.find('tr input:checkbox:checked').length).toEqual(20); - FileList._nextPage(true); - expect(FileList.$fileList.find('tr input:checkbox:checked').length).toEqual(40); - FileList._nextPage(true); - expect(FileList.$fileList.find('tr input:checkbox:checked').length).toEqual(42); - expect(_.pluck(FileList.getSelectedFiles(), 'name').length).toEqual(42); + expect(fileList.$fileList.find('tr input:checkbox:checked').length).toEqual(20); + fileList._nextPage(true); + expect(fileList.$fileList.find('tr input:checkbox:checked').length).toEqual(40); + fileList._nextPage(true); + expect(fileList.$fileList.find('tr input:checkbox:checked').length).toEqual(42); + expect(_.pluck(fileList.getSelectedFiles(), 'name').length).toEqual(42); }); it('Selecting files updates selection summary', function() { var $summary = $('#headerName a.name>span:first'); expect($summary.text()).toEqual('Name'); - FileList.findFileEl('One.txt').find('input:checkbox').click(); - FileList.findFileEl('Three.pdf').find('input:checkbox').click(); - FileList.findFileEl('somedir').find('input:checkbox').click(); + fileList.findFileEl('One.txt').find('input:checkbox').click(); + fileList.findFileEl('Three.pdf').find('input:checkbox').click(); + fileList.findFileEl('somedir').find('input:checkbox').click(); expect($summary.text()).toEqual('1 folder & 2 files'); }); it('Unselecting files hides selection summary', function() { var $summary = $('#headerName a.name>span:first'); - FileList.findFileEl('One.txt').find('input:checkbox').click().click(); + fileList.findFileEl('One.txt').find('input:checkbox').click().click(); expect($summary.text()).toEqual('Name'); }); it('Select/deselect files shows/hides file actions', function() { var $actions = $('#headerName .selectedActions'); - var $checkbox = FileList.findFileEl('One.txt').find('input:checkbox'); + var $checkbox = fileList.findFileEl('One.txt').find('input:checkbox'); expect($actions.hasClass('hidden')).toEqual(true); $checkbox.click(); expect($actions.hasClass('hidden')).toEqual(false); @@ -1300,31 +1309,31 @@ describe('FileList tests', function() { }, JSON.stringify(data) ]); - FileList.changeDirectory('/'); + fileList.changeDirectory('/'); fakeServer.respond(); expect($('#select_all').prop('checked')).toEqual(false); - expect(_.pluck(FileList.getSelectedFiles(), 'name')).toEqual([]); + expect(_.pluck(fileList.getSelectedFiles(), 'name')).toEqual([]); }); it('getSelectedFiles returns the selected files even when they are on the next page', function() { var selectedFiles; - FileList.setFiles(generateFiles(0, 41)); + fileList.setFiles(generateFiles(0, 41)); $('#select_all').click(); // unselect one to not have the "allFiles" case - FileList.$fileList.find('tr input:checkbox:first').click(); + fileList.$fileList.find('tr input:checkbox:first').click(); // only 20 files visible, must still return all the selected ones - selectedFiles = _.pluck(FileList.getSelectedFiles(), 'name'); + selectedFiles = _.pluck(fileList.getSelectedFiles(), 'name'); expect(selectedFiles.length).toEqual(41); }); describe('Actions', function() { beforeEach(function() { - FileList.findFileEl('One.txt').find('input:checkbox').click(); - FileList.findFileEl('Three.pdf').find('input:checkbox').click(); - FileList.findFileEl('somedir').find('input:checkbox').click(); + fileList.findFileEl('One.txt').find('input:checkbox').click(); + fileList.findFileEl('Three.pdf').find('input:checkbox').click(); + fileList.findFileEl('somedir').find('input:checkbox').click(); }); it('getSelectedFiles returns the selected file data', function() { - var files = FileList.getSelectedFiles(); + var files = fileList.getSelectedFiles(); expect(files.length).toEqual(3); expect(files[0]).toEqual({ id: 1, @@ -1352,8 +1361,8 @@ describe('FileList tests', function() { }); }); it('Removing a file removes it from the selection', function() { - FileList.remove('Three.pdf'); - var files = FileList.getSelectedFiles(); + fileList.remove('Three.pdf'); + var files = fileList.getSelectedFiles(); expect(files.length).toEqual(2); expect(files[0]).toEqual({ id: 1, @@ -1412,10 +1421,10 @@ describe('FileList tests', function() { { 'Content-Type': 'application/json' }, JSON.stringify({status: 'success'}) ); - expect(FileList.findFileEl('One.txt').length).toEqual(0); - expect(FileList.findFileEl('Three.pdf').length).toEqual(0); - expect(FileList.findFileEl('somedir').length).toEqual(0); - expect(FileList.findFileEl('Two.jpg').length).toEqual(1); + expect(fileList.findFileEl('One.txt').length).toEqual(0); + expect(fileList.findFileEl('Three.pdf').length).toEqual(0); + expect(fileList.findFileEl('somedir').length).toEqual(0); + expect(fileList.findFileEl('Two.jpg').length).toEqual(1); }); it('Deletes all files when all selected when "Delete" clicked', function() { var request; @@ -1431,20 +1440,20 @@ describe('FileList tests', function() { { 'Content-Type': 'application/json' }, JSON.stringify({status: 'success'}) ); - expect(FileList.isEmpty).toEqual(true); + expect(fileList.isEmpty).toEqual(true); }); }); }); it('resets the file selection on reload', function() { - FileList.$el.find('#select_all').click(); - FileList.reload(); - expect(FileList.$el.find('#select_all').prop('checked')).toEqual(false); - expect(FileList.getSelectedFiles()).toEqual([]); + fileList.$el.find('#select_all').click(); + fileList.reload(); + expect(fileList.$el.find('#select_all').prop('checked')).toEqual(false); + expect(fileList.getSelectedFiles()).toEqual([]); }); }); describe('Sorting files', function() { it('Sorts by name by default', function() { - FileList.reload(); + fileList.reload(); expect(fakeServer.requests.length).toEqual(1); var url = fakeServer.requests[0].url; var query = OC.parseQueryString(url.substr(url.indexOf('?') + 1)); @@ -1452,7 +1461,7 @@ describe('FileList tests', function() { expect(query.sortdirection).toEqual('asc'); }); it('Reloads file list with a different sort when clicking on column header of unsorted column', function() { - FileList.$el.find('.column-size .columntitle').click(); + fileList.$el.find('.column-size .columntitle').click(); expect(fakeServer.requests.length).toEqual(1); var url = fakeServer.requests[0].url; var query = OC.parseQueryString(url.substr(url.indexOf('?') + 1)); @@ -1460,7 +1469,7 @@ describe('FileList tests', function() { expect(query.sortdirection).toEqual('asc'); }); it('Toggles sort direction when clicking on already sorted column', function() { - FileList.$el.find('.column-name .columntitle').click(); + fileList.$el.find('.column-name .columntitle').click(); expect(fakeServer.requests.length).toEqual(1); var url = fakeServer.requests[0].url; var query = OC.parseQueryString(url.substr(url.indexOf('?') + 1)); @@ -1468,42 +1477,42 @@ describe('FileList tests', function() { expect(query.sortdirection).toEqual('desc'); }); it('Toggles the sort indicator when clicking on a column header', function() { - var ASC_CLASS = FileList.SORT_INDICATOR_ASC_CLASS; - var DESC_CLASS = FileList.SORT_INDICATOR_DESC_CLASS; - FileList.$el.find('.column-size .columntitle').click(); + var ASC_CLASS = fileList.SORT_INDICATOR_ASC_CLASS; + var DESC_CLASS = fileList.SORT_INDICATOR_DESC_CLASS; + fileList.$el.find('.column-size .columntitle').click(); // moves triangle to size column expect( - FileList.$el.find('.column-name .sort-indicator').hasClass(ASC_CLASS + ' ' + DESC_CLASS) + fileList.$el.find('.column-name .sort-indicator').hasClass(ASC_CLASS + ' ' + DESC_CLASS) ).toEqual(false); expect( - FileList.$el.find('.column-size .sort-indicator').hasClass(ASC_CLASS) + fileList.$el.find('.column-size .sort-indicator').hasClass(ASC_CLASS) ).toEqual(true); // click again on size column, reverses direction - FileList.$el.find('.column-size .columntitle').click(); + fileList.$el.find('.column-size .columntitle').click(); expect( - FileList.$el.find('.column-size .sort-indicator').hasClass(DESC_CLASS) + fileList.$el.find('.column-size .sort-indicator').hasClass(DESC_CLASS) ).toEqual(true); // click again on size column, reverses direction - FileList.$el.find('.column-size .columntitle').click(); + fileList.$el.find('.column-size .columntitle').click(); expect( - FileList.$el.find('.column-size .sort-indicator').hasClass(ASC_CLASS) + fileList.$el.find('.column-size .sort-indicator').hasClass(ASC_CLASS) ).toEqual(true); // click on mtime column, moves indicator there - FileList.$el.find('.column-mtime .columntitle').click(); + fileList.$el.find('.column-mtime .columntitle').click(); expect( - FileList.$el.find('.column-size .sort-indicator').hasClass(ASC_CLASS + ' ' + DESC_CLASS) + fileList.$el.find('.column-size .sort-indicator').hasClass(ASC_CLASS + ' ' + DESC_CLASS) ).toEqual(false); expect( - FileList.$el.find('.column-mtime .sort-indicator').hasClass(ASC_CLASS) + fileList.$el.find('.column-mtime .sort-indicator').hasClass(ASC_CLASS) ).toEqual(true); }); it('Uses correct sort comparator when inserting files', function() { - testFiles.sort(FileList.Comparators.size); + testFiles.sort(OCA.Files.FileList.Comparators.size); // this will make it reload the testFiles with the correct sorting - FileList.$el.find('.column-size .columntitle').click(); + fileList.$el.find('.column-size .columntitle').click(); expect(fakeServer.requests.length).toEqual(1); fakeServer.requests[0].respond( 200, @@ -1524,20 +1533,20 @@ describe('FileList tests', function() { size: 40001, etag: '999' }; - FileList.add(newFileData); - expect(FileList.files.length).toEqual(5); - expect(FileList.$fileList.find('tr').length).toEqual(5); - expect(FileList.findFileEl('One.txt').index()).toEqual(0); - expect(FileList.findFileEl('somedir').index()).toEqual(1); - expect(FileList.findFileEl('Two.jpg').index()).toEqual(2); - expect(FileList.findFileEl('new file.txt').index()).toEqual(3); - expect(FileList.findFileEl('Three.pdf').index()).toEqual(4); + fileList.add(newFileData); + expect(fileList.files.length).toEqual(5); + expect(fileList.$fileList.find('tr').length).toEqual(5); + expect(fileList.findFileEl('One.txt').index()).toEqual(0); + expect(fileList.findFileEl('somedir').index()).toEqual(1); + expect(fileList.findFileEl('Two.jpg').index()).toEqual(2); + expect(fileList.findFileEl('new file.txt').index()).toEqual(3); + expect(fileList.findFileEl('Three.pdf').index()).toEqual(4); }); it('Uses correct reversed sort comparator when inserting files', function() { - testFiles.sort(FileList.Comparators.size); + testFiles.sort(OCA.Files.FileList.Comparators.size); testFiles.reverse(); // this will make it reload the testFiles with the correct sorting - FileList.$el.find('.column-size .columntitle').click(); + fileList.$el.find('.column-size .columntitle').click(); expect(fakeServer.requests.length).toEqual(1); fakeServer.requests[0].respond( 200, @@ -1551,7 +1560,7 @@ describe('FileList tests', function() { }) ); // reverse sort - FileList.$el.find('.column-size .columntitle').click(); + fileList.$el.find('.column-size .columntitle').click(); fakeServer.requests[1].respond( 200, { 'Content-Type': 'application/json' }, @@ -1571,14 +1580,14 @@ describe('FileList tests', function() { size: 40001, etag: '999' }; - FileList.add(newFileData); - expect(FileList.files.length).toEqual(5); - expect(FileList.$fileList.find('tr').length).toEqual(5); - expect(FileList.findFileEl('One.txt').index()).toEqual(4); - expect(FileList.findFileEl('somedir').index()).toEqual(3); - expect(FileList.findFileEl('Two.jpg').index()).toEqual(2); - expect(FileList.findFileEl('new file.txt').index()).toEqual(1); - expect(FileList.findFileEl('Three.pdf').index()).toEqual(0); + fileList.add(newFileData); + expect(fileList.files.length).toEqual(5); + expect(fileList.$fileList.find('tr').length).toEqual(5); + expect(fileList.findFileEl('One.txt').index()).toEqual(4); + expect(fileList.findFileEl('somedir').index()).toEqual(3); + expect(fileList.findFileEl('Two.jpg').index()).toEqual(2); + expect(fileList.findFileEl('new file.txt').index()).toEqual(1); + expect(fileList.findFileEl('Three.pdf').index()).toEqual(0); }); }); }); diff --git a/apps/files/tests/js/filesSpec.js b/apps/files/tests/js/filesSpec.js index 7f8848619f5..4f8d5a29318 100644 --- a/apps/files/tests/js/filesSpec.js +++ b/apps/files/tests/js/filesSpec.js @@ -19,8 +19,9 @@ * */ -/* global OC, Files */ -describe('Files tests', function() { +describe('OCA.Files.Files tests', function() { + var Files = OCA.Files.Files; + describe('File name validation', function() { it('Validates correct file names', function() { var fileNames = [ @@ -83,18 +84,6 @@ describe('Files tests', function() { }); }); describe('getDownloadUrl', function() { - var curDirStub; - beforeEach(function() { - curDirStub = sinon.stub(FileList, 'getCurrentDirectory'); - }); - afterEach(function() { - curDirStub.restore(); - }); - it('returns the ajax download URL when only filename specified', function() { - curDirStub.returns('/subdir'); - var url = Files.getDownloadUrl('test file.txt'); - expect(url).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=test%20file.txt'); - }); it('returns the ajax download URL when filename and dir specified', function() { var url = Files.getDownloadUrl('test file.txt', '/subdir'); expect(url).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=test%20file.txt'); diff --git a/apps/files/tests/js/filesummarySpec.js b/apps/files/tests/js/filesummarySpec.js index c493700de38..5e39dd1d232 100644 --- a/apps/files/tests/js/filesummarySpec.js +++ b/apps/files/tests/js/filesummarySpec.js @@ -20,7 +20,8 @@ */ /* global FileSummary */ -describe('FileSummary tests', function() { +describe('OCA.Files.FileSummary tests', function() { + var FileSummary = OCA.Files.FileSummary; var $container; beforeEach(function() { |