2015-09-15 11:27:33 +03:00
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
|
|
|
* @author Vincent Petry
|
|
|
|
* @copyright 2015 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-04-24 11:39:37 +03:00
|
|
|
/* global oc_appconfig, sinon */
|
2015-09-15 11:27:33 +03:00
|
|
|
describe('OC.Share.ShareDialogView', function() {
|
|
|
|
var $container;
|
|
|
|
var oldAppConfig;
|
|
|
|
var autocompleteStub;
|
|
|
|
var avatarStub;
|
|
|
|
var placeholderStub;
|
|
|
|
var oldCurrentUser;
|
2016-01-22 19:30:18 +03:00
|
|
|
var saveLinkShareStub;
|
2015-09-15 11:27:33 +03:00
|
|
|
|
|
|
|
var fetchStub;
|
2016-01-22 19:30:18 +03:00
|
|
|
var notificationStub;
|
2015-09-15 11:27:33 +03:00
|
|
|
|
|
|
|
var configModel;
|
|
|
|
var shareModel;
|
|
|
|
var fileInfoModel;
|
|
|
|
var dialog;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
// horrible parameters
|
|
|
|
$('#testArea').append('<input id="allowShareWithLink" type="hidden" value="yes">');
|
|
|
|
$container = $('#shareContainer');
|
|
|
|
/* jshint camelcase:false */
|
|
|
|
oldAppConfig = _.extend({}, oc_appconfig.core);
|
|
|
|
oc_appconfig.core.enforcePasswordForPublicLink = false;
|
|
|
|
|
|
|
|
fetchStub = sinon.stub(OC.Share.ShareItemModel.prototype, 'fetch');
|
2016-01-22 19:30:18 +03:00
|
|
|
saveLinkShareStub = sinon.stub(OC.Share.ShareItemModel.prototype, 'saveLinkShare');
|
2015-09-15 11:27:33 +03:00
|
|
|
|
|
|
|
fileInfoModel = new OCA.Files.FileInfoModel({
|
|
|
|
id: 123,
|
|
|
|
name: 'shared_file_name.txt',
|
|
|
|
path: '/subdir',
|
|
|
|
size: 100,
|
|
|
|
mimetype: 'text/plain',
|
|
|
|
permissions: 31,
|
|
|
|
sharePermissions: 31
|
|
|
|
});
|
|
|
|
|
|
|
|
var attributes = {
|
|
|
|
itemType: fileInfoModel.isDirectory() ? 'folder' : 'file',
|
|
|
|
itemSource: fileInfoModel.get('id'),
|
|
|
|
possiblePermissions: 31,
|
|
|
|
permissions: 31
|
|
|
|
};
|
2015-09-15 16:29:30 +03:00
|
|
|
configModel = new OC.Share.ShareConfigModel({
|
|
|
|
enforcePasswordForPublicLink: false,
|
|
|
|
isResharingAllowed: true,
|
|
|
|
isDefaultExpireDateEnabled: false,
|
|
|
|
isDefaultExpireDateEnforced: false,
|
|
|
|
defaultExpireDate: 7
|
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
shareModel = new OC.Share.ShareItemModel(attributes, {
|
|
|
|
configModel: configModel,
|
|
|
|
fileInfoModel: fileInfoModel
|
|
|
|
});
|
|
|
|
dialog = new OC.Share.ShareDialogView({
|
|
|
|
configModel: configModel,
|
|
|
|
model: shareModel
|
|
|
|
});
|
|
|
|
|
2015-10-16 11:54:45 +03:00
|
|
|
// required for proper event propagation when simulating clicks in some cases (jquery bugs)
|
|
|
|
$('#testArea').append(dialog.$el);
|
|
|
|
|
2015-09-15 11:27:33 +03:00
|
|
|
// triggers rendering
|
|
|
|
shareModel.set({
|
|
|
|
shares: [],
|
|
|
|
linkShare: {isLinkShare: false}
|
|
|
|
});
|
|
|
|
|
2017-04-24 11:39:37 +03:00
|
|
|
autocompleteStub = sinon.stub($.fn, 'autocomplete').callsFake(function() {
|
2015-09-15 11:27:33 +03:00
|
|
|
// dummy container with the expected attributes
|
|
|
|
if (!$(this).length) {
|
|
|
|
// simulate the real autocomplete that returns
|
|
|
|
// nothing at all when no element is specified
|
|
|
|
// (and potentially break stuff)
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
var $el = $('<div></div>').data('ui-autocomplete', {});
|
|
|
|
return $el;
|
|
|
|
});
|
|
|
|
|
|
|
|
avatarStub = sinon.stub($.fn, 'avatar');
|
|
|
|
placeholderStub = sinon.stub($.fn, 'imageplaceholder');
|
|
|
|
|
|
|
|
oldCurrentUser = OC.currentUser;
|
|
|
|
OC.currentUser = 'user0';
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
OC.currentUser = oldCurrentUser;
|
|
|
|
/* jshint camelcase:false */
|
|
|
|
oc_appconfig.core = oldAppConfig;
|
|
|
|
|
2015-10-16 11:54:45 +03:00
|
|
|
dialog.remove();
|
2015-09-15 11:27:33 +03:00
|
|
|
fetchStub.restore();
|
2016-01-22 19:30:18 +03:00
|
|
|
saveLinkShareStub.restore();
|
2015-09-15 11:27:33 +03:00
|
|
|
|
|
|
|
autocompleteStub.restore();
|
|
|
|
avatarStub.restore();
|
|
|
|
placeholderStub.restore();
|
|
|
|
});
|
|
|
|
describe('Share with link', function() {
|
|
|
|
// TODO: test ajax calls
|
|
|
|
// TODO: test password field visibility (whenever enforced or not)
|
|
|
|
it('update password on focus out', function() {
|
|
|
|
$('#allowShareWithLink').val('yes');
|
|
|
|
|
2016-01-22 19:30:18 +03:00
|
|
|
dialog.model.set('linkShare', {
|
|
|
|
isLinkShare: true
|
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
dialog.render();
|
|
|
|
|
|
|
|
// Enable password, enter password and focusout
|
|
|
|
dialog.$el.find('[name=showPassword]').click();
|
2015-10-16 11:54:45 +03:00
|
|
|
dialog.$el.find('.linkPassText').focus();
|
|
|
|
dialog.$el.find('.linkPassText').val('foo');
|
|
|
|
dialog.$el.find('.linkPassText').focusout();
|
2015-09-15 11:27:33 +03:00
|
|
|
|
2016-01-22 19:30:18 +03:00
|
|
|
expect(saveLinkShareStub.calledOnce).toEqual(true);
|
|
|
|
expect(saveLinkShareStub.firstCall.args[0]).toEqual({
|
|
|
|
password: 'foo'
|
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
|
|
|
it('update password on enter', function() {
|
|
|
|
$('#allowShareWithLink').val('yes');
|
|
|
|
|
2016-01-22 19:30:18 +03:00
|
|
|
dialog.model.set('linkShare', {
|
|
|
|
isLinkShare: true
|
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
dialog.render();
|
|
|
|
|
|
|
|
// Toggle linkshare
|
2015-10-16 11:54:45 +03:00
|
|
|
dialog.$el.find('.linkCheckbox').click();
|
2015-09-15 11:27:33 +03:00
|
|
|
|
|
|
|
// Enable password and enter password
|
|
|
|
dialog.$el.find('[name=showPassword]').click();
|
2015-10-16 11:54:45 +03:00
|
|
|
dialog.$el.find('.linkPassText').focus();
|
|
|
|
dialog.$el.find('.linkPassText').val('foo');
|
|
|
|
dialog.$el.find('.linkPassText').trigger(new $.Event('keyup', {keyCode: 13}));
|
2015-09-15 11:27:33 +03:00
|
|
|
|
2016-01-22 19:30:18 +03:00
|
|
|
expect(saveLinkShareStub.calledOnce).toEqual(true);
|
|
|
|
expect(saveLinkShareStub.firstCall.args[0]).toEqual({
|
|
|
|
password: 'foo'
|
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
|
|
|
it('shows share with link checkbox when allowed', function() {
|
|
|
|
$('#allowShareWithLink').val('yes');
|
|
|
|
|
|
|
|
dialog.render();
|
|
|
|
|
2015-10-16 11:54:45 +03:00
|
|
|
expect(dialog.$el.find('.linkCheckbox').length).toEqual(1);
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
|
|
|
it('does not show share with link checkbox when not allowed', function() {
|
|
|
|
$('#allowShareWithLink').val('no');
|
|
|
|
|
|
|
|
dialog.render();
|
|
|
|
|
2015-10-16 11:54:45 +03:00
|
|
|
expect(dialog.$el.find('.linkCheckbox').length).toEqual(0);
|
2015-12-07 18:53:56 +03:00
|
|
|
expect(dialog.$el.find('.shareWithField').length).toEqual(1);
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
|
|
|
it('shows populated link share when a link share exists', function() {
|
2015-09-15 16:29:30 +03:00
|
|
|
// this is how the OC.Share class does it...
|
|
|
|
var link = parent.location.protocol + '//' + location.host +
|
|
|
|
OC.generateUrl('/s/') + 'tehtoken';
|
2015-09-15 11:27:33 +03:00
|
|
|
shareModel.set('linkShare', {
|
|
|
|
isLinkShare: true,
|
|
|
|
token: 'tehtoken',
|
2015-09-15 16:29:30 +03:00
|
|
|
link: link,
|
2015-09-15 11:27:33 +03:00
|
|
|
expiration: '',
|
|
|
|
permissions: OC.PERMISSION_READ,
|
|
|
|
stime: 1403884258,
|
|
|
|
});
|
|
|
|
|
2015-09-15 16:29:30 +03:00
|
|
|
dialog.render();
|
|
|
|
|
2015-10-16 11:54:45 +03:00
|
|
|
expect(dialog.$el.find('.linkCheckbox').prop('checked')).toEqual(true);
|
|
|
|
expect(dialog.$el.find('.linkText').val()).toEqual(link);
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
2015-10-26 14:49:52 +03:00
|
|
|
it('autofocus link text when clicked', function() {
|
|
|
|
$('#allowShareWithLink').val('yes');
|
|
|
|
|
2016-01-22 19:30:18 +03:00
|
|
|
dialog.model.set('linkShare', {
|
|
|
|
isLinkShare: true
|
|
|
|
});
|
2015-10-26 14:49:52 +03:00
|
|
|
dialog.render();
|
|
|
|
|
|
|
|
var focusStub = sinon.stub($.fn, 'focus');
|
|
|
|
var selectStub = sinon.stub($.fn, 'select');
|
|
|
|
dialog.$el.find('.linkText').click();
|
|
|
|
|
|
|
|
expect(focusStub.calledOnce).toEqual(true);
|
|
|
|
expect(selectStub.calledOnce).toEqual(true);
|
|
|
|
|
|
|
|
focusStub.restore();
|
|
|
|
selectStub.restore();
|
|
|
|
});
|
2015-10-04 11:28:58 +03:00
|
|
|
describe('password', function() {
|
|
|
|
var slideToggleStub;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
$('#allowShareWithLink').val('yes');
|
|
|
|
configModel.set({
|
|
|
|
enforcePasswordForPublicLink: false
|
|
|
|
});
|
|
|
|
|
|
|
|
slideToggleStub = sinon.stub($.fn, 'slideToggle');
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
slideToggleStub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('enforced but toggled does not fire request', function() {
|
|
|
|
configModel.set('enforcePasswordForPublicLink', true);
|
|
|
|
dialog.render();
|
|
|
|
|
2015-10-16 11:54:45 +03:00
|
|
|
dialog.$el.find('.linkCheckbox').click();
|
2015-10-04 11:28:58 +03:00
|
|
|
|
|
|
|
// The password linkPass field is shown (slideToggle is called).
|
|
|
|
// No request is made yet
|
|
|
|
expect(slideToggleStub.callCount).toEqual(1);
|
|
|
|
expect(slideToggleStub.getCall(0).thisValue.eq(0).attr('id')).toEqual('linkPass');
|
|
|
|
expect(fakeServer.requests.length).toEqual(0);
|
2016-11-02 13:37:25 +03:00
|
|
|
|
2015-10-04 11:28:58 +03:00
|
|
|
// Now untoggle share by link
|
2015-10-16 11:54:45 +03:00
|
|
|
dialog.$el.find('.linkCheckbox').click();
|
2015-10-04 11:28:58 +03:00
|
|
|
dialog.render();
|
|
|
|
|
|
|
|
// Password field disappears and no ajax requests have been made
|
|
|
|
expect(fakeServer.requests.length).toEqual(0);
|
|
|
|
expect(slideToggleStub.callCount).toEqual(2);
|
|
|
|
expect(slideToggleStub.getCall(1).thisValue.eq(0).attr('id')).toEqual('linkPass');
|
|
|
|
});
|
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
describe('expiration date', function() {
|
|
|
|
var shareData;
|
|
|
|
var shareItem;
|
|
|
|
var clock;
|
|
|
|
var expectedMinDate;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
// pick a fake date
|
|
|
|
clock = sinon.useFakeTimers(new Date(2014, 0, 20, 14, 0, 0).getTime());
|
|
|
|
expectedMinDate = new Date(2014, 0, 21, 14, 0, 0);
|
|
|
|
|
2015-09-15 16:29:30 +03:00
|
|
|
configModel.set({
|
|
|
|
enforcePasswordForPublicLink: false,
|
|
|
|
isDefaultExpireDateEnabled: false,
|
|
|
|
isDefaultExpireDateEnforced: false,
|
|
|
|
defaultExpireDate: 7
|
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
|
|
|
|
shareModel.set('linkShare', {
|
|
|
|
isLinkShare: true,
|
|
|
|
token: 'tehtoken',
|
|
|
|
permissions: OC.PERMISSION_READ,
|
|
|
|
expiration: null
|
|
|
|
});
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
clock.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not check expiration date checkbox when no date was set', function() {
|
|
|
|
shareModel.get('linkShare').expiration = null;
|
|
|
|
dialog.render();
|
|
|
|
|
|
|
|
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(false);
|
2015-10-16 11:54:45 +03:00
|
|
|
expect(dialog.$el.find('.datepicker').val()).toEqual('');
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
|
|
|
it('does not check expiration date checkbox for new share', function() {
|
|
|
|
dialog.render();
|
|
|
|
|
|
|
|
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(false);
|
2015-10-16 11:54:45 +03:00
|
|
|
expect(dialog.$el.find('.datepicker').val()).toEqual('');
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
|
|
|
it('checks expiration date checkbox and populates field when expiration date was set', function() {
|
2015-10-03 18:06:48 +03:00
|
|
|
shareModel.get('linkShare').expiration = '2014-02-01 00:00:00';
|
2015-09-15 11:27:33 +03:00
|
|
|
dialog.render();
|
|
|
|
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(true);
|
2015-10-16 11:54:45 +03:00
|
|
|
expect(dialog.$el.find('.datepicker').val()).toEqual('01-02-2014');
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
|
|
|
it('sets default date when default date setting is enabled', function() {
|
2015-09-15 16:29:30 +03:00
|
|
|
configModel.set('isDefaultExpireDateEnabled', true);
|
2015-09-15 11:27:33 +03:00
|
|
|
dialog.render();
|
2015-10-16 11:54:45 +03:00
|
|
|
dialog.$el.find('.linkCheckbox').click();
|
2015-09-15 16:29:30 +03:00
|
|
|
// here fetch would be called and the server returns the expiration date
|
|
|
|
shareModel.get('linkShare').expiration = '2014-1-27 00:00:00';
|
|
|
|
dialog.render();
|
|
|
|
|
2015-09-15 11:27:33 +03:00
|
|
|
// enabled by default
|
|
|
|
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(true);
|
2015-10-16 11:54:45 +03:00
|
|
|
expect(dialog.$el.find('.datepicker').val()).toEqual('27-01-2014');
|
2015-09-15 11:27:33 +03:00
|
|
|
|
|
|
|
// disabling is allowed
|
|
|
|
dialog.$el.find('[name=expirationCheckbox]').click();
|
|
|
|
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(false);
|
|
|
|
});
|
|
|
|
it('enforces default date when enforced date setting is enabled', function() {
|
2015-09-15 16:29:30 +03:00
|
|
|
configModel.set({
|
|
|
|
isDefaultExpireDateEnabled: true,
|
|
|
|
isDefaultExpireDateEnforced: true
|
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
dialog.render();
|
2015-10-16 11:54:45 +03:00
|
|
|
dialog.$el.find('.linkCheckbox').click();
|
2015-09-15 16:29:30 +03:00
|
|
|
// here fetch would be called and the server returns the expiration date
|
|
|
|
shareModel.get('linkShare').expiration = '2014-1-27 00:00:00';
|
|
|
|
dialog.render();
|
|
|
|
|
2015-09-15 11:27:33 +03:00
|
|
|
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(true);
|
2015-10-16 11:54:45 +03:00
|
|
|
expect(dialog.$el.find('.datepicker').val()).toEqual('27-01-2014');
|
2015-09-15 11:27:33 +03:00
|
|
|
|
|
|
|
// disabling is not allowed
|
|
|
|
expect(dialog.$el.find('[name=expirationCheckbox]').prop('disabled')).toEqual(true);
|
|
|
|
dialog.$el.find('[name=expirationCheckbox]').click();
|
|
|
|
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(true);
|
|
|
|
});
|
|
|
|
it('enforces default date when enforced date setting is enabled and password is enforced', function() {
|
2015-09-15 16:29:30 +03:00
|
|
|
configModel.set({
|
|
|
|
enforcePasswordForPublicLink: true,
|
|
|
|
isDefaultExpireDateEnabled: true,
|
|
|
|
isDefaultExpireDateEnforced: true
|
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
dialog.render();
|
2015-10-16 11:54:45 +03:00
|
|
|
dialog.$el.find('.linkCheckbox').click();
|
2015-09-15 16:29:30 +03:00
|
|
|
// here fetch would be called and the server returns the expiration date
|
|
|
|
shareModel.get('linkShare').expiration = '2014-1-27 00:00:00';
|
|
|
|
dialog.render();
|
2015-09-15 11:27:33 +03:00
|
|
|
|
|
|
|
//Enter password
|
2015-10-16 11:54:45 +03:00
|
|
|
dialog.$el.find('.linkPassText').val('foo');
|
|
|
|
dialog.$el.find('.linkPassText').trigger(new $.Event('keyup', {keyCode: 13}));
|
2015-09-15 11:27:33 +03:00
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{ 'Content-Type': 'application/json' },
|
|
|
|
JSON.stringify({data: {token: 'xyz'}, status: 'success'})
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(true);
|
2015-10-16 11:54:45 +03:00
|
|
|
expect(dialog.$el.find('.datepicker').val()).toEqual('27-01-2014');
|
2015-09-15 11:27:33 +03:00
|
|
|
|
|
|
|
// disabling is not allowed
|
|
|
|
expect(dialog.$el.find('[name=expirationCheckbox]').prop('disabled')).toEqual(true);
|
|
|
|
dialog.$el.find('[name=expirationCheckbox]').click();
|
|
|
|
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(true);
|
|
|
|
});
|
|
|
|
it('sets picker minDate to today and no maxDate by default', function() {
|
|
|
|
dialog.render();
|
2015-10-16 11:54:45 +03:00
|
|
|
dialog.$el.find('.linkCheckbox').click();
|
2015-09-15 11:27:33 +03:00
|
|
|
dialog.$el.find('[name=expirationCheckbox]').click();
|
|
|
|
expect($.datepicker._defaults.minDate).toEqual(expectedMinDate);
|
|
|
|
expect($.datepicker._defaults.maxDate).toEqual(null);
|
|
|
|
});
|
|
|
|
it('limits the date range to X days after share time when enforced', function() {
|
2015-09-15 16:29:30 +03:00
|
|
|
configModel.set({
|
|
|
|
isDefaultExpireDateEnabled: true,
|
|
|
|
isDefaultExpireDateEnforced: true
|
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
dialog.render();
|
2015-10-16 11:54:45 +03:00
|
|
|
dialog.$el.find('.linkCheckbox').click();
|
2015-09-15 11:27:33 +03:00
|
|
|
expect($.datepicker._defaults.minDate).toEqual(expectedMinDate);
|
|
|
|
expect($.datepicker._defaults.maxDate).toEqual(new Date(2014, 0, 27, 0, 0, 0, 0));
|
|
|
|
});
|
|
|
|
it('limits the date range to X days after share time when enforced, even when redisplayed the next days', function() {
|
|
|
|
// item exists, was created two days ago
|
2015-09-15 16:29:30 +03:00
|
|
|
var shareItem = shareModel.get('linkShare');
|
2015-09-15 11:27:33 +03:00
|
|
|
shareItem.expiration = '2014-1-27';
|
|
|
|
// share time has time component but must be stripped later
|
|
|
|
shareItem.stime = new Date(2014, 0, 20, 11, 0, 25).getTime() / 1000;
|
2015-09-15 16:29:30 +03:00
|
|
|
configModel.set({
|
|
|
|
isDefaultExpireDateEnabled: true,
|
|
|
|
isDefaultExpireDateEnforced: true
|
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
dialog.render();
|
|
|
|
expect($.datepicker._defaults.minDate).toEqual(expectedMinDate);
|
|
|
|
expect($.datepicker._defaults.maxDate).toEqual(new Date(2014, 0, 27, 0, 0, 0, 0));
|
|
|
|
});
|
|
|
|
});
|
2015-10-08 13:21:38 +03:00
|
|
|
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
|
|
|
describe('check for avatar', function() {
|
|
|
|
beforeEach(function() {
|
2015-09-15 16:29:30 +03:00
|
|
|
shareModel.set({
|
2015-09-15 11:27:33 +03:00
|
|
|
reshare: {
|
|
|
|
share_type: OC.Share.SHARE_TYPE_USER,
|
|
|
|
uid_owner: 'owner',
|
|
|
|
displayname_owner: 'Owner',
|
|
|
|
permissions: 31
|
|
|
|
},
|
|
|
|
shares: [{
|
|
|
|
id: 100,
|
|
|
|
item_source: 123,
|
|
|
|
permissions: 31,
|
|
|
|
share_type: OC.Share.SHARE_TYPE_USER,
|
|
|
|
share_with: 'user1',
|
|
|
|
share_with_displayname: 'User One'
|
|
|
|
},{
|
|
|
|
id: 101,
|
|
|
|
item_source: 123,
|
|
|
|
permissions: 31,
|
|
|
|
share_type: OC.Share.SHARE_TYPE_GROUP,
|
|
|
|
share_with: 'group',
|
|
|
|
share_with_displayname: 'group'
|
|
|
|
},{
|
|
|
|
id: 102,
|
|
|
|
item_source: 123,
|
|
|
|
permissions: 31,
|
|
|
|
share_type: OC.Share.SHARE_TYPE_REMOTE,
|
|
|
|
share_with: 'foo@bar.com/baz',
|
|
|
|
share_with_displayname: 'foo@bar.com/baz'
|
|
|
|
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('avatars enabled', function() {
|
|
|
|
beforeEach(function() {
|
2015-09-15 16:29:30 +03:00
|
|
|
avatarStub.reset();
|
|
|
|
dialog.render();
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('test correct function calls', function() {
|
|
|
|
expect(avatarStub.calledTwice).toEqual(true);
|
2017-02-14 02:49:05 +03:00
|
|
|
expect(placeholderStub.callCount).toEqual(4);
|
2015-10-16 11:54:45 +03:00
|
|
|
expect(dialog.$('.shareWithList').children().length).toEqual(3);
|
2015-09-15 16:29:30 +03:00
|
|
|
expect(dialog.$('.avatar').length).toEqual(4);
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('test avatar owner', function() {
|
|
|
|
var args = avatarStub.getCall(0).args;
|
|
|
|
expect(args.length).toEqual(2);
|
|
|
|
expect(args[0]).toEqual('owner');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('test avatar user', function() {
|
|
|
|
var args = avatarStub.getCall(1).args;
|
2016-11-29 15:40:41 +03:00
|
|
|
expect(args.length).toEqual(6);
|
2015-09-15 11:27:33 +03:00
|
|
|
expect(args[0]).toEqual('user1');
|
2016-11-29 15:40:41 +03:00
|
|
|
expect(args[5]).toEqual('User One');
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('test avatar for groups', function() {
|
|
|
|
var args = placeholderStub.getCall(0).args;
|
|
|
|
expect(args.length).toEqual(1);
|
|
|
|
expect(args[0]).toEqual('group ' + OC.Share.SHARE_TYPE_GROUP);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('test avatar for remotes', function() {
|
|
|
|
var args = placeholderStub.getCall(1).args;
|
|
|
|
expect(args.length).toEqual(1);
|
|
|
|
expect(args[0]).toEqual('foo@bar.com/baz ' + OC.Share.SHARE_TYPE_REMOTE);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2015-10-21 13:00:29 +03:00
|
|
|
describe('remote sharing', function() {
|
2015-10-27 14:26:49 +03:00
|
|
|
it('shows remote share info when allowed', function() {
|
2015-10-21 13:00:29 +03:00
|
|
|
configModel.set({
|
|
|
|
isRemoteShareAllowed: true
|
|
|
|
});
|
|
|
|
dialog.render();
|
|
|
|
expect(dialog.$el.find('.shareWithRemoteInfo').length).toEqual(1);
|
|
|
|
});
|
|
|
|
it('does not show remote share info when not allowed', function() {
|
|
|
|
configModel.set({
|
|
|
|
isRemoteShareAllowed: false
|
|
|
|
});
|
|
|
|
dialog.render();
|
|
|
|
expect(dialog.$el.find('.shareWithRemoteInfo').length).toEqual(0);
|
|
|
|
});
|
|
|
|
});
|
2015-10-27 14:26:49 +03:00
|
|
|
describe('autocompletion of users', function() {
|
2015-10-21 15:46:08 +03:00
|
|
|
it('triggers autocomplete display and focus with data when ajax search succeeds', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
|
|
|
dialog.autocompleteHandler({term: 'bob'}, response);
|
|
|
|
var jsonData = JSON.stringify({
|
2015-12-23 12:49:27 +03:00
|
|
|
'ocs' : {
|
|
|
|
'meta' : {
|
|
|
|
'status' : 'success',
|
|
|
|
'statuscode' : 100,
|
|
|
|
'message' : null
|
|
|
|
},
|
|
|
|
'data' : {
|
|
|
|
'exact' : {
|
|
|
|
'users' : [],
|
|
|
|
'groups' : [],
|
|
|
|
'remotes': []
|
|
|
|
},
|
|
|
|
'users' : [{'label': 'bob', 'value': {'shareType': 0, 'shareWith': 'test'}}],
|
|
|
|
'groups' : [],
|
2016-11-19 13:36:51 +03:00
|
|
|
'remotes': [],
|
|
|
|
'lookup': []
|
2015-12-23 12:49:27 +03:00
|
|
|
}
|
|
|
|
}
|
2015-10-21 15:46:08 +03:00
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
2015-12-23 12:49:27 +03:00
|
|
|
expect(response.calledWithExactly(JSON.parse(jsonData).ocs.data.users)).toEqual(true);
|
2015-10-21 15:46:08 +03:00
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
|
|
|
|
2015-12-30 12:46:19 +03:00
|
|
|
describe('filter out', function() {
|
|
|
|
it('the current user', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
|
|
|
dialog.autocompleteHandler({term: 'bob'}, response);
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': []
|
|
|
|
},
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': 0,
|
|
|
|
'shareWith': OC.currentUser
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'label': 'bobby',
|
|
|
|
'value': {
|
|
|
|
'shareType': 0,
|
|
|
|
'shareWith': 'imbob'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [],
|
2016-11-19 13:36:51 +03:00
|
|
|
'remotes': [],
|
|
|
|
'lookup': []
|
2015-12-30 12:46:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
expect(response.calledWithExactly([{
|
|
|
|
'label': 'bobby',
|
|
|
|
'value': {'shareType': 0, 'shareWith': 'imbob'}
|
|
|
|
}])).toEqual(true);
|
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('the share owner', function () {
|
|
|
|
shareModel.set({
|
|
|
|
reshare: {
|
|
|
|
uid_owner: 'user1'
|
|
|
|
},
|
|
|
|
shares: [],
|
|
|
|
permissions: OC.PERMISSION_READ
|
|
|
|
});
|
|
|
|
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
|
|
|
dialog.autocompleteHandler({term: 'bob'}, response);
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': []
|
|
|
|
},
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': 0,
|
|
|
|
'shareWith': 'user1'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'label': 'bobby',
|
|
|
|
'value': {
|
|
|
|
'shareType': 0,
|
|
|
|
'shareWith': 'imbob'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [],
|
2016-11-19 13:36:51 +03:00
|
|
|
'remotes': [],
|
|
|
|
'lookup': []
|
2015-12-30 12:46:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
expect(response.calledWithExactly([{
|
|
|
|
'label': 'bobby',
|
|
|
|
'value': {'shareType': 0, 'shareWith': 'imbob'}
|
|
|
|
}])).toEqual(true);
|
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('already shared with', function () {
|
|
|
|
beforeEach(function() {
|
|
|
|
shareModel.set({
|
|
|
|
reshare: {},
|
|
|
|
shares: [{
|
|
|
|
id: 100,
|
|
|
|
item_source: 123,
|
|
|
|
permissions: 31,
|
|
|
|
share_type: OC.Share.SHARE_TYPE_USER,
|
|
|
|
share_with: 'user1',
|
|
|
|
share_with_displayname: 'User One'
|
|
|
|
},{
|
|
|
|
id: 101,
|
|
|
|
item_source: 123,
|
|
|
|
permissions: 31,
|
|
|
|
share_type: OC.Share.SHARE_TYPE_GROUP,
|
|
|
|
share_with: 'group',
|
|
|
|
share_with_displayname: 'group'
|
|
|
|
},{
|
|
|
|
id: 102,
|
|
|
|
item_source: 123,
|
|
|
|
permissions: 31,
|
|
|
|
share_type: OC.Share.SHARE_TYPE_REMOTE,
|
|
|
|
share_with: 'foo@bar.com/baz',
|
|
|
|
share_with_displayname: 'foo@bar.com/baz'
|
|
|
|
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('users', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
|
|
|
dialog.autocompleteHandler({term: 'bob'}, response);
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': []
|
|
|
|
},
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'user1'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'label': 'bobby',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'imbob'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [],
|
2016-11-19 13:36:51 +03:00
|
|
|
'remotes': [],
|
|
|
|
'lookup': []
|
2015-12-30 12:46:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
expect(response.calledWithExactly([{
|
|
|
|
'label': 'bobby',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
|
|
|
|
}])).toEqual(true);
|
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('groups', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
|
|
|
dialog.autocompleteHandler({term: 'group'}, response);
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': []
|
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [
|
|
|
|
{
|
|
|
|
'label': 'group',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_GROUP,
|
|
|
|
'shareWith': 'group'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'label': 'group2',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_GROUP,
|
|
|
|
'shareWith': 'group2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2016-11-19 13:36:51 +03:00
|
|
|
'remotes': [],
|
|
|
|
'lookup': []
|
2015-12-30 12:46:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
expect(response.calledWithExactly([{
|
|
|
|
'label': 'group2',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group2'}
|
|
|
|
}])).toEqual(true);
|
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('remotes', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
|
|
|
dialog.autocompleteHandler({term: 'bob'}, response);
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': []
|
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [
|
|
|
|
{
|
|
|
|
'label': 'foo@bar.com/baz',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_REMOTE,
|
|
|
|
'shareWith': 'foo@bar.com/baz'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'label': 'foo2@bar.com/baz',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_REMOTE,
|
|
|
|
'shareWith': 'foo2@bar.com/baz'
|
|
|
|
}
|
|
|
|
}
|
2016-11-19 13:36:51 +03:00
|
|
|
],
|
|
|
|
'lookup': []
|
2015-12-30 12:46:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
expect(response.calledWithExactly([{
|
|
|
|
'label': 'foo2@bar.com/baz',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_REMOTE, 'shareWith': 'foo2@bar.com/baz'}
|
|
|
|
}])).toEqual(true);
|
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-10-21 15:46:08 +03:00
|
|
|
it('gracefully handles successful ajax call with failure content', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
|
|
|
dialog.autocompleteHandler({term: 'bob'}, response);
|
2015-12-23 12:49:27 +03:00
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs' : {
|
|
|
|
'meta' : {
|
|
|
|
'status': 'failure',
|
|
|
|
'statuscode': 400
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-10-21 15:46:08 +03:00
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
expect(response.calledWithExactly()).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws a notification when the ajax search lookup fails', function () {
|
|
|
|
notificationStub = sinon.stub(OC.Notification, 'show');
|
|
|
|
dialog.render();
|
|
|
|
dialog.autocompleteHandler({term: 'bob'}, sinon.stub());
|
|
|
|
fakeServer.requests[0].respond(500);
|
|
|
|
expect(notificationStub.calledOnce).toEqual(true);
|
|
|
|
notificationStub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('renders the autocomplete elements', function() {
|
|
|
|
it('renders a group element', function() {
|
|
|
|
dialog.render();
|
2015-10-21 16:30:42 +03:00
|
|
|
var el = dialog.autocompleteRenderItem(
|
|
|
|
$("<ul></ul>"),
|
|
|
|
{label: "1", value: { shareType: OC.Share.SHARE_TYPE_GROUP }}
|
|
|
|
);
|
2015-10-21 15:46:08 +03:00
|
|
|
expect(el.is('li')).toEqual(true);
|
|
|
|
expect(el.hasClass('group')).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a remote element', function() {
|
|
|
|
dialog.render();
|
2015-10-21 16:30:42 +03:00
|
|
|
var el = dialog.autocompleteRenderItem(
|
|
|
|
$("<ul></ul>"),
|
|
|
|
{label: "1", value: { shareType: OC.Share.SHARE_TYPE_REMOTE }}
|
|
|
|
);
|
2015-10-21 15:46:08 +03:00
|
|
|
expect(el.is('li')).toEqual(true);
|
|
|
|
expect(el.hasClass('user')).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
2016-01-22 19:30:18 +03:00
|
|
|
|
|
|
|
it('calls addShare after selection', function() {
|
|
|
|
dialog.render();
|
2016-02-12 16:31:00 +03:00
|
|
|
|
|
|
|
var shareWith = $('.shareWithField')[0];
|
|
|
|
var $shareWith = $(shareWith);
|
2016-01-22 19:30:18 +03:00
|
|
|
var addShareStub = sinon.stub(shareModel, 'addShare');
|
|
|
|
var autocompleteOptions = autocompleteStub.getCall(0).args[0];
|
2016-02-12 16:31:00 +03:00
|
|
|
autocompleteOptions.select(new $.Event('select', {target: shareWith}), {
|
2016-01-22 19:30:18 +03:00
|
|
|
item: {
|
|
|
|
label: 'User Two',
|
|
|
|
value: {
|
|
|
|
shareType: OC.Share.SHARE_TYPE_USER,
|
|
|
|
shareWith: 'user2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(addShareStub.calledOnce).toEqual(true);
|
|
|
|
expect(addShareStub.firstCall.args[0]).toEqual({
|
|
|
|
shareType: OC.Share.SHARE_TYPE_USER,
|
|
|
|
shareWith: 'user2'
|
|
|
|
});
|
|
|
|
|
2016-02-12 16:31:00 +03:00
|
|
|
//Input is locked
|
|
|
|
expect($shareWith.val()).toEqual('User Two');
|
|
|
|
expect($shareWith.attr('disabled')).toEqual('disabled');
|
|
|
|
|
|
|
|
//Callback is called
|
|
|
|
addShareStub.firstCall.args[1].success();
|
|
|
|
|
|
|
|
//Input is unlocked
|
|
|
|
expect($shareWith.val()).toEqual('');
|
|
|
|
expect($shareWith.attr('disabled')).toEqual(undefined);
|
|
|
|
|
2016-01-22 19:30:18 +03:00
|
|
|
addShareStub.restore();
|
|
|
|
});
|
2016-02-16 21:40:44 +03:00
|
|
|
|
|
|
|
it('calls addShare after selection and fail to share', function() {
|
|
|
|
dialog.render();
|
|
|
|
|
|
|
|
var shareWith = $('.shareWithField')[0];
|
|
|
|
var $shareWith = $(shareWith);
|
|
|
|
var addShareStub = sinon.stub(shareModel, 'addShare');
|
|
|
|
var autocompleteOptions = autocompleteStub.getCall(0).args[0];
|
|
|
|
autocompleteOptions.select(new $.Event('select', {target: shareWith}), {
|
|
|
|
item: {
|
|
|
|
label: 'User Two',
|
|
|
|
value: {
|
|
|
|
shareType: OC.Share.SHARE_TYPE_USER,
|
|
|
|
shareWith: 'user2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(addShareStub.calledOnce).toEqual(true);
|
|
|
|
expect(addShareStub.firstCall.args[0]).toEqual({
|
|
|
|
shareType: OC.Share.SHARE_TYPE_USER,
|
|
|
|
shareWith: 'user2'
|
|
|
|
});
|
|
|
|
|
|
|
|
//Input is locked
|
|
|
|
expect($shareWith.val()).toEqual('User Two');
|
|
|
|
expect($shareWith.attr('disabled')).toEqual('disabled');
|
|
|
|
|
|
|
|
//Callback is called
|
|
|
|
addShareStub.firstCall.args[1].error();
|
|
|
|
|
|
|
|
//Input is unlocked
|
|
|
|
expect($shareWith.val()).toEqual('User Two');
|
|
|
|
expect($shareWith.attr('disabled')).toEqual(undefined);
|
|
|
|
|
|
|
|
addShareStub.restore();
|
|
|
|
});
|
2016-01-22 19:30:18 +03:00
|
|
|
});
|
|
|
|
describe('reshare permissions', function() {
|
|
|
|
it('does not show sharing options when sharing not allowed', function() {
|
|
|
|
shareModel.set({
|
|
|
|
reshare: {},
|
|
|
|
shares: [],
|
|
|
|
permissions: OC.PERMISSION_READ
|
|
|
|
});
|
|
|
|
dialog.render();
|
|
|
|
expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(true);
|
|
|
|
});
|
2016-11-30 22:56:10 +03:00
|
|
|
it('shows reshare owner for single user share', function() {
|
2016-01-22 19:30:18 +03:00
|
|
|
shareModel.set({
|
|
|
|
reshare: {
|
2016-11-30 22:56:10 +03:00
|
|
|
uid_owner: 'user1',
|
|
|
|
displayname_owner: 'User One',
|
|
|
|
share_type: OC.Share.SHARE_TYPE_USER
|
2016-01-22 19:30:18 +03:00
|
|
|
},
|
|
|
|
shares: [],
|
|
|
|
permissions: OC.PERMISSION_READ
|
|
|
|
});
|
|
|
|
dialog.render();
|
|
|
|
expect(dialog.$el.find('.resharerInfoView .reshare').length).toEqual(1);
|
2016-11-30 22:56:10 +03:00
|
|
|
expect(dialog.$el.find('.resharerInfoView .reshare').text().trim()).toEqual('Shared with you by User One');
|
|
|
|
});
|
|
|
|
it('shows reshare owner for single user share', function() {
|
|
|
|
shareModel.set({
|
|
|
|
reshare: {
|
|
|
|
uid_owner: 'user1',
|
|
|
|
displayname_owner: 'User One',
|
|
|
|
share_with: 'group2',
|
|
|
|
share_with_displayname: 'Group Two',
|
|
|
|
share_type: OC.Share.SHARE_TYPE_GROUP
|
|
|
|
},
|
|
|
|
shares: [],
|
|
|
|
permissions: OC.PERMISSION_READ
|
|
|
|
});
|
|
|
|
dialog.render();
|
|
|
|
expect(dialog.$el.find('.resharerInfoView .reshare').length).toEqual(1);
|
|
|
|
expect(dialog.$el.find('.resharerInfoView .reshare').text().trim()).toEqual('Shared with you and the group Group Two by User One');
|
2016-01-22 19:30:18 +03:00
|
|
|
});
|
|
|
|
it('does not show reshare owner if owner is current user', function() {
|
|
|
|
shareModel.set({
|
|
|
|
reshare: {
|
|
|
|
uid_owner: OC.currentUser
|
|
|
|
},
|
|
|
|
shares: [],
|
|
|
|
permissions: OC.PERMISSION_READ
|
|
|
|
});
|
|
|
|
dialog.render();
|
|
|
|
expect(dialog.$el.find('.resharerInfoView .reshare').length).toEqual(0);
|
|
|
|
});
|
2015-10-21 15:46:08 +03:00
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|