diff options
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r-- | apps/files_trashbin/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | apps/files_trashbin/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | apps/files_trashbin/lib/AppInfo/Application.php | 19 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Listeners/LoadAdditionalScripts.php | 41 | ||||
-rw-r--r-- | apps/files_trashbin/src/main.ts | 39 | ||||
-rw-r--r-- | apps/files_trashbin/src/services/client.ts (renamed from apps/files_trashbin/src/files_trashbin.js) | 20 | ||||
-rw-r--r-- | apps/files_trashbin/src/services/trashbin.ts | 95 | ||||
-rw-r--r-- | apps/files_trashbin/src/trash.scss | 22 | ||||
-rw-r--r-- | apps/files_trashbin/tests/js/appSpec.js | 70 | ||||
-rw-r--r-- | apps/files_trashbin/tests/js/filelistSpec.js | 397 |
10 files changed, 197 insertions, 508 deletions
diff --git a/apps/files_trashbin/composer/composer/autoload_classmap.php b/apps/files_trashbin/composer/composer/autoload_classmap.php index 760044d4f87..01f602448d4 100644 --- a/apps/files_trashbin/composer/composer/autoload_classmap.php +++ b/apps/files_trashbin/composer/composer/autoload_classmap.php @@ -21,6 +21,7 @@ return array( 'OCA\\Files_Trashbin\\Expiration' => $baseDir . '/../lib/Expiration.php', 'OCA\\Files_Trashbin\\Helper' => $baseDir . '/../lib/Helper.php', 'OCA\\Files_Trashbin\\Hooks' => $baseDir . '/../lib/Hooks.php', + 'OCA\\Files_Trashbin\\Listeners\\LoadAdditionalScripts' => $baseDir . '/../lib/Listeners/LoadAdditionalScripts.php', 'OCA\\Files_Trashbin\\Migration\\Version1010Date20200630192639' => $baseDir . '/../lib/Migration/Version1010Date20200630192639.php', 'OCA\\Files_Trashbin\\Sabre\\AbstractTrash' => $baseDir . '/../lib/Sabre/AbstractTrash.php', 'OCA\\Files_Trashbin\\Sabre\\AbstractTrashFile' => $baseDir . '/../lib/Sabre/AbstractTrashFile.php', diff --git a/apps/files_trashbin/composer/composer/autoload_static.php b/apps/files_trashbin/composer/composer/autoload_static.php index ef52ac0e1e7..40f3310c663 100644 --- a/apps/files_trashbin/composer/composer/autoload_static.php +++ b/apps/files_trashbin/composer/composer/autoload_static.php @@ -36,6 +36,7 @@ class ComposerStaticInitFiles_Trashbin 'OCA\\Files_Trashbin\\Expiration' => __DIR__ . '/..' . '/../lib/Expiration.php', 'OCA\\Files_Trashbin\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php', 'OCA\\Files_Trashbin\\Hooks' => __DIR__ . '/..' . '/../lib/Hooks.php', + 'OCA\\Files_Trashbin\\Listeners\\LoadAdditionalScripts' => __DIR__ . '/..' . '/../lib/Listeners/LoadAdditionalScripts.php', 'OCA\\Files_Trashbin\\Migration\\Version1010Date20200630192639' => __DIR__ . '/..' . '/../lib/Migration/Version1010Date20200630192639.php', 'OCA\\Files_Trashbin\\Sabre\\AbstractTrash' => __DIR__ . '/..' . '/../lib/Sabre/AbstractTrash.php', 'OCA\\Files_Trashbin\\Sabre\\AbstractTrashFile' => __DIR__ . '/..' . '/../lib/Sabre/AbstractTrashFile.php', diff --git a/apps/files_trashbin/lib/AppInfo/Application.php b/apps/files_trashbin/lib/AppInfo/Application.php index 41466a865ac..461eade6802 100644 --- a/apps/files_trashbin/lib/AppInfo/Application.php +++ b/apps/files_trashbin/lib/AppInfo/Application.php @@ -26,8 +26,10 @@ namespace OCA\Files_Trashbin\AppInfo; use OCA\DAV\Connector\Sabre\Principal; +use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCA\Files_Trashbin\Capabilities; use OCA\Files_Trashbin\Expiration; +use OCA\Files_Trashbin\Listeners\LoadAdditionalScripts; use OCA\Files_Trashbin\Trash\ITrashManager; use OCA\Files_Trashbin\Trash\TrashManager; use OCA\Files_Trashbin\UserMigration\TrashbinMigrator; @@ -55,6 +57,11 @@ class Application extends App implements IBootstrap { $context->registerServiceAlias('principalBackend', Principal::class); $context->registerUserMigrator(TrashbinMigrator::class); + + $context->registerEventListener( + LoadAdditionalScriptsEvent::class, + LoadAdditionalScripts::class + ); } public function boot(IBootContext $context): void { @@ -68,18 +75,6 @@ class Application extends App implements IBootstrap { \OCP\Util::connectHook('OC_Filesystem', 'post_write', 'OCA\Files_Trashbin\Hooks', 'post_write_hook'); // pre and post-rename, disable trash logic for the copy+unlink case \OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Files_Trashbin\Trashbin', 'ensureFileScannedHook'); - - \OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N(self::APP_ID); - return [ - 'id' => 'trashbin', - 'appname' => self::APP_ID, - 'script' => 'list.php', - 'order' => 50, - 'name' => $l->t('Deleted files'), - 'classes' => 'pinned', - ]; - }); } public function registerTrashBackends(IServerContainer $serverContainer, ILogger $logger, IAppManager $appManager, ITrashManager $trashManager) { diff --git a/apps/files_trashbin/lib/Listeners/LoadAdditionalScripts.php b/apps/files_trashbin/lib/Listeners/LoadAdditionalScripts.php new file mode 100644 index 00000000000..33b1b2de1cc --- /dev/null +++ b/apps/files_trashbin/lib/Listeners/LoadAdditionalScripts.php @@ -0,0 +1,41 @@ +<?php +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2022, John Molakvoæ <skjnldsv@protonmail.com> + * + * @author John Molakvoæ <skjnldsv@protonmail.com> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ +namespace OCA\Files_Trashbin\Listeners; + +use OCA\Files_Trashbin\AppInfo\Application; +use OCA\Files\Event\LoadAdditionalScriptsEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Util; + +class LoadAdditionalScripts implements IEventListener { + public function handle(Event $event): void { + if (!($event instanceof LoadAdditionalScriptsEvent)) { + return; + } + + Util::addScript(Application::APP_ID, 'main'); + } +} diff --git a/apps/files_trashbin/src/main.ts b/apps/files_trashbin/src/main.ts new file mode 100644 index 00000000000..626b9ef813d --- /dev/null +++ b/apps/files_trashbin/src/main.ts @@ -0,0 +1,39 @@ +/** + * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com> + * + * @author John Molakvoæ <skjnldsv@protonmail.com> + * + * @license AGPL-3.0-or-later + * + * 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 <http://www.gnu.org/licenses/>. + * + */ +import type NavigationService from '../../files/src/services/Navigation' + +import { translate as t } from '@nextcloud/l10n' +import DeleteSvg from '@mdi/svg/svg/delete.svg?raw' + +import getContents from './services/trashbin' + +const Navigation = window.OCP.Files.Navigation as NavigationService +Navigation.register({ + id: 'trashbin', + name: t('files_trashbin', 'Deleted files'), + + icon: DeleteSvg, + order: 50, + sticky: true, + + getContents, +}) diff --git a/apps/files_trashbin/src/files_trashbin.js b/apps/files_trashbin/src/services/client.ts index f66e78905f6..9fb3361839a 100644 --- a/apps/files_trashbin/src/files_trashbin.js +++ b/apps/files_trashbin/src/services/client.ts @@ -1,7 +1,7 @@ /** - * @copyright Copyright (c) 2016 Roeland Jago Douma <roeland@famdouma.nl> + * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com> * - * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author John Molakvoæ <skjnldsv@protonmail.com> * * @license AGPL-3.0-or-later * @@ -19,9 +19,15 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ +import { createClient } from 'webdav' +import { generateRemoteUrl } from '@nextcloud/router' +import { getCurrentUser, getRequestToken } from '@nextcloud/auth' -import './app.js' -import './filelist.js' -import './trash.scss' - -window.OCA.Trashbin = OCA.Trashbin +export const rootPath = `/trashbin/${getCurrentUser()?.uid}/trash` +export const rootUrl = generateRemoteUrl('dav' + rootPath) +const client = createClient(rootUrl, { + headers: { + requesttoken: getRequestToken(), + }, +}) +export default client diff --git a/apps/files_trashbin/src/services/trashbin.ts b/apps/files_trashbin/src/services/trashbin.ts new file mode 100644 index 00000000000..2070cfc92b0 --- /dev/null +++ b/apps/files_trashbin/src/services/trashbin.ts @@ -0,0 +1,95 @@ +/** + * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com> + * + * @author John Molakvoæ <skjnldsv@protonmail.com> + * + * @license AGPL-3.0-or-later + * + * 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 <http://www.gnu.org/licenses/>. + * + */ +/* eslint-disable */ +import { getCurrentUser } from '@nextcloud/auth' +import { File, Folder, parseWebdavPermissions } from '@nextcloud/files' +import { generateRemoteUrl } from '@nextcloud/router' + +import type { FileStat, ResponseDataDetailed } from 'webdav' +import type { ContentsWithRoot } from '../../../files/src/services/Navigation' + +import client, { rootPath } from './client' + +const data = `<?xml version="1.0"?> +<d:propfind xmlns:d="DAV:" + xmlns:oc="http://owncloud.org/ns" + xmlns:nc="http://nextcloud.org/ns"> + <d:prop> + <nc:trashbin-filename /> + <nc:trashbin-deletion-time /> + <nc:trashbin-original-location /> + <nc:trashbin-title /> + <d:getlastmodified /> + <d:getetag /> + <d:getcontenttype /> + <d:resourcetype /> + <oc:fileid /> + <oc:permissions /> + <oc:size /> + <d:getcontentlength /> + </d:prop> +</d:propfind>` + +const resultToNode = function(node: FileStat): File | Folder { + const permissions = parseWebdavPermissions(node.props?.permissions) + const owner = getCurrentUser()?.uid as string + + const nodeData = { + id: node.props?.fileid as number || 0, + source: generateRemoteUrl('dav' + rootPath + node.filename), + mtime: new Date(node.lastmod), + mime: node.mime as string, + size: node.props?.size as number || 0, + permissions, + owner, + root: rootPath, + attributes: { + ...node, + ...node.props, + // Override displayed name on the list + displayName: node.props?.['trashbin-filename'], + }, + } + + return node.type === 'file' + ? new File(nodeData) + : new Folder(nodeData) +} + +export default async (path: string = '/'): Promise<ContentsWithRoot> => { + // TODO: use only one request when webdav-client supports it + // @see https://github.com/perry-mitchell/webdav-client/pull/334 + const rootResponse = await client.stat(path, { + details: true, + data, + }) as ResponseDataDetailed<FileStat> + + const contentsResponse = await client.getDirectoryContents(path, { + details: true, + data, + }) as ResponseDataDetailed<FileStat[]> + + return { + folder: resultToNode(rootResponse.data) as Folder, + contents: contentsResponse.data.map(resultToNode), + } +} diff --git a/apps/files_trashbin/src/trash.scss b/apps/files_trashbin/src/trash.scss deleted file mode 100644 index 633107c9d6d..00000000000 --- a/apps/files_trashbin/src/trash.scss +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2014 - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * - */ -#app-content-trashbin tbody tr[data-type="file"] td a.name, -#app-content-trashbin tbody tr[data-type="file"] td a.name span.nametext, -#app-content-trashbin tbody tr[data-type="file"] td a.name span.nametext span { - cursor: default; -} - -#app-content-trashbin .summary :last-child { - padding: 0; -} -#app-content-trashbin .files-filestable .summary .filesize { - display: none; -} - diff --git a/apps/files_trashbin/tests/js/appSpec.js b/apps/files_trashbin/tests/js/appSpec.js deleted file mode 100644 index 281e7bbc2ba..00000000000 --- a/apps/files_trashbin/tests/js/appSpec.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @copyright 2014 Vincent Petry <pvince81@owncloud.com> - * - * @author Vincent Petry <vincent@nextcloud.com> - * - * @license AGPL-3.0-or-later - * - * 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 <http://www.gnu.org/licenses/>. - * - */ - -describe('OCA.Trashbin.App tests', function() { - var App = OCA.Trashbin.App; - - beforeEach(function() { - $('#testArea').append( - '<div id="app-navigation">' + - '<ul><li data-id="files"><a>Files</a></li>' + - '<li data-id="trashbin"><a>Trashbin</a></li>' + - '</div>' + - '<div id="app-content">' + - '<div id="app-content-files" class="hidden">' + - '</div>' + - '<div id="app-content-trashbin" class="hidden">' + - '</div>' + - '</div>' + - '</div>' - ); - App.initialize($('#app-content-trashbin')); - }); - afterEach(function() { - App._initialized = false; - App.fileList = null; - }); - - describe('initialization', function() { - it('creates a custom filelist instance', function() { - App.initialize(); - expect(App.fileList).toBeDefined(); - expect(App.fileList.$el.is('#app-content-trashbin')).toEqual(true); - }); - - it('registers custom file actions', function() { - var fileActions; - App.initialize(); - - fileActions = App.fileList.fileActions; - - expect(fileActions.actions.all).toBeDefined(); - expect(fileActions.actions.all.Restore).toBeDefined(); - expect(fileActions.actions.all.Delete).toBeDefined(); - - expect(fileActions.actions.all.Rename).not.toBeDefined(); - expect(fileActions.actions.all.Download).not.toBeDefined(); - - expect(fileActions.defaults.dir).toEqual('Open'); - }); - }); -}); diff --git a/apps/files_trashbin/tests/js/filelistSpec.js b/apps/files_trashbin/tests/js/filelistSpec.js deleted file mode 100644 index 9e27188efb8..00000000000 --- a/apps/files_trashbin/tests/js/filelistSpec.js +++ /dev/null @@ -1,397 +0,0 @@ -/** - * @copyright 2014 Vincent Petry <pvince81@owncloud.com> - * - * @author Abijeet <abijeetpatro@gmail.com> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Jan C. Borchardt <hey@jancborchardt.net> - * @author Jan-Christoph Borchardt <hey@jancborchardt.net> - * @author John Molakvoæ <skjnldsv@protonmail.com> - * @author Robin Appelman <robin@icewind.nl> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @license AGPL-3.0-or-later - * - * 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 <http://www.gnu.org/licenses/>. - * - */ - -describe('OCA.Trashbin.FileList tests', function () { - var testFiles, alertStub, notificationStub, fileList, client; - - beforeEach(function () { - alertStub = sinon.stub(OC.dialogs, 'alert'); - notificationStub = sinon.stub(OC.Notification, 'show'); - - client = new OC.Files.Client({ - host: 'localhost', - port: 80, - root: '/remote.php/dav/trashbin/user', - useHTTPS: OC.getProtocol() === 'https' - }); - - // init parameters and test table elements - $('#testArea').append( - '<div id="app-content">' + - // set this but it shouldn't be used (could be the one from the - // files app) - '<input type="hidden" id="permissions" value="31"></input>' + - // dummy controls - '<div class="files-controls">' + - ' <div class="actions creatable"></div>' + - ' <div class="notCreatable"></div>' + - '</div>' + - // dummy table - // TODO: at some point this will be rendered by the fileList class itself! - '<table class="files-filestable list-container view-grid">' + - '<thead><tr><th class="hidden column-name">' + - '<input type="checkbox" id="select_all_trash" class="select-all">' + - '<span class="name">Name</span>' + - '<span class="selectedActions hidden">' + - '<a href="" class="actions-selected"><span class="icon icon-more"></span><span>Actions</span>' + - '</span>' + - '</th></tr></thead>' + - '<tbody class="files-fileList"></tbody>' + - '<tfoot></tfoot>' + - '</table>' + - '<div class="emptyfilelist emptycontent">Empty content message</div>' + - '</div>' - ); - - testFiles = [{ - id: 1, - type: 'file', - name: 'One.txt.d11111', - displayName: 'One.txt', - mtime: 11111000, - mimetype: 'text/plain', - etag: 'abc' - }, { - id: 2, - type: 'file', - name: 'Two.jpg.d22222', - displayName: 'Two.jpg', - mtime: 22222000, - mimetype: 'image/jpeg', - etag: 'def', - }, { - id: 3, - type: 'file', - name: 'Three.pdf.d33333', - displayName: 'Three.pdf', - mtime: 33333000, - mimetype: 'application/pdf', - etag: '123', - }, { - id: 4, - type: 'dir', - mtime: 99999000, - name: 'somedir.d99999', - displayName: 'somedir', - mimetype: 'httpd/unix-directory', - etag: '456' - }]; - - // register file actions like the trashbin App does - var fileActions = OCA.Trashbin.App._createFileActions(fileList); - fileList = new OCA.Trashbin.FileList( - $('#app-content'), { - fileActions: fileActions, - multiSelectMenu: [{ - name: 'restore', - displayName: t('files', 'Restore'), - iconClass: 'icon-history', - }, - { - name: 'delete', - displayName: t('files', 'Delete'), - iconClass: 'icon-delete', - } - ], - client: client - } - ); - }); - afterEach(function () { - testFiles = undefined; - fileList.destroy(); - fileList = undefined; - - notificationStub.restore(); - alertStub.restore(); - }); - describe('Initialization', function () { - it('Sorts by mtime by default', function () { - expect(fileList._sort).toEqual('mtime'); - expect(fileList._sortDirection).toEqual('desc'); - }); - it('Always returns read and delete permission', function () { - expect(fileList.getDirectoryPermissions()).toEqual(OC.PERMISSION_READ | OC.PERMISSION_DELETE); - }); - }); - describe('Breadcrumbs', function () { - beforeEach(function () { - var data = { - status: 'success', - data: { - files: testFiles, - permissions: 1 - } - }; - fakeServer.respondWith(/\/index\.php\/apps\/files_trashbin\/ajax\/list.php\?dir=%2Fsubdir/, [ - 200, { - "Content-Type": "application/json" - }, - JSON.stringify(data) - ]); - }); - it('links the breadcrumb to the trashbin view', function () { - fileList.changeDirectory('/subdir', false, true); - fakeServer.respond(); - var $crumbs = fileList.$el.find('.files-controls .crumb'); - expect($crumbs.length).toEqual(3); - expect($crumbs.eq(1).find('a').text()).toEqual('Home'); - expect($crumbs.eq(1).find('a').attr('href')) - .toEqual(OC.getRootPath() + '/index.php/apps/files?view=trashbin&dir=/'); - expect($crumbs.eq(2).find('a').text()).toEqual('subdir'); - expect($crumbs.eq(2).find('a').attr('href')) - .toEqual(OC.getRootPath() + '/index.php/apps/files?view=trashbin&dir=/subdir'); - }); - }); - describe('Rendering rows', function () { - it('renders rows with the correct data when in root', function () { - // dir listing is false when in root - fileList.setFiles(testFiles); - var $rows = fileList.$el.find('tbody tr'); - var $tr = $rows.eq(0); - expect($rows.length).toEqual(4); - expect($tr.attr('data-id')).toEqual('1'); - expect($tr.attr('data-type')).toEqual('file'); - expect($tr.attr('data-file')).toEqual('One.txt.d11111'); - expect($tr.attr('data-size')).not.toBeDefined(); - expect($tr.attr('data-etag')).toEqual('abc'); - expect($tr.attr('data-permissions')).toEqual('9'); // read and delete - expect($tr.attr('data-mime')).toEqual('text/plain'); - expect($tr.attr('data-mtime')).toEqual('11111000'); - expect($tr.find('a.name').attr('href')).toEqual('#'); - - expect($tr.find('.nametext').text().trim()).toEqual('One.txt'); - - expect(fileList.findFileEl('One.txt.d11111')[0]).toEqual($tr[0]); - }); - it('renders rows with the correct data when in root after calling setFiles with the same data set', function () { - // dir listing is false when in root - fileList.setFiles(testFiles); - fileList.setFiles(fileList.files); - var $rows = fileList.$el.find('tbody tr'); - var $tr = $rows.eq(0); - expect($rows.length).toEqual(4); - expect($tr.attr('data-id')).toEqual('1'); - expect($tr.attr('data-type')).toEqual('file'); - expect($tr.attr('data-file')).toEqual('One.txt.d11111'); - expect($tr.attr('data-size')).not.toBeDefined(); - expect($tr.attr('data-etag')).toEqual('abc'); - expect($tr.attr('data-permissions')).toEqual('9'); // read and delete - expect($tr.attr('data-mime')).toEqual('text/plain'); - expect($tr.attr('data-mtime')).toEqual('11111000'); - expect($tr.find('a.name').attr('href')).toEqual('#'); - - expect($tr.find('.nametext').text().trim()).toEqual('One.txt'); - - expect(fileList.findFileEl('One.txt.d11111')[0]).toEqual($tr[0]); - }); - it('renders rows with the correct data when in subdirectory', function () { - fileList.setFiles(testFiles.map(function (file) { - file.name = file.displayName; - return file; - })); - var $rows = fileList.$el.find('tbody tr'); - var $tr = $rows.eq(0); - expect($rows.length).toEqual(4); - expect($tr.attr('data-id')).toEqual('1'); - expect($tr.attr('data-type')).toEqual('file'); - expect($tr.attr('data-file')).toEqual('One.txt'); - expect($tr.attr('data-size')).not.toBeDefined(); - expect($tr.attr('data-etag')).toEqual('abc'); - expect($tr.attr('data-permissions')).toEqual('9'); // read and delete - expect($tr.attr('data-mime')).toEqual('text/plain'); - expect($tr.attr('data-mtime')).toEqual('11111000'); - expect($tr.find('a.name').attr('href')).toEqual('#'); - - expect($tr.find('.nametext').text().trim()).toEqual('One.txt'); - - expect(fileList.findFileEl('One.txt')[0]).toEqual($tr[0]); - }); - it('does not render a size column', function () { - expect(fileList.$el.find('tbody tr .filesize').length).toEqual(0); - }); - }); - describe('File actions', function () { - describe('Deleting single files', function () { - // TODO: checks ajax call - // TODO: checks spinner - // TODO: remove item after delete - // TODO: bring back item if delete failed - }); - describe('Restoring single files', function () { - // TODO: checks ajax call - // TODO: checks spinner - // TODO: remove item after restore - // TODO: bring back item if restore failed - }); - }); - describe('file previews', function () { - // TODO: check that preview URL is going through files_trashbin - }); - describe('loading file list', function () { - // TODO: check that ajax URL is going through files_trashbin - }); - describe('breadcrumbs', function () { - // TODO: test label + URL - }); - describe('elementToFile', function () { - var $tr; - - beforeEach(function () { - fileList.setFiles(testFiles); - $tr = fileList.findFileEl('One.txt.d11111'); - }); - - it('converts data attributes to file info structure', function () { - var fileInfo = fileList.elementToFile($tr); - expect(fileInfo.id).toEqual(1); - expect(fileInfo.name).toEqual('One.txt.d11111'); - expect(fileInfo.displayName).toEqual('One.txt'); - expect(fileInfo.mtime).toEqual(11111000); - expect(fileInfo.etag).toEqual('abc'); - expect(fileInfo.permissions).toEqual(OC.PERMISSION_READ | OC.PERMISSION_DELETE); - expect(fileInfo.mimetype).toEqual('text/plain'); - expect(fileInfo.type).toEqual('file'); - }); - }); - describe('Global Actions', function () { - beforeEach(function () { - fileList.setFiles(testFiles); - fileList.findFileEl('One.txt.d11111').find('input:checkbox').click(); - fileList.findFileEl('Three.pdf.d33333').find('input:checkbox').click(); - fileList.findFileEl('somedir.d99999').find('input:checkbox').click(); - fileList.$el.find('.actions-selected').click(); - }); - - afterEach(function () { - fileList.$el.find('.actions-selected').click(); - }); - - describe('Delete', function () { - it('Shows trashbin actions', function () { - // visible because a few files were selected - expect($('.selectedActions').is(':visible')).toEqual(true); - expect($('.selectedActions .item-delete').is(':visible')).toEqual(true); - expect($('.selectedActions .item-restore').is(':visible')).toEqual(true); - - // check - fileList.$el.find('.select-all').click(); - - // stays visible - expect($('.selectedActions').is(':visible')).toEqual(true); - expect($('.selectedActions .item-delete').is(':visible')).toEqual(true); - expect($('.selectedActions .item-restore').is(':visible')).toEqual(true); - - // uncheck - fileList.$el.find('.select-all').click(); - - // becomes hidden now - expect($('.selectedActions').is(':visible')).toEqual(false); - expect($('.selectedActions .item-delete').is(':visible')).toEqual(false); - expect($('.selectedActions .item-restore').is(':visible')).toEqual(false); - }); - it('Deletes selected files when "Delete" clicked', function (done) { - var request; - var promise = fileList._onClickDeleteSelected({ - preventDefault: function () { - } - }); - var files = ["One.txt.d11111", "Three.pdf.d33333", "somedir.d99999"]; - expect(fakeServer.requests.length).toEqual(files.length); - for (var i = 0; i < files.length; i++) { - request = fakeServer.requests[i]; - expect(request.url).toEqual(OC.getRootPath() + '/remote.php/dav/trashbin/user/trash/' + files[i]); - request.respond(200); - } - return promise.then(function () { - expect(fileList.findFileEl('One.txt.d11111').length).toEqual(0); - expect(fileList.findFileEl('Three.pdf.d33333').length).toEqual(0); - expect(fileList.findFileEl('somedir.d99999').length).toEqual(0); - expect(fileList.findFileEl('Two.jpg.d22222').length).toEqual(1); - }).then(done, done); - }); - it('Deletes all files when all selected when "Delete" clicked', function (done) { - var request; - $('.select-all').click(); - var promise = fileList._onClickDeleteSelected({ - preventDefault: function () { - } - }); - expect(fakeServer.requests.length).toEqual(1); - request = fakeServer.requests[0]; - expect(request.url).toEqual(OC.getRootPath() + '/remote.php/dav/trashbin/user/trash'); - request.respond(200); - return promise.then(function () { - expect(fileList.isEmpty).toEqual(true); - }).then(done, done); - }); - }); - describe('Restore', function () { - it('Restores selected files when "Restore" clicked', function (done) { - var request; - var promise = fileList._onClickRestoreSelected({ - preventDefault: function () { - } - }); - var files = ["One.txt.d11111", "Three.pdf.d33333", "somedir.d99999"]; - expect(fakeServer.requests.length).toEqual(files.length); - for (var i = 0; i < files.length; i++) { - request = fakeServer.requests[i]; - expect(request.url).toEqual(OC.getRootPath() + '/remote.php/dav/trashbin/user/trash/' + files[i]); - expect(request.requestHeaders.Destination).toEqual(OC.getRootPath() + '/remote.php/dav/trashbin/user/restore/' + files[i]); - request.respond(200); - } - return promise.then(function() { - expect(fileList.findFileEl('One.txt.d11111').length).toEqual(0); - expect(fileList.findFileEl('Three.pdf.d33333').length).toEqual(0); - expect(fileList.findFileEl('somedir.d99999').length).toEqual(0); - expect(fileList.findFileEl('Two.jpg.d22222').length).toEqual(1); - }).then(done, done); - }); - it('Restores all files when all selected when "Restore" clicked', function (done) { - var request; - $('.select-all').click(); - var promise = fileList._onClickRestoreSelected({ - preventDefault: function () { - } - }); - var files = ["One.txt.d11111", "Two.jpg.d22222", "Three.pdf.d33333", "somedir.d99999"]; - expect(fakeServer.requests.length).toEqual(files.length); - for (var i = 0; i < files.length; i++) { - request = fakeServer.requests[i]; - expect(request.url).toEqual(OC.getRootPath() + '/remote.php/dav/trashbin/user/trash/' + files[i]); - expect(request.requestHeaders.Destination).toEqual(OC.getRootPath() + '/remote.php/dav/trashbin/user/restore/' + files[i]); - request.respond(200); - } - return promise.then(function() { - expect(fileList.isEmpty).toEqual(true); - }).then(done, done); - }); - }); - }); -}); |