123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- /**
- * 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('OC.Share tests', function() {
- describe('markFileAsShared', function() {
- var $file;
- var tooltipStub;
-
- beforeEach(function() {
- tooltipStub = sinon.stub($.fn, 'tooltip');
- $file = $('<tr><td class="filename"><div class="thumbnail"></div><span class="name">File name</span></td></tr>');
- $file.find('.filename').append(
- '<span class="fileactions">' +
- '<a href="#" class="action action-share" data-action="Share">' +
- '<img></img><span> Share</span>' +
- '</a>' +
- '</span>'
- );
- });
- afterEach(function() {
- $file = null;
- tooltipStub.restore();
- });
- describe('displaying the share owner', function() {
- function checkOwner(input, output, title) {
- var $action;
-
- $file.attr('data-share-owner', input);
- $file.attr('data-share-owner-id', input);
- OC.Share.markFileAsShared($file);
-
- $action = $file.find('.action-share>span').parent();
- expect($action.text().trim()).toEqual(output);
- if (_.isString(title)) {
- expect($action.find('.remoteAddress').attr('title')).toEqual(title);
- } else {
- expect($action.find('.remoteAddress').attr('title')).not.toBeDefined();
- }
- expect(tooltipStub.calledOnce).toEqual(true);
- tooltipStub.reset();
- }
-
- it('displays the local share owner with "Shared by" prefix', function() {
- checkOwner('User One', 'Shared by User One', null);
- });
- it('displays the user name part of a remote share owner', function() {
- checkOwner(
- 'User One@someserver.com',
- 'User One@…',
- 'Shared by User One@someserver.com'
- );
- checkOwner(
- 'User One@someserver.com/',
- 'User One@…',
- 'Shared by User One@someserver.com'
- );
- checkOwner(
- 'User One@someserver.com/root/of/owncloud',
- 'User One@…',
- 'Shared by User One@someserver.com'
- );
- });
- it('displays the user name part with domain of a remote share owner', function() {
- checkOwner(
- 'User One@example.com@someserver.com',
- 'User One@example.com',
- 'Shared by User One@example.com@someserver.com'
- );
- checkOwner(
- 'User One@example.com@someserver.com/',
- 'User One@example.com',
- 'Shared by User One@example.com@someserver.com'
- );
- checkOwner(
- 'User One@example.com@someserver.com/root/of/owncloud',
- 'User One@example.com',
- 'Shared by User One@example.com@someserver.com'
- );
- });
- });
-
- describe('displaying the folder icon', function() {
- function checkIcon(expectedImage) {
- var imageUrl = OC.TestUtil.getImageUrl($file.find('.filename .thumbnail'));
- expectedIcon = OC.imagePath('core', expectedImage);
- expect(imageUrl).toEqual(expectedIcon);
- }
-
- it('shows a plain folder icon for non-shared folders', function() {
- $file.attr('data-type', 'dir');
- OC.Share.markFileAsShared($file);
-
- checkIcon('filetypes/folder');
- });
- it('shows a shared folder icon for folders shared with another user', function() {
- $file.attr('data-type', 'dir');
- OC.Share.markFileAsShared($file, true);
-
- checkIcon('filetypes/folder-shared');
- });
- it('shows a shared folder icon for folders shared with the current user', function() {
- $file.attr('data-type', 'dir');
- $file.attr('data-share-owner', 'someoneelse');
- $file.attr('data-share-owner-id', 'someoneelse');
- OC.Share.markFileAsShared($file);
-
- checkIcon('filetypes/folder-shared');
- });
- it('shows a link folder icon for folders shared with link', function() {
- $file.attr('data-type', 'dir');
- OC.Share.markFileAsShared($file, false, true);
-
- checkIcon('filetypes/folder-public');
- });
- it('shows a link folder icon for folders shared with both link and another user', function() {
- $file.attr('data-type', 'dir');
- OC.Share.markFileAsShared($file, true, true);
-
- checkIcon('filetypes/folder-public');
- });
- it('shows a link folder icon for folders reshared with link', function() {
- $file.attr('data-type', 'dir');
- $file.attr('data-share-owner', 'someoneelse');
- OC.Share.markFileAsShared($file, false, true);
-
- checkIcon('filetypes/folder-public');
- });
- it('shows external storage icon if external mount point', function() {
- $file.attr('data-type', 'dir');
- $file.attr('data-mountType', 'external');
- OC.Share.markFileAsShared($file, false, false);
-
- checkIcon('filetypes/folder-external');
- });
- it('shows encrypted icon if encrypted folder', function() {
- $file.attr('data-type', 'dir');
- $file.attr('data-e2eencrypted', true);
- OC.Share.markFileAsShared($file, false, false);
-
- checkIcon('filetypes/folder-encrypted');
- });
- });
-
- describe('displaying the recipients', function() {
- function checkRecipients(input, output, title) {
- var $action;
-
- $file.attr('data-share-recipient-data', JSON.stringify(input));
- OC.Share.markFileAsShared($file, true);
-
- $action = $file.find('.action-share>span').parent();
- expect($action.text().trim()).toEqual(output);
- if (_.isString(title)) {
- expect($action.find('.remoteAddress').attr('title')).toEqual(title);
- } else if (_.isArray(title)) {
- var tooltips = $action.find('.remoteAddress');
- expect(tooltips.length).toEqual(title.length);
-
- tooltips.each(function(i) {
- expect($(this).attr('title')).toEqual(title[i]);
- });
- } else {
- expect($action.find('.remoteAddress').attr('title')).not.toBeDefined();
- }
- expect(tooltipStub.calledOnce).toEqual(true);
- tooltipStub.reset();
- }
-
- it('displays the local share owner as is', function() {
- var input = {
- 0: {
- shareWith: 'User One',
- shareWithDisplayName: 'User One'
- }
- };
- checkRecipients(input, 'Shared with User One', null);
- });
- it('displays the user name part of a remote recipient', function() {
- var input = {
- 0: {
- shareWith: 'User One@someserver.com',
- shareWithDisplayName: 'User One@someserver.com'
- }
- };
- checkRecipients(
- input,
- 'User One@…',
- 'Shared with User One@someserver.com'
- );
-
- input = {
- 0: {
- shareWith: 'User One@someserver.com/',
- shareWithDisplayName: 'User One@someserver.com/'
- }
- };
- checkRecipients(
- input,
- 'User One@…',
- 'Shared with User One@someserver.com'
- );
-
- input = {
- 0: {
- shareWith: 'User One@someserver.com/root/of/nextcloud',
- shareWithDisplayName: 'User One@someserver.com/root/of/nextcloud'
- }
- };
- checkRecipients(
- input,
- 'User One@…',
- 'Shared with User One@someserver.com'
- );
- });
- it('displays the user name part with domain of a remote share owner', function() {
- var input = {
- 0: {
- shareWith: 'User One@example.com@someserver.com',
- shareWithDisplayName: 'User One@example.com@someserver.com'
- }
- };
- checkRecipients(
- input,
- 'User One@example.com',
- 'Shared with User One@example.com@someserver.com'
- );
-
- input = {
- 0: {
- shareWith: 'User One@example.com@someserver.com/',
- shareWithDisplayName: 'User One@example.com@someserver.com/'
- }
- };
- checkRecipients(
- input,
- 'User One@example.com',
- 'Shared with User One@example.com@someserver.com'
- );
-
- input = {
- 0: {
- shareWith: 'User One@example.com@someserver.com/root/of/nextcloud',
- shareWithDisplayName: 'User One@example.com@someserver.com/root/of/nextcloud'
- }
- };
- checkRecipients(
- input,
- 'User One@example.com',
- 'Shared with User One@example.com@someserver.com'
- );
- });
- it('display multiple remote recipients', function() {
- var input = {
- 0: {
- shareWith: 'One@someserver.com',
- shareWithDisplayName: 'One@someserver.com'
- },
- 1: {
- shareWith: 'two@otherserver.com',
- shareWithDisplayName: 'two@otherserver.com'
- }
- };
- checkRecipients(
- input,
- 'One@… two@…',
- ['Shared with One@someserver.com', 'Shared with two@otherserver.com']
- );
-
- input = {
- 0: {
- shareWith: 'One@someserver.com/',
- shareWithDisplayName: 'One@someserver.com/'
- },
- 1: {
- shareWith: 'two@someserver.com',
- shareWithDisplayName: 'two@someserver.com'
- }
- };
- checkRecipients(
- input,
- 'One@… two@…',
- ['Shared with One@someserver.com', 'Shared with two@otherserver.com']
- );
-
- input = {
- 0: {
- shareWith: 'One@someserver.com/root/of/nextcloud',
- shareWithDisplayName: 'One@someserver.com/root/of/nextcloud'
- },
- 1: {
- shareWith: 'two@someserver.com',
- shareWithDisplayName: 'two@someserver.com'
- }
- };
- checkRecipients(
- input,
- 'One@… two@…',
- ['Shared with One@someserver.com', 'Shared with two@otherserver.com']
- );
- });
- it('display mixed recipients', function() {
- checkRecipients(
- {
- 0: {
- shareWith: 'One',
- shareWithDisplayName: 'One'
- },
- 1: {
- shareWith: 'two@otherserver.com',
- shareWithDisplayName: 'two@otherserver.com'
- }
- },
- 'Shared with One two@…',
- ['Shared with two@otherserver.com']
- );
- });
- it('display multiple with divergent displaynames', function() {
- var recipients = {
- 0: {
- shareWith: 'One',
- shareWithDisplayName: 'Yoko Ono',
- _output: 'Shared with Yoko Ono'
- },
- 1: {
- shareWith: 'two@otherserver.com',
- shareWithDisplayName: 'two@othererver.com',
- _output: 'two@…'
- },
- 2: {
- shareWith: 'Three',
- shareWithDisplayName: 'Green, Mina',
- _output: 'Shared with Green, Mina'
- }
- };
-
- // we cannot assume the locale, also because PhantomJS has a bug.
- var sortArray = _.toArray(recipients)
- .sort(function(a, b) {
- return a.shareWithDisplayName.localeCompare(b.shareWithDisplayName);
- });
- var sortedOutput = _.map(sortArray, function(recipient) {
- return recipient._output;
- }).join(' ');
-
- checkRecipients(
- recipients,
- sortedOutput,
- ['Shared with two@otherserver.com']
- );
- });
- });
- });
- });
|