2014-06-02 17:59:06 +04: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 19:23:52 +04: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 17:59:06 +04:00
|
|
|
beforeEach(function() {
|
|
|
|
var $content = $('<div id="content"></div>');
|
|
|
|
$('#testArea').append($content);
|
|
|
|
// dummy file list
|
|
|
|
var $div = $(
|
2015-01-26 19:06:07 +03:00
|
|
|
'<div id="listContainer">' +
|
2018-10-03 22:42:24 +03:00
|
|
|
'<table id="filestable" class="list-container view-grid">' +
|
2014-06-02 17:59:06 +04:00
|
|
|
'<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 18:17:28 +03:00
|
|
|
OCA.Sharing.Util.attach(fileList);
|
2014-06-02 17:59:06 +04:00
|
|
|
|
|
|
|
testFiles = [{
|
|
|
|
id: 1,
|
|
|
|
type: 'file',
|
|
|
|
name: 'One.txt',
|
|
|
|
path: '/subdir',
|
|
|
|
mimetype: 'text/plain',
|
|
|
|
size: 12,
|
2014-06-03 13:04:57 +04:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2014-06-02 17:59:06 +04:00
|
|
|
etag: 'abc',
|
|
|
|
shareOwner: 'User One',
|
2016-03-02 20:25:31 +03:00
|
|
|
isShareMountPoint: false,
|
|
|
|
shareTypes: [OC.Share.SHARE_TYPE_USER]
|
2014-06-02 17:59:06 +04:00
|
|
|
}];
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
delete OCA.Sharing.sharesLoaded;
|
2014-06-02 19:23:52 +04:00
|
|
|
delete OC.Share.droppedDown;
|
2014-06-27 15:36:18 +04:00
|
|
|
fileList.destroy();
|
|
|
|
fileList = null;
|
2014-06-02 17:59:06 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
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() {
|
2014-06-02 19:23:52 +04:00
|
|
|
var $action, $tr;
|
2014-06-02 17:59:06 +04:00
|
|
|
OC.Share.statuses = {};
|
|
|
|
fileList.setFiles([{
|
|
|
|
id: 1,
|
2014-06-02 19:23:52 +04:00
|
|
|
type: 'dir',
|
|
|
|
name: 'One',
|
2014-06-02 17:59:06 +04:00
|
|
|
path: '/subdir',
|
2015-07-09 19:42:46 +03:00
|
|
|
mimetype: 'httpd/unix-directory',
|
2014-06-02 17:59:06 +04:00
|
|
|
size: 12,
|
2014-06-03 13:04:57 +04:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2016-03-02 20:25:31 +03:00
|
|
|
etag: 'abc',
|
|
|
|
shareTypes: []
|
2014-06-02 17:59:06 +04:00
|
|
|
}]);
|
2014-06-02 19:23:52 +04:00
|
|
|
$tr = fileList.$el.find('tbody tr:first');
|
|
|
|
$action = $tr.find('.action-share');
|
2017-04-12 16:04:12 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
|
2016-02-17 13:04:29 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
|
2014-12-11 19:36:14 +03:00
|
|
|
expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder.svg');
|
2014-06-02 17:59:06 +04:00
|
|
|
});
|
|
|
|
it('shows simple share text with share icon', function() {
|
2014-06-02 19:23:52 +04:00
|
|
|
var $action, $tr;
|
2014-06-02 17:59:06 +04:00
|
|
|
fileList.setFiles([{
|
|
|
|
id: 1,
|
2014-06-02 19:23:52 +04:00
|
|
|
type: 'dir',
|
|
|
|
name: 'One',
|
2014-06-02 17:59:06 +04:00
|
|
|
path: '/subdir',
|
|
|
|
mimetype: 'text/plain',
|
|
|
|
size: 12,
|
2014-06-03 13:04:57 +04:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2016-03-02 20:25:31 +03:00
|
|
|
etag: 'abc',
|
|
|
|
shareTypes: [OC.Share.SHARE_TYPE_USER]
|
2014-06-02 17:59:06 +04:00
|
|
|
}]);
|
2014-06-02 19:23:52 +04:00
|
|
|
$tr = fileList.$el.find('tbody tr:first');
|
|
|
|
$action = $tr.find('.action-share');
|
2018-06-30 14:45:23 +03:00
|
|
|
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');
|
2015-08-26 12:39:22 +03:00
|
|
|
expect($action.find('>span').text().trim()).toEqual('Shared');
|
2017-04-12 16:04:12 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
|
2016-02-17 13:04:29 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
|
2014-12-11 19:36:14 +03:00
|
|
|
expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg');
|
2014-06-02 17:59:06 +04:00
|
|
|
});
|
|
|
|
it('shows simple share text with public icon when shared with link', function() {
|
2014-06-02 19:23:52 +04:00
|
|
|
var $action, $tr;
|
2014-06-02 17:59:06 +04:00
|
|
|
OC.Share.statuses = {1: {link: true, path: '/subdir'}};
|
|
|
|
fileList.setFiles([{
|
|
|
|
id: 1,
|
2014-06-02 19:23:52 +04:00
|
|
|
type: 'dir',
|
|
|
|
name: 'One',
|
2014-06-02 17:59:06 +04:00
|
|
|
path: '/subdir',
|
|
|
|
mimetype: 'text/plain',
|
|
|
|
size: 12,
|
2014-06-03 13:04:57 +04:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2016-03-02 20:25:31 +03:00
|
|
|
etag: 'abc',
|
|
|
|
shareTypes: [OC.Share.SHARE_TYPE_LINK]
|
2014-06-02 17:59:06 +04:00
|
|
|
}]);
|
2014-06-02 19:23:52 +04:00
|
|
|
$tr = fileList.$el.find('tbody tr:first');
|
|
|
|
$action = $tr.find('.action-share');
|
2015-08-26 12:39:22 +03:00
|
|
|
expect($action.find('>span').text().trim()).toEqual('Shared');
|
2017-04-12 16:04:12 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-shared')).toEqual(false);
|
2016-02-17 13:04:29 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-public')).toEqual(true);
|
2014-12-11 19:36:14 +03:00
|
|
|
expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-public.svg');
|
2014-06-02 17:59:06 +04:00
|
|
|
});
|
|
|
|
it('shows owner name when owner is available', function() {
|
2014-06-02 19:23:52 +04:00
|
|
|
var $action, $tr;
|
2014-06-02 17:59:06 +04:00
|
|
|
fileList.setFiles([{
|
|
|
|
id: 1,
|
2014-06-02 19:23:52 +04:00
|
|
|
type: 'dir',
|
2014-06-02 17:59:06 +04:00
|
|
|
name: 'One.txt',
|
|
|
|
path: '/subdir',
|
|
|
|
mimetype: 'text/plain',
|
|
|
|
size: 12,
|
2014-06-03 13:04:57 +04:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2014-06-02 17:59:06 +04:00
|
|
|
shareOwner: 'User One',
|
2017-11-21 13:29:42 +03:00
|
|
|
shareOwnerId: 'User One',
|
2016-03-02 20:25:31 +03:00
|
|
|
etag: 'abc',
|
2016-03-30 19:09:02 +03:00
|
|
|
shareTypes: []
|
2014-06-02 17:59:06 +04:00
|
|
|
}]);
|
2014-06-02 19:23:52 +04:00
|
|
|
$tr = fileList.$el.find('tbody tr:first');
|
|
|
|
$action = $tr.find('.action-share');
|
2017-11-02 15:51:08 +03:00
|
|
|
expect($action.find('>span').text().trim()).toEqual('Shared by User One');
|
2017-04-12 16:04:12 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
|
2016-02-17 13:04:29 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
|
2014-12-11 19:36:14 +03:00
|
|
|
expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg');
|
2014-06-02 17:59:06 +04:00
|
|
|
});
|
|
|
|
it('shows recipients when recipients are available', function() {
|
2014-06-02 19:23:52 +04:00
|
|
|
var $action, $tr;
|
2014-06-02 17:59:06 +04:00
|
|
|
fileList.setFiles([{
|
|
|
|
id: 1,
|
2014-06-02 19:23:52 +04:00
|
|
|
type: 'dir',
|
2014-06-02 17:59:06 +04:00
|
|
|
name: 'One.txt',
|
|
|
|
path: '/subdir',
|
|
|
|
mimetype: 'text/plain',
|
|
|
|
size: 12,
|
2014-06-03 13:04:57 +04:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2014-06-02 17:59:06 +04:00
|
|
|
recipientsDisplayName: 'User One, User Two',
|
2017-11-21 13:29:42 +03:00
|
|
|
recipientData: {
|
|
|
|
0: {
|
|
|
|
shareWith: 'User One',
|
|
|
|
shareWithDisplayName: 'User One'
|
|
|
|
},
|
|
|
|
1: {
|
|
|
|
shareWith: 'User Two',
|
|
|
|
shareWithDisplayName: 'User Two'
|
|
|
|
}
|
|
|
|
},
|
2016-03-02 20:25:31 +03:00
|
|
|
etag: 'abc',
|
|
|
|
shareTypes: [OC.Share.SHARE_TYPE_USER]
|
2014-06-02 17:59:06 +04:00
|
|
|
}]);
|
2014-06-02 19:23:52 +04:00
|
|
|
$tr = fileList.$el.find('tbody tr:first');
|
|
|
|
$action = $tr.find('.action-share');
|
2017-11-02 15:51:08 +03:00
|
|
|
expect($action.text().trim()).toEqual('Shared with User One Shared with User Two');
|
2017-04-12 16:04:12 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
|
2016-02-17 13:04:29 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
|
2014-12-11 19:36:14 +03:00
|
|
|
expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg');
|
2014-06-02 17:59:06 +04:00
|
|
|
});
|
2015-09-28 17:23:33 +03:00
|
|
|
it('shows share action when shared with user who has no share permission', function() {
|
2014-06-03 13:04:57 +04:00
|
|
|
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');
|
2015-09-28 17:23:33 +03:00
|
|
|
expect($tr.find('.action-share').length).toEqual(1);
|
2014-06-03 13:04:57 +04:00
|
|
|
});
|
2015-09-28 17:23:33 +03:00
|
|
|
it('do not show share action when share exists but neither permission nor owner is available', function() {
|
2015-07-02 17:38:20 +03:00
|
|
|
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);
|
|
|
|
});
|
2014-06-02 17:59:06 +04:00
|
|
|
});
|
|
|
|
describe('Share action', function() {
|
2015-09-15 11:27:33 +03:00
|
|
|
var shareTab;
|
2014-06-02 19:23:52 +04:00
|
|
|
|
2014-06-04 12:37:04 +04:00
|
|
|
function makeDummyShareItem(displayName) {
|
|
|
|
return {
|
|
|
|
share_with_displayname: displayName
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-06-02 19:23:52 +04:00
|
|
|
beforeEach(function() {
|
2015-09-15 11:27:33 +03:00
|
|
|
// make it look like not the "All files" list
|
|
|
|
fileList.id = 'test';
|
|
|
|
shareTab = fileList._detailsView._tabViews[0];
|
2014-06-02 19:23:52 +04:00
|
|
|
});
|
|
|
|
afterEach(function() {
|
2015-09-15 11:27:33 +03:00
|
|
|
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();
|
2014-06-02 19:23:52 +04:00
|
|
|
});
|
|
|
|
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 13:04:57 +04:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2014-06-02 19:23:52 +04:00
|
|
|
etag: 'abc'
|
|
|
|
}]);
|
|
|
|
$action = fileList.$el.find('tbody tr:first .action-share');
|
|
|
|
$tr = fileList.$el.find('tr:first');
|
|
|
|
|
|
|
|
$tr.find('.action-share').click();
|
|
|
|
|
2015-09-15 11:27:33 +03:00
|
|
|
// simulate updating shares
|
|
|
|
shareTab._dialog.model.set({
|
|
|
|
shares: [
|
2017-11-21 13:29:42 +03:00
|
|
|
{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'}
|
2015-09-15 11:27:33 +03:00
|
|
|
]
|
|
|
|
});
|
2014-06-02 19:23:52 +04:00
|
|
|
|
2017-11-02 15:51:08 +03:00
|
|
|
expect($action.text().trim()).toEqual('Shared with Group One Shared with Group Two Shared with User One Shared with User Two');
|
2017-04-12 16:04:12 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
|
2016-02-17 13:04:29 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
|
2014-06-02 19:23:52 +04:00
|
|
|
});
|
2014-06-04 12:37:04 +04:00
|
|
|
it('updates share icon after updating shares of a file', function() {
|
2014-06-02 19:23:52 +04: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 13:04:57 +04:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2014-06-02 19:23:52 +04:00
|
|
|
etag: 'abc'
|
|
|
|
}]);
|
|
|
|
$action = fileList.$el.find('tbody tr:first .action-share');
|
|
|
|
$tr = fileList.$el.find('tr:first');
|
|
|
|
|
|
|
|
$tr.find('.action-share').click();
|
|
|
|
|
2015-09-15 11:27:33 +03:00
|
|
|
// simulate updating shares
|
|
|
|
shareTab._dialog.model.set({
|
|
|
|
shares: [
|
2017-11-21 13:29:42 +03:00
|
|
|
{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'}
|
2015-09-15 11:27:33 +03:00
|
|
|
]
|
|
|
|
});
|
2014-06-02 19:23:52 +04:00
|
|
|
|
2017-11-02 15:51:08 +03:00
|
|
|
expect($action.text().trim()).toEqual('Shared with User One Shared with User Three Shared with User Two');
|
2017-04-12 16:04:12 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
|
2016-02-17 13:04:29 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
|
2014-06-02 19:23:52 +04:00
|
|
|
});
|
2014-06-04 12:37:04 +04:00
|
|
|
it('removes share icon after removing all shares from a file', function() {
|
2014-06-02 19:23:52 +04: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 13:04:57 +04:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2014-06-02 19:23:52 +04:00
|
|
|
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();
|
|
|
|
|
2015-09-15 11:27:33 +03:00
|
|
|
// simulate updating shares
|
|
|
|
shareTab._dialog.model.set({
|
|
|
|
shares: []
|
|
|
|
});
|
2014-06-02 19:23:52 +04:00
|
|
|
|
2017-11-21 14:45:57 +03:00
|
|
|
expect($tr.attr('data-share-recipient-data')).not.toBeDefined();
|
2014-06-02 17:59:06 +04:00
|
|
|
});
|
2014-06-03 13:04:57 +04: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',
|
2017-11-21 13:29:42 +03:00
|
|
|
shareOwner: 'User One',
|
|
|
|
shareOwnerId: 'User One'
|
2014-06-03 13:04:57 +04:00
|
|
|
}]);
|
|
|
|
$action = fileList.$el.find('tbody tr:first .action-share');
|
|
|
|
$tr = fileList.$el.find('tr:first');
|
|
|
|
|
|
|
|
$tr.find('.action-share').click();
|
|
|
|
|
2015-09-15 11:27:33 +03:00
|
|
|
// simulate updating shares
|
|
|
|
shareTab._dialog.model.set({
|
|
|
|
shares: [{share_with_displayname: 'User Two'}]
|
|
|
|
});
|
2014-06-03 13:04:57 +04:00
|
|
|
|
2017-11-02 15:51:08 +03:00
|
|
|
expect($action.find('>span').text().trim()).toEqual('Shared by User One');
|
2017-04-12 16:04:12 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
|
2016-02-17 13:04:29 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
|
2014-06-03 13:04:57 +04:00
|
|
|
});
|
|
|
|
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',
|
2017-11-21 13:29:42 +03:00
|
|
|
shareOwnerId: 'User One',
|
|
|
|
recipients: 'User Two',
|
|
|
|
recipientData: {'User Two': 'User Two'}
|
2014-06-03 13:04:57 +04:00
|
|
|
}]);
|
|
|
|
$action = fileList.$el.find('tbody tr:first .action-share');
|
|
|
|
$tr = fileList.$el.find('tr:first');
|
|
|
|
|
|
|
|
$tr.find('.action-share').click();
|
|
|
|
|
2015-09-15 11:27:33 +03:00
|
|
|
// simulate updating shares
|
|
|
|
shareTab._dialog.model.set({
|
|
|
|
shares: []
|
|
|
|
});
|
2014-06-03 13:04:57 +04:00
|
|
|
|
2017-11-21 14:45:57 +03:00
|
|
|
expect($tr.attr('data-share-recipient-data')).not.toBeDefined();
|
2014-06-03 13:04:57 +04:00
|
|
|
|
2017-11-02 15:51:08 +03:00
|
|
|
expect($action.find('>span').text().trim()).toEqual('Shared by User One');
|
2017-04-12 16:04:12 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
|
2016-02-17 13:04:29 +03:00
|
|
|
expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
|
2014-06-03 13:04:57 +04:00
|
|
|
});
|
2014-06-02 17:59:06 +04:00
|
|
|
});
|
2015-01-26 19:06:07 +03: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);
|
|
|
|
});
|
|
|
|
});
|
2017-04-12 16:04:12 +03:00
|
|
|
|
2016-08-17 13:25:58 +03:00
|
|
|
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);
|
|
|
|
});
|
2018-10-03 22:42:24 +03:00
|
|
|
afterEach(function() {
|
|
|
|
shareTabSpy.restore();
|
2016-08-17 13:25:58 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('updates fileInfoModel when shares changed', function() {
|
|
|
|
var changeHandler = sinon.stub();
|
|
|
|
fileInfoModel.on('change', changeHandler);
|
|
|
|
|
Fix constructor spy in unit test with Sinon 4.1.3
When a constructor is spied using Sinon it is wrapped by a proxy
function, which calls the original constructor when invoked. When "new
Foo()" is executed a "Foo" object is created, "Foo" is invoked with the
object as "this", and the object is returned as the result of the whole
"new" expression.
Before Sinon 4.1.3 the proxy called the original constructor directly
using the "thisValue" of the spied call; "thisValue" was the object
created by the "new" operator that called the proxy. The proxy assigned
"thisValue" to "returnValue", so it was also the value returned by the
proxy and, in turn, the value returned by the whole "new" expression.
Since Sinon 4.1.3 (see pull request 1626) the proxy calls the original
constructor using "new" instead of directly. The "thisValue" created by
the outermost "new" (the one that called the proxy) is no longer used by
the original constructor; the internal "new" creates a new object, which
is the one passed to the original constructor and returned by the
internal "new" expression. This object is also the value returned by the
proxy ("returnValue") and, in turn, the value returned by the whole
outermost "new" expression.
Thus, now "returnValue" should be used instead of "thisValue" to get the
object created by the spied constructor.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2017-12-08 20:55:38 +03:00
|
|
|
shareTabSpy.getCall(0).returnValue.trigger('sharesChanged', shareModel);
|
2016-08-17 13:25:58 +03:00
|
|
|
|
|
|
|
expect(changeHandler.calledOnce).toEqual(true);
|
|
|
|
expect(changeHandler.getCall(0).args[0].changed).toEqual({
|
|
|
|
shareTypes: [
|
|
|
|
OC.Share.SHARE_TYPE_USER,
|
|
|
|
OC.Share.SHARE_TYPE_REMOTE
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-06-02 17:59:06 +04:00
|
|
|
});
|