More unit tests for share dialog

remotes/origin/db-empty-migrate
Vincent Petry 10 years ago
parent 886f1ed660
commit 996639f4fb
  1. 9
      apps/files_sharing/js/sharetabview.js
  2. 23
      core/js/sharedialogexpirationview.js
  3. 4
      core/js/sharedialogresharerinfoview.js
  4. 11
      core/js/sharedialogshareelistview.js
  5. 24
      core/js/sharedialogview.js
  6. 467
      core/js/tests/specs/sharedialogviewSpec.js
  7. 73
      core/js/tests/specs/shareitemmodelSpec.js

@ -11,7 +11,6 @@
(function() { (function() {
var TEMPLATE = var TEMPLATE =
'<div>' + '<div>' +
'<ul>{{#if owner}}<li>Owner: {{owner}}</li>{{/if}}</ul>' +
'<div class="dialogContainer"></div>' + '<div class="dialogContainer"></div>' +
'</div>'; '</div>';
@ -47,13 +46,7 @@
} }
if (this.model) { if (this.model) {
var owner = this.model.get('shareOwner'); this.$el.html(this.template());
if (owner === OC.currentUser) {
owner = null;
}
this.$el.html(this.template({
owner: owner
}));
// TODO: the model should read these directly off the passed fileInfoModel // TODO: the model should read these directly off the passed fileInfoModel
var attributes = { var attributes = {

@ -130,7 +130,7 @@
); );
} }
var isExpirationSet = !!this.model.get('linkShare').expiration; var isExpirationSet = !!this.model.get('linkShare').expiration || isExpirationEnforced;
var expirationTemplate = this.template(); var expirationTemplate = this.template();
this.$el.html(expirationTemplate({ this.$el.html(expirationTemplate({
@ -145,13 +145,13 @@
expirationValue: this.model.get('linkShare').expiration expirationValue: this.model.get('linkShare').expiration
})); }));
if(isExpirationSet) { // what if there is another date picker on that page?
// what if there is another date picker on that page? var minDate = new Date();
var minDate = new Date(); var maxDate = null;
// min date should always be the next day // min date should always be the next day
minDate.setDate(minDate.getDate()+1); minDate.setDate(minDate.getDate()+1);
var maxDate = null; if(isExpirationSet) {
if(isExpirationEnforced) { if(isExpirationEnforced) {
// TODO: hack: backend returns string instead of integer // TODO: hack: backend returns string instead of integer
var shareTime = this.model.get('linkShare').stime; var shareTime = this.model.get('linkShare').stime;
@ -164,12 +164,11 @@
shareTime = OC.Util.stripTime(shareTime).getTime(); shareTime = OC.Util.stripTime(shareTime).getTime();
maxDate = new Date(shareTime + defaultExpireDays * 24 * 3600 * 1000); maxDate = new Date(shareTime + defaultExpireDays * 24 * 3600 * 1000);
} }
$.datepicker.setDefaults({
minDate: minDate,
maxDate: maxDate
});
} }
$.datepicker.setDefaults({
minDate: minDate,
maxDate: maxDate
});
this.$el.find('.datepicker').datepicker({dateFormat : 'dd-mm-yy'}); this.$el.find('.datepicker').datepicker({dateFormat : 'dd-mm-yy'});

@ -63,8 +63,8 @@
}, },
render: function() { render: function() {
if ( !this.model.hasReshare() if (!this.model.hasReshare()
|| !this.model.getReshareOwner() !== OC.currentUser) || this.model.getReshareOwner() === OC.currentUser)
{ {
this.$el.empty(); this.$el.empty();
return this; return this;

@ -211,11 +211,12 @@
if(this.configModel.areAvatarsEnabled()) { if(this.configModel.areAvatarsEnabled()) {
this.$el.find('.avatar').each(function() { this.$el.find('.avatar').each(function() {
var $this = $(this); var $this = $(this);
$this.avatar($this.data('username'), 32); if ($this.hasClass('imageplaceholderseed')) {
}); $this.css({width: 32, height: 32});
this.$el.find('.avatar.imageplaceholderseed').each(function() { $this.imageplaceholder($this.data('seed'));
var $this = $(this); } else {
$this.imageplaceholder($this.data('seed')); $this.avatar($this.data('username'), 32);
}
}); });
} }

@ -15,6 +15,7 @@
var TEMPLATE_BASE = var TEMPLATE_BASE =
'<div class="resharerInfoView"></div>' + '<div class="resharerInfoView"></div>' +
'{{#if isSharingAllowed}}' +
'<label for="shareWith" class="hidden-visually">{{shareLabel}}</label>' + '<label for="shareWith" class="hidden-visually">{{shareLabel}}</label>' +
'<div class="oneline">' + '<div class="oneline">' +
' <input id="shareWith" type="text" placeholder="{{sharePlaceholder}}" />' + ' <input id="shareWith" type="text" placeholder="{{sharePlaceholder}}" />' +
@ -22,6 +23,7 @@
'</div>' + '</div>' +
// FIXME: find a good position for remoteShareInfo // FIXME: find a good position for remoteShareInfo
'{{{remoteShareInfo}}}' + '{{{remoteShareInfo}}}' +
'{{/if}}' +
'<div class="shareeListView"></div>' + '<div class="shareeListView"></div>' +
'<div class="linkShareView"></div>' + '<div class="linkShareView"></div>' +
'<div class="expirationView"></div>' '<div class="expirationView"></div>'
@ -82,6 +84,9 @@
this.configModel.on('change:isRemoteShareAllowed', function() { this.configModel.on('change:isRemoteShareAllowed', function() {
view.render(); view.render();
}); });
this.model.on('change:permissions', function() {
view.render();
});
var subViewOptions = { var subViewOptions = {
model: this.model, model: this.model,
@ -163,16 +168,19 @@
this.$el.html(baseTemplate({ this.$el.html(baseTemplate({
shareLabel: t('core', 'Share'), shareLabel: t('core', 'Share'),
sharePlaceholder: this._renderSharePlaceholderPart(), sharePlaceholder: this._renderSharePlaceholderPart(),
remoteShareInfo: this._renderRemoteShareInfoPart() remoteShareInfo: this._renderRemoteShareInfoPart(),
isSharingAllowed: this.model.sharePermissionPossible()
})); }));
var view = this; var $shareField = this.$el.find('#shareWith');
this.$el.find('#shareWith').autocomplete({ if ($shareField.length) {
minLength: 2, $shareField.autocomplete({
delay: 750, minLength: 2,
source: this.autocompleteHandler, delay: 750,
select: this._onSelectRecipient source: this.autocompleteHandler,
}).data('ui-autocomplete')._renderItem = this.autocompleteRenderItem; select: this._onSelectRecipient
}).data('ui-autocomplete')._renderItem = this.autocompleteRenderItem;
}
this.resharerInfoView.$el = this.$el.find('.resharerInfoView'); this.resharerInfoView.$el = this.$el.find('.resharerInfoView');
this.resharerInfoView.render(); this.resharerInfoView.render();

@ -63,7 +63,14 @@ describe('OC.Share.ShareDialogView', function() {
possiblePermissions: 31, possiblePermissions: 31,
permissions: 31 permissions: 31
}; };
configModel = new OC.Share.ShareConfigModel(); configModel = new OC.Share.ShareConfigModel({
enforcePasswordForPublicLink: false,
isResharingAllowed: true,
enforcePasswordForPublicLink: false,
isDefaultExpireDateEnabled: false,
isDefaultExpireDateEnforced: false,
defaultExpireDate: 7
});
shareModel = new OC.Share.ShareItemModel(attributes, { shareModel = new OC.Share.ShareItemModel(attributes, {
configModel: configModel, configModel: configModel,
fileInfoModel: fileInfoModel fileInfoModel: fileInfoModel
@ -112,9 +119,6 @@ describe('OC.Share.ShareDialogView', function() {
oc_config.enable_avatars = oldEnableAvatars; oc_config.enable_avatars = oldEnableAvatars;
}); });
describe('Share with link', function() { describe('Share with link', function() {
beforeEach(function() {
configModel.set('enforcePasswordForPublicLink', false);
});
// TODO: test ajax calls // TODO: test ajax calls
// TODO: test password field visibility (whenever enforced or not) // TODO: test password field visibility (whenever enforced or not)
it('update password on focus out', function() { it('update password on focus out', function() {
@ -138,7 +142,9 @@ describe('OC.Share.ShareDialogView', function() {
expect(fakeServer.requests[1].method).toEqual('POST'); expect(fakeServer.requests[1].method).toEqual('POST');
var body = OC.parseQueryString(fakeServer.requests[1].requestBody); var body = OC.parseQueryString(fakeServer.requests[1].requestBody);
expect(body['shareWith']).toEqual('foo'); expect(body.shareWith).toEqual('foo');
fetchStub.reset();
// Set password response // Set password response
fakeServer.requests[1].respond( fakeServer.requests[1].respond(
@ -147,6 +153,10 @@ describe('OC.Share.ShareDialogView', function() {
JSON.stringify({data: {token: 'xyz'}, status: 'success'}) JSON.stringify({data: {token: 'xyz'}, status: 'success'})
); );
expect(fetchStub.calledOnce).toEqual(true);
// fetching the model will rerender the view
dialog.render();
expect(dialog.$el.find('#linkPassText').val()).toEqual(''); expect(dialog.$el.find('#linkPassText').val()).toEqual('');
expect(dialog.$el.find('#linkPassText').attr('placeholder')).toEqual('Password protected'); expect(dialog.$el.find('#linkPassText').attr('placeholder')).toEqual('Password protected');
}); });
@ -171,7 +181,9 @@ describe('OC.Share.ShareDialogView', function() {
expect(fakeServer.requests[1].method).toEqual('POST'); expect(fakeServer.requests[1].method).toEqual('POST');
var body = OC.parseQueryString(fakeServer.requests[1].requestBody); var body = OC.parseQueryString(fakeServer.requests[1].requestBody);
expect(body['shareWith']).toEqual('foo'); expect(body.shareWith).toEqual('foo');
fetchStub.reset();
// Set password response // Set password response
fakeServer.requests[1].respond( fakeServer.requests[1].respond(
@ -180,6 +192,10 @@ describe('OC.Share.ShareDialogView', function() {
JSON.stringify({data: {token: 'xyz'}, status: 'success'}) JSON.stringify({data: {token: 'xyz'}, status: 'success'})
); );
expect(fetchStub.calledOnce).toEqual(true);
// fetching the model will rerender the view
dialog.render();
expect(dialog.$el.find('#linkPassText').val()).toEqual(''); expect(dialog.$el.find('#linkPassText').val()).toEqual('');
expect(dialog.$el.find('#linkPassText').attr('placeholder')).toEqual('Password protected'); expect(dialog.$el.find('#linkPassText').attr('placeholder')).toEqual('Password protected');
}); });
@ -198,8 +214,7 @@ describe('OC.Share.ShareDialogView', function() {
expect(dialog.$el.find('#linkCheckbox').length).toEqual(0); expect(dialog.$el.find('#linkCheckbox').length).toEqual(0);
}); });
it('Reset link when password is enforced and link is toggled', function() { it('Reset link when password is enforced and link is toggled', function() {
var old = oc_appconfig.core.enforcePasswordForPublicLink; configModel.set('enforcePasswordForPublicLink', true);
oc_appconfig.core.enforcePasswordForPublicLink = true;
$('#allowShareWithLink').val('yes'); $('#allowShareWithLink').val('yes');
dialog.render(); dialog.render();
@ -238,13 +253,9 @@ describe('OC.Share.ShareDialogView', function() {
*/ */
dialog.$el.find('[name=linkCheckbox]').click(); dialog.$el.find('[name=linkCheckbox]').click();
expect(fakeServer.requests.length).toEqual(2); expect(fakeServer.requests.length).toEqual(2);
oc_appconfig.core.enforcePasswordForPublicLink = old;
}); });
it('Reset password placeholder when password is enforced and link is toggled', function() { it('Reset password placeholder when password is enforced and link is toggled', function() {
var old = oc_appconfig.core.enforcePasswordForPublicLink;
oc_appconfig.core.enforcePasswordForPublicLink = true;
$('#allowShareWithLink').val('yes'); $('#allowShareWithLink').val('yes');
dialog.render(); dialog.render();
@ -261,6 +272,7 @@ describe('OC.Share.ShareDialogView', function() {
{ 'Content-Type': 'application/json' }, { 'Content-Type': 'application/json' },
JSON.stringify({data: {token: 'xyz'}, status: 'success'}) JSON.stringify({data: {token: 'xyz'}, status: 'success'})
); );
dialog.render();
expect(dialog.$el.find('#linkPassText').attr('placeholder')).toEqual('**********'); expect(dialog.$el.find('#linkPassText').attr('placeholder')).toEqual('**********');
// Remove link // Remove link
@ -274,119 +286,23 @@ describe('OC.Share.ShareDialogView', function() {
// Try to share again // Try to share again
dialog.$el.find('[name=linkCheckbox]').click(); dialog.$el.find('[name=linkCheckbox]').click();
expect(dialog.$el.find('#linkPassText').attr('placeholder')).toEqual('Choose a password for the public link'); expect(dialog.$el.find('#linkPassText').attr('placeholder')).toEqual('Choose a password for the public link');
oc_appconfig.core.enforcePasswordForPublicLink = old;
});
it('reset password on toggle of share', function() {
$('#allowShareWithLink').val('yes');
dialog.render();
dialog.$el.find('[name=linkCheckbox]').click();
fakeServer.requests[0].respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({data: {token: 'xyz'}, status: 'success'})
);
//Password protection should be unchecked and password field not visible
expect(dialog.$el.find('[name=showPassword]').prop('checked')).toEqual(false);
expect(dialog.$el.find('#linkPass').is(":visible")).toEqual(false);
// Toggle and set password
dialog.$el.find('[name=showPassword]').click();
dialog.$el.find('#linkPassText').val('foo');
dialog.$el.find('#linkPassText').trigger(new $.Event('keyup', {keyCode: 13}));
fakeServer.requests[1].respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({data: {token: 'xyz2'}, status: 'success'})
);
// Unshare
dialog.$el.find('[name=linkCheckbox]').click();
fakeServer.requests[2].respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({status: 'success'})
);
// Toggle share again
dialog.$el.find('[name=linkCheckbox]').click();
fakeServer.requests[3].respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({data: {token: 'xyz3'}, status: 'success'})
);
// Password checkbox should be unchecked
expect(dialog.$el.find('[name=showPassword]').prop('checked')).toEqual(false);
expect(dialog.$el.find('#linkPass').is(":visible")).toEqual(false);
});
it('reset expiration on toggle of share', function() {
$('#allowShareWithLink').val('yes');
dialog.render();
dialog.$el.find('[name=linkCheckbox]').click();
fakeServer.requests[0].respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({data: {token: 'xyz'}, status: 'success'})
);
//Expiration should be unchecked and expiration field not visible
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(false);
expect(dialog.$el.find('#expirationDate').is(":visible")).toEqual(false);
// Toggle and set password
dialog.$el.find('[name=expirationCheckbox]').click();
d = new Date();
d.setDate(d.getDate() + 1);
date=d.getDate() + '-' + (d.getMonth()+1) + '-' + d.getFullYear();
dialog.$el.find('#expirationDate').val(date);
dialog.$el.find('#expirationDate').change();
fakeServer.requests[1].respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({data: {token: 'xyz2'}, status: 'success'})
);
// Unshare
dialog.$el.find('[name=linkCheckbox]').click();
fakeServer.requests[2].respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({status: 'success'})
);
// Toggle share again
dialog.$el.find('[name=linkCheckbox]').click();
fakeServer.requests[3].respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({data: {token: 'xyz3'}, status: 'success'})
);
// Recheck expire visibility
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(false);
expect(dialog.$el.find('#expirationDate').is(":visible")).toEqual(false);
}); });
it('shows populated link share when a link share exists', function() { it('shows populated link share when a link share exists', function() {
// this is how the OC.Share class does it...
var link = parent.location.protocol + '//' + location.host +
OC.generateUrl('/s/') + 'tehtoken';
shareModel.set('linkShare', { shareModel.set('linkShare', {
isLinkShare: true, isLinkShare: true,
token: 'tehtoken', token: 'tehtoken',
link: 'TODO', link: link,
expiration: '', expiration: '',
permissions: OC.PERMISSION_READ, permissions: OC.PERMISSION_READ,
stime: 1403884258, stime: 1403884258,
}); });
dialog.render();
expect(dialog.$el.find('#linkCheckbox').prop('checked')).toEqual(true); expect(dialog.$el.find('#linkCheckbox').prop('checked')).toEqual(true);
// this is how the OC.Share class does it...
var link = parent.location.protocol + '//' + location.host +
OC.generateUrl('/s/') + 'tehtoken';
expect(dialog.$el.find('#linkText').val()).toEqual(link); expect(dialog.$el.find('#linkText').val()).toEqual(link);
}); });
describe('expiration date', function() { describe('expiration date', function() {
@ -400,10 +316,12 @@ describe('OC.Share.ShareDialogView', function() {
clock = sinon.useFakeTimers(new Date(2014, 0, 20, 14, 0, 0).getTime()); clock = sinon.useFakeTimers(new Date(2014, 0, 20, 14, 0, 0).getTime());
expectedMinDate = new Date(2014, 0, 21, 14, 0, 0); expectedMinDate = new Date(2014, 0, 21, 14, 0, 0);
oc_appconfig.core.defaultExpireDate = 7; configModel.set({
oc_appconfig.core.enforcePasswordForPublicLink = false; enforcePasswordForPublicLink: false,
oc_appconfig.core.defaultExpireDateEnabled = false; isDefaultExpireDateEnabled: false,
oc_appconfig.core.defaultExpireDateEnforced = false; isDefaultExpireDateEnforced: false,
defaultExpireDate: 7
});
shareModel.set('linkShare', { shareModel.set('linkShare', {
isLinkShare: true, isLinkShare: true,
@ -436,10 +354,13 @@ describe('OC.Share.ShareDialogView', function() {
expect(dialog.$el.find('#expirationDate').val()).toEqual('1234'); expect(dialog.$el.find('#expirationDate').val()).toEqual('1234');
}); });
it('sets default date when default date setting is enabled', function() { it('sets default date when default date setting is enabled', function() {
/* jshint camelcase:false */ configModel.set('isDefaultExpireDateEnabled', true);
oc_appconfig.core.defaultExpireDateEnabled = true;
dialog.render(); dialog.render();
dialog.$el.find('[name=linkCheckbox]').click(); dialog.$el.find('[name=linkCheckbox]').click();
// here fetch would be called and the server returns the expiration date
shareModel.get('linkShare').expiration = '2014-1-27 00:00:00';
dialog.render();
// enabled by default // enabled by default
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(true); expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(true);
// TODO: those zeros must go... // TODO: those zeros must go...
@ -450,11 +371,16 @@ describe('OC.Share.ShareDialogView', function() {
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(false); expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(false);
}); });
it('enforces default date when enforced date setting is enabled', function() { it('enforces default date when enforced date setting is enabled', function() {
/* jshint camelcase:false */ configModel.set({
oc_appconfig.core.defaultExpireDateEnabled = true; isDefaultExpireDateEnabled: true,
oc_appconfig.core.defaultExpireDateEnforced = true; isDefaultExpireDateEnforced: true
});
dialog.render(); dialog.render();
dialog.$el.find('[name=linkCheckbox]').click(); dialog.$el.find('[name=linkCheckbox]').click();
// here fetch would be called and the server returns the expiration date
shareModel.get('linkShare').expiration = '2014-1-27 00:00:00';
dialog.render();
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(true); expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(true);
// TODO: those zeros must go... // TODO: those zeros must go...
expect(dialog.$el.find('#expirationDate').val()).toEqual('2014-1-27 00:00:00'); expect(dialog.$el.find('#expirationDate').val()).toEqual('2014-1-27 00:00:00');
@ -465,12 +391,16 @@ describe('OC.Share.ShareDialogView', function() {
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(true); 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() { it('enforces default date when enforced date setting is enabled and password is enforced', function() {
/* jshint camelcase:false */ configModel.set({
oc_appconfig.core.enforcePasswordForPublicLink = true; enforcePasswordForPublicLink: true,
oc_appconfig.core.defaultExpireDateEnabled = true; isDefaultExpireDateEnabled: true,
oc_appconfig.core.defaultExpireDateEnforced = true; isDefaultExpireDateEnforced: true
});
dialog.render(); dialog.render();
dialog.$el.find('[name=linkCheckbox]').click(); dialog.$el.find('[name=linkCheckbox]').click();
// here fetch would be called and the server returns the expiration date
shareModel.get('linkShare').expiration = '2014-1-27 00:00:00';
dialog.render();
//Enter password //Enter password
dialog.$el.find('#linkPassText').val('foo'); dialog.$el.find('#linkPassText').val('foo');
@ -493,12 +423,12 @@ describe('OC.Share.ShareDialogView', function() {
it('displayes email form when sending emails is enabled', function() { it('displayes email form when sending emails is enabled', function() {
$('input[name=mailPublicNotificationEnabled]').val('yes'); $('input[name=mailPublicNotificationEnabled]').val('yes');
dialog.render(); dialog.render();
expect($('#emailPrivateLink').length).toEqual(1); expect(dialog.$('#emailPrivateLink').length).toEqual(1);
}); });
it('not renders email form when sending emails is disabled', function() { it('not renders email form when sending emails is disabled', function() {
$('input[name=mailPublicNotificationEnabled]').val('no'); $('input[name=mailPublicNotificationEnabled]').val('no');
dialog.render(); dialog.render();
expect($('#emailPrivateLink').length).toEqual(0); expect(dialog.$('#emailPrivateLink').length).toEqual(0);
}); });
it('sets picker minDate to today and no maxDate by default', function() { it('sets picker minDate to today and no maxDate by default', function() {
dialog.render(); dialog.render();
@ -508,9 +438,10 @@ describe('OC.Share.ShareDialogView', function() {
expect($.datepicker._defaults.maxDate).toEqual(null); expect($.datepicker._defaults.maxDate).toEqual(null);
}); });
it('limits the date range to X days after share time when enforced', function() { it('limits the date range to X days after share time when enforced', function() {
/* jshint camelcase:false */ configModel.set({
oc_appconfig.core.defaultExpireDateEnabled = true; isDefaultExpireDateEnabled: true,
oc_appconfig.core.defaultExpireDateEnforced = true; isDefaultExpireDateEnforced: true
});
dialog.render(); dialog.render();
dialog.$el.find('[name=linkCheckbox]').click(); dialog.$el.find('[name=linkCheckbox]').click();
expect($.datepicker._defaults.minDate).toEqual(expectedMinDate); expect($.datepicker._defaults.minDate).toEqual(expectedMinDate);
@ -518,13 +449,14 @@ describe('OC.Share.ShareDialogView', function() {
}); });
it('limits the date range to X days after share time when enforced, even when redisplayed the next days', function() { 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 // item exists, was created two days ago
var shareItem = shareModel.get('linkShare');
shareItem.expiration = '2014-1-27'; shareItem.expiration = '2014-1-27';
// share time has time component but must be stripped later // share time has time component but must be stripped later
shareItem.stime = new Date(2014, 0, 20, 11, 0, 25).getTime() / 1000; shareItem.stime = new Date(2014, 0, 20, 11, 0, 25).getTime() / 1000;
shareData.shares.push(shareItem); configModel.set({
/* jshint camelcase:false */ isDefaultExpireDateEnabled: true,
oc_appconfig.core.defaultExpireDateEnabled = true; isDefaultExpireDateEnforced: true
oc_appconfig.core.defaultExpireDateEnforced = true; });
dialog.render(); dialog.render();
expect($.datepicker._defaults.minDate).toEqual(expectedMinDate); expect($.datepicker._defaults.minDate).toEqual(expectedMinDate);
expect($.datepicker._defaults.maxDate).toEqual(new Date(2014, 0, 27, 0, 0, 0, 0)); expect($.datepicker._defaults.maxDate).toEqual(new Date(2014, 0, 27, 0, 0, 0, 0));
@ -533,7 +465,7 @@ describe('OC.Share.ShareDialogView', function() {
}); });
describe('check for avatar', function() { describe('check for avatar', function() {
beforeEach(function() { beforeEach(function() {
loadItemStub.returns({ shareModel.set({
reshare: { reshare: {
share_type: OC.Share.SHARE_TYPE_USER, share_type: OC.Share.SHARE_TYPE_USER,
uid_owner: 'owner', uid_owner: 'owner',
@ -569,14 +501,8 @@ describe('OC.Share.ShareDialogView', function() {
describe('avatars enabled', function() { describe('avatars enabled', function() {
beforeEach(function() { beforeEach(function() {
oc_config.enable_avatars = true; oc_config.enable_avatars = true;
OC.Share.showDropDown( avatarStub.reset();
'file', dialog.render();
123,
$container,
true,
31,
'shared_file_name.txt'
);
}); });
afterEach(function() { afterEach(function() {
@ -586,8 +512,8 @@ describe('OC.Share.ShareDialogView', function() {
it('test correct function calls', function() { it('test correct function calls', function() {
expect(avatarStub.calledTwice).toEqual(true); expect(avatarStub.calledTwice).toEqual(true);
expect(placeholderStub.calledTwice).toEqual(true); expect(placeholderStub.calledTwice).toEqual(true);
expect($('#shareWithList').children().length).toEqual(3); expect(dialog.$('#shareWithList').children().length).toEqual(3);
expect($('.avatar').length).toEqual(4); expect(dialog.$('.avatar').length).toEqual(4);
}); });
it('test avatar owner', function() { it('test avatar owner', function() {
@ -617,14 +543,7 @@ describe('OC.Share.ShareDialogView', function() {
describe('avatars disabled', function() { describe('avatars disabled', function() {
beforeEach(function() { beforeEach(function() {
OC.Share.showDropDown( dialog.render();
'file',
123,
$container,
true,
31,
'shared_file_name.txt'
);
}); });
it('no avatar classes', function() { it('no avatar classes', function() {
@ -634,104 +553,6 @@ describe('OC.Share.ShareDialogView', function() {
}); });
}); });
}); });
describe('"sharesChanged" event', function() {
var autocompleteOptions;
var handler;
beforeEach(function() {
handler = sinon.stub();
loadItemStub.returns({
reshare: [],
shares: [{
id: 100,
item_source: 123,
permissions: 31,
share_type: OC.Share.SHARE_TYPE_USER,
share_with: 'user1',
share_with_displayname: 'User One'
}]
});
OC.Share.showDropDown(
'file',
123,
$container,
true,
31,
'shared_file_name.txt'
);
$('#dropdown').on('sharesChanged', handler);
autocompleteOptions = autocompleteStub.getCall(0).args[0];
});
afterEach(function() {
autocompleteOptions = null;
handler = null;
});
it('triggers "sharesChanged" event when adding shares', function() {
// simulate autocomplete selection
autocompleteOptions.select(new $.Event('select'), {
item: {
label: 'User Two',
value: {
shareType: OC.Share.SHARE_TYPE_USER,
shareWith: 'user2'
}
}
});
fakeServer.requests[0].respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({status: 'success'})
);
expect(handler.calledOnce).toEqual(true);
var shares = handler.getCall(0).args[0].shares;
expect(shares).toBeDefined();
expect(shares[OC.Share.SHARE_TYPE_USER][0].share_with_displayname).toEqual('User One');
expect(shares[OC.Share.SHARE_TYPE_USER][1].share_with_displayname).toEqual('User Two');
expect(shares[OC.Share.SHARE_TYPE_GROUP]).not.toBeDefined();
});
it('triggers "sharesChanged" event when deleting shares', function() {
dialog.$el.find('.unshare:eq(0)').click();
fakeServer.requests[0].respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({status: 'success'})
);
expect(handler.calledOnce).toEqual(true);
var shares = handler.getCall(0).args[0].shares;
expect(shares).toBeDefined();
expect(shares[OC.Share.SHARE_TYPE_USER]).toEqual([]);
expect(shares[OC.Share.SHARE_TYPE_GROUP]).not.toBeDefined();
});
it('triggers "sharesChanged" event when toggling link share', function() {
// simulate autocomplete selection
dialog.$el.find('#linkCheckbox').click();
fakeServer.requests[0].respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({status: 'success', data: { token: 'abc' }})
);
expect(handler.calledOnce).toEqual(true);
var shares = handler.getCall(0).args[0].shares;
expect(shares).toBeDefined();
expect(shares[OC.Share.SHARE_TYPE_USER][0].share_with_displayname).toEqual('User One');
expect(shares[OC.Share.SHARE_TYPE_GROUP]).not.toBeDefined();
handler.reset();
// uncheck checkbox
dialog.$el.find('#linkCheckbox').click();
fakeServer.requests[1].respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({status: 'success'})
);
expect(handler.calledOnce).toEqual(true);
shares = handler.getCall(0).args[0].shares;
expect(shares).toBeDefined();
expect(shares[OC.Share.SHARE_TYPE_USER][0].share_with_displayname).toEqual('User One');
expect(shares[OC.Share.SHARE_TYPE_GROUP]).not.toBeDefined();
});
});
describe('share permissions', function() { describe('share permissions', function() {
beforeEach(function() { beforeEach(function() {
oc_appconfig.core.resharingAllowed = true; oc_appconfig.core.resharingAllowed = true;
@ -744,14 +565,11 @@ describe('OC.Share.ShareDialogView', function() {
* @return {int} permissions sent to the server * @return {int} permissions sent to the server
*/ */
function testWithPermissions(possiblePermissions) { function testWithPermissions(possiblePermissions) {
OC.Share.showDropDown( shareModel.set({
'file', permissions: possiblePermissions,
123, possiblePermissions: possiblePermissions
$container, });
true, dialog.render();
possiblePermissions,
'shared_file_name.txt'
);
var autocompleteOptions = autocompleteStub.getCall(0).args[0]; var autocompleteOptions = autocompleteStub.getCall(0).args[0];
// simulate autocomplete selection // simulate autocomplete selection
autocompleteOptions.select(new $.Event('select'), { autocompleteOptions.select(new $.Event('select'), {
@ -770,8 +588,8 @@ describe('OC.Share.ShareDialogView', function() {
describe('regular sharing', function() { describe('regular sharing', function() {
it('shares with given permissions with default config', function() { it('shares with given permissions with default config', function() {
loadItemStub.returns({ shareModel.set({
reshare: [], reshare: {},
shares: [] shares: []
}); });
expect( expect(
@ -782,9 +600,9 @@ describe('OC.Share.ShareDialogView', function() {
).toEqual(OC.PERMISSION_READ | OC.PERMISSION_SHARE); ).toEqual(OC.PERMISSION_READ | OC.PERMISSION_SHARE);
}); });
it('removes share permission when not allowed', function() { it('removes share permission when not allowed', function() {
oc_appconfig.core.resharingAllowed = false; configModel.set('isResharingAllowed', false);
loadItemStub.returns({ shareModel.set({
reshare: [], reshare: {},
shares: [] shares: []
}); });
expect( expect(
@ -792,9 +610,9 @@ describe('OC.Share.ShareDialogView', function() {
).toEqual(OC.PERMISSION_READ | OC.PERMISSION_UPDATE); ).toEqual(OC.PERMISSION_READ | OC.PERMISSION_UPDATE);
}); });
it('automatically adds READ permission even when not specified', function() { it('automatically adds READ permission even when not specified', function() {
oc_appconfig.core.resharingAllowed = false; configModel.set('isResharingAllowed', false);
loadItemStub.returns({ shareModel.set({
reshare: [], reshare: {},
shares: [] shares: []
}); });
expect( expect(
@ -802,108 +620,35 @@ describe('OC.Share.ShareDialogView', function() {
).toEqual(OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_UPDATE); ).toEqual(OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_UPDATE);
}); });
it('does not show sharing options when sharing not allowed', function() { it('does not show sharing options when sharing not allowed', function() {
loadItemStub.returns({ shareModel.set({
reshare: [], reshare: {},
shares: [] shares: [],
permissions: OC.PERMISSION_READ
}); });
OC.Share.showDropDown( dialog.render();
'file', expect(dialog.$el.find('#shareWith').prop('disabled')).toEqual(true);
123,
$container,
true,
OC.PERMISSION_READ,
'shared_file_name.txt'
);
expect(dialog.$el.find('#shareWithList').length).toEqual(0);
});
});
describe('resharing', function() {
it('shares with given permissions when original share had all permissions', function() {
loadItemStub.returns({
reshare: {
permissions: OC.PERMISSION_ALL
},
shares: []
});
expect(
testWithPermissions(OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_SHARE)
).toEqual(OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_SHARE);
});
it('reduces reshare permissions to the ones from the original share', function() {
loadItemStub.returns({
reshare: {
permissions: OC.PERMISSION_READ,
uid_owner: 'user1'
},
shares: []
});
OC.Share.showDropDown(
'file',
123,
$container,
true,
OC.PERMISSION_ALL,
'shared_file_name.txt'
);
// no resharing allowed
expect(dialog.$el.find('#shareWithList').length).toEqual(0);
});
it('reduces reshare permissions to possible permissions', function() {
loadItemStub.returns({
reshare: {
permissions: OC.PERMISSION_ALL,
uid_owner: 'user1'
},
shares: []
});
OC.Share.showDropDown(
'file',
123,
$container,
true,
OC.PERMISSION_READ,
'shared_file_name.txt'
);
// no resharing allowed
expect(dialog.$el.find('#shareWithList').length).toEqual(0);
}); });
it('does not show sharing options when resharing not allowed', function() { it('shows reshare owner', function() {
loadItemStub.returns({ shareModel.set({
reshare: { reshare: {
permissions: OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE,
uid_owner: 'user1' uid_owner: 'user1'
}, },
shares: [] shares: [],
permissions: OC.PERMISSION_READ
}); });
OC.Share.showDropDown( dialog.render();
'file', expect(dialog.$el.find('.resharerInfoView .reshare').length).toEqual(1);
123,
$container,
true,
OC.PERMISSION_ALL,
'shared_file_name.txt'
);
expect(dialog.$el.find('#shareWithList').length).toEqual(0);
}); });
it('allows owner to share their own share when they are also the recipient', function() { it('does not show reshare owner if owner is current user', function() {
OC.currentUser = 'user1'; shareModel.set({
loadItemStub.returns({
reshare: { reshare: {
permissions: OC.PERMISSION_READ, uid_owner: OC.currentUser
uid_owner: 'user1'
}, },
shares: [] shares: [],
permissions: OC.PERMISSION_READ
}); });
OC.Share.showDropDown( dialog.render();
'file', expect(dialog.$el.find('.resharerInfoView .reshare').length).toEqual(0);
123,
$container,
true,
OC.PERMISSION_ALL,
'shared_file_name.txt'
);
// sharing still allowed
expect(dialog.$el.find('#shareWithList').length).toEqual(1);
}); });
}); });
}); });

@ -23,13 +23,12 @@
describe('OC.Share.ShareItemModel', function() { describe('OC.Share.ShareItemModel', function() {
var loadItemStub; var loadItemStub;
var fileInfoModel, configModel, model; var fileInfoModel, configModel, model;
var oldCurrentUser;
beforeEach(function() { beforeEach(function() {
oldCurrentUser = OC.currentUser;
loadItemStub = sinon.stub(OC.Share, 'loadItem'); loadItemStub = sinon.stub(OC.Share, 'loadItem');
loadItemStub.returns({
reshare: [],
shares: []
});
fileInfoModel = new OCA.Files.FileInfoModel({ fileInfoModel = new OCA.Files.FileInfoModel({
id: 123, id: 123,
@ -54,6 +53,7 @@ describe('OC.Share.ShareItemModel', function() {
}); });
afterEach(function() { afterEach(function() {
loadItemStub.restore(); loadItemStub.restore();
OC.currentUser = oldCurrentUser;
}); });
describe('Fetching and parsing', function() { describe('Fetching and parsing', function() {
@ -64,7 +64,7 @@ describe('OC.Share.ShareItemModel', function() {
expect(loadItemStub.calledWith('file', 123)).toEqual(true); expect(loadItemStub.calledWith('file', 123)).toEqual(true);
}); });
it('populates attributes with parsed response', function() { it('populates attributes with parsed response', function() {
loadItemStub.returns({ loadItemStub.yields({
/* jshint camelcase: false */ /* jshint camelcase: false */
reshare: { reshare: {
share_type: OC.Share.SHARE_TYPE_USER, share_type: OC.Share.SHARE_TYPE_USER,
@ -118,7 +118,11 @@ describe('OC.Share.ShareItemModel', function() {
var shares = model.get('shares'); var shares = model.get('shares');
expect(shares.length).toEqual(3); expect(shares.length).toEqual(3);
expect(shares.file_source).toEqual(123); expect(shares[0].id).toEqual(100);
expect(shares[0].permissions).toEqual(31);
expect(shares[0].share_type).toEqual(OC.Share.SHARE_TYPE_USER);
expect(shares[0].share_with).toEqual('user1');
expect(shares[0].share_with_displayname).toEqual('User One');
var linkShare = model.get('linkShare'); var linkShare = model.get('linkShare');
expect(linkShare.isLinkShare).toEqual(true); expect(linkShare.isLinkShare).toEqual(true);
@ -126,7 +130,7 @@ describe('OC.Share.ShareItemModel', function() {
// TODO: check more attributes // TODO: check more attributes
}); });
it('does not parse link share when for a different file', function() { it('does not parse link share when for a different file', function() {
loadItemStub.returns({ loadItemStub.yields({
reshare: [], reshare: [],
/* jshint camelcase: false */ /* jshint camelcase: false */
shares: [{ shares: [{
@ -153,13 +157,14 @@ describe('OC.Share.ShareItemModel', function() {
model.fetch(); model.fetch();
var shares = model.get('shares'); var shares = model.get('shares');
expect(shares.length).toEqual(0); // remaining share appears in this list
expect(shares.length).toEqual(1);
var linkShare = model.get('linkShare'); var linkShare = model.get('linkShare');
expect(linkShare.isLinkShare).toEqual(false); expect(linkShare.isLinkShare).toEqual(false);
}); });
it('parsess correct link share when a nested link share exists along with parent one', function() { it('parses correct link share when a nested link share exists along with parent one', function() {
loadItemStub.returns({ loadItemStub.yields({
reshare: [], reshare: [],
/* jshint camelcase: false */ /* jshint camelcase: false */
shares: [{ shares: [{
@ -204,14 +209,58 @@ describe('OC.Share.ShareItemModel', function() {
model.fetch(); model.fetch();
var shares = model.get('shares'); var shares = model.get('shares');
expect(shares.length).toEqual(0); // the parent share remains in the list
expect(shares.length).toEqual(1);
var linkShare = model.get('linkShare'); var linkShare = model.get('linkShare');
expect(linkShare.isLinkShare).toEqual(false); expect(linkShare.isLinkShare).toEqual(true);
expect(linkShare.token).toEqual('tehtoken'); expect(linkShare.token).toEqual('tehtoken');
// TODO: check child too // TODO: check child too
}); });
it('reduces reshare permissions to the ones from the original share', function() {
loadItemStub.yields({
reshare: {
permissions: OC.PERMISSION_READ,
uid_owner: 'user1'
},
shares: []
});
model.fetch();
// no resharing allowed
expect(model.get('permissions')).toEqual(OC.PERMISSION_READ);
});
it('reduces reshare permissions to possible permissions', function() {
loadItemStub.yields({
reshare: {
permissions: OC.PERMISSION_ALL,
uid_owner: 'user1'
},
shares: []
});
model.set('possiblePermissions', OC.PERMISSION_READ);
model.fetch();
// no resharing allowed
expect(model.get('permissions')).toEqual(OC.PERMISSION_READ);
});
it('allows owner to share their own share when they are also the recipient', function() {
OC.currentUser = 'user1';
loadItemStub.yields({
reshare: {
permissions: OC.PERMISSION_READ,
uid_owner: 'user1'
},
shares: []
});
model.fetch();
// sharing still allowed
expect(model.get('permissions') & OC.PERMISSION_SHARE).toEqual(OC.PERMISSION_SHARE);
});
}); });
describe('Util', function() { describe('Util', function() {

Loading…
Cancel
Save