/** * Copyright (c) 2014 Vincent Petry * * @author John Molakvoæ * @author Vincent Petry * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 program. If not, see . * */ describe('OCA.Files.FavoritesPlugin tests', function() { var Plugin = OCA.Files.FavoritesPlugin; var fileList; beforeEach(function() { $('#testArea').append( '
' + '
' + '
' + '
' + '' + '' + '
' + '
' + '' ); OC.Plugins.attach('OCA.Files.App', Plugin); fileList = Plugin.showFileList($('#app-content-favorites')); }); afterEach(function() { OC.Plugins.detach('OCA.Files.App', Plugin); }); describe('initialization', function() { it('inits favorites list on show', function() { expect(fileList).toBeDefined(); }); }); describe('file actions', function() { it('provides default file actions', function() { var fileActions = fileList.fileActions; expect(fileActions.actions.all).toBeDefined(); expect(fileActions.actions.all.Delete).toBeDefined(); expect(fileActions.actions.all.Rename).toBeDefined(); expect(fileActions.actions.all.Download).toBeDefined(); expect(fileActions.defaults.dir).toEqual('Open'); }); it('provides custom file actions', function() { var actionStub = sinon.stub(); // regular file action OCA.Files.fileActions.register( 'all', 'RegularTest', OC.PERMISSION_READ, OC.imagePath('core', 'actions/shared'), actionStub ); Plugin.favoritesFileList = null; fileList = Plugin.showFileList($('#app-content-favorites')); expect(fileList.fileActions.actions.all.RegularTest).toBeDefined(); }); it('redirects to files app when opening a directory', function() { var oldList = OCA.Files.App.fileList; // dummy new list to make sure it exists OCA.Files.App.fileList = new OCA.Files.FileList($('
')); var setActiveViewStub = sinon.stub(OCA.Files.App, 'setActiveView'); // create dummy table so we can click the dom var $table = '
'; $('#app-content-favorites').append($table); Plugin.favoritesFileList = null; fileList = Plugin.showFileList($('#app-content-favorites')); fileList.setFiles([{ name: 'testdir', type: 'dir', path: '/somewhere/inside/subdir', counterParts: ['user2'], shareOwner: 'user2' }]); fileList.findFileEl('testdir').find('td .nametext').click(); expect(OCA.Files.App.fileList.getCurrentDirectory()).toEqual('/somewhere/inside/subdir/testdir'); expect(setActiveViewStub.calledOnce).toEqual(true); expect(setActiveViewStub.calledWith('files')).toEqual(true); setActiveViewStub.restore(); // restore old list OCA.Files.App.fileList = oldList; }); }); });