diff options
Diffstat (limited to 'apps/files_sharing/tests/js')
-rw-r--r-- | apps/files_sharing/tests/js/fileDropSpec.js | 98 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/publicAppSpec.js | 159 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/shareSpec.js | 343 |
3 files changed, 0 insertions, 600 deletions
diff --git a/apps/files_sharing/tests/js/fileDropSpec.js b/apps/files_sharing/tests/js/fileDropSpec.js deleted file mode 100644 index 18eee661e7f..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) - * - * @author Artur Neumann <info@individual-it.net> - * - * @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("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/dav/files/" + sharingToken + '/' + encodeURI(testFile.name)); - }); - } - }); -}); diff --git a/apps/files_sharing/tests/js/publicAppSpec.js b/apps/files_sharing/tests/js/publicAppSpec.js deleted file mode 100644 index 229e57ac4ed..00000000000 --- a/apps/files_sharing/tests/js/publicAppSpec.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @copyright 2015 Vincent Petry <pvince81@owncloud.com> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Jan-Christoph Borchardt <hey@jancborchardt.net> - * @author Roeland Jago Douma <roeland@famdouma.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.Sharing.PublicApp tests', function() { - var App = OCA.Sharing.PublicApp; - var hostStub, protocolStub; - var originalWebroot; - var $preview; - - beforeEach(function() { - originalWebroot = OC.webroot; - OC.webroot = '/owncloud'; - protocolStub = sinon.stub(OC, 'getProtocol').returns('https'); - hostStub = sinon.stub(OC, 'getHost').returns('example.com:9876'); - - $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() { - OC.webroot = originalWebroot; - protocolStub.restore(); - hostStub.restore(); - }); - - describe('File list', function() { - var parseUrlQueryStub - // 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="permissions" value="31"/>' + - // dummy controls - '<div class="files-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 class="files-filestable list-container view-grid">' + - '<thead><tr>' + - '<th 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>' + - '</span>' + - '</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 class="files-fileList"></tbody>' + - '<tfoot></tfoot>' + - '</table>' + - // TODO: move to handlebars template - '<div class="emptyfilelist emptycontent"><h2>Empty content message</h2><p class="uploadmessage">Upload message</p></div>' + - '<div class="nofilterresults hidden"></div>' + - '</div>' - ); - - parseUrlQueryStub = sinon.stub(OC.Util.History, 'parseUrlQuery'); - parseUrlQueryStub.returns({path: '/subdir'}); - App.initialize($('#preview')); - }); - afterEach(function() { - App._initialized = false; - parseUrlQueryStub.restore(); - }); - - 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/dav/files/sh4tok/subdir'); - 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.getRootPath() + '/index.php/s/sh4tok/download?path=%2Fsubdir&files=some%20file.txt'); - expect(fileList.getDownloadUrl('some file.txt', '/anotherpath/abc')) - .toEqual(OC.getRootPath() + '/index.php/s/sh4tok/download?path=%2Fanotherpath%2Fabc&files=some%20file.txt'); - fileList.changeDirectory('/'); - expect(fileList.getDownloadUrl('some file.txt')) - .toEqual(OC.getRootPath() + '/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.getRootPath() + '/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.getRootPath() + '/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.getRootPath() + '/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/dav/files/sh4tok/subdir/some%20file.txt'); - }); - it('returns correct upload URL with specified dir', function() { - expect(fileList.getUploadUrl('some file.txt', 'sub')) - .toEqual('/owncloud/public.php/dav/files/sh4tok/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 8a48ce54f19..00000000000 --- a/apps/files_sharing/tests/js/shareSpec.js +++ /dev/null @@ -1,343 +0,0 @@ -/** - * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Daniel Calviño Sánchez <danxuliu@gmail.com> - * @author Jan-Christoph Borchardt <hey@jancborchardt.net> - * @author John Molakvoæ <skjnldsv@protonmail.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.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.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="app-content"></div>'); - $('#testArea').append($content); - // dummy file list - var $div = $( - '<div id="listContainer">' + - '<table class="files-filestable list-container view-grid">' + - '<thead></thead>' + - '<tbody class="files-fileList"></tbody>' + - '</table>' + - '</div>'); - $('#app-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 share icon when shared to a room', 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_ROOM] - }]); - $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 but no icons', 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(false); - 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('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(); - }); - }); -}); |