diff options
Diffstat (limited to 'apps/files_sharing/tests/js')
-rw-r--r-- | apps/files_sharing/tests/js/appSpec.js | 148 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/fileDropSpec.js | 98 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/publicAppSpec.js | 149 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/shareSpec.js | 512 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/sharedbreadcrumviewSpec.js | 240 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/sharedfilelistSpec.js | 779 |
6 files changed, 0 insertions, 1926 deletions
diff --git a/apps/files_sharing/tests/js/appSpec.js b/apps/files_sharing/tests/js/appSpec.js deleted file mode 100644 index 133bd44f750..00000000000 --- a/apps/files_sharing/tests/js/appSpec.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* 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.Sharing.App tests', function() { - var App = OCA.Sharing.App; - var fileListIn; - var fileListOut; - - 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-sharingin" class="hidden">' + - '</div>' + - '<div id="app-content-sharingout" class="hidden">' + - '</div>' + - '</div>' + - '</div>' - ); - fileListIn = App.initSharingIn($('#app-content-sharingin')); - fileListOut = App.initSharingOut($('#app-content-sharingout')); - }); - afterEach(function() { - App.destroy(); - }); - - describe('initialization', function() { - it('inits sharing-in list on show', function() { - expect(fileListIn._sharedWithUser).toEqual(true); - }); - it('inits sharing-out list on show', function() { - expect(fileListOut._sharedWithUser).toBeFalsy(); - }); - }); - 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() { - _.each([fileListIn, fileListOut], function(fileList) { - 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 - ); - - App._inFileList = null; - fileListIn = App.initSharingIn($('#app-content-sharingin')); - - expect(fileListIn.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 - ); - - App._inFileList = null; - fileListIn = App.initSharingIn($('#app-content-sharingin')); - - expect(fileListIn.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-sharingin').append($table); - - App._inFileList = null; - fileListIn = App.initSharingIn($('#app-content-sharingin')); - - fileListIn.setFiles([{ - name: 'testdir', - type: 'dir', - path: '/somewhere/inside/subdir', - counterParts: ['user2'], - shareOwner: 'user2' - }]); - - fileListIn.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; - }); - }); -}); diff --git a/apps/files_sharing/tests/js/fileDropSpec.js b/apps/files_sharing/tests/js/fileDropSpec.js deleted file mode 100644 index 22bb95878b4..00000000000 --- a/apps/files_sharing/tests/js/fileDropSpec.js +++ /dev/null @@ -1,98 +0,0 @@ -/** - * - * @copyright Copyright (c) 2017, Artur Neumann (info@individual-it.net) - * - * @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/>. - * - */ - -describe("files Drop tests", function() { - //some testing data - var sharingToken = "fVCiSMhScgWfiuv"; - var testFiles = [ - { name: 'test.txt', expectedValidationResult: true }, - { name: 'testनेपाल.txt', expectedValidationResult: true }, - { name: 'test.part', expectedValidationResult: false }, - { name: 'test.filepart', expectedValidationResult: false }, - { name: '.', expectedValidationResult: false }, - { name: '..', expectedValidationResult: false }, - ]; - - //this pre/post positions should not change the result of the file name validation - var prePostPositions = [""," "," "," "]; - - //use the testFiles and the pre/post positions to generate more testing data - var replicatedTestFiles = []; - prePostPositions.map(function (prePostPosition) { - testFiles.map(function (testFile) { - replicatedTestFiles.push( - { - name: testFile.name + prePostPosition, - expectedValidationResult: testFile.expectedValidationResult - } - ); - replicatedTestFiles.push( - { - name: prePostPosition + testFile.name, - expectedValidationResult: testFile.expectedValidationResult - } - ); - replicatedTestFiles.push( - { - name: prePostPosition + testFile.name + prePostPosition, - expectedValidationResult: testFile.expectedValidationResult - } - ); - }); - }); - - beforeEach (function () { - //fake input for the sharing token - $('#testArea').append( - '<input name="sharingToken" value="" id="sharingToken" type="hidden">' - ); - }); - - - replicatedTestFiles.map(function (testFile) { - it("validates the filenames correctly", function() { - data = { - 'submit': function() {}, - 'files': [testFile] - } - expect(OCA.FilesSharingDrop.addFileToUpload('',data)). - toBe( - testFile.expectedValidationResult, - 'wrongly validated file named "'+testFile.name+'"' - ); - }); - - if (testFile.expectedValidationResult === true) { - it("should set correct PUT URL, Auth header and submit", function () { - data = { - 'submit': sinon.stub(), - 'files': [testFile] - } - $('#sharingToken').val(sharingToken); - - OCA.FilesSharingDrop.addFileToUpload('',data); - expect(data.submit.calledOnce).toEqual(true); - expect(data.url).toContain("/public.php/webdav/" + encodeURI(testFile.name)); - expect(data.headers['Authorization']).toEqual('Basic ' + btoa(sharingToken+":")); - }); - } - }); -}); diff --git a/apps/files_sharing/tests/js/publicAppSpec.js b/apps/files_sharing/tests/js/publicAppSpec.js deleted file mode 100644 index 8ea339fd9de..00000000000 --- a/apps/files_sharing/tests/js/publicAppSpec.js +++ /dev/null @@ -1,149 +0,0 @@ -/** -* ownCloud -* -* @author Vincent Petry -* @copyright 2015 Vincent Petry <pvince81@owncloud.com> -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -describe('OCA.Sharing.PublicApp tests', function() { - var App = OCA.Sharing.PublicApp; - var hostStub, protocolStub, webrootStub; - var $preview; - - beforeEach(function() { - protocolStub = sinon.stub(OC, 'getProtocol').returns('https'); - hostStub = sinon.stub(OC, 'getHost').returns('example.com:9876'); - webrootStub = sinon.stub(OC, 'getRootPath').returns('/owncloud'); - $preview = $('<div id="preview"></div>'); - $('#testArea').append($preview); - $preview.append( - '<div id="mimetype"></div>' + - '<div id="mimetypeIcon"></div>' + - '<input type="hidden" id="sharingToken" value="sh4tok"></input>' - ); - }); - - afterEach(function() { - protocolStub.restore(); - hostStub.restore(); - webrootStub.restore(); - }); - - describe('File list', function() { - // TODO: this should be moved to a separate file once the PublicFileList is extracted from public.js - beforeEach(function() { - $preview.append( - '<div id="app-content-files">' + - // init horrible parameters - '<input type="hidden" id="dir" value="/subdir"/>' + - '<input type="hidden" id="permissions" value="31"/>' + - // dummy controls - '<div id="controls">' + - ' <div class="actions creatable"></div>' + - ' <div class="notCreatable"></div>' + - '</div>' + - // uploader - '<input type="file" id="file_upload_start" name="files[]" multiple="multiple">' + - // dummy table - // 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">' + - '<input type="checkbox" id="select_all_files" class="select-all">' + - '<a class="name columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' + - '<span class="selectedActions hidden">' + - '<a href class="download">Download</a>' + - '</th>' + - '<th class="hidden column-size"><a class="columntitle" data-sort="size"><span class="sort-indicator"></span></a></th>' + - '<th class="hidden column-mtime"><a class="columntitle" data-sort="mtime"><span class="sort-indicator"></span></a></th>' + - '</tr></thead>' + - '<tbody id="fileList"></tbody>' + - '<tfoot></tfoot>' + - '</table>' + - // TODO: move to handlebars template - '<div id="emptycontent"><h2>Empty content message</h2><p class="uploadmessage">Upload message</p></div>' + - '<div class="nofilterresults hidden"></div>' + - '</div>' - ); - - App.initialize($('#preview')); - }); - afterEach(function() { - App._initialized = false; - }); - - it('Uses public webdav endpoint', function() { - App._initialized = false; - fakeServer.restore(); - window.fakeServer = sinon.fakeServer.create(); - - // uploader function messes up with fakeServer - var uploaderDetectStub = sinon.stub(OC.Uploader.prototype, '_supportAjaxUploadWithProgress'); - App.initialize($('#preview')); - expect(fakeServer.requests.length).toEqual(1); - expect(fakeServer.requests[0].method).toEqual('PROPFIND'); - expect(fakeServer.requests[0].url).toEqual('https://example.com:9876/owncloud/public.php/webdav/subdir'); - expect(fakeServer.requests[0].requestHeaders.Authorization).toEqual('Basic c2g0dG9rOm51bGw='); - uploaderDetectStub.restore(); - }); - - describe('Download Url', function() { - var fileList; - - beforeEach(function() { - fileList = App.fileList; - }); - - it('returns correct download URL for single files', function() { - expect(fileList.getDownloadUrl('some file.txt')) - .toEqual(OC.webroot + '/index.php/s/sh4tok/download?path=%2Fsubdir&files=some%20file.txt'); - expect(fileList.getDownloadUrl('some file.txt', '/anotherpath/abc')) - .toEqual(OC.webroot + '/index.php/s/sh4tok/download?path=%2Fanotherpath%2Fabc&files=some%20file.txt'); - fileList.changeDirectory('/'); - expect(fileList.getDownloadUrl('some file.txt')) - .toEqual(OC.webroot + '/index.php/s/sh4tok/download?path=%2F&files=some%20file.txt'); - }); - it('returns correct download URL for multiple files', function() { - expect(fileList.getDownloadUrl(['a b c.txt', 'd e f.txt'])) - .toEqual(OC.webroot + '/index.php/s/sh4tok/download?path=%2Fsubdir&files=%5B%22a%20b%20c.txt%22%2C%22d%20e%20f.txt%22%5D'); - }); - it('returns the correct ajax URL', function() { - expect(fileList.getAjaxUrl('test', {a:1, b:'x y'})) - .toEqual(OC.webroot + '/index.php/apps/files_sharing/ajax/test.php?a=1&b=x%20y&t=sh4tok'); - }); - it('returns correct download URL for downloading everything', function() { - expect(fileList.getDownloadUrl()) - .toEqual(OC.webroot + '/index.php/s/sh4tok/download?path=%2Fsubdir'); - }); - }); - describe('Upload Url', function() { - var fileList; - - beforeEach(function() { - fileList = App.fileList; - }); - it('returns correct upload URL', function() { - expect(fileList.getUploadUrl('some file.txt')) - .toEqual('/owncloud/public.php/webdav/subdir/some%20file.txt'); - }); - it('returns correct upload URL with specified dir', function() { - expect(fileList.getUploadUrl('some file.txt', 'sub')) - .toEqual('/owncloud/public.php/webdav/sub/some%20file.txt'); - }); - }); - }); -}); diff --git a/apps/files_sharing/tests/js/shareSpec.js b/apps/files_sharing/tests/js/shareSpec.js deleted file mode 100644 index 91060f6a735..00000000000 --- a/apps/files_sharing/tests/js/shareSpec.js +++ /dev/null @@ -1,512 +0,0 @@ -/* - * 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.Sharing.Util tests', function() { - var fileList; - var testFiles; - - function getImageUrl($el) { - // might be slightly different cross-browser - var url = $el.css('background-image'); - var r = url.match(/url\(['"]?([^'")]*)['"]?\)/); - if (!r) { - return url; - } - return r[1]; - } - - beforeEach(function() { - var $content = $('<div id="content"></div>'); - $('#testArea').append($content); - // dummy file list - var $div = $( - '<div id="listContainer">' + - '<table id="filestable">' + - '<thead></thead>' + - '<tbody id="fileList"></tbody>' + - '</table>' + - '</div>'); - $('#content').append($div); - - var fileActions = new OCA.Files.FileActions(); - fileList = new OCA.Files.FileList( - $div, { - fileActions : fileActions - } - ); - OCA.Sharing.Util.attach(fileList); - - testFiles = [{ - id: 1, - type: 'file', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - etag: 'abc', - shareOwner: 'User One', - isShareMountPoint: false, - shareTypes: [OC.Share.SHARE_TYPE_USER] - }]; - }); - afterEach(function() { - delete OCA.Sharing.sharesLoaded; - delete OC.Share.droppedDown; - fileList.destroy(); - fileList = null; - }); - - describe('Sharing data in table row', function() { - // TODO: test data-permissions, data-share-owner, etc - }); - describe('Share action icon', function() { - it('do not shows share text when not shared', function() { - var $action, $tr; - OC.Share.statuses = {}; - fileList.setFiles([{ - id: 1, - type: 'dir', - name: 'One', - path: '/subdir', - mimetype: 'httpd/unix-directory', - size: 12, - permissions: OC.PERMISSION_ALL, - etag: 'abc', - shareTypes: [] - }]); - $tr = fileList.$el.find('tbody tr:first'); - $action = $tr.find('.action-share'); - expect($action.find('.icon').hasClass('icon-shared')).toEqual(true); - expect($action.find('.icon').hasClass('icon-public')).toEqual(false); - expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder.svg'); - }); - it('shows simple share text with share icon', function() { - var $action, $tr; - fileList.setFiles([{ - id: 1, - type: 'dir', - name: 'One', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - etag: 'abc', - shareTypes: [OC.Share.SHARE_TYPE_USER] - }]); - $tr = fileList.$el.find('tbody tr:first'); - $action = $tr.find('.action-share'); - expect($action.find('>span').text().trim()).toEqual('Shared'); - expect($action.find('.icon').hasClass('icon-shared')).toEqual(true); - expect($action.find('.icon').hasClass('icon-public')).toEqual(false); - expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg'); - }); - it('shows simple share text with public icon when shared with link', function() { - var $action, $tr; - OC.Share.statuses = {1: {link: true, path: '/subdir'}}; - fileList.setFiles([{ - id: 1, - type: 'dir', - name: 'One', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - etag: 'abc', - shareTypes: [OC.Share.SHARE_TYPE_LINK] - }]); - $tr = fileList.$el.find('tbody tr:first'); - $action = $tr.find('.action-share'); - expect($action.find('>span').text().trim()).toEqual('Shared'); - expect($action.find('.icon').hasClass('icon-shared')).toEqual(false); - expect($action.find('.icon').hasClass('icon-public')).toEqual(true); - expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-public.svg'); - }); - it('shows owner name when owner is available', function() { - var $action, $tr; - fileList.setFiles([{ - id: 1, - type: 'dir', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - shareOwner: 'User One', - shareOwnerId: 'User One', - etag: 'abc', - shareTypes: [] - }]); - $tr = fileList.$el.find('tbody tr:first'); - $action = $tr.find('.action-share'); - expect($action.find('>span').text().trim()).toEqual('Shared by User One'); - expect($action.find('.icon').hasClass('icon-shared')).toEqual(true); - expect($action.find('.icon').hasClass('icon-public')).toEqual(false); - expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg'); - }); - it('shows recipients when recipients are available', function() { - var $action, $tr; - fileList.setFiles([{ - id: 1, - type: 'dir', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - recipientsDisplayName: 'User One, User Two', - recipientData: { - 0: { - shareWith: 'User One', - shareWithDisplayName: 'User One' - }, - 1: { - shareWith: 'User Two', - shareWithDisplayName: 'User Two' - } - }, - etag: 'abc', - shareTypes: [OC.Share.SHARE_TYPE_USER] - }]); - $tr = fileList.$el.find('tbody tr:first'); - $action = $tr.find('.action-share'); - expect($action.text().trim()).toEqual('Shared with User One Shared with User Two'); - expect($action.find('.icon').hasClass('icon-shared')).toEqual(true); - expect($action.find('.icon').hasClass('icon-public')).toEqual(false); - expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg'); - }); - it('shows share action when shared with user who has no share permission', function() { - var $action, $tr; - fileList.setFiles([{ - id: 1, - type: 'dir', - name: 'One', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_CREATE, - etag: 'abc', - shareOwner: 'User One' - }]); - $tr = fileList.$el.find('tbody tr:first'); - expect($tr.find('.action-share').length).toEqual(1); - }); - it('do not show share action when share exists but neither permission nor owner is available', function() { - var $action, $tr; - fileList.setFiles([{ - id: 1, - type: 'dir', - name: 'One', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_CREATE, - etag: 'abc' - }]); - $tr = fileList.$el.find('tbody tr:first'); - expect($tr.find('.action-share').length).toEqual(0); - }); - }); - describe('Share action', function() { - var shareTab; - - function makeDummyShareItem(displayName) { - return { - share_with_displayname: displayName - }; - } - - beforeEach(function() { - // make it look like not the "All files" list - fileList.id = 'test'; - shareTab = fileList._detailsView._tabViews[0]; - }); - afterEach(function() { - shareTab = null; - }); - it('clicking share action opens sidebar and share tab', function() { - var showDetailsViewStub = sinon.stub(fileList, 'showDetailsView'); - - fileList.setFiles([{ - id: 1, - type: 'file', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - etag: 'abc' - }]); - - var $tr = fileList.$el.find('tr:first'); - $tr.find('.action-share').click(); - - expect(showDetailsViewStub.calledOnce).toEqual(true); - expect(showDetailsViewStub.getCall(0).args[0]).toEqual('One.txt'); - expect(showDetailsViewStub.getCall(0).args[1]).toEqual('shareTabView'); - - showDetailsViewStub.restore(); - }); - it('adds share icon after sharing a non-shared file', function() { - var $action, $tr; - OC.Share.statuses = {}; - fileList.setFiles([{ - id: 1, - type: 'file', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - etag: 'abc' - }]); - $action = fileList.$el.find('tbody tr:first .action-share'); - $tr = fileList.$el.find('tr:first'); - - $tr.find('.action-share').click(); - - // simulate updating shares - shareTab._dialog.model.set({ - shares: [ - {share_with_displayname: 'User One', share_with: 'User One'}, - {share_with_displayname: 'User Two', share_with: 'User Two'}, - {share_with_displayname: 'Group One', share_with: 'Group One'}, - {share_with_displayname: 'Group Two', share_with: 'Group Two'} - ] - }); - - expect($action.text().trim()).toEqual('Shared with Group One Shared with Group Two Shared with User One Shared with User Two'); - expect($action.find('.icon').hasClass('icon-shared')).toEqual(true); - expect($action.find('.icon').hasClass('icon-public')).toEqual(false); - }); - it('updates share icon after updating shares of a file', function() { - var $action, $tr; - OC.Share.statuses = {1: {link: false, path: '/subdir'}}; - fileList.setFiles([{ - id: 1, - type: 'file', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - etag: 'abc' - }]); - $action = fileList.$el.find('tbody tr:first .action-share'); - $tr = fileList.$el.find('tr:first'); - - $tr.find('.action-share').click(); - - // simulate updating shares - shareTab._dialog.model.set({ - shares: [ - {share_with_displayname: 'User One', share_with: 'User One'}, - {share_with_displayname: 'User Two', share_with: 'User Two'}, - {share_with_displayname: 'User Three', share_with: 'User Three'} - ] - }); - - expect($action.text().trim()).toEqual('Shared with User One Shared with User Three Shared with User Two'); - expect($action.find('.icon').hasClass('icon-shared')).toEqual(true); - expect($action.find('.icon').hasClass('icon-public')).toEqual(false); - }); - it('removes share icon after removing all shares from a file', function() { - var $action, $tr; - OC.Share.statuses = {1: {link: false, path: '/subdir'}}; - fileList.setFiles([{ - id: 1, - type: 'file', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - etag: 'abc', - recipients: 'User One, User Two' - }]); - $action = fileList.$el.find('tbody tr:first .action-share'); - $tr = fileList.$el.find('tr:first'); - - $tr.find('.action-share').click(); - - // simulate updating shares - shareTab._dialog.model.set({ - shares: [] - }); - - expect($tr.attr('data-share-recipient-data')).not.toBeDefined(); - }); - it('keep share text after updating reshare', function() { - var $action, $tr; - OC.Share.statuses = {1: {link: false, path: '/subdir'}}; - fileList.setFiles([{ - id: 1, - type: 'file', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - etag: 'abc', - shareOwner: 'User One', - shareOwnerId: 'User One' - }]); - $action = fileList.$el.find('tbody tr:first .action-share'); - $tr = fileList.$el.find('tr:first'); - - $tr.find('.action-share').click(); - - // simulate updating shares - shareTab._dialog.model.set({ - shares: [{share_with_displayname: 'User Two'}] - }); - - expect($action.find('>span').text().trim()).toEqual('Shared by User One'); - expect($action.find('.icon').hasClass('icon-shared')).toEqual(true); - expect($action.find('.icon').hasClass('icon-public')).toEqual(false); - }); - it('keep share text after unsharing reshare', function() { - var $action, $tr; - OC.Share.statuses = {1: {link: false, path: '/subdir'}}; - fileList.setFiles([{ - id: 1, - type: 'file', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - etag: 'abc', - shareOwner: 'User One', - shareOwnerId: 'User One', - recipients: 'User Two', - recipientData: {'User Two': 'User Two'} - }]); - $action = fileList.$el.find('tbody tr:first .action-share'); - $tr = fileList.$el.find('tr:first'); - - $tr.find('.action-share').click(); - - // simulate updating shares - shareTab._dialog.model.set({ - shares: [] - }); - - expect($tr.attr('data-share-recipient-data')).not.toBeDefined(); - - expect($action.find('>span').text().trim()).toEqual('Shared by User One'); - expect($action.find('.icon').hasClass('icon-shared')).toEqual(true); - expect($action.find('.icon').hasClass('icon-public')).toEqual(false); - }); - }); - describe('Excluded lists', function() { - function createListThenAttach(listId) { - var fileActions = new OCA.Files.FileActions(); - fileList.destroy(); - fileList = new OCA.Files.FileList( - $('#listContainer'), { - id: listId, - fileActions: fileActions - } - ); - OCA.Sharing.Util.attach(fileList); - fileList.setFiles(testFiles); - return fileList; - } - - it('does not attach to trashbin or public file lists', function() { - createListThenAttach('trashbin'); - expect($('.action-share').length).toEqual(0); - expect($('[data-share-recipient]').length).toEqual(0); - createListThenAttach('files.public'); - expect($('.action-share').length).toEqual(0); - expect($('[data-share-recipient]').length).toEqual(0); - }); - }); - - describe('ShareTabView interaction', function() { - var shareTabSpy; - var fileInfoModel; - var configModel; - var shareModel; - - beforeEach(function() { - shareTabSpy = sinon.spy(OCA.Sharing, 'ShareTabView'); - - var attributes = { - itemType: 'file', - itemSource: 123, - possiblePermissions: 31, - permissions: 31 - }; - fileInfoModel = new OCA.Files.FileInfoModel(testFiles[0]); - configModel = new OC.Share.ShareConfigModel({ - enforcePasswordForPublicLink: false, - isResharingAllowed: true, - isDefaultExpireDateEnabled: false, - isDefaultExpireDateEnforced: false, - defaultExpireDate: 7 - }); - shareModel = new OC.Share.ShareItemModel(attributes, { - configModel: configModel, - fileInfoModel: fileInfoModel - }); - - /* jshint camelcase: false */ - shareModel.set({ - reshare: {}, - shares: [{ - id: 100, - item_source: 1, - permissions: 31, - share_type: OC.Share.SHARE_TYPE_USER, - share_with: 'user1', - share_with_displayname: 'User One' - }, { - id: 102, - item_source: 1, - permissions: 31, - share_type: OC.Share.SHARE_TYPE_REMOTE, - share_with: 'foo@bar.com/baz', - share_with_displayname: 'foo@bar.com/baz' - - }] - }, {parse: true}); - - fileList.destroy(); - fileList = new OCA.Files.FileList( - $('#listContainer'), { - id: 'files', - fileActions: new OCA.Files.FileActions() - } - ); - OCA.Sharing.Util.attach(fileList); - fileList.setFiles(testFiles); - }); - afterEach(function() { - shareTabSpy.restore(); - }); - - it('updates fileInfoModel when shares changed', function() { - var changeHandler = sinon.stub(); - fileInfoModel.on('change', changeHandler); - - shareTabSpy.getCall(0).returnValue.trigger('sharesChanged', shareModel); - - expect(changeHandler.calledOnce).toEqual(true); - expect(changeHandler.getCall(0).args[0].changed).toEqual({ - shareTypes: [ - OC.Share.SHARE_TYPE_USER, - OC.Share.SHARE_TYPE_REMOTE - ] - }); - }); - }); -}); diff --git a/apps/files_sharing/tests/js/sharedbreadcrumviewSpec.js b/apps/files_sharing/tests/js/sharedbreadcrumviewSpec.js deleted file mode 100644 index c58e038c4ab..00000000000 --- a/apps/files_sharing/tests/js/sharedbreadcrumviewSpec.js +++ /dev/null @@ -1,240 +0,0 @@ -/** - * @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl> - * - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @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/>. - * - */ - -describe('OCA.Sharing.ShareBreadCrumbView tests', function() { - var BreadCrumb = OCA.Files.BreadCrumb; - var SharedBreadCrum = OCA.Sharing.ShareBreadCrumbView; - - describe('Rendering', function() { - var bc; - var sbc; - var shareTab; - beforeEach(function() { - bc = new BreadCrumb({ - getCrumbUrl: function(part, index) { - // for testing purposes - return part.dir + '#' + index; - } - }); - shareTab = new OCA.Sharing.ShareTabView(); - sbc = new SharedBreadCrum({ - shareTab: shareTab - }); - bc.addDetailView(sbc); - }); - afterEach(function() { - bc = null; - sbc = null; - shareModel = null; - }); - it('Do not render in root', function() { - var dirInfo = new OC.Files.FileInfo({ - id: 42, - path: '/', - type: 'dir', - name: '' - }); - bc.setDirectoryInfo(dirInfo); - bc.setDirectory(''); - bc.render(); - expect(bc.$el.hasClass('breadcrumb')).toEqual(true); - expect(bc.$el.find('.icon-shared').length).toEqual(0); - expect(bc.$el.find('.shared').length).toEqual(0); - expect(bc.$el.find('.icon-public').length).toEqual(0); - }); - it('Render in dir', function() { - var dirInfo = new OC.Files.FileInfo({ - id: 42, - path: '/foo', - type: 'dir' - }); - bc.setDirectoryInfo(dirInfo); - bc.setDirectory('/foo'); - bc.render(); - expect(bc.$el.hasClass('breadcrumb')).toEqual(true); - expect(bc.$el.find('.icon-shared').length).toEqual(1); - expect(bc.$el.find('.shared').length).toEqual(0); - expect(bc.$el.find('.icon-public').length).toEqual(0); - }); - it('Render shared if dir is shared with user', function() { - var dirInfo = new OC.Files.FileInfo({ - id: 42, - path: '/foo', - type: 'dir', - shareTypes: [OC.Share.SHARE_TYPE_USER] - }); - bc.setDirectoryInfo(dirInfo); - bc.setDirectory('/foo'); - bc.render(); - expect(bc.$el.hasClass('breadcrumb')).toEqual(true); - expect(bc.$el.find('.icon-shared').length).toEqual(1); - expect(bc.$el.find('.shared').length).toEqual(1); - expect(bc.$el.find('.icon-public').length).toEqual(0); - }); - it('Render shared if dir is shared with group', function() { - var dirInfo = new OC.Files.FileInfo({ - id: 42, - path: '/foo', - type: 'dir', - shareTypes: [OC.Share.SHARE_TYPE_GROUP] - }); - bc.setDirectoryInfo(dirInfo); - bc.setDirectory('/foo'); - bc.render(); - expect(bc.$el.hasClass('breadcrumb')).toEqual(true); - expect(bc.$el.find('.icon-shared').length).toEqual(1); - expect(bc.$el.find('.shared').length).toEqual(1); - expect(bc.$el.find('.icon-public').length).toEqual(0); - }); - it('Render shared if dir is shared by link', function() { - var dirInfo = new OC.Files.FileInfo({ - id: 42, - path: '/foo', - type: 'dir', - shareTypes: [OC.Share.SHARE_TYPE_LINK] - }); - bc.setDirectoryInfo(dirInfo); - bc.setDirectory('/foo'); - bc.render(); - expect(bc.$el.hasClass('breadcrumb')).toEqual(true); - expect(bc.$el.find('.icon-shared').length).toEqual(0); - expect(bc.$el.find('.shared').length).toEqual(1); - expect(bc.$el.find('.icon-public').length).toEqual(1); - }); - it('Render shared if dir is shared by circle', function() { - var dirInfo = new OC.Files.FileInfo({ - id: 42, - path: '/foo', - type: 'dir', - shareTypes: [OC.Share.SHARE_TYPE_CIRCLE] - }); - bc.setDirectoryInfo(dirInfo); - bc.setDirectory('/foo'); - bc.render(); - expect(bc.$el.hasClass('breadcrumb')).toEqual(true); - expect(bc.$el.find('.icon-shared').length).toEqual(1); - expect(bc.$el.find('.shared').length).toEqual(1); - expect(bc.$el.find('.icon-public').length).toEqual(0); - }); - it('Render shared if dir is shared with remote', function() { - var dirInfo = new OC.Files.FileInfo({ - id: 42, - path: '/foo', - type: 'dir', - shareTypes: [OC.Share.SHARE_TYPE_REMOTE] - }); - bc.setDirectoryInfo(dirInfo); - bc.setDirectory('/foo'); - bc.render(); - expect(bc.$el.hasClass('breadcrumb')).toEqual(true); - expect(bc.$el.find('.icon-shared').length).toEqual(1); - expect(bc.$el.find('.shared').length).toEqual(1); - expect(bc.$el.find('.icon-public').length).toEqual(0); - }); - it('Render link shared if at least one is a link share', function() { - var dirInfo = new OC.Files.FileInfo({ - id: 42, - path: '/foo', - type: 'dir', - shareTypes: [ - OC.Share.SHARE_TYPE_USER, - OC.Share.SHARE_TYPE_GROUP, - OC.Share.SHARE_TYPE_LINK, - OC.Share.SHARE_TYPE_EMAIL, - OC.Share.SHARE_TYPE_REMOTE, - OC.Share.SHARE_TYPE_CIRCLE - ] - }); - bc.setDirectoryInfo(dirInfo); - bc.setDirectory('/foo'); - bc.render(); - expect(bc.$el.hasClass('breadcrumb')).toEqual(true); - expect(bc.$el.find('.icon-shared').length).toEqual(0); - expect(bc.$el.find('.shared').length).toEqual(1); - expect(bc.$el.find('.icon-public').length).toEqual(1); - }); - it('Remove shared status from user share', function() { - var dirInfo = new OC.Files.FileInfo({ - id: 42, - path: '/foo', - type: 'dir', - shareTypes: [OC.Share.SHARE_TYPE_USER] - }); - - bc.setDirectory('/foo'); - bc.setDirectoryInfo(dirInfo); - bc.render(); - - var mock = sinon.createStubInstance(OCA.Files.FileList); - mock.showDetailsView = function() { }; - OCA.Files.App.fileList = mock; - var spy = sinon.spy(mock, 'showDetailsView'); - bc.$el.find('.icon-shared').click(); - - expect(spy.calledOnce).toEqual(true); - - var model = sinon.createStubInstance(OC.Share.ShareItemModel); - model.getSharesWithCurrentItem = function() { return [] }; - model.hasLinkShare = function() { return false; }; - - shareTab.trigger('sharesChanged', model); - - expect(bc.$el.hasClass('breadcrumb')).toEqual(true); - expect(bc.$el.find('.icon-shared').length).toEqual(1); - expect(bc.$el.find('.shared').length).toEqual(0); - expect(bc.$el.find('.icon-public').length).toEqual(0); - }); - it('Add link share to user share', function() { - var dirInfo = new OC.Files.FileInfo({ - id: 42, - path: '/foo', - type: 'dir', - shareTypes: [OC.Share.SHARE_TYPE_USER] - }); - - bc.setDirectory('/foo'); - bc.setDirectoryInfo(dirInfo); - bc.render(); - - var mock = sinon.createStubInstance(OCA.Files.FileList); - mock.showDetailsView = function() { }; - OCA.Files.App.fileList = mock; - var spy = sinon.spy(mock, 'showDetailsView'); - bc.$el.find('.icon-shared').click(); - - expect(spy.calledOnce).toEqual(true); - - var model = sinon.createStubInstance(OC.Share.ShareItemModel); - model.getSharesWithCurrentItem = function() { return [ - {share_type: OC.Share.SHARE_TYPE_USER} - ] }; - model.hasLinkShare = function() { return true; }; - - shareTab.trigger('sharesChanged', model); - - expect(bc.$el.hasClass('breadcrumb')).toEqual(true); - expect(bc.$el.find('.icon-shared').length).toEqual(0); - expect(bc.$el.find('.shared').length).toEqual(1); - expect(bc.$el.find('.icon-public').length).toEqual(1); - }); - }); -}); diff --git a/apps/files_sharing/tests/js/sharedfilelistSpec.js b/apps/files_sharing/tests/js/sharedfilelistSpec.js deleted file mode 100644 index 903234947bd..00000000000 --- a/apps/files_sharing/tests/js/sharedfilelistSpec.js +++ /dev/null @@ -1,779 +0,0 @@ -/* - * 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.Sharing.FileList tests', function() { - var testFiles, alertStub, notificationStub, fileList; - - beforeEach(function() { - alertStub = sinon.stub(OC.dialogs, 'alert'); - notificationStub = sinon.stub(OC.Notification, 'show'); - - // init parameters and test table elements - $('#testArea').append( - '<div id="app-content-container">' + - // init horrible parameters - '<input type="hidden" id="dir" value="/"></input>' + - '<input type="hidden" id="permissions" value="31"></input>' + - // dummy controls - '<div id="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 id="filestable">' + - '<thead><tr>' + - '<th id="headerName" class="hidden column-name">' + - '<input type="checkbox" id="select_all_files" class="select-all">' + - '<a class="name columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' + - '<span class="selectedActions hidden">' + - '</th>' + - '<th class="hidden column-mtime">' + - '<a class="columntitle" data-sort="mtime"><span class="sort-indicator"></span></a>' + - '</th>' + - '<th class="column-expiration">' + - '<a class="columntitle"><span>Expiration date</span></a>' + - '</th>' + - '</tr></thead>' + - '<tbody id="fileList"></tbody>' + - '<tfoot></tfoot>' + - '</table>' + - '<div id="emptycontent">Empty content message</div>' + - '</div>' - ); - - OC.Plugins.register('OCA.Files.FileList', OCA.Files.TagsPlugin); - }); - afterEach(function() { - testFiles = undefined; - fileList.destroy(); - fileList = undefined; - - notificationStub.restore(); - alertStub.restore(); - }); - - describe('loading file list for incoming shares', function() { - var ocsResponse; - var ocsResponseRemote; - - beforeEach(function() { - fileList = new OCA.Sharing.FileList( - $('#app-content-container'), { - sharedWithUser: true - } - ); - OCA.Sharing.Util.attach(fileList); - - fileList.reload(); - - /* jshint camelcase: false */ - ocsResponse = { - ocs: { - meta: { - status: 'ok', - statuscode: 100, - message: null - }, - data: [{ - id: 7, - item_type: 'file', - item_source: 49, - item_target: '/49', - file_source: 49, - file_target: '/local path/local name.txt', - path: 'files/something shared.txt', - permissions: 31, - stime: 11111, - share_type: OC.Share.SHARE_TYPE_USER, - share_with: 'user1', - share_with_displayname: 'User One', - tags: [OC.TAG_FAVORITE], - mimetype: 'text/plain', - uid_owner: 'user2', - displayname_owner: 'User Two' - }] - } - }; - - /* jshint camelcase: false */ - ocsResponseRemote = { - ocs: { - meta: { - status: 'ok', - statuscode: 100, - message: null - }, - data: [{ - id: 8, - remote: 'https://foo.bar/', - remote_id: 42, - share_token: 'abc', - name: '/a.txt', - owner: 'user3', - user: 'user1', - mountpoint: '/b.txt', - mountpoint_hash: 'def', - accepted: 1, - mimetype: 'text/plain', - mtime: 22222, - permissions: 31, - type: 'file', - file_id: 1337 - }] - } - }; - - }); - it('render file shares', function() { - expect(fakeServer.requests.length).toEqual(2); - expect(fakeServer.requests[0].url).toEqual( - OC.linkToOCS('apps/files_sharing/api/v1') + - 'shares?format=json&shared_with_me=true&include_tags=true' - ); - - expect(fakeServer.requests[1].url).toEqual( - OC.linkToOCS('apps/files_sharing/api/v1') + - 'remote_shares?format=json&include_tags=true' - ); - - fakeServer.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(ocsResponse) - ); - - fakeServer.requests[1].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(ocsResponseRemote) - ); - - var $rows = fileList.$el.find('tbody tr'); - expect($rows.length).toEqual(2); - - var $tr = $rows.eq(0); - expect($tr.attr('data-id')).toEqual('49'); - expect($tr.attr('data-type')).toEqual('file'); - expect($tr.attr('data-file')).toEqual('local name.txt'); - expect($tr.attr('data-path')).toEqual('/local path'); - expect($tr.attr('data-size')).not.toBeDefined(); - expect($tr.attr('data-permissions')).toEqual('31'); // read and delete - expect($tr.attr('data-mime')).toEqual('text/plain'); - expect($tr.attr('data-mtime')).toEqual('11111000'); - expect($tr.attr('data-share-owner')).toEqual('User Two'); - expect($tr.attr('data-share-id')).toEqual('7'); - expect($tr.attr('data-favorite')).toEqual('true'); - expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE); - expect($tr.find('a.name').attr('href')).toEqual( - OC.webroot + - '/remote.php/webdav/local%20path/local%20name.txt' - ); - expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); - - $tr = $rows.eq(1); - expect($tr.attr('data-id')).toEqual('1337'); - expect($tr.attr('data-type')).toEqual('file'); - expect($tr.attr('data-file')).toEqual('b.txt'); - expect($tr.attr('data-path')).toEqual(''); - expect($tr.attr('data-size')).not.toBeDefined(); - expect(parseInt($tr.attr('data-permissions'), 10)) - .toEqual(OC.PERMISSION_ALL); // read and delete - expect($tr.attr('data-mime')).toEqual('text/plain'); - expect($tr.attr('data-mtime')).toEqual('22222000'); - expect($tr.attr('data-share-owner')).toEqual('user3@foo.bar/'); - expect($tr.attr('data-share-id')).toEqual('8'); - expect($tr.attr('data-favorite')).not.toBeDefined(); - expect($tr.attr('data-tags')).toEqual(''); - expect($tr.find('a.name').attr('href')).toEqual( - OC.webroot + - '/remote.php/webdav/b.txt' - ); - expect($tr.find('.nametext').text().trim()).toEqual('b.txt'); - }); - it('render folder shares', function() { - /* jshint camelcase: false */ - ocsResponse.ocs.data[0] = _.extend(ocsResponse.ocs.data[0], { - item_type: 'folder', - file_target: '/local path/local name', - path: 'files/something shared', - }); - - ocsResponseRemote.ocs.data[0] = _.extend(ocsResponseRemote.ocs.data[0], { - type: 'dir', - mimetype: 'httpd/unix-directory', - name: '/a', - mountpoint: '/b' - }); - - expect(fakeServer.requests.length).toEqual(2); - expect(fakeServer.requests[0].url).toEqual( - OC.linkToOCS('apps/files_sharing/api/v1') + - 'shares?format=json&shared_with_me=true&include_tags=true' - ); - expect(fakeServer.requests[1].url).toEqual( - OC.linkToOCS('apps/files_sharing/api/v1') + - 'remote_shares?format=json&include_tags=true' - ); - - fakeServer.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(ocsResponse) - ); - fakeServer.requests[1].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(ocsResponseRemote) - ); - - var $rows = fileList.$el.find('tbody tr'); - expect($rows.length).toEqual(2); - - var $tr = $rows.eq(0); - expect($tr.attr('data-id')).toEqual('49'); - expect($tr.attr('data-type')).toEqual('dir'); - expect($tr.attr('data-file')).toEqual('local name'); - expect($tr.attr('data-path')).toEqual('/local path'); - expect($tr.attr('data-size')).not.toBeDefined(); - expect($tr.attr('data-permissions')).toEqual('31'); // read and delete - expect($tr.attr('data-mime')).toEqual('httpd/unix-directory'); - expect($tr.attr('data-mtime')).toEqual('11111000'); - expect($tr.attr('data-share-owner')).toEqual('User Two'); - expect($tr.attr('data-share-id')).toEqual('7'); - expect($tr.attr('data-favorite')).toEqual('true'); - expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE); - expect($tr.find('a.name').attr('href')).toEqual( - OC.webroot + - '/index.php/apps/files' + - '?dir=/local%20path/local%20name' - ); - expect($tr.find('.nametext').text().trim()).toEqual('local name'); - - $tr = $rows.eq(1); - expect($tr.attr('data-id')).toEqual('1337'); - expect($tr.attr('data-type')).toEqual('dir'); - expect($tr.attr('data-file')).toEqual('b'); - expect($tr.attr('data-path')).toEqual(''); - expect($tr.attr('data-size')).not.toBeDefined(); - expect(parseInt($tr.attr('data-permissions'), 10)) - .toEqual(OC.PERMISSION_ALL); // read and delete - expect($tr.attr('data-mime')).toEqual('httpd/unix-directory'); - expect($tr.attr('data-mtime')).toEqual('22222000'); - expect($tr.attr('data-share-owner')).toEqual('user3@foo.bar/'); - expect($tr.attr('data-share-id')).toEqual('8'); - expect($tr.attr('data-favorite')).not.toBeDefined(); - expect($tr.attr('data-tags')).toEqual(''); - expect($tr.find('a.name').attr('href')).toEqual( - OC.webroot + - '/index.php/apps/files' + - '?dir=/b' - ); - expect($tr.find('.nametext').text().trim()).toEqual('b'); - - }); - }); - describe('loading file list for outgoing shares', function() { - var ocsResponse; - - beforeEach(function() { - fileList = new OCA.Sharing.FileList( - $('#app-content-container'), { - sharedWithUser: false - } - ); - OCA.Sharing.Util.attach(fileList); - - fileList.reload(); - - /* jshint camelcase: false */ - ocsResponse = { - ocs: { - meta: { - status: 'ok', - statuscode: 100, - message: null - }, - data: [{ - id: 7, - item_type: 'file', - item_source: 49, - file_source: 49, - path: '/local path/local name.txt', - permissions: 27, - stime: 11111, - share_type: OC.Share.SHARE_TYPE_USER, - share_with: 'user2', - share_with_displayname: 'User Two', - tags: [OC.TAG_FAVORITE], - mimetype: 'text/plain', - uid_owner: 'user1', - displayname_owner: 'User One' - }] - } - }; - }); - it('render file shares', function() { - var request; - - expect(fakeServer.requests.length).toEqual(1); - request = fakeServer.requests[0]; - expect(request.url).toEqual( - OC.linkToOCS('apps/files_sharing/api/v1') + - 'shares?format=json&shared_with_me=false&include_tags=true' - ); - - fakeServer.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(ocsResponse) - ); - - var $rows = fileList.$el.find('tbody tr'); - var $tr = $rows.eq(0); - expect($rows.length).toEqual(1); - expect($tr.attr('data-id')).toEqual('49'); - expect($tr.attr('data-type')).toEqual('file'); - expect($tr.attr('data-file')).toEqual('local name.txt'); - expect($tr.attr('data-path')).toEqual('/local path'); - expect($tr.attr('data-size')).not.toBeDefined(); - expect($tr.attr('data-permissions')).toEqual('31'); // read and delete - expect($tr.attr('data-mime')).toEqual('text/plain'); - expect($tr.attr('data-mtime')).toEqual('11111000'); - expect($tr.attr('data-share-owner')).not.toBeDefined(); - expect($tr.attr('data-share-id')).toEqual('7'); - expect($tr.attr('data-favorite')).toEqual('true'); - expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE); - expect($tr.find('a.name').attr('href')).toEqual( - OC.webroot + - '/remote.php/webdav/local%20path/local%20name.txt' - ); - expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); - }); - it('render folder shares', function() { - var request; - /* jshint camelcase: false */ - ocsResponse.ocs.data[0] = _.extend(ocsResponse.ocs.data[0], { - item_type: 'folder', - path: '/local path/local name', - }); - - expect(fakeServer.requests.length).toEqual(1); - request = fakeServer.requests[0]; - expect(request.url).toEqual( - OC.linkToOCS('apps/files_sharing/api/v1') + - 'shares?format=json&shared_with_me=false&include_tags=true' - ); - - fakeServer.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(ocsResponse) - ); - - var $rows = fileList.$el.find('tbody tr'); - var $tr = $rows.eq(0); - expect($rows.length).toEqual(1); - expect($tr.attr('data-id')).toEqual('49'); - expect($tr.attr('data-type')).toEqual('dir'); - expect($tr.attr('data-file')).toEqual('local name'); - expect($tr.attr('data-path')).toEqual('/local path'); - expect($tr.attr('data-size')).not.toBeDefined(); - expect($tr.attr('data-permissions')).toEqual('31'); // read and delete - expect($tr.attr('data-mime')).toEqual('httpd/unix-directory'); - expect($tr.attr('data-mtime')).toEqual('11111000'); - expect($tr.attr('data-share-owner')).not.toBeDefined(); - expect($tr.attr('data-share-id')).toEqual('7'); - expect($tr.attr('data-favorite')).toEqual('true'); - expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE); - expect($tr.find('a.name').attr('href')).toEqual( - OC.webroot + - '/index.php/apps/files' + - '?dir=/local%20path/local%20name' - ); - expect($tr.find('.nametext').text().trim()).toEqual('local name'); - }); - it('render link shares', function() { - /* jshint camelcase: false */ - var request; - ocsResponse.ocs.data[0] = { - id: 7, - item_type: 'file', - item_source: 49, - file_source: 49, - path: '/local path/local name.txt', - permissions: 1, - stime: 11111, - share_type: OC.Share.SHARE_TYPE_LINK, - share_with: null, - token: 'abc', - mimetype: 'text/plain', - uid_owner: 'user1', - displayname_owner: 'User One', - tags: [OC.TAG_FAVORITE] - }; - expect(fakeServer.requests.length).toEqual(1); - request = fakeServer.requests[0]; - expect(request.url).toEqual( - OC.linkToOCS('apps/files_sharing/api/v1') + - 'shares?format=json&shared_with_me=false&include_tags=true' - ); - - fakeServer.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(ocsResponse) - ); - - var $rows = fileList.$el.find('tbody tr'); - var $tr = $rows.eq(0); - expect($rows.length).toEqual(1); - expect($tr.attr('data-id')).toEqual('49'); - expect($tr.attr('data-type')).toEqual('file'); - expect($tr.attr('data-file')).toEqual('local name.txt'); - expect($tr.attr('data-path')).toEqual('/local path'); - expect($tr.attr('data-size')).not.toBeDefined(); - expect($tr.attr('data-permissions')).toEqual('31'); // read and delete - expect($tr.attr('data-mime')).toEqual('text/plain'); - expect($tr.attr('data-mtime')).toEqual('11111000'); - expect($tr.attr('data-share-owner')).not.toBeDefined(); - expect($tr.attr('data-share-id')).toEqual('7'); - expect($tr.attr('data-favorite')).toEqual('true'); - expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE); - expect($tr.find('a.name').attr('href')).toEqual( - OC.webroot + '/remote.php/webdav/local%20path/local%20name.txt' - ); - - expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); - }); - it('groups link shares with regular shares', function() { - /* jshint camelcase: false */ - var request; - // link share - ocsResponse.ocs.data.push({ - id: 8, - item_type: 'file', - item_source: 49, - file_source: 49, - path: '/local path/local name.txt', - permissions: 1, - stime: 11111, - share_type: OC.Share.SHARE_TYPE_LINK, - share_with: null, - token: 'abc', - mimetype: 'text/plain', - uid_owner: 'user1', - displayname_owner: 'User One', - tags: [OC.TAG_FAVORITE], - }); - // another share of the same file - ocsResponse.ocs.data.push({ - id: 9, - item_type: 'file', - item_source: 49, - file_source: 49, - path: '/local path/local name.txt', - permissions: 27, - stime: 22222, - share_type: OC.Share.SHARE_TYPE_USER, - share_with: 'user3', - share_with_displayname: 'User Three', - mimetype: 'text/plain', - uid_owner: 'user1', - displayname_owner: 'User One' - }); - expect(fakeServer.requests.length).toEqual(1); - request = fakeServer.requests[0]; - expect(request.url).toEqual( - OC.linkToOCS('apps/files_sharing/api/v1') + - 'shares?format=json&shared_with_me=false&include_tags=true' - ); - - fakeServer.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(ocsResponse) - ); - - var $rows = fileList.$el.find('tbody tr'); - var $tr = $rows.eq(0); - expect($rows.length).toEqual(1); - expect($tr.attr('data-id')).toEqual('49'); - expect($tr.attr('data-type')).toEqual('file'); - expect($tr.attr('data-file')).toEqual('local name.txt'); - expect($tr.attr('data-path')).toEqual('/local path'); - expect($tr.attr('data-size')).not.toBeDefined(); - expect($tr.attr('data-permissions')).toEqual('31'); // read and delete - expect($tr.attr('data-mime')).toEqual('text/plain'); - // always use the most recent stime - expect($tr.attr('data-mtime')).toEqual('22222000'); - expect($tr.attr('data-share-owner')).not.toBeDefined(); - expect($tr.attr('data-share-id')).toEqual('7,8,9'); - expect($tr.attr('data-favorite')).toEqual('true'); - expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE); - expect($tr.find('a.name').attr('href')).toEqual( - OC.webroot + '/remote.php/webdav/local%20path/local%20name.txt' - ); - expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); - }); - }); - describe('loading file list for link shares', function() { - var ocsResponse; - - beforeEach(function() { - fileList = new OCA.Sharing.FileList( - $('#app-content-container'), { - linksOnly: true - } - ); - OCA.Sharing.Util.attach(fileList); - - fileList.reload(); - - var expirationDateInADay = moment() - .add(1, 'days').format('YYYY-MM-DD HH:mm:ss'); - - /* jshint camelcase: false */ - ocsResponse = { - ocs: { - meta: { - status: 'ok', - statuscode: 100, - message: null - }, - data: [{ - id: 7, - item_type: 'file', - item_source: 49, - file_source: 49, - path: '/local path/local name.txt', - permissions: 1, - stime: 11111, - expiration: null, - share_type: OC.Share.SHARE_TYPE_LINK, - share_with: null, - token: 'abc', - mimetype: 'text/plain', - uid_owner: 'user1', - displayname_owner: 'User One', - tags: [OC.TAG_FAVORITE] - },{ - id: 8, - item_type: 'file', - item_source: 50, - file_source: 50, - path: '/local path2/local name2.txt', - permissions: 1, - stime: 11112, - expiration: expirationDateInADay, - share_type: OC.Share.SHARE_TYPE_LINK, - share_with: null, - token: 'abcd', - mimetype: 'text/plain2', - uid_owner: 'user2', - displayname_owner: 'User One2' - }] - } - }; - }); - it('render only link shares', function() { - /* jshint camelcase: false */ - var request; - ocsResponse.ocs.data.push({ - // non-link share - id: 8, - item_type: 'file', - item_source: 49, - file_source: 49, - path: '/local path/local name.txt', - permissions: 27, - stime: 11111, - share_type: OC.Share.SHARE_TYPE_USER, - share_with: 'user2', - share_with_displayname: 'User Two', - mimetype: 'text/plain', - uid_owner: 'user1', - displayname_owner: 'User One', - tags: [OC.TAG_FAVORITE] - }); - expect(fakeServer.requests.length).toEqual(1); - request = fakeServer.requests[0]; - expect(request.url).toEqual( - OC.linkToOCS('apps/files_sharing/api/v1') + - 'shares?format=json&shared_with_me=false&include_tags=true' - ); - - fakeServer.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(ocsResponse) - ); - - // only renders the link share entries - var $rows = fileList.$el.find('tbody tr'); - var $tr = $rows.eq(0); - expect($rows.length).toEqual(2); - expect($tr.attr('data-id')).toEqual('49'); - expect($tr.attr('data-type')).toEqual('file'); - expect($tr.attr('data-file')).toEqual('local name.txt'); - expect($tr.attr('data-path')).toEqual('/local path'); - expect($tr.attr('data-size')).not.toBeDefined(); - expect($tr.attr('data-permissions')).toEqual('31'); // read and delete - expect($tr.attr('data-mime')).toEqual('text/plain'); - expect($tr.attr('data-mtime')).toEqual('11111000'); - expect($tr.attr('data-share-recipient-data')).not.toBeDefined(); - expect($tr.attr('data-share-owner')).not.toBeDefined(); - expect($tr.attr('data-share-id')).toEqual('7'); - expect($tr.attr('data-favorite')).toEqual('true'); - expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE); - expect($tr.find('a.name').attr('href')).toEqual( - OC.webroot + '/remote.php/webdav/local%20path/local%20name.txt' - ); - expect($tr.attr('data-expiration')).toEqual('0'); - expect($tr.find('td:last-child span').text()).toEqual(''); - - expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); - - // change to next row - $tr = $rows.eq(1); - expect($tr.attr('data-id')).toEqual('50'); - expect($tr.attr('data-file')).toEqual('local name2.txt'); - expect($tr.attr('data-expiration')).not.toEqual('0'); - expect($tr.attr('data-favorite')).not.toBeDefined(); - expect($tr.attr('data-tags')).toEqual(''); - expect($tr.find('td:last-child span').text()).toEqual('in a day'); - }); - it('does not show virtual token recipient as recipient when password was set', function() { - /* jshint camelcase: false */ - var request; - // when a password is set, share_with contains an auth token - ocsResponse.ocs.data[0].share_with = 'abc01234/01234abc'; - ocsResponse.ocs.data[0].share_with_displayname = 'abc01234/01234abc'; - expect(fakeServer.requests.length).toEqual(1); - request = fakeServer.requests[0]; - expect(request.url).toEqual( - OC.linkToOCS('apps/files_sharing/api/v1') + - 'shares?format=json&shared_with_me=false&include_tags=true' - ); - - fakeServer.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(ocsResponse) - ); - - // only renders the link share entry - var $rows = fileList.$el.find('tbody tr'); - var $tr = $rows.eq(0); - expect($rows.length).toEqual(2); - expect($tr.attr('data-id')).toEqual('49'); - expect($tr.attr('data-type')).toEqual('file'); - expect($tr.attr('data-file')).toEqual('local name.txt'); - expect($tr.attr('data-path')).toEqual('/local path'); - expect($tr.attr('data-size')).not.toBeDefined(); - expect($tr.attr('data-permissions')).toEqual('31'); // read and delete - expect($tr.attr('data-mime')).toEqual('text/plain'); - expect($tr.attr('data-mtime')).toEqual('11111000'); - expect($tr.attr('data-share-recipient-data')).not.toBeDefined(); - expect($tr.attr('data-share-owner')).not.toBeDefined(); - expect($tr.attr('data-share-id')).toEqual('7'); - expect($tr.attr('data-favorite')).toEqual('true'); - expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE); - expect($tr.find('a.name').attr('href')).toEqual( - OC.webroot + - '/remote.php/webdav/local%20path/local%20name.txt'); - - expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); - }); - }); - describe('setting share permissions for files', function () { - beforeEach(function () { - - var $content = $('<div id="content"></div>'); - $('#testArea').append($content); - // dummy file list - var $div = $( - '<div>' + - '<table id="filestable">' + - '<thead></thead>' + - '<tbody id="fileList"></tbody>' + - '</table>' + - '</div>'); - $('#content').append($div); - - fileList = new OCA.Files.FileList($div); - OCA.Sharing.Util.attach(fileList); - }); - - it('external storage root folder', function () { - var $tr; - OC.Share.statuses = {1: {link: false, path: '/subdir'}}; - fileList.setFiles([{ - id: 1, - type: 'dir', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_READ, - etag: 'abc', - shareOwner: 'User One', - recipients: 'User Two', - mountType: 'external-root' - }]); - $tr = fileList.$el.find('tr:first'); - - expect(parseInt($tr.attr('data-share-permissions'), 10)).toEqual(OC.PERMISSION_ALL - OC.PERMISSION_SHARE); - }); - - it('external storage root folder reshare', function () { - var $tr; - OC.Share.statuses = {1: {link: false, path: '/subdir'}}; - fileList.setFiles([{ - id: 1, - type: 'dir', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_READ + OC.PERMISSION_SHARE, - etag: 'abc', - shareOwner: 'User One', - recipients: 'User Two', - mountType: 'external-root' - }]); - $tr = fileList.$el.find('tr:first'); - - expect(parseInt($tr.attr('data-share-permissions'), 10)).toEqual(OC.PERMISSION_ALL); - }); - - it('external storage root folder file', function () { - var $tr; - OC.Share.statuses = {1: {link: false, path: '/subdir'}}; - fileList.setFiles([{ - id: 1, - type: 'file', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_READ, - etag: 'abc', - shareOwner: 'User One', - recipients: 'User Two', - mountType: 'external-root' - }]); - $tr = fileList.$el.find('tr:first'); - - expect(parseInt($tr.attr('data-share-permissions'), 10)) - .toEqual(OC.PERMISSION_ALL - OC.PERMISSION_SHARE - OC.PERMISSION_DELETE - OC.PERMISSION_CREATE); - }); - }); -}); |