2014-06-02 13:59:06 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2014-06-02 15:23:52 +00:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2014-06-02 13:59:06 +00:00
|
|
|
beforeEach(function() {
|
|
|
|
var $content = $('<div id="content"></div>');
|
|
|
|
$('#testArea').append($content);
|
|
|
|
// dummy file list
|
|
|
|
var $div = $(
|
2015-01-26 16:06:07 +00:00
|
|
|
'<div id="listContainer">' +
|
2014-06-02 13:59:06 +00:00
|
|
|
'<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
|
|
|
|
}
|
|
|
|
);
|
2014-12-01 15:17:28 +00:00
|
|
|
OCA.Sharing.Util.attach(fileList);
|
2014-06-02 13:59:06 +00:00
|
|
|
|
|
|
|
testFiles = [{
|
|
|
|
id: 1,
|
|
|
|
type: 'file',
|
|
|
|
name: 'One.txt',
|
|
|
|
path: '/subdir',
|
|
|
|
mimetype: 'text/plain',
|
|
|
|
size: 12,
|
2014-06-03 09:04:57 +00:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2014-06-02 13:59:06 +00:00
|
|
|
etag: 'abc',
|
|
|
|
shareOwner: 'User One',
|
|
|
|
isShareMountPoint: false
|
|
|
|
}];
|
|
|
|
|
|
|
|
OCA.Sharing.sharesLoaded = true;
|
|
|
|
OC.Share.statuses = {
|
|
|
|
1: {link: false, path: '/subdir'}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
delete OCA.Sharing.sharesLoaded;
|
2014-06-02 15:23:52 +00:00
|
|
|
delete OC.Share.droppedDown;
|
2014-06-27 11:36:18 +00:00
|
|
|
fileList.destroy();
|
|
|
|
fileList = null;
|
2014-06-02 13:59:06 +00:00
|
|
|
OC.Share.statuses = {};
|
2014-06-04 08:37:04 +00:00
|
|
|
OC.Share.currentShares = {};
|
2014-06-02 13:59:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Sharing data in table row', function() {
|
|
|
|
// TODO: test data-permissions, data-share-owner, etc
|
|
|
|
});
|
|
|
|
describe('Share action icon', function() {
|
2014-07-01 19:32:04 +00:00
|
|
|
beforeEach(function() {
|
|
|
|
OC.Share.statuses = {1: {link: false, path: '/subdir'}};
|
|
|
|
OCA.Sharing.sharesLoaded = true;
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
OC.Share.statuses = {};
|
|
|
|
OCA.Sharing.sharesLoaded = false;
|
|
|
|
});
|
2014-06-02 13:59:06 +00:00
|
|
|
it('do not shows share text when not shared', function() {
|
2014-06-02 15:23:52 +00:00
|
|
|
var $action, $tr;
|
2014-06-02 13:59:06 +00:00
|
|
|
OC.Share.statuses = {};
|
|
|
|
fileList.setFiles([{
|
|
|
|
id: 1,
|
2014-06-02 15:23:52 +00:00
|
|
|
type: 'dir',
|
|
|
|
name: 'One',
|
2014-06-02 13:59:06 +00:00
|
|
|
path: '/subdir',
|
2015-07-09 16:42:46 +00:00
|
|
|
mimetype: 'httpd/unix-directory',
|
2014-06-02 13:59:06 +00:00
|
|
|
size: 12,
|
2014-06-03 09:04:57 +00:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2014-06-02 13:59:06 +00:00
|
|
|
etag: 'abc'
|
|
|
|
}]);
|
2014-06-02 15:23:52 +00:00
|
|
|
$tr = fileList.$el.find('tbody tr:first');
|
|
|
|
$action = $tr.find('.action-share');
|
2015-08-10 13:57:21 +00:00
|
|
|
expect($action.hasClass('permanent')).toEqual(true);
|
2014-06-02 13:59:06 +00:00
|
|
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
2014-12-11 16:36:14 +00:00
|
|
|
expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder.svg');
|
2014-06-02 15:23:52 +00:00
|
|
|
expect($action.find('img').length).toEqual(1);
|
2014-06-02 13:59:06 +00:00
|
|
|
});
|
|
|
|
it('shows simple share text with share icon', function() {
|
2014-06-02 15:23:52 +00:00
|
|
|
var $action, $tr;
|
2014-06-02 13:59:06 +00:00
|
|
|
fileList.setFiles([{
|
|
|
|
id: 1,
|
2014-06-02 15:23:52 +00:00
|
|
|
type: 'dir',
|
|
|
|
name: 'One',
|
2014-06-02 13:59:06 +00:00
|
|
|
path: '/subdir',
|
|
|
|
mimetype: 'text/plain',
|
|
|
|
size: 12,
|
2014-06-03 09:04:57 +00:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2014-06-02 13:59:06 +00:00
|
|
|
etag: 'abc'
|
|
|
|
}]);
|
2014-06-02 15:23:52 +00:00
|
|
|
$tr = fileList.$el.find('tbody tr:first');
|
|
|
|
$action = $tr.find('.action-share');
|
2014-06-02 13:59:06 +00:00
|
|
|
expect($action.hasClass('permanent')).toEqual(true);
|
2015-08-26 09:39:22 +00:00
|
|
|
expect($action.find('>span').text().trim()).toEqual('Shared');
|
2014-06-02 13:59:06 +00:00
|
|
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
2014-12-11 16:36:14 +00:00
|
|
|
expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg');
|
2014-06-02 15:23:52 +00:00
|
|
|
expect($action.find('img').length).toEqual(1);
|
2014-06-02 13:59:06 +00:00
|
|
|
});
|
|
|
|
it('shows simple share text with public icon when shared with link', function() {
|
2014-06-02 15:23:52 +00:00
|
|
|
var $action, $tr;
|
2014-06-02 13:59:06 +00:00
|
|
|
OC.Share.statuses = {1: {link: true, path: '/subdir'}};
|
|
|
|
fileList.setFiles([{
|
|
|
|
id: 1,
|
2014-06-02 15:23:52 +00:00
|
|
|
type: 'dir',
|
|
|
|
name: 'One',
|
2014-06-02 13:59:06 +00:00
|
|
|
path: '/subdir',
|
|
|
|
mimetype: 'text/plain',
|
|
|
|
size: 12,
|
2014-06-03 09:04:57 +00:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2014-06-02 13:59:06 +00:00
|
|
|
etag: 'abc'
|
|
|
|
}]);
|
2014-06-02 15:23:52 +00:00
|
|
|
$tr = fileList.$el.find('tbody tr:first');
|
|
|
|
$action = $tr.find('.action-share');
|
2014-06-02 13:59:06 +00:00
|
|
|
expect($action.hasClass('permanent')).toEqual(true);
|
2015-08-26 09:39:22 +00:00
|
|
|
expect($action.find('>span').text().trim()).toEqual('Shared');
|
2014-06-02 13:59:06 +00:00
|
|
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('public.svg');
|
2014-12-11 16:36:14 +00:00
|
|
|
expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-public.svg');
|
2014-06-02 15:23:52 +00:00
|
|
|
expect($action.find('img').length).toEqual(1);
|
2014-06-02 13:59:06 +00:00
|
|
|
});
|
|
|
|
it('shows owner name when owner is available', function() {
|
2014-06-02 15:23:52 +00:00
|
|
|
var $action, $tr;
|
2014-06-02 13:59:06 +00:00
|
|
|
fileList.setFiles([{
|
|
|
|
id: 1,
|
2014-06-02 15:23:52 +00:00
|
|
|
type: 'dir',
|
2014-06-02 13:59:06 +00:00
|
|
|
name: 'One.txt',
|
|
|
|
path: '/subdir',
|
|
|
|
mimetype: 'text/plain',
|
|
|
|
size: 12,
|
2014-06-03 09:04:57 +00:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2014-06-02 13:59:06 +00:00
|
|
|
shareOwner: 'User One',
|
|
|
|
etag: 'abc'
|
|
|
|
}]);
|
2014-06-02 15:23:52 +00:00
|
|
|
$tr = fileList.$el.find('tbody tr:first');
|
|
|
|
$action = $tr.find('.action-share');
|
2014-06-02 13:59:06 +00:00
|
|
|
expect($action.hasClass('permanent')).toEqual(true);
|
2015-08-26 09:39:22 +00:00
|
|
|
expect($action.find('>span').text().trim()).toEqual('User One');
|
2014-06-02 13:59:06 +00:00
|
|
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
2014-12-11 16:36:14 +00:00
|
|
|
expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg');
|
2014-06-02 13:59:06 +00:00
|
|
|
});
|
|
|
|
it('shows recipients when recipients are available', function() {
|
2014-06-02 15:23:52 +00:00
|
|
|
var $action, $tr;
|
2014-06-02 13:59:06 +00:00
|
|
|
fileList.setFiles([{
|
|
|
|
id: 1,
|
2014-06-02 15:23:52 +00:00
|
|
|
type: 'dir',
|
2014-06-02 13:59:06 +00:00
|
|
|
name: 'One.txt',
|
|
|
|
path: '/subdir',
|
|
|
|
mimetype: 'text/plain',
|
|
|
|
size: 12,
|
2014-06-03 09:04:57 +00:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2014-06-02 13:59:06 +00:00
|
|
|
recipientsDisplayName: 'User One, User Two',
|
|
|
|
etag: 'abc'
|
|
|
|
}]);
|
2014-06-02 15:23:52 +00:00
|
|
|
$tr = fileList.$el.find('tbody tr:first');
|
|
|
|
$action = $tr.find('.action-share');
|
2014-06-02 13:59:06 +00:00
|
|
|
expect($action.hasClass('permanent')).toEqual(true);
|
2015-08-26 09:39:22 +00:00
|
|
|
expect($action.find('>span').text().trim()).toEqual('Shared with User One, User Two');
|
2014-06-02 13:59:06 +00:00
|
|
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
2014-12-11 16:36:14 +00:00
|
|
|
expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg');
|
2014-06-02 15:23:52 +00:00
|
|
|
expect($action.find('img').length).toEqual(1);
|
2014-06-02 13:59:06 +00:00
|
|
|
});
|
2014-06-03 09:04:57 +00:00
|
|
|
it('shows static share text when file shared with user that 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(0);
|
|
|
|
$action = $tr.find('.action-share-notification');
|
|
|
|
expect($action.hasClass('permanent')).toEqual(true);
|
2014-07-11 13:16:26 +00:00
|
|
|
expect($action.find('>span').text().trim()).toEqual('User One');
|
2014-06-03 09:04:57 +00:00
|
|
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
2014-12-11 16:36:14 +00:00
|
|
|
expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg');
|
2014-06-03 09:04:57 +00:00
|
|
|
expect($action.find('img').length).toEqual(1);
|
|
|
|
});
|
2015-07-02 14:38:20 +00:00
|
|
|
it('do not show static share text 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);
|
|
|
|
$action = $tr.find('.action-share-notification');
|
|
|
|
expect($action.length).toEqual(0);
|
|
|
|
});
|
2014-06-02 13:59:06 +00:00
|
|
|
});
|
|
|
|
describe('Share action', function() {
|
2014-06-02 15:23:52 +00:00
|
|
|
var showDropDownStub;
|
|
|
|
|
2014-06-04 08:37:04 +00:00
|
|
|
function makeDummyShareItem(displayName) {
|
|
|
|
return {
|
|
|
|
share_with_displayname: displayName
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-06-02 15:23:52 +00:00
|
|
|
beforeEach(function() {
|
|
|
|
showDropDownStub = sinon.stub(OC.Share, 'showDropDown', function() {
|
|
|
|
$('#testArea').append($('<div id="dropdown"></div>'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
showDropDownStub.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,
|
2014-06-03 09:04:57 +00:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2014-06-02 15:23:52 +00:00
|
|
|
etag: 'abc'
|
|
|
|
}]);
|
|
|
|
$action = fileList.$el.find('tbody tr:first .action-share');
|
|
|
|
$tr = fileList.$el.find('tr:first');
|
|
|
|
|
2015-08-10 13:57:21 +00:00
|
|
|
expect($action.hasClass('permanent')).toEqual(true);
|
2014-06-02 15:23:52 +00:00
|
|
|
|
|
|
|
$tr.find('.action-share').click();
|
|
|
|
|
|
|
|
expect(showDropDownStub.calledOnce).toEqual(true);
|
|
|
|
|
|
|
|
// simulate what the dropdown does
|
2014-06-04 08:37:04 +00:00
|
|
|
var shares = {};
|
|
|
|
OC.Share.itemShares[OC.Share.SHARE_TYPE_USER] = ['user1', 'user2'];
|
|
|
|
OC.Share.itemShares[OC.Share.SHARE_TYPE_GROUP] = ['group1', 'group2'];
|
|
|
|
shares[OC.Share.SHARE_TYPE_USER] = _.map(['User One', 'User Two'], makeDummyShareItem);
|
|
|
|
shares[OC.Share.SHARE_TYPE_GROUP] = _.map(['Group One', 'Group Two'], makeDummyShareItem);
|
|
|
|
$('#dropdown').trigger(new $.Event('sharesChanged', {shares: shares}));
|
2014-06-02 15:23:52 +00:00
|
|
|
|
|
|
|
expect($tr.attr('data-share-recipients')).toEqual('Group One, Group Two, User One, User Two');
|
|
|
|
|
|
|
|
OC.Share.updateIcon('file', 1);
|
|
|
|
expect($action.hasClass('permanent')).toEqual(true);
|
2015-08-26 09:39:22 +00:00
|
|
|
expect($action.find('>span').text().trim()).toEqual('Shared with Group One, Group Two, User One, User Two');
|
2014-06-02 15:23:52 +00:00
|
|
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
|
|
|
});
|
2014-06-04 08:37:04 +00:00
|
|
|
it('updates share icon after updating shares of a file', function() {
|
2014-06-02 15:23:52 +00:00
|
|
|
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,
|
2014-06-03 09:04:57 +00:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2014-06-02 15:23:52 +00:00
|
|
|
etag: 'abc'
|
|
|
|
}]);
|
|
|
|
$action = fileList.$el.find('tbody tr:first .action-share');
|
|
|
|
$tr = fileList.$el.find('tr:first');
|
|
|
|
|
|
|
|
expect($action.hasClass('permanent')).toEqual(true);
|
|
|
|
|
|
|
|
$tr.find('.action-share').click();
|
|
|
|
|
|
|
|
expect(showDropDownStub.calledOnce).toEqual(true);
|
|
|
|
|
|
|
|
// simulate what the dropdown does
|
2014-06-04 08:37:04 +00:00
|
|
|
var shares = {};
|
|
|
|
OC.Share.itemShares[OC.Share.SHARE_TYPE_USER] = ['user1', 'user2', 'user3'];
|
|
|
|
shares[OC.Share.SHARE_TYPE_USER] = _.map(['User One', 'User Two', 'User Three'], makeDummyShareItem);
|
|
|
|
$('#dropdown').trigger(new $.Event('sharesChanged', {shares: shares}));
|
2014-06-02 15:23:52 +00:00
|
|
|
|
|
|
|
expect($tr.attr('data-share-recipients')).toEqual('User One, User Three, User Two');
|
|
|
|
|
|
|
|
OC.Share.updateIcon('file', 1);
|
|
|
|
|
|
|
|
expect($action.hasClass('permanent')).toEqual(true);
|
2015-08-26 09:39:22 +00:00
|
|
|
expect($action.find('>span').text().trim()).toEqual('Shared with User One, User Three, User Two');
|
2014-06-02 15:23:52 +00:00
|
|
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
|
|
|
});
|
2014-06-04 08:37:04 +00:00
|
|
|
it('removes share icon after removing all shares from a file', function() {
|
2014-06-02 15:23:52 +00:00
|
|
|
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,
|
2014-06-03 09:04:57 +00:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2014-06-02 15:23:52 +00:00
|
|
|
etag: 'abc',
|
|
|
|
recipients: 'User One, User Two'
|
|
|
|
}]);
|
|
|
|
$action = fileList.$el.find('tbody tr:first .action-share');
|
|
|
|
$tr = fileList.$el.find('tr:first');
|
|
|
|
|
|
|
|
expect($action.hasClass('permanent')).toEqual(true);
|
|
|
|
|
|
|
|
$tr.find('.action-share').click();
|
|
|
|
|
|
|
|
expect(showDropDownStub.calledOnce).toEqual(true);
|
|
|
|
|
|
|
|
// simulate what the dropdown does
|
2014-06-04 08:37:04 +00:00
|
|
|
OC.Share.itemShares = {};
|
|
|
|
$('#dropdown').trigger(new $.Event('sharesChanged', {shares: {}}));
|
2014-06-02 15:23:52 +00:00
|
|
|
|
|
|
|
expect($tr.attr('data-share-recipients')).not.toBeDefined();
|
|
|
|
|
|
|
|
OC.Share.updateIcon('file', 1);
|
2015-08-10 13:57:21 +00:00
|
|
|
expect($action.hasClass('permanent')).toEqual(true);
|
2014-06-02 13:59:06 +00:00
|
|
|
});
|
2014-06-03 09:04:57 +00:00
|
|
|
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'
|
|
|
|
}]);
|
|
|
|
$action = fileList.$el.find('tbody tr:first .action-share');
|
|
|
|
$tr = fileList.$el.find('tr:first');
|
|
|
|
|
|
|
|
expect($action.hasClass('permanent')).toEqual(true);
|
|
|
|
|
|
|
|
$tr.find('.action-share').click();
|
|
|
|
|
|
|
|
expect(showDropDownStub.calledOnce).toEqual(true);
|
|
|
|
|
|
|
|
// simulate what the dropdown does
|
2014-06-04 08:37:04 +00:00
|
|
|
var shares = {};
|
|
|
|
OC.Share.itemShares[OC.Share.SHARE_TYPE_USER] = ['user2'];
|
|
|
|
shares[OC.Share.SHARE_TYPE_USER] = _.map(['User Two'], makeDummyShareItem);
|
|
|
|
$('#dropdown').trigger(new $.Event('sharesChanged', {shares: shares}));
|
2014-06-03 09:04:57 +00:00
|
|
|
|
|
|
|
expect($tr.attr('data-share-recipients')).toEqual('User Two');
|
|
|
|
|
|
|
|
OC.Share.updateIcon('file', 1);
|
|
|
|
|
|
|
|
expect($action.hasClass('permanent')).toEqual(true);
|
2015-08-26 09:39:22 +00:00
|
|
|
expect($action.find('>span').text().trim()).toEqual('User One');
|
2014-06-03 09:04:57 +00:00
|
|
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
|
|
|
});
|
|
|
|
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',
|
|
|
|
recipients: 'User Two'
|
|
|
|
}]);
|
|
|
|
$action = fileList.$el.find('tbody tr:first .action-share');
|
|
|
|
$tr = fileList.$el.find('tr:first');
|
|
|
|
|
|
|
|
expect($action.hasClass('permanent')).toEqual(true);
|
|
|
|
|
|
|
|
$tr.find('.action-share').click();
|
|
|
|
|
|
|
|
expect(showDropDownStub.calledOnce).toEqual(true);
|
|
|
|
|
|
|
|
// simulate what the dropdown does
|
2014-06-04 08:37:04 +00:00
|
|
|
OC.Share.itemShares = {};
|
|
|
|
$('#dropdown').trigger(new $.Event('sharesChanged', {shares: {}}));
|
2014-06-03 09:04:57 +00:00
|
|
|
|
|
|
|
expect($tr.attr('data-share-recipients')).not.toBeDefined();
|
|
|
|
|
|
|
|
OC.Share.updateIcon('file', 1);
|
|
|
|
|
|
|
|
expect($action.hasClass('permanent')).toEqual(true);
|
2015-08-26 09:39:22 +00:00
|
|
|
expect($action.find('>span').text().trim()).toEqual('User One');
|
2014-06-03 09:04:57 +00:00
|
|
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
|
|
|
});
|
2014-06-02 13:59:06 +00:00
|
|
|
});
|
|
|
|
describe('formatRecipients', function() {
|
|
|
|
it('returns a single recipient when one passed', function() {
|
|
|
|
expect(OCA.Sharing.Util.formatRecipients(['User one']))
|
|
|
|
.toEqual('User one');
|
|
|
|
});
|
|
|
|
it('returns two recipients when two passed', function() {
|
|
|
|
expect(OCA.Sharing.Util.formatRecipients(['User one', 'User two']))
|
|
|
|
.toEqual('User one, User two');
|
|
|
|
});
|
|
|
|
it('returns four recipients with plus when five passed', function() {
|
|
|
|
var recipients = [
|
|
|
|
'User one',
|
|
|
|
'User two',
|
|
|
|
'User three',
|
|
|
|
'User four',
|
|
|
|
'User five'
|
|
|
|
];
|
|
|
|
expect(OCA.Sharing.Util.formatRecipients(recipients))
|
|
|
|
.toEqual('User four, User one, User three, User two, +1');
|
|
|
|
});
|
|
|
|
it('returns four recipients with plus when ten passed', function() {
|
|
|
|
var recipients = [
|
|
|
|
'User one',
|
|
|
|
'User two',
|
|
|
|
'User three',
|
|
|
|
'User four',
|
|
|
|
'User five',
|
|
|
|
'User six',
|
|
|
|
'User seven',
|
|
|
|
'User eight',
|
|
|
|
'User nine',
|
|
|
|
'User ten'
|
|
|
|
];
|
|
|
|
expect(OCA.Sharing.Util.formatRecipients(recipients))
|
|
|
|
.toEqual('User four, User one, User three, User two, +6');
|
|
|
|
});
|
|
|
|
it('returns four recipients with plus when four passed with counter', function() {
|
|
|
|
var recipients = [
|
|
|
|
'User one',
|
|
|
|
'User two',
|
|
|
|
'User three',
|
|
|
|
'User four'
|
|
|
|
];
|
|
|
|
expect(OCA.Sharing.Util.formatRecipients(recipients, 10))
|
|
|
|
.toEqual('User four, User one, User three, User two, +6');
|
|
|
|
});
|
|
|
|
});
|
2015-01-26 16:06:07 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2014-06-02 13:59:06 +00:00
|
|
|
|
|
|
|
});
|