aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/tests/js/favoritespluginspec.js
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-11-18 18:53:45 +0100
committerVincent Petry <pvince81@owncloud.com>2014-12-15 12:10:54 +0100
commita5bb66f4a723bce5c5fbe919a48cd5133204ef62 (patch)
treeb2e067bde8aaa1de6973adc7760fafb1e37e9084 /apps/files/tests/js/favoritespluginspec.js
parentc6be491a89a4eebe15bcb20f6e0b01f23a093761 (diff)
downloadnextcloud-server-a5bb66f4a723bce5c5fbe919a48cd5133204ef62.tar.gz
nextcloud-server-a5bb66f4a723bce5c5fbe919a48cd5133204ef62.zip
Added favorites feature to the files app
Diffstat (limited to 'apps/files/tests/js/favoritespluginspec.js')
-rw-r--r--apps/files/tests/js/favoritespluginspec.js130
1 files changed, 130 insertions, 0 deletions
diff --git a/apps/files/tests/js/favoritespluginspec.js b/apps/files/tests/js/favoritespluginspec.js
new file mode 100644
index 00000000000..90b40ede74b
--- /dev/null
+++ b/apps/files/tests/js/favoritespluginspec.js
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+describe('OCA.Files.FavoritesPlugin tests', function() {
+ var Plugin = OCA.Files.FavoritesPlugin;
+ var fileList;
+
+ beforeEach(function() {
+ $('#testArea').append(
+ '<div id="app-navigation">' +
+ '<ul><li data-id="files"><a>Files</a></li>' +
+ '<li data-id="sharingin"><a></a></li>' +
+ '<li data-id="sharingout"><a></a></li>' +
+ '</ul></div>' +
+ '<div id="app-content">' +
+ '<div id="app-content-files" class="hidden">' +
+ '</div>' +
+ '<div id="app-content-favorites" class="hidden">' +
+ '</div>' +
+ '</div>' +
+ '</div>'
+ );
+ 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() {
+ var oldLegacyFileActions;
+
+ beforeEach(function() {
+ oldLegacyFileActions = window.FileActions;
+ window.FileActions = new OCA.Files.FileActions();
+ });
+
+ afterEach(function() {
+ window.FileActions = oldLegacyFileActions;
+ });
+ 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('does not provide legacy file actions', function() {
+ var actionStub = sinon.stub();
+ // legacy file action
+ window.FileActions.register(
+ 'all',
+ 'LegacyTest',
+ OC.PERMISSION_READ,
+ OC.imagePath('core', 'actions/shared'),
+ actionStub
+ );
+
+ Plugin.favoritesFileList = null;
+ fileList = Plugin.showFileList($('#app-content-favorites'));
+
+ expect(fileList.fileActions.actions.all.LegacyTest).not.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($('<table><thead></thead><tbody></tbody></table>'));
+
+ var setActiveViewStub = sinon.stub(OCA.Files.App, 'setActiveView');
+ // create dummy table so we can click the dom
+ var $table = '<table><thead></thead><tbody id="fileList"></tbody></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 a.name').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;
+ });
+ });
+});
+