2014-05-13 13:15:06 +04:00
|
|
|
/**
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* global oc_appconfig */
|
|
|
|
describe('OC.Share tests', function() {
|
2014-07-03 15:19:14 +04:00
|
|
|
describe('markFileAsShared', function() {
|
|
|
|
var $file;
|
2017-02-28 00:25:05 +03:00
|
|
|
var tooltipStub;
|
2014-07-03 15:19:14 +04:00
|
|
|
|
|
|
|
beforeEach(function() {
|
2017-02-28 00:25:05 +03:00
|
|
|
tooltipStub = sinon.stub($.fn, 'tooltip');
|
2014-12-11 19:36:14 +03:00
|
|
|
$file = $('<tr><td class="filename"><div class="thumbnail"></div><span class="name">File name</span></td></tr>');
|
2014-07-03 15:19:14 +04:00
|
|
|
$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;
|
2017-02-28 00:25:05 +03:00
|
|
|
tooltipStub.restore();
|
2014-07-03 15:19:14 +04:00
|
|
|
});
|
|
|
|
describe('displaying the share owner', function() {
|
|
|
|
function checkOwner(input, output, title) {
|
|
|
|
var $action;
|
|
|
|
|
|
|
|
$file.attr('data-share-owner', input);
|
2017-11-20 00:41:28 +03:00
|
|
|
$file.attr('data-share-owner-id', input);
|
2014-07-03 15:19:14 +04:00
|
|
|
OC.Share.markFileAsShared($file);
|
|
|
|
|
2017-11-01 17:14:45 +03:00
|
|
|
$action = $file.find('.action-share>span').parent();
|
2015-08-26 12:39:22 +03:00
|
|
|
expect($action.text().trim()).toEqual(output);
|
2014-07-03 15:19:14 +04:00
|
|
|
if (_.isString(title)) {
|
2015-05-16 15:22:10 +03:00
|
|
|
expect($action.find('.remoteAddress').attr('title')).toEqual(title);
|
2014-07-03 15:19:14 +04:00
|
|
|
} else {
|
2015-05-16 15:22:10 +03:00
|
|
|
expect($action.find('.remoteAddress').attr('title')).not.toBeDefined();
|
2014-07-03 15:19:14 +04:00
|
|
|
}
|
2017-02-28 00:25:05 +03:00
|
|
|
expect(tooltipStub.calledOnce).toEqual(true);
|
|
|
|
tooltipStub.reset();
|
2014-07-03 15:19:14 +04:00
|
|
|
}
|
|
|
|
|
2017-11-01 13:41:22 +03:00
|
|
|
it('displays the local share owner with "Shared by" prefix', function() {
|
|
|
|
checkOwner('User One', 'Shared by User One', null);
|
2014-07-03 15:19:14 +04:00
|
|
|
});
|
|
|
|
it('displays the user name part of a remote share owner', function() {
|
|
|
|
checkOwner(
|
|
|
|
'User One@someserver.com',
|
2015-01-27 13:06:18 +03:00
|
|
|
'User One@…',
|
2017-11-01 17:14:45 +03:00
|
|
|
'Shared by User One@someserver.com'
|
2014-07-03 15:19:14 +04:00
|
|
|
);
|
|
|
|
checkOwner(
|
|
|
|
'User One@someserver.com/',
|
2015-01-27 13:06:18 +03:00
|
|
|
'User One@…',
|
2017-11-01 17:14:45 +03:00
|
|
|
'Shared by User One@someserver.com'
|
2014-07-03 15:19:14 +04:00
|
|
|
);
|
|
|
|
checkOwner(
|
|
|
|
'User One@someserver.com/root/of/owncloud',
|
2015-01-27 13:06:18 +03:00
|
|
|
'User One@…',
|
2017-11-01 17:14:45 +03:00
|
|
|
'Shared by User One@someserver.com'
|
2014-07-03 15:19:14 +04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
it('displays the user name part with domain of a remote share owner', function() {
|
|
|
|
checkOwner(
|
|
|
|
'User One@example.com@someserver.com',
|
2014-07-11 17:16:26 +04:00
|
|
|
'User One@example.com',
|
2017-11-01 17:14:45 +03:00
|
|
|
'Shared by User One@example.com@someserver.com'
|
2014-07-03 15:19:14 +04:00
|
|
|
);
|
|
|
|
checkOwner(
|
|
|
|
'User One@example.com@someserver.com/',
|
2014-07-11 17:16:26 +04:00
|
|
|
'User One@example.com',
|
2017-11-01 17:14:45 +03:00
|
|
|
'Shared by User One@example.com@someserver.com'
|
2014-07-03 15:19:14 +04:00
|
|
|
);
|
|
|
|
checkOwner(
|
|
|
|
'User One@example.com@someserver.com/root/of/owncloud',
|
2014-07-11 17:16:26 +04:00
|
|
|
'User One@example.com',
|
2017-11-01 17:14:45 +03:00
|
|
|
'Shared by User One@example.com@someserver.com'
|
2014-07-03 15:19:14 +04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-08-15 18:19:50 +04:00
|
|
|
describe('displaying the folder icon', function() {
|
|
|
|
function checkIcon(expectedImage) {
|
2014-12-11 19:36:14 +03:00
|
|
|
var imageUrl = OC.TestUtil.getImageUrl($file.find('.filename .thumbnail'));
|
2014-08-15 18:19:50 +04:00
|
|
|
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');
|
2017-11-20 00:41:28 +03:00
|
|
|
$file.attr('data-share-owner-id', 'someoneelse');
|
2014-08-15 18:19:50 +04:00
|
|
|
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');
|
|
|
|
});
|
2015-10-28 19:43:36 +03:00
|
|
|
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');
|
|
|
|
});
|
2014-08-15 18:19:50 +04:00
|
|
|
});
|
2015-05-16 15:22:10 +03:00
|
|
|
|
2017-11-01 17:14:45 +03:00
|
|
|
describe('displaying the recipients', function() {
|
2015-05-16 15:22:10 +03:00
|
|
|
function checkRecipients(input, output, title) {
|
|
|
|
var $action;
|
|
|
|
|
2017-11-20 00:41:28 +03:00
|
|
|
$file.attr('data-share-recipient-data', JSON.stringify(input));
|
2015-05-16 15:22:10 +03:00
|
|
|
OC.Share.markFileAsShared($file, true);
|
|
|
|
|
2017-11-01 17:14:45 +03:00
|
|
|
$action = $file.find('.action-share>span').parent();
|
2015-08-26 12:39:22 +03:00
|
|
|
expect($action.text().trim()).toEqual(output);
|
2015-05-16 15:22:10 +03:00
|
|
|
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();
|
|
|
|
}
|
2017-02-28 00:25:05 +03:00
|
|
|
expect(tooltipStub.calledOnce).toEqual(true);
|
|
|
|
tooltipStub.reset();
|
2015-05-16 15:22:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
it('displays the local share owner as is', function() {
|
2017-11-21 13:29:42 +03:00
|
|
|
var input = {
|
|
|
|
0: {
|
|
|
|
shareWith: 'User One',
|
|
|
|
shareWithDisplayName: 'User One'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
checkRecipients(input, 'Shared with User One', null);
|
2015-05-16 15:22:10 +03:00
|
|
|
});
|
|
|
|
it('displays the user name part of a remote recipient', function() {
|
2017-11-21 13:29:42 +03:00
|
|
|
var input = {
|
|
|
|
0: {
|
|
|
|
shareWith: 'User One@someserver.com',
|
|
|
|
shareWithDisplayName: 'User One@someserver.com'
|
|
|
|
}
|
|
|
|
};
|
2015-05-16 15:22:10 +03:00
|
|
|
checkRecipients(
|
2017-11-21 13:29:42 +03:00
|
|
|
input,
|
2017-11-01 17:14:45 +03:00
|
|
|
'User One@…',
|
|
|
|
'Shared with User One@someserver.com'
|
2015-05-16 15:22:10 +03:00
|
|
|
);
|
2017-11-21 13:29:42 +03:00
|
|
|
|
|
|
|
input = {
|
|
|
|
0: {
|
|
|
|
shareWith: 'User One@someserver.com/',
|
|
|
|
shareWithDisplayName: 'User One@someserver.com/'
|
|
|
|
}
|
|
|
|
};
|
2015-05-16 15:22:10 +03:00
|
|
|
checkRecipients(
|
2017-11-21 13:29:42 +03:00
|
|
|
input,
|
2017-11-01 17:14:45 +03:00
|
|
|
'User One@…',
|
|
|
|
'Shared with User One@someserver.com'
|
2015-05-16 15:22:10 +03:00
|
|
|
);
|
2017-11-21 13:29:42 +03:00
|
|
|
|
|
|
|
input = {
|
|
|
|
0: {
|
|
|
|
shareWith: 'User One@someserver.com/root/of/nextcloud',
|
|
|
|
shareWithDisplayName: 'User One@someserver.com/root/of/nextcloud'
|
|
|
|
}
|
|
|
|
};
|
2015-05-16 15:22:10 +03:00
|
|
|
checkRecipients(
|
2017-11-21 13:29:42 +03:00
|
|
|
input,
|
2017-11-01 17:14:45 +03:00
|
|
|
'User One@…',
|
|
|
|
'Shared with User One@someserver.com'
|
2015-05-16 15:22:10 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
it('displays the user name part with domain of a remote share owner', function() {
|
2017-11-21 13:29:42 +03:00
|
|
|
var input = {
|
|
|
|
0: {
|
|
|
|
shareWith: 'User One@example.com@someserver.com',
|
|
|
|
shareWithDisplayName: 'User One@example.com@someserver.com'
|
|
|
|
}
|
|
|
|
};
|
2015-05-16 15:22:10 +03:00
|
|
|
checkRecipients(
|
2017-11-21 13:29:42 +03:00
|
|
|
input,
|
2017-11-01 17:14:45 +03:00
|
|
|
'User One@example.com',
|
|
|
|
'Shared with User One@example.com@someserver.com'
|
2015-05-16 15:22:10 +03:00
|
|
|
);
|
2017-11-21 13:29:42 +03:00
|
|
|
|
|
|
|
input = {
|
|
|
|
0: {
|
|
|
|
shareWith: 'User One@example.com@someserver.com/',
|
|
|
|
shareWithDisplayName: 'User One@example.com@someserver.com/'
|
|
|
|
}
|
|
|
|
};
|
2015-05-16 15:22:10 +03:00
|
|
|
checkRecipients(
|
2017-11-21 13:29:42 +03:00
|
|
|
input,
|
2017-11-01 17:14:45 +03:00
|
|
|
'User One@example.com',
|
|
|
|
'Shared with User One@example.com@someserver.com'
|
2015-05-16 15:22:10 +03:00
|
|
|
);
|
2017-11-21 13:29:42 +03:00
|
|
|
|
|
|
|
input = {
|
|
|
|
0: {
|
|
|
|
shareWith: 'User One@example.com@someserver.com/root/of/nextcloud',
|
|
|
|
shareWithDisplayName: 'User One@example.com@someserver.com/root/of/nextcloud'
|
|
|
|
}
|
|
|
|
};
|
2015-05-16 15:22:10 +03:00
|
|
|
checkRecipients(
|
2017-11-21 13:29:42 +03:00
|
|
|
input,
|
2017-11-01 17:14:45 +03:00
|
|
|
'User One@example.com',
|
|
|
|
'Shared with User One@example.com@someserver.com'
|
2015-05-16 15:22:10 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
it('display multiple remote recipients', function() {
|
2017-11-21 13:29:42 +03:00
|
|
|
var input = {
|
|
|
|
0: {
|
|
|
|
shareWith: 'One@someserver.com',
|
|
|
|
shareWithDisplayName: 'One@someserver.com'
|
2017-11-20 00:41:28 +03:00
|
|
|
},
|
2017-11-21 13:29:42 +03:00
|
|
|
1: {
|
2017-11-21 14:45:57 +03:00
|
|
|
shareWith: 'two@otherserver.com',
|
|
|
|
shareWithDisplayName: 'two@otherserver.com'
|
2017-11-21 13:29:42 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
checkRecipients(
|
|
|
|
input,
|
2017-11-01 17:14:45 +03:00
|
|
|
'One@… two@…',
|
|
|
|
['Shared with One@someserver.com', 'Shared with two@otherserver.com']
|
2015-05-16 15:22:10 +03:00
|
|
|
);
|
2017-11-21 13:29:42 +03:00
|
|
|
|
|
|
|
input = {
|
|
|
|
0: {
|
|
|
|
shareWith: 'One@someserver.com/',
|
|
|
|
shareWithDisplayName: 'One@someserver.com/'
|
2017-11-20 00:41:28 +03:00
|
|
|
},
|
2017-11-21 13:29:42 +03:00
|
|
|
1: {
|
|
|
|
shareWith: 'two@someserver.com',
|
|
|
|
shareWithDisplayName: 'two@someserver.com'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
checkRecipients(
|
|
|
|
input,
|
2017-11-01 17:14:45 +03:00
|
|
|
'One@… two@…',
|
|
|
|
['Shared with One@someserver.com', 'Shared with two@otherserver.com']
|
2015-05-16 15:22:10 +03:00
|
|
|
);
|
2017-11-21 13:29:42 +03:00
|
|
|
|
|
|
|
input = {
|
|
|
|
0: {
|
|
|
|
shareWith: 'One@someserver.com/root/of/nextcloud',
|
|
|
|
shareWithDisplayName: 'One@someserver.com/root/of/nextcloud'
|
2017-11-20 00:41:28 +03:00
|
|
|
},
|
2017-11-21 13:29:42 +03:00
|
|
|
1: {
|
|
|
|
shareWith: 'two@someserver.com',
|
|
|
|
shareWithDisplayName: 'two@someserver.com'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
checkRecipients(
|
|
|
|
input,
|
2017-11-01 17:14:45 +03:00
|
|
|
'One@… two@…',
|
|
|
|
['Shared with One@someserver.com', 'Shared with two@otherserver.com']
|
2015-05-16 15:22:10 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
it('display mixed recipients', function() {
|
|
|
|
checkRecipients(
|
2017-11-20 00:41:28 +03:00
|
|
|
{
|
2017-11-21 13:29:42 +03:00
|
|
|
0: {
|
|
|
|
shareWith: 'One',
|
|
|
|
shareWithDisplayName: 'One'
|
|
|
|
},
|
|
|
|
1: {
|
2017-11-21 14:45:57 +03:00
|
|
|
shareWith: 'two@otherserver.com',
|
|
|
|
shareWithDisplayName: 'two@otherserver.com'
|
2017-11-21 13:29:42 +03:00
|
|
|
}
|
2017-11-20 00:41:28 +03:00
|
|
|
},
|
2017-11-01 17:14:45 +03:00
|
|
|
'Shared with One two@…',
|
|
|
|
['Shared with two@otherserver.com']
|
2015-05-16 15:22:10 +03:00
|
|
|
);
|
|
|
|
});
|
2017-11-20 00:41:28 +03:00
|
|
|
it('display multiple with divergent displaynames', function() {
|
|
|
|
checkRecipients(
|
|
|
|
{
|
2017-11-21 13:29:42 +03:00
|
|
|
0: {
|
|
|
|
shareWith: 'One',
|
|
|
|
shareWithDisplayName: 'Yoko Ono'
|
|
|
|
},
|
|
|
|
1: {
|
2017-11-21 14:45:57 +03:00
|
|
|
shareWith: 'two@otherserver.com',
|
|
|
|
shareWithDisplayName: 'two@othererver.com'
|
2017-11-21 13:29:42 +03:00
|
|
|
},
|
|
|
|
2: {
|
|
|
|
shareWith: 'Three',
|
|
|
|
shareWithDisplayName: 'Green, Mina'
|
|
|
|
}
|
2017-11-20 00:41:28 +03:00
|
|
|
},
|
2017-11-21 14:45:57 +03:00
|
|
|
'Shared with Green, Mina two@… Shared with Yoko Ono',
|
2017-11-20 00:41:28 +03:00
|
|
|
['Shared with two@otherserver.com']
|
|
|
|
);
|
|
|
|
});
|
2015-05-16 15:22:10 +03:00
|
|
|
});
|
2014-07-03 15:19:14 +04:00
|
|
|
});
|
2014-05-13 13:15:06 +04:00
|
|
|
});
|