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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-05-03 09:42:42 +03:00
|
|
|
/* global sinon, OC */
|
2015-09-15 11:27:33 +03:00
|
|
|
describe('OC.Share.ShareDialogView', function() {
|
|
|
|
var $container;
|
2018-09-11 00:27:18 +03:00
|
|
|
var oldConfig;
|
2015-09-15 11:27:33 +03:00
|
|
|
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;
|
|
|
|
|
|
|
|
var configModel;
|
|
|
|
var shareModel;
|
|
|
|
var fileInfoModel;
|
|
|
|
var dialog;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
// horrible parameters
|
|
|
|
$('#testArea').append('<input id="allowShareWithLink" type="hidden" value="yes">');
|
|
|
|
$container = $('#shareContainer');
|
2019-05-02 09:28:24 +03:00
|
|
|
oldConfig = OC.config;
|
|
|
|
OC.config['sharing.maxAutocompleteResults'] = 0;
|
2015-09-15 11:27:33 +03:00
|
|
|
/* jshint camelcase:false */
|
2019-05-03 09:42:42 +03:00
|
|
|
oldAppConfig = _.extend({}, OC.appConfig.core);
|
|
|
|
OC.appConfig.core.enforcePasswordForPublicLink = false;
|
2015-09-15 11:27:33 +03:00
|
|
|
|
|
|
|
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: [],
|
2018-11-01 18:22:22 +03:00
|
|
|
linkShares: []
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
|
|
|
|
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;
|
2019-05-02 09:28:24 +03:00
|
|
|
OC.config = oldConfig;
|
2015-09-15 11:27:33 +03:00
|
|
|
/* jshint camelcase:false */
|
2019-05-03 09:42:42 +03:00
|
|
|
OC.appConfig.core = oldAppConfig;
|
2015-09-15 11:27:33 +03:00
|
|
|
|
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)
|
2018-11-16 18:19:13 +03:00
|
|
|
it('update password on enter', function() {
|
2015-09-15 11:27:33 +03:00
|
|
|
$('#allowShareWithLink').val('yes');
|
|
|
|
|
2018-11-01 18:22:22 +03:00
|
|
|
dialog.model.set({
|
|
|
|
linkShares: [{
|
|
|
|
id: 123
|
|
|
|
}]
|
2016-01-22 19:30:18 +03:00
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
dialog.render();
|
|
|
|
|
2018-11-16 18:19:13 +03:00
|
|
|
// Enable password and enter password
|
2015-09-15 11:27:33 +03:00
|
|
|
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');
|
2018-11-16 18:19:13 +03:00
|
|
|
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({
|
2018-11-01 18:22:22 +03:00
|
|
|
cid: 123,
|
2016-01-22 19:30:18 +03:00
|
|
|
password: 'foo'
|
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
2018-11-16 18:19:13 +03:00
|
|
|
it('update password on submit', function() {
|
2015-09-15 11:27:33 +03:00
|
|
|
$('#allowShareWithLink').val('yes');
|
|
|
|
|
2018-11-01 18:22:22 +03:00
|
|
|
dialog.model.set({
|
|
|
|
linkShares: [{
|
|
|
|
id: 123
|
|
|
|
}]
|
2016-01-22 19:30:18 +03:00
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
dialog.render();
|
|
|
|
|
|
|
|
// 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');
|
2018-11-16 18:19:13 +03:00
|
|
|
dialog.$el.find('.linkPassText + .icon-confirm').click();
|
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({
|
2018-11-01 18:22:22 +03:00
|
|
|
cid: 123,
|
2016-01-22 19:30:18 +03:00
|
|
|
password: 'foo'
|
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
2018-11-01 18:22:22 +03:00
|
|
|
it('shows add share with link button when allowed', function() {
|
2015-09-15 11:27:33 +03:00
|
|
|
$('#allowShareWithLink').val('yes');
|
|
|
|
|
|
|
|
dialog.render();
|
|
|
|
|
2018-11-01 18:22:22 +03:00
|
|
|
expect(dialog.$el.find('.new-share').length).toEqual(1);
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
2018-11-01 18:22:22 +03:00
|
|
|
it('does not show add share with link button when not allowed', function() {
|
2015-09-15 11:27:33 +03:00
|
|
|
$('#allowShareWithLink').val('no');
|
|
|
|
|
|
|
|
dialog.render();
|
|
|
|
|
2018-11-01 18:22:22 +03:00
|
|
|
expect(dialog.$el.find('.new-share').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 +
|
2018-11-01 18:22:22 +03:00
|
|
|
OC.generateUrl('/s/') + 'thetoken';
|
|
|
|
shareModel.set({
|
|
|
|
linkShares: [{
|
|
|
|
id: 123,
|
|
|
|
url: link
|
|
|
|
}]
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
|
|
|
|
2015-09-15 16:29:30 +03:00
|
|
|
dialog.render();
|
|
|
|
|
2018-11-01 18:22:22 +03:00
|
|
|
expect(dialog.$el.find('.share-menu .icon-more').length).toEqual(1);
|
2015-10-16 11:54:45 +03:00
|
|
|
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');
|
|
|
|
|
2018-11-01 18:22:22 +03:00
|
|
|
dialog.model.set({
|
|
|
|
linkShares: [{
|
|
|
|
id: 123
|
|
|
|
}]
|
2016-01-22 19:30:18 +03:00
|
|
|
});
|
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-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'
|
2017-06-06 14:21:42 +03:00
|
|
|
},{
|
|
|
|
id: 103,
|
|
|
|
item_source: 123,
|
|
|
|
permissions: 31,
|
|
|
|
share_type: OC.Share.SHARE_TYPE_CIRCLE,
|
|
|
|
share_with: 'circle-0',
|
|
|
|
share_with_displayname: 'Circle (Personal circle, user0)',
|
|
|
|
share_with_avatar: 'path/to/the/avatar'
|
|
|
|
},{
|
|
|
|
id: 104,
|
|
|
|
item_source: 123,
|
|
|
|
permissions: 31,
|
|
|
|
share_type: OC.Share.SHARE_TYPE_CIRCLE,
|
|
|
|
share_with: 'circle-1',
|
|
|
|
share_with_displayname: 'Circle (Public circle, user0)',
|
2015-09-15 11:27:33 +03:00
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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() {
|
2017-06-06 14:21:42 +03:00
|
|
|
expect(avatarStub.calledThrice).toEqual(true);
|
2017-02-14 02:49:05 +03:00
|
|
|
expect(placeholderStub.callCount).toEqual(4);
|
2018-07-20 12:22:24 +03:00
|
|
|
expect(dialog.$('.shareWithList').children().length).toEqual(6);
|
|
|
|
expect(dialog.$('.avatar').length).toEqual(7);
|
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);
|
|
|
|
});
|
2017-06-06 14:21:42 +03:00
|
|
|
|
|
|
|
it('test avatar for circle', function() {
|
2018-08-24 23:05:43 +03:00
|
|
|
var avatarElement = dialog.$('.avatar').eq(5);
|
2017-06-06 14:21:42 +03:00
|
|
|
expect(avatarElement.css('background')).toContain('path/to/the/avatar');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('test avatar for circle without avatar', function() {
|
|
|
|
var args = avatarStub.getCall(2).args;
|
|
|
|
expect(args.length).toEqual(6);
|
|
|
|
// Note that "data-username" is set to "circle-{shareIndex}",
|
|
|
|
// not to the "shareWith" field.
|
|
|
|
expect(args[0]).toEqual('circle-4');
|
|
|
|
expect(args[5]).toEqual('Circle (Public circle, user0)');
|
|
|
|
});
|
2015-09-15 11:27:33 +03:00
|
|
|
});
|
|
|
|
});
|
Return also exact matches besides all suggestions
"_getSuggestions" returned all the suggestions from the server, which
are composed by exact matches and partial matches. Now the exact matches
are also returned on their own parameter. This will be used by the
button to confirm a share.
Note that until now the order of the suggestions was "exact users,
partial users, exact groups, partial groups, exact..."; this commit also
changes that order to become "exact users, exact groups, exact...,
partial users, partial groups, partial...". This is not a problem, as
the suggestions were used in the autocomplete dropdown, and this new
order is arguably better than the old one, as all exact matches appear
now at the beginning.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2018-03-19 19:16:11 +03:00
|
|
|
describe('get suggestions', function() {
|
|
|
|
it('no matches', function() {
|
|
|
|
var doneStub = sinon.stub();
|
|
|
|
var failStub = sinon.stub();
|
|
|
|
|
|
|
|
dialog._getSuggestions('bob', 42, shareModel).done(doneStub).fail(failStub);
|
|
|
|
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
Return also exact matches besides all suggestions
"_getSuggestions" returned all the suggestions from the server, which
are composed by exact matches and partial matches. Now the exact matches
are also returned on their own parameter. This will be used by the
button to confirm a share.
Note that until now the order of the suggestions was "exact users,
partial users, exact groups, partial groups, exact..."; this commit also
changes that order to become "exact users, exact groups, exact...,
partial users, partial groups, partial...". This is not a problem, as
the suggestions were used in the autocomplete dropdown, and this new
order is arguably better than the old one, as all exact matches appear
now at the beginning.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2018-03-19 19:16:11 +03:00
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2019-02-21 23:36:14 +03:00
|
|
|
'lookup': [],
|
|
|
|
'lookupEnabled': true,
|
Return also exact matches besides all suggestions
"_getSuggestions" returned all the suggestions from the server, which
are composed by exact matches and partial matches. Now the exact matches
are also returned on their own parameter. This will be used by the
button to confirm a share.
Note that until now the order of the suggestions was "exact users,
partial users, exact groups, partial groups, exact..."; this commit also
changes that order to become "exact users, exact groups, exact...,
partial users, partial groups, partial...". This is not a problem, as
the suggestions were used in the autocomplete dropdown, and this new
order is arguably better than the old one, as all exact matches appear
now at the beginning.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2018-03-19 19:16:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(doneStub.called).toEqual(false);
|
|
|
|
expect(failStub.called).toEqual(false);
|
|
|
|
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(doneStub.calledOnce).toEqual(true);
|
2019-02-21 23:36:14 +03:00
|
|
|
sinon.assert.calledWithExactly(doneStub, [{
|
|
|
|
label: t('core', 'Search globally'),
|
|
|
|
value: {},
|
|
|
|
lookup: true
|
|
|
|
}], [], false, true);
|
Return also exact matches besides all suggestions
"_getSuggestions" returned all the suggestions from the server, which
are composed by exact matches and partial matches. Now the exact matches
are also returned on their own parameter. This will be used by the
button to confirm a share.
Note that until now the order of the suggestions was "exact users,
partial users, exact groups, partial groups, exact..."; this commit also
changes that order to become "exact users, exact groups, exact...,
partial users, partial groups, partial...". This is not a problem, as
the suggestions were used in the autocomplete dropdown, and this new
order is arguably better than the old one, as all exact matches appear
now at the beginning.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2018-03-19 19:16:11 +03:00
|
|
|
expect(failStub.called).toEqual(false);
|
|
|
|
});
|
2018-09-11 00:27:18 +03:00
|
|
|
|
Return also exact matches besides all suggestions
"_getSuggestions" returned all the suggestions from the server, which
are composed by exact matches and partial matches. Now the exact matches
are also returned on their own parameter. This will be used by the
button to confirm a share.
Note that until now the order of the suggestions was "exact users,
partial users, exact groups, partial groups, exact..."; this commit also
changes that order to become "exact users, exact groups, exact...,
partial users, partial groups, partial...". This is not a problem, as
the suggestions were used in the autocomplete dropdown, and this new
order is arguably better than the old one, as all exact matches appear
now at the beginning.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2018-03-19 19:16:11 +03:00
|
|
|
it('single partial match', function() {
|
|
|
|
var doneStub = sinon.stub();
|
|
|
|
var failStub = sinon.stub();
|
|
|
|
|
|
|
|
dialog._getSuggestions('bob', 42, shareModel).done(doneStub).fail(failStub);
|
|
|
|
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
Return also exact matches besides all suggestions
"_getSuggestions" returned all the suggestions from the server, which
are composed by exact matches and partial matches. Now the exact matches
are also returned on their own parameter. This will be used by the
button to confirm a share.
Note that until now the order of the suggestions was "exact users,
partial users, exact groups, partial groups, exact..."; this commit also
changes that order to become "exact users, exact groups, exact...,
partial users, partial groups, partial...". This is not a problem, as
the suggestions were used in the autocomplete dropdown, and this new
order is arguably better than the old one, as all exact matches appear
now at the beginning.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2018-03-19 19:16:11 +03:00
|
|
|
},
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bobby',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'imbob'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2019-02-21 23:36:14 +03:00
|
|
|
'lookup': [],
|
|
|
|
'lookupEnabled': true,
|
Return also exact matches besides all suggestions
"_getSuggestions" returned all the suggestions from the server, which
are composed by exact matches and partial matches. Now the exact matches
are also returned on their own parameter. This will be used by the
button to confirm a share.
Note that until now the order of the suggestions was "exact users,
partial users, exact groups, partial groups, exact..."; this commit also
changes that order to become "exact users, exact groups, exact...,
partial users, partial groups, partial...". This is not a problem, as
the suggestions were used in the autocomplete dropdown, and this new
order is arguably better than the old one, as all exact matches appear
now at the beginning.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2018-03-19 19:16:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(doneStub.called).toEqual(false);
|
|
|
|
expect(failStub.called).toEqual(false);
|
|
|
|
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(doneStub.calledOnce).toEqual(true);
|
2019-02-21 23:36:14 +03:00
|
|
|
sinon.assert.calledWithExactly(doneStub,
|
2018-09-11 00:27:18 +03:00
|
|
|
[{
|
|
|
|
'label': 'bobby',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
|
2019-02-21 23:36:14 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('core', 'Search globally'),
|
|
|
|
value: {},
|
|
|
|
lookup: true
|
2018-09-11 00:27:18 +03:00
|
|
|
}],
|
|
|
|
[],
|
2019-02-21 23:36:14 +03:00
|
|
|
false,
|
|
|
|
true
|
|
|
|
);
|
Return also exact matches besides all suggestions
"_getSuggestions" returned all the suggestions from the server, which
are composed by exact matches and partial matches. Now the exact matches
are also returned on their own parameter. This will be used by the
button to confirm a share.
Note that until now the order of the suggestions was "exact users,
partial users, exact groups, partial groups, exact..."; this commit also
changes that order to become "exact users, exact groups, exact...,
partial users, partial groups, partial...". This is not a problem, as
the suggestions were used in the autocomplete dropdown, and this new
order is arguably better than the old one, as all exact matches appear
now at the beginning.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2018-03-19 19:16:11 +03:00
|
|
|
expect(failStub.called).toEqual(false);
|
|
|
|
});
|
|
|
|
it('single exact match', function() {
|
|
|
|
var doneStub = sinon.stub();
|
|
|
|
var failStub = sinon.stub();
|
|
|
|
|
|
|
|
dialog._getSuggestions('bob', 42, shareModel).done(doneStub).fail(failStub);
|
|
|
|
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'user1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
Return also exact matches besides all suggestions
"_getSuggestions" returned all the suggestions from the server, which
are composed by exact matches and partial matches. Now the exact matches
are also returned on their own parameter. This will be used by the
button to confirm a share.
Note that until now the order of the suggestions was "exact users,
partial users, exact groups, partial groups, exact..."; this commit also
changes that order to become "exact users, exact groups, exact...,
partial users, partial groups, partial...". This is not a problem, as
the suggestions were used in the autocomplete dropdown, and this new
order is arguably better than the old one, as all exact matches appear
now at the beginning.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2018-03-19 19:16:11 +03:00
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2019-02-21 23:36:14 +03:00
|
|
|
'lookup': [],
|
|
|
|
'lookupEnabled': true,
|
Return also exact matches besides all suggestions
"_getSuggestions" returned all the suggestions from the server, which
are composed by exact matches and partial matches. Now the exact matches
are also returned on their own parameter. This will be used by the
button to confirm a share.
Note that until now the order of the suggestions was "exact users,
partial users, exact groups, partial groups, exact..."; this commit also
changes that order to become "exact users, exact groups, exact...,
partial users, partial groups, partial...". This is not a problem, as
the suggestions were used in the autocomplete dropdown, and this new
order is arguably better than the old one, as all exact matches appear
now at the beginning.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2018-03-19 19:16:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(doneStub.called).toEqual(false);
|
|
|
|
expect(failStub.called).toEqual(false);
|
|
|
|
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(doneStub.calledOnce).toEqual(true);
|
2019-02-21 23:36:14 +03:00
|
|
|
sinon.assert.calledWithExactly(doneStub,
|
2018-09-11 00:27:18 +03:00
|
|
|
[{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
|
2019-02-21 23:36:14 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('core', 'Search globally'),
|
|
|
|
value: {},
|
|
|
|
lookup: true
|
2018-09-11 00:27:18 +03:00
|
|
|
}],
|
|
|
|
[{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
|
|
|
|
}],
|
2019-02-21 23:36:14 +03:00
|
|
|
false,
|
|
|
|
true
|
|
|
|
);
|
Return also exact matches besides all suggestions
"_getSuggestions" returned all the suggestions from the server, which
are composed by exact matches and partial matches. Now the exact matches
are also returned on their own parameter. This will be used by the
button to confirm a share.
Note that until now the order of the suggestions was "exact users,
partial users, exact groups, partial groups, exact..."; this commit also
changes that order to become "exact users, exact groups, exact...,
partial users, partial groups, partial...". This is not a problem, as
the suggestions were used in the autocomplete dropdown, and this new
order is arguably better than the old one, as all exact matches appear
now at the beginning.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2018-03-19 19:16:11 +03:00
|
|
|
expect(failStub.called).toEqual(false);
|
|
|
|
});
|
|
|
|
it('mixed matches', function() {
|
|
|
|
var doneStub = sinon.stub();
|
|
|
|
var failStub = sinon.stub();
|
|
|
|
|
|
|
|
dialog._getSuggestions('bob', 42, shareModel).done(doneStub).fail(failStub);
|
|
|
|
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'user1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_GROUP,
|
|
|
|
'shareWith': 'group1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
Return also exact matches besides all suggestions
"_getSuggestions" returned all the suggestions from the server, which
are composed by exact matches and partial matches. Now the exact matches
are also returned on their own parameter. This will be used by the
button to confirm a share.
Note that until now the order of the suggestions was "exact users,
partial users, exact groups, partial groups, exact..."; this commit also
changes that order to become "exact users, exact groups, exact...,
partial users, partial groups, partial...". This is not a problem, as
the suggestions were used in the autocomplete dropdown, and this new
order is arguably better than the old one, as all exact matches appear
now at the beginning.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2018-03-19 19:16:11 +03:00
|
|
|
},
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bobby',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'imbob'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'label': 'bob the second',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'user2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [
|
|
|
|
{
|
|
|
|
'label': 'bobfans',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_GROUP,
|
|
|
|
'shareWith': 'fans'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2019-02-21 23:36:14 +03:00
|
|
|
'lookup': [],
|
|
|
|
'lookupEnabled': true
|
Return also exact matches besides all suggestions
"_getSuggestions" returned all the suggestions from the server, which
are composed by exact matches and partial matches. Now the exact matches
are also returned on their own parameter. This will be used by the
button to confirm a share.
Note that until now the order of the suggestions was "exact users,
partial users, exact groups, partial groups, exact..."; this commit also
changes that order to become "exact users, exact groups, exact...,
partial users, partial groups, partial...". This is not a problem, as
the suggestions were used in the autocomplete dropdown, and this new
order is arguably better than the old one, as all exact matches appear
now at the beginning.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2018-03-19 19:16:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(doneStub.called).toEqual(false);
|
|
|
|
expect(failStub.called).toEqual(false);
|
|
|
|
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(doneStub.calledOnce).toEqual(true);
|
2019-02-21 23:36:14 +03:00
|
|
|
sinon.assert.calledWithExactly(doneStub,
|
2018-09-11 00:27:18 +03:00
|
|
|
[{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
|
|
|
|
}, {
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group1'}
|
|
|
|
}, {
|
|
|
|
'label': 'bobby',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
|
|
|
|
}, {
|
|
|
|
'label': 'bob the second',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user2'}
|
|
|
|
}, {
|
|
|
|
'label': 'bobfans',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'fans'}
|
2019-02-21 23:36:14 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('core', 'Search globally'),
|
|
|
|
value: {},
|
|
|
|
lookup: true
|
2018-09-11 00:27:18 +03:00
|
|
|
}],
|
|
|
|
[{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
|
|
|
|
}, {
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group1'}
|
|
|
|
}],
|
2019-02-21 23:36:14 +03:00
|
|
|
false,
|
|
|
|
true
|
|
|
|
);
|
2018-09-11 00:27:18 +03:00
|
|
|
expect(failStub.called).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('capped mixed matches', function() {
|
2019-05-02 09:28:24 +03:00
|
|
|
OC.config['sharing.maxAutocompleteResults'] = 3;
|
2018-09-11 00:27:18 +03:00
|
|
|
var doneStub = sinon.stub();
|
|
|
|
var failStub = sinon.stub();
|
|
|
|
|
|
|
|
dialog._getSuggestions('bob', 42, shareModel).done(doneStub).fail(failStub);
|
|
|
|
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'user1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_GROUP,
|
|
|
|
'shareWith': 'group1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
|
|
|
},
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bobby',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'imbob'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'label': 'bob the second',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'user2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [
|
|
|
|
{
|
|
|
|
'label': 'bobfans',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_GROUP,
|
|
|
|
'shareWith': 'fans'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2019-02-21 23:36:14 +03:00
|
|
|
'lookup': [],
|
|
|
|
'lookupEnabled': true
|
2018-09-11 00:27:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(doneStub.called).toEqual(false);
|
|
|
|
expect(failStub.called).toEqual(false);
|
|
|
|
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(doneStub.calledOnce).toEqual(true);
|
2019-02-21 23:36:14 +03:00
|
|
|
sinon.assert.calledWithExactly(doneStub,
|
2018-09-11 00:27:18 +03:00
|
|
|
[{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
|
|
|
|
}, {
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group1'}
|
|
|
|
}, {
|
|
|
|
'label': 'bobby',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
|
|
|
|
}, {
|
|
|
|
'label': 'bob the second',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user2'}
|
|
|
|
}, {
|
|
|
|
'label': 'bobfans',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'fans'}
|
2019-02-21 23:36:14 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('core', 'Search globally'),
|
|
|
|
value: {},
|
|
|
|
lookup: true
|
2018-09-11 00:27:18 +03:00
|
|
|
}],
|
|
|
|
[{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
|
|
|
|
}, {
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group1'}
|
|
|
|
}],
|
2019-02-21 23:36:14 +03:00
|
|
|
true,
|
2018-09-11 00:27:18 +03:00
|
|
|
true
|
2019-02-21 23:36:14 +03:00
|
|
|
);
|
Return also exact matches besides all suggestions
"_getSuggestions" returned all the suggestions from the server, which
are composed by exact matches and partial matches. Now the exact matches
are also returned on their own parameter. This will be used by the
button to confirm a share.
Note that until now the order of the suggestions was "exact users,
partial users, exact groups, partial groups, exact..."; this commit also
changes that order to become "exact users, exact groups, exact...,
partial users, partial groups, partial...". This is not a problem, as
the suggestions were used in the autocomplete dropdown, and this new
order is arguably better than the old one, as all exact matches appear
now at the beginning.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2018-03-19 19:16:11 +03:00
|
|
|
expect(failStub.called).toEqual(false);
|
|
|
|
});
|
2018-03-20 15:14:26 +03:00
|
|
|
|
|
|
|
it('does not send a request to the server again for the same parameters', function() {
|
|
|
|
var doneStub = sinon.stub();
|
|
|
|
var failStub = sinon.stub();
|
|
|
|
|
|
|
|
dialog._getSuggestions('bob', 42, shareModel).done(doneStub).fail(failStub);
|
|
|
|
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'user1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2018-03-20 15:14:26 +03:00
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2019-02-21 23:36:14 +03:00
|
|
|
'lookup': [],
|
|
|
|
'lookupEnabled': true
|
2018-03-20 15:14:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(doneStub.called).toEqual(false);
|
|
|
|
expect(failStub.called).toEqual(false);
|
|
|
|
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(doneStub.calledOnce).toEqual(true);
|
2018-09-11 00:27:18 +03:00
|
|
|
expect(doneStub.calledWithExactly(
|
|
|
|
[{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
|
2019-02-21 23:36:14 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('core', 'Search globally'),
|
|
|
|
value: {},
|
|
|
|
lookup: true
|
|
|
|
}],
|
|
|
|
[{
|
2018-09-11 00:27:18 +03:00
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
|
|
|
|
}],
|
2019-02-21 23:36:14 +03:00
|
|
|
false,
|
|
|
|
true
|
2018-09-11 00:27:18 +03:00
|
|
|
)).toEqual(true);
|
2018-03-20 15:14:26 +03:00
|
|
|
expect(failStub.called).toEqual(false);
|
|
|
|
|
|
|
|
var done2Stub = sinon.stub();
|
|
|
|
var fail2Stub = sinon.stub();
|
|
|
|
|
|
|
|
dialog._getSuggestions('bob', 42, shareModel).done(done2Stub).fail(fail2Stub);
|
|
|
|
|
|
|
|
expect(doneStub.calledOnce).toEqual(true);
|
|
|
|
expect(failStub.called).toEqual(false);
|
|
|
|
|
|
|
|
expect(done2Stub.calledOnce).toEqual(true);
|
2019-02-21 23:36:14 +03:00
|
|
|
sinon.assert.calledWithExactly(doneStub,
|
2018-09-11 00:27:18 +03:00
|
|
|
[{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
|
2019-02-21 23:36:14 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('core', 'Search globally'),
|
|
|
|
value: {},
|
|
|
|
lookup: true
|
2018-09-11 00:27:18 +03:00
|
|
|
}],
|
|
|
|
[{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
|
|
|
|
}],
|
2019-02-21 23:36:14 +03:00
|
|
|
false,
|
|
|
|
true
|
|
|
|
);
|
2018-03-20 15:14:26 +03:00
|
|
|
expect(fail2Stub.called).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sends a request to the server again for the same parameters if the calls are not consecutive', function() {
|
|
|
|
var doneStub = sinon.stub();
|
|
|
|
var failStub = sinon.stub();
|
|
|
|
|
|
|
|
dialog._getSuggestions('bob', 42, shareModel).done(doneStub).fail(failStub);
|
|
|
|
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'user1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2018-03-20 15:14:26 +03:00
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2019-02-21 23:36:14 +03:00
|
|
|
'lookup': [],
|
|
|
|
'lookupEnabled': true
|
2018-03-20 15:14:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(doneStub.called).toEqual(false);
|
|
|
|
expect(failStub.called).toEqual(false);
|
|
|
|
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(doneStub.calledOnce).toEqual(true);
|
2019-02-21 23:36:14 +03:00
|
|
|
sinon.assert.calledWithExactly(doneStub,
|
2018-09-11 00:27:18 +03:00
|
|
|
[{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
|
2019-02-21 23:36:14 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('core', 'Search globally'),
|
|
|
|
value: {},
|
|
|
|
lookup: true
|
2018-09-11 00:27:18 +03:00
|
|
|
}],
|
|
|
|
[{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
|
|
|
|
}],
|
2019-02-21 23:36:14 +03:00
|
|
|
false,
|
|
|
|
true
|
|
|
|
);
|
2018-03-20 15:14:26 +03:00
|
|
|
expect(failStub.called).toEqual(false);
|
|
|
|
|
|
|
|
var done2Stub = sinon.stub();
|
|
|
|
var fail2Stub = sinon.stub();
|
|
|
|
|
|
|
|
dialog._getSuggestions('bob', 108, shareModel).done(done2Stub).fail(fail2Stub);
|
|
|
|
|
|
|
|
expect(done2Stub.called).toEqual(false);
|
|
|
|
expect(fail2Stub.called).toEqual(false);
|
|
|
|
|
|
|
|
fakeServer.requests[1].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(done2Stub.calledOnce).toEqual(true);
|
|
|
|
expect(fail2Stub.called).toEqual(false);
|
|
|
|
|
|
|
|
var done3Stub = sinon.stub();
|
|
|
|
var fail3Stub = sinon.stub();
|
|
|
|
|
|
|
|
dialog._getSuggestions('bob', 42, shareModel).done(done3Stub).fail(fail3Stub);
|
|
|
|
|
|
|
|
expect(done3Stub.called).toEqual(false);
|
|
|
|
expect(fail3Stub.called).toEqual(false);
|
|
|
|
|
|
|
|
fakeServer.requests[2].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(doneStub.calledOnce).toEqual(true);
|
|
|
|
expect(failStub.called).toEqual(false);
|
|
|
|
expect(done2Stub.calledOnce).toEqual(true);
|
|
|
|
expect(fail2Stub.called).toEqual(false);
|
|
|
|
|
|
|
|
expect(done3Stub.calledOnce).toEqual(true);
|
2019-02-21 23:36:14 +03:00
|
|
|
sinon.assert.calledWithExactly(done3Stub,
|
2018-09-11 00:27:18 +03:00
|
|
|
[{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
|
2019-02-21 23:36:14 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('core', 'Search globally'),
|
|
|
|
value: {},
|
|
|
|
lookup: true
|
2018-09-11 00:27:18 +03:00
|
|
|
}],
|
|
|
|
[{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
|
|
|
|
}],
|
2019-02-21 23:36:14 +03:00
|
|
|
false,
|
|
|
|
true
|
|
|
|
);
|
2018-03-20 15:14:26 +03:00
|
|
|
expect(fail3Stub.called).toEqual(false);
|
|
|
|
});
|
Return also exact matches besides all suggestions
"_getSuggestions" returned all the suggestions from the server, which
are composed by exact matches and partial matches. Now the exact matches
are also returned on their own parameter. This will be used by the
button to confirm a share.
Note that until now the order of the suggestions was "exact users,
partial users, exact groups, partial groups, exact..."; this commit also
changes that order to become "exact users, exact groups, exact...,
partial users, partial groups, partial...". This is not a problem, as
the suggestions were used in the autocomplete dropdown, and this new
order is arguably better than the old one, as all exact matches appear
now at the beginning.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2018-03-19 19:16:11 +03:00
|
|
|
});
|
2015-10-27 14:26:49 +03:00
|
|
|
describe('autocompletion of users', function() {
|
2018-03-19 17:28:15 +03:00
|
|
|
var showTemporaryNotificationStub;
|
2018-03-19 16:12:06 +03:00
|
|
|
|
|
|
|
beforeEach(function() {
|
2019-05-22 14:29:38 +03:00
|
|
|
showTemporaryNotificationStub = sinon.stub(OC.Notification, 'showTemporary');
|
2018-03-19 16:12:06 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
2018-03-19 17:28:15 +03:00
|
|
|
showTemporaryNotificationStub.restore();
|
2018-03-19 16:12:06 +03:00
|
|
|
});
|
|
|
|
|
2018-03-16 19:19:34 +03:00
|
|
|
describe('triggers autocomplete display and focus with data when ajax search succeeds', function () {
|
|
|
|
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
|
2015-12-23 12:49:27 +03:00
|
|
|
},
|
2018-03-16 19:19:34 +03:00
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'user1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:34 +03:00
|
|
|
},
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bobby',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'imbob'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2019-02-21 23:36:14 +03:00
|
|
|
'lookup': [],
|
|
|
|
'lookupEnabled': true
|
2018-03-16 19:19:34 +03:00
|
|
|
}
|
2015-12-23 12:49:27 +03:00
|
|
|
}
|
2018-03-16 19:19:34 +03:00
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
2019-02-21 23:36:14 +03:00
|
|
|
sinon.assert.calledWithExactly(response, [{
|
2018-03-16 19:19:34 +03:00
|
|
|
'label': 'bob',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
|
|
|
|
}, {
|
|
|
|
'label': 'bobby',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
|
2019-02-21 23:36:14 +03:00
|
|
|
}, {
|
|
|
|
label: t('core', 'Search globally'),
|
|
|
|
value: {},
|
|
|
|
lookup: true
|
|
|
|
}]);
|
2018-03-16 19:19:34 +03:00
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
2015-10-21 15:46:08 +03:00
|
|
|
});
|
2018-03-16 19:19:34 +03:00
|
|
|
|
|
|
|
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': [
|
|
|
|
{
|
|
|
|
'label': 'group',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_GROUP,
|
|
|
|
'shareWith': 'group'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:34 +03:00
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [
|
|
|
|
{
|
|
|
|
'label': 'group2',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_GROUP,
|
|
|
|
'shareWith': 'group2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2019-02-21 23:36:14 +03:00
|
|
|
'lookup': [],
|
|
|
|
'lookupEnabled': true
|
2018-03-16 19:19:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
2015-10-21 15:46:08 +03:00
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
2018-03-16 19:19:34 +03:00
|
|
|
);
|
2019-02-21 23:36:14 +03:00
|
|
|
sinon.assert.calledWithExactly(response, [{
|
2018-03-16 19:19:34 +03:00
|
|
|
'label': 'group',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group'}
|
|
|
|
}, {
|
|
|
|
'label': 'group2',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group2'}
|
2019-02-21 23:36:14 +03:00
|
|
|
}, {
|
|
|
|
label: t('core', 'Search globally'),
|
|
|
|
value: {},
|
|
|
|
lookup: true
|
|
|
|
}]);
|
2018-03-16 19:19:34 +03:00
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('remotes', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
|
|
|
dialog.autocompleteHandler({term: 'foo@bar.com/baz'}, response);
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [
|
|
|
|
{
|
|
|
|
'label': 'foo@bar.com/baz',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_REMOTE,
|
|
|
|
'shareWith': 'foo@bar.com/baz'
|
|
|
|
}
|
|
|
|
}
|
2018-07-04 14:13:36 +03:00
|
|
|
],
|
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:34 +03:00
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [
|
|
|
|
{
|
|
|
|
'label': 'foo@bar.com/baz2',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_REMOTE,
|
|
|
|
'shareWith': 'foo@bar.com/baz2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:34 +03:00
|
|
|
'lookup': []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
expect(response.calledWithExactly([{
|
|
|
|
'label': 'foo@bar.com/baz',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_REMOTE, 'shareWith': 'foo@bar.com/baz'}
|
|
|
|
}, {
|
|
|
|
'label': 'foo@bar.com/baz2',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_REMOTE, 'shareWith': 'foo@bar.com/baz2'}
|
|
|
|
}])).toEqual(true);
|
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('emails', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
|
|
|
dialog.autocompleteHandler({term: 'foo@bar.com'}, response);
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:34 +03:00
|
|
|
'emails': [
|
|
|
|
{
|
|
|
|
'label': 'foo@bar.com',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_EMAIL,
|
|
|
|
'shareWith': 'foo@bar.com'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:34 +03:00
|
|
|
'lookup': [],
|
|
|
|
'emails': [
|
|
|
|
{
|
|
|
|
'label': 'foo@bar.com2',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_EMAIL,
|
|
|
|
'shareWith': 'foo@bar.com2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
expect(response.calledWithExactly([{
|
|
|
|
'label': 'foo@bar.com',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_EMAIL, 'shareWith': 'foo@bar.com'}
|
|
|
|
}, {
|
|
|
|
'label': 'foo@bar.com2',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_EMAIL, 'shareWith': 'foo@bar.com2'}
|
|
|
|
}])).toEqual(true);
|
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('circles', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
|
|
|
dialog.autocompleteHandler({term: 'CircleName'}, response);
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:34 +03:00
|
|
|
'circles': [
|
|
|
|
{
|
|
|
|
'label': 'CircleName (type, owner)',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_CIRCLE,
|
|
|
|
'shareWith': 'shortId'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'label': 'CircleName (type2, owner)',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_CIRCLE,
|
|
|
|
'shareWith': 'shortId2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:34 +03:00
|
|
|
'lookup': [],
|
|
|
|
'circles': [
|
|
|
|
{
|
|
|
|
'label': 'CircleName2 (type, owner)',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_CIRCLE,
|
|
|
|
'shareWith': 'shortId3'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
expect(response.calledWithExactly([{
|
|
|
|
'label': 'CircleName (type, owner)',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_CIRCLE, 'shareWith': 'shortId'}
|
|
|
|
}, {
|
|
|
|
'label': 'CircleName (type2, owner)',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_CIRCLE, 'shareWith': 'shortId2'}
|
|
|
|
}, {
|
|
|
|
'label': 'CircleName2 (type, owner)',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_CIRCLE, 'shareWith': 'shortId3'}
|
|
|
|
}])).toEqual(true);
|
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
2015-10-21 15:46:08 +03:00
|
|
|
});
|
|
|
|
|
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': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2015-12-30 12:46:19 +03:00
|
|
|
},
|
|
|
|
'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': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
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': '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': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2015-12-30 12:46:19 +03:00
|
|
|
},
|
|
|
|
'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': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
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': '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'
|
2018-03-16 19:19:22 +03:00
|
|
|
},{
|
|
|
|
id: 103,
|
|
|
|
item_source: 123,
|
|
|
|
permissions: 31,
|
|
|
|
share_type: OC.Share.SHARE_TYPE_EMAIL,
|
|
|
|
share_with: 'foo@bar.com',
|
|
|
|
share_with_displayname: 'foo@bar.com'
|
|
|
|
},{
|
|
|
|
id: 104,
|
|
|
|
item_source: 123,
|
|
|
|
permissions: 31,
|
|
|
|
share_type: OC.Share.SHARE_TYPE_CIRCLE,
|
|
|
|
share_with: 'shortId',
|
|
|
|
share_with_displayname: 'CircleName (type, owner)'
|
2015-12-30 12:46:19 +03:00
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('users', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
2018-03-16 16:59:01 +03:00
|
|
|
dialog.autocompleteHandler({term: 'bo'}, response);
|
2015-12-30 12:46:19 +03:00
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2015-12-30 12:46:19 +03:00
|
|
|
},
|
|
|
|
'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': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
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': 'bobby',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
|
|
|
|
}])).toEqual(true);
|
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
|
|
|
|
2018-03-16 19:19:29 +03:00
|
|
|
it('users (exact)', 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': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'user1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:29 +03:00
|
|
|
},
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bobby',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'imbob'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:29 +03:00
|
|
|
'lookup': []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2015-12-30 12:46:19 +03:00
|
|
|
it('groups', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
2018-03-16 16:59:01 +03:00
|
|
|
dialog.autocompleteHandler({term: 'grou'}, response);
|
2015-12-30 12:46:19 +03:00
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2015-12-30 12:46:19 +03:00
|
|
|
},
|
|
|
|
'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': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
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': 'group2',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group2'}
|
|
|
|
}])).toEqual(true);
|
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
|
|
|
|
2018-03-16 19:19:29 +03:00
|
|
|
it('groups (exact)', 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': [
|
|
|
|
{
|
|
|
|
'label': 'group',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_GROUP,
|
|
|
|
'shareWith': 'group'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:29 +03:00
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [
|
|
|
|
{
|
|
|
|
'label': 'group2',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_GROUP,
|
|
|
|
'shareWith': 'group2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:29 +03:00
|
|
|
'lookup': []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2015-12-30 12:46:19 +03:00
|
|
|
it('remotes', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
2018-03-16 16:59:01 +03:00
|
|
|
dialog.autocompleteHandler({term: 'foo'}, response);
|
2015-12-30 12:46:19 +03:00
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2015-12-30 12:46:19 +03:00
|
|
|
},
|
|
|
|
'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
|
|
|
],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
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);
|
|
|
|
});
|
2018-03-16 19:19:22 +03:00
|
|
|
|
2018-03-16 19:19:29 +03:00
|
|
|
it('remotes (exact)', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
|
|
|
dialog.autocompleteHandler({term: 'foo@bar.com/baz'}, response);
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [
|
|
|
|
{
|
|
|
|
'label': 'foo@bar.com/baz',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_REMOTE,
|
|
|
|
'shareWith': 'foo@bar.com/baz'
|
|
|
|
}
|
|
|
|
}
|
2018-07-04 14:13:36 +03:00
|
|
|
],
|
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:29 +03:00
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [
|
|
|
|
{
|
|
|
|
'label': 'foo@bar.com/baz2',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_REMOTE,
|
|
|
|
'shareWith': 'foo@bar.com/baz2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:29 +03:00
|
|
|
'lookup': []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
expect(response.calledWithExactly([{
|
|
|
|
'label': 'foo@bar.com/baz2',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_REMOTE, 'shareWith': 'foo@bar.com/baz2'}
|
|
|
|
}])).toEqual(true);
|
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
|
|
|
|
2018-03-16 19:19:22 +03:00
|
|
|
it('emails', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
|
|
|
dialog.autocompleteHandler({term: 'foo'}, response);
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:22 +03:00
|
|
|
'emails': []
|
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
|
|
|
'lookup': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:22 +03:00
|
|
|
'emails': [
|
|
|
|
{
|
|
|
|
'label': 'foo@bar.com',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_EMAIL,
|
|
|
|
'shareWith': 'foo@bar.com'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'label': 'foo2@bar.com',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_EMAIL,
|
|
|
|
'shareWith': 'foo2@bar.com'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
expect(response.calledWithExactly([{
|
|
|
|
'label': 'foo2@bar.com',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_EMAIL, 'shareWith': 'foo2@bar.com'}
|
|
|
|
}])).toEqual(true);
|
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
|
|
|
|
2018-03-16 19:19:29 +03:00
|
|
|
it('emails (exact)', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
|
|
|
dialog.autocompleteHandler({term: 'foo@bar.com'}, response);
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:29 +03:00
|
|
|
'emails': [
|
|
|
|
{
|
|
|
|
'label': 'foo@bar.com',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_EMAIL,
|
|
|
|
'shareWith': 'foo@bar.com'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:29 +03:00
|
|
|
'lookup': [],
|
|
|
|
'emails': [
|
|
|
|
{
|
|
|
|
'label': 'foo@bar.com2',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_EMAIL,
|
|
|
|
'shareWith': 'foo@bar.com2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
expect(response.calledWithExactly([{
|
|
|
|
'label': 'foo@bar.com2',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_EMAIL, 'shareWith': 'foo@bar.com2'}
|
|
|
|
}])).toEqual(true);
|
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
|
|
|
|
2018-03-16 19:19:22 +03:00
|
|
|
it('circles', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
|
|
|
dialog.autocompleteHandler({term: 'CircleNam'}, response);
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:22 +03:00
|
|
|
'circles': []
|
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:22 +03:00
|
|
|
'lookup': [],
|
|
|
|
'circles': [
|
|
|
|
{
|
|
|
|
'label': 'CircleName (type, owner)',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_CIRCLE,
|
|
|
|
'shareWith': 'shortId'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'label': 'CircleName (type2, owner)',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_CIRCLE,
|
|
|
|
'shareWith': 'shortId2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
expect(response.calledWithExactly([{
|
|
|
|
'label': 'CircleName (type2, owner)',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_CIRCLE, 'shareWith': 'shortId2'}
|
|
|
|
}])).toEqual(true);
|
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
2018-03-16 19:19:29 +03:00
|
|
|
|
|
|
|
it('circles (exact)', function () {
|
|
|
|
dialog.render();
|
|
|
|
var response = sinon.stub();
|
|
|
|
dialog.autocompleteHandler({term: 'CircleName'}, response);
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:29 +03:00
|
|
|
'circles': [
|
|
|
|
{
|
|
|
|
'label': 'CircleName (type, owner)',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_CIRCLE,
|
|
|
|
'shareWith': 'shortId'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'label': 'CircleName (type2, owner)',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_CIRCLE,
|
|
|
|
'shareWith': 'shortId2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-16 19:19:29 +03:00
|
|
|
'lookup': [],
|
|
|
|
'circles': [
|
|
|
|
{
|
|
|
|
'label': 'CircleName2 (type, owner)',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_CIRCLE,
|
|
|
|
'shareWith': 'shortId3'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
expect(response.calledWithExactly([{
|
|
|
|
'label': 'CircleName (type2, owner)',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_CIRCLE, 'shareWith': 'shortId2'}
|
|
|
|
}, {
|
|
|
|
'label': 'CircleName2 (type, owner)',
|
|
|
|
'value': {'shareType': OC.Share.SHARE_TYPE_CIRCLE, 'shareWith': 'shortId3'}
|
|
|
|
}])).toEqual(true);
|
|
|
|
expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true);
|
|
|
|
});
|
2015-12-30 12:46:19 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-19 17:36:08 +03:00
|
|
|
it('throws a notification for a successful ajax call with failure content', function () {
|
2015-10-21 15:46:08 +03:00
|
|
|
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',
|
2018-03-19 17:36:08 +03:00
|
|
|
'statuscode': 400,
|
|
|
|
'message': 'error message'
|
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
|
|
|
|
);
|
2018-03-19 17:36:08 +03:00
|
|
|
expect(response.called).toEqual(false);
|
|
|
|
expect(showTemporaryNotificationStub.calledOnce).toEqual(true);
|
|
|
|
expect(showTemporaryNotificationStub.firstCall.args[0]).toContain('error message');
|
2015-10-21 15:46:08 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('throws a notification when the ajax search lookup fails', function () {
|
|
|
|
dialog.render();
|
|
|
|
dialog.autocompleteHandler({term: 'bob'}, sinon.stub());
|
|
|
|
fakeServer.requests[0].respond(500);
|
2018-03-19 17:28:15 +03:00
|
|
|
expect(showTemporaryNotificationStub.calledOnce).toEqual(true);
|
2015-10-21 15:46:08 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
2018-03-20 18:58:04 +03:00
|
|
|
|
|
|
|
it('hides the loading icon when all the pending operations finish', function() {
|
|
|
|
dialog.render();
|
|
|
|
|
|
|
|
expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
|
|
|
|
expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
|
|
|
|
|
|
|
|
var response = sinon.stub();
|
|
|
|
dialog.autocompleteHandler({term: 'bob'}, response);
|
|
|
|
dialog.autocompleteHandler({term: 'bobby'}, response);
|
|
|
|
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2018-03-20 18:58:04 +03:00
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-20 18:58:04 +03:00
|
|
|
'lookup': []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(false);
|
|
|
|
expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(true);
|
|
|
|
|
|
|
|
fakeServer.requests[1].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
|
|
|
|
expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
|
|
|
|
});
|
2016-01-22 19:30:18 +03:00
|
|
|
});
|
2018-03-19 20:54:27 +03:00
|
|
|
describe('confirm share', function() {
|
|
|
|
var addShareStub;
|
|
|
|
var tooltipStub;
|
|
|
|
var showTemporaryNotificationStub;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
addShareStub = sinon.stub(shareModel, 'addShare');
|
|
|
|
|
|
|
|
tooltipStub = sinon.stub($.fn, 'tooltip').callsFake(function() {
|
|
|
|
return $('<div></div>');
|
|
|
|
});
|
|
|
|
|
|
|
|
showTemporaryNotificationStub = sinon.stub(OC.Notification, 'showTemporary');
|
|
|
|
|
|
|
|
dialog.render();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
addShareStub.restore();
|
|
|
|
tooltipStub.restore();
|
|
|
|
showTemporaryNotificationStub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the appropriate UI state while waiting to get the suggestions', function() {
|
|
|
|
expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
|
|
|
|
expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
|
|
|
|
expect(autocompleteStub.callCount).toEqual(1);
|
|
|
|
expect(typeof autocompleteStub.firstCall.args[0]).toEqual('object');
|
|
|
|
expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(false);
|
|
|
|
|
|
|
|
dialog.$el.find('.shareWithField').val('bob');
|
|
|
|
|
|
|
|
dialog._confirmShare();
|
|
|
|
|
|
|
|
expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(false);
|
|
|
|
expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(true);
|
2018-03-20 14:02:49 +03:00
|
|
|
expect(autocompleteStub.lastCall.args[0]).toEqual('disable');
|
|
|
|
expect(autocompleteStub.calledWith('close')).toEqual(true);
|
2018-03-19 20:54:27 +03:00
|
|
|
expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(true);
|
|
|
|
expect(dialog.$el.find('.shareWithField').val()).toEqual('bob');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls addShare with the only suggestion', function() {
|
|
|
|
dialog.$el.find('.shareWithField').val('bob');
|
|
|
|
|
|
|
|
dialog._confirmShare();
|
|
|
|
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'user1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2018-03-19 20:54:27 +03:00
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-19 20:54:27 +03:00
|
|
|
'lookup': []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
// Ensure that the UI is not restored before adding the share
|
|
|
|
expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(false);
|
|
|
|
expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(true);
|
2018-03-20 14:02:49 +03:00
|
|
|
expect(autocompleteStub.lastCall.args[0]).toEqual('disable');
|
2018-03-19 20:54:27 +03:00
|
|
|
expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(true);
|
|
|
|
expect(dialog.$el.find('.shareWithField').val()).toEqual('bob');
|
|
|
|
|
|
|
|
expect(addShareStub.calledOnce).toEqual(true);
|
|
|
|
expect(addShareStub.firstCall.args[0]).toEqual({
|
|
|
|
shareType: OC.Share.SHARE_TYPE_USER,
|
|
|
|
shareWith: 'user1'
|
|
|
|
});
|
|
|
|
|
|
|
|
// "yield" and "callArg" from SinonJS can not be used, as the
|
|
|
|
// callback is a property not in the first argument.
|
|
|
|
addShareStub.firstCall.args[1]['success'].apply(shareModel);
|
|
|
|
|
|
|
|
expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
|
|
|
|
expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
|
2018-03-20 14:02:49 +03:00
|
|
|
expect(autocompleteStub.lastCall.args[0]).toEqual('enable');
|
2018-03-19 20:54:27 +03:00
|
|
|
expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(false);
|
|
|
|
expect(dialog.$el.find('.shareWithField').val()).toEqual('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles a failure to share', function() {
|
|
|
|
expect(showTemporaryNotificationStub.called).toEqual(false);
|
|
|
|
|
|
|
|
dialog.$el.find('.shareWithField').val('bob');
|
|
|
|
|
|
|
|
dialog._confirmShare();
|
|
|
|
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'user1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2018-03-19 20:54:27 +03:00
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-19 20:54:27 +03:00
|
|
|
'lookup': []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
// Ensure that the UI is not restored before adding the share
|
|
|
|
expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(false);
|
|
|
|
expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(true);
|
2018-03-20 14:02:49 +03:00
|
|
|
expect(autocompleteStub.lastCall.args[0]).toEqual('disable');
|
2018-03-19 20:54:27 +03:00
|
|
|
expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(true);
|
|
|
|
expect(dialog.$el.find('.shareWithField').val()).toEqual('bob');
|
|
|
|
|
|
|
|
expect(addShareStub.calledOnce).toEqual(true);
|
|
|
|
expect(addShareStub.firstCall.args[0]).toEqual({
|
|
|
|
shareType: OC.Share.SHARE_TYPE_USER,
|
|
|
|
shareWith: 'user1'
|
|
|
|
});
|
|
|
|
|
|
|
|
// "yield" and "callArg" from SinonJS can not be used, as the
|
|
|
|
// callback is a property not in the first argument.
|
|
|
|
addShareStub.firstCall.args[1]['error'].apply(shareModel);
|
|
|
|
|
|
|
|
expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
|
|
|
|
expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
|
2018-03-20 14:02:49 +03:00
|
|
|
expect(autocompleteStub.lastCall.args[0]).toEqual('enable');
|
2018-03-19 20:54:27 +03:00
|
|
|
expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(false);
|
|
|
|
expect(dialog.$el.find('.shareWithField').val()).toEqual('bob');
|
|
|
|
|
|
|
|
expect(showTemporaryNotificationStub.calledOnce).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('restores UI if there are no matches at all', function() {
|
|
|
|
dialog.$el.find('.shareWithField').val('bob');
|
|
|
|
|
|
|
|
dialog._confirmShare();
|
|
|
|
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2018-03-19 20:54:27 +03:00
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'lookup': [],
|
|
|
|
'remote_groups': [],
|
2018-03-19 20:54:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(addShareStub.called).toEqual(false);
|
|
|
|
|
|
|
|
expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
|
|
|
|
expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
|
2018-03-20 14:02:49 +03:00
|
|
|
expect(autocompleteStub.lastCall.args[0]).toEqual('enable');
|
2018-03-19 20:54:27 +03:00
|
|
|
expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(false);
|
|
|
|
expect(dialog.$el.find('.shareWithField').val()).toEqual('bob');
|
|
|
|
|
|
|
|
// No explicit tooltip is shown; it is automatically shown when the
|
|
|
|
// autocomplete is activated again and it finds no matches.
|
|
|
|
expect(tooltipStub.lastCall.args[0]).not.toEqual('show');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows tooltip if there are matches but no exact matches', function() {
|
|
|
|
dialog.$el.find('.shareWithField').val('bo');
|
|
|
|
|
|
|
|
dialog._confirmShare();
|
|
|
|
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2018-03-19 20:54:27 +03:00
|
|
|
},
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'user1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-19 20:54:27 +03:00
|
|
|
'lookup': []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(addShareStub.called).toEqual(false);
|
|
|
|
|
|
|
|
expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
|
|
|
|
expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
|
2018-03-20 14:02:49 +03:00
|
|
|
expect(autocompleteStub.lastCall.args[0]).toEqual('enable');
|
2018-03-19 20:54:27 +03:00
|
|
|
expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(false);
|
|
|
|
expect(dialog.$el.find('.shareWithField').val()).toEqual('bo');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows tooltip if there is more than one exact match', function() {
|
|
|
|
dialog.$el.find('.shareWithField').val('bob');
|
|
|
|
|
|
|
|
dialog._confirmShare();
|
|
|
|
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs': {
|
|
|
|
'meta': {
|
|
|
|
'status': 'success',
|
|
|
|
'statuscode': 100,
|
|
|
|
'message': null
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'exact': {
|
|
|
|
'users': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_USER,
|
|
|
|
'shareWith': 'user1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'groups': [
|
|
|
|
{
|
|
|
|
'label': 'bob',
|
|
|
|
'value': {
|
|
|
|
'shareType': OC.Share.SHARE_TYPE_GROUP,
|
|
|
|
'shareWith': 'group1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remotes': [],
|
|
|
|
'remote_groups': [],
|
2018-03-19 20:54:27 +03:00
|
|
|
},
|
|
|
|
'users': [],
|
|
|
|
'groups': [],
|
|
|
|
'remotes': [],
|
2018-07-04 14:13:36 +03:00
|
|
|
'remote_groups': [],
|
2018-03-19 20:54:27 +03:00
|
|
|
'lookup': []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(addShareStub.called).toEqual(false);
|
|
|
|
|
|
|
|
expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
|
|
|
|
expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
|
2018-03-20 14:02:49 +03:00
|
|
|
expect(autocompleteStub.lastCall.args[0]).toEqual('enable');
|
2018-03-19 20:54:27 +03:00
|
|
|
expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(false);
|
|
|
|
expect(dialog.$el.find('.shareWithField').val()).toEqual('bob');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws a notification for a successful ajax call with failure content', function () {
|
|
|
|
dialog.$el.find('.shareWithField').val('bob');
|
|
|
|
|
|
|
|
dialog._confirmShare();
|
|
|
|
|
|
|
|
var jsonData = JSON.stringify({
|
|
|
|
'ocs' : {
|
|
|
|
'meta' : {
|
|
|
|
'status': 'failure',
|
|
|
|
'statuscode': 400,
|
|
|
|
'message': 'error message'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fakeServer.requests[0].respond(
|
|
|
|
200,
|
|
|
|
{'Content-Type': 'application/json'},
|
|
|
|
jsonData
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(addShareStub.called).toEqual(false);
|
|
|
|
|
|
|
|
expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
|
|
|
|
expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
|
2018-03-20 14:02:49 +03:00
|
|
|
expect(autocompleteStub.lastCall.args[0]).toEqual('enable');
|
2018-03-19 20:54:27 +03:00
|
|
|
expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(false);
|
|
|
|
expect(dialog.$el.find('.shareWithField').val()).toEqual('bob');
|
|
|
|
|
|
|
|
expect(showTemporaryNotificationStub.called).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws a notification when the ajax search lookup fails', function () {
|
|
|
|
dialog.$el.find('.shareWithField').val('bob');
|
|
|
|
|
|
|
|
dialog._confirmShare();
|
|
|
|
|
|
|
|
fakeServer.requests[0].respond(500);
|
|
|
|
|
|
|
|
expect(addShareStub.called).toEqual(false);
|
|
|
|
|
|
|
|
expect(dialog.$el.find('.shareWithLoading').hasClass('hidden')).toEqual(true);
|
|
|
|
expect(dialog.$el.find('.shareWithConfirm').hasClass('hidden')).toEqual(false);
|
2018-03-20 14:02:49 +03:00
|
|
|
expect(autocompleteStub.lastCall.args[0]).toEqual('enable');
|
2018-03-19 20:54:27 +03:00
|
|
|
expect(dialog.$el.find('.shareWithField').prop('disabled')).toEqual(false);
|
|
|
|
expect(dialog.$el.find('.shareWithField').val()).toEqual('bob');
|
|
|
|
|
|
|
|
expect(showTemporaryNotificationStub.called).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
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
|
|
|
});
|