-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Expand file tree
/
Copy pathsharedialogshareelistview.js
More file actions
243 lines (221 loc) · 7.4 KB
/
Copy pathsharedialogshareelistview.js
File metadata and controls
243 lines (221 loc) · 7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/**
* ownCloud
*
* @author Tom Needham
* @copyright 2015 Tom Needham <tom@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/>.
*
*/
/* global oc_appconfig */
describe('OC.Share.ShareDialogShareeListView', function () {
var oldCurrentUser;
var fileInfoModel;
var configModel;
var shareModel;
var listView;
var updateShareStub;
beforeEach(function () {
/* jshint camelcase:false */
oldAppConfig = _.extend({}, oc_appconfig.core);
oc_appconfig.core.enforcePasswordForPublicLink = false;
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
};
shareModel = new OC.Share.ShareItemModel(attributes, {
configModel: configModel,
fileInfoModel: fileInfoModel
});
configModel = new OC.Share.ShareConfigModel({
enforcePasswordForPublicLink: false,
isResharingAllowed: true,
isDefaultExpireDateEnabled: false,
isDefaultExpireDateEnforced: false,
defaultExpireDate: 7
});
listView = new OC.Share.ShareDialogShareeListView({
configModel: configModel,
model: shareModel
});
// required for proper event propagation when simulating clicks in some cases (jquery bugs)
$('#testArea').append(listView.$el);
shareModel.set({
linkShares: []
});
oldCurrentUser = OC.currentUser;
OC.currentUser = 'user0';
updateShareStub = sinon.stub(OC.Share.ShareItemModel.prototype, 'updateShare');
});
afterEach(function () {
OC.currentUser = oldCurrentUser;
/* jshint camelcase:false */
oc_appconfig.core = oldAppConfig;
listView.remove();
updateShareStub.restore();
});
describe('Sets correct initial checkbox state', function () {
it('marks edit box as unchecked for file shares without edit permissions', function () {
shareModel.set('shares', [{
id: 100,
item_source: 123,
permissions: 1,
share_type: OC.Share.SHARE_TYPE_USER,
share_with: 'user1',
share_with_displayname: 'User One',
uid_owner: oc_current_user,
itemType: 'file'
}]);
listView.render();
expect(listView.$el.find("input[name='edit']").is(':not(:checked)')).toEqual(true);
});
it('marks edit box as checked for file shares', function () {
shareModel.set('shares', [{
id: 100,
item_source: 123,
permissions: 1 | OC.PERMISSION_UPDATE,
share_type: OC.Share.SHARE_TYPE_USER,
share_with: 'user1',
share_with_displayname: 'User One',
uid_owner: oc_current_user,
itemType: 'file'
}]);
listView.render();
expect(listView.$el.find("input[name='edit']").is(':checked')).toEqual(true);
});
it('marks edit box as indeterminate when only some permissions are given', function () {
shareModel.set('shares', [{
id: 100,
item_source: 123,
permissions: 1 | OC.PERMISSION_UPDATE,
share_type: OC.Share.SHARE_TYPE_USER,
share_with: 'user1',
share_with_displayname: 'User One',
uid_owner: oc_current_user,
itemType: 'folder'
}]);
shareModel.set('itemType', 'folder');
listView.render();
expect(listView.$el.find("input[name='edit']").is(':indeterminate')).toEqual(true);
});
it('marks edit box as indeterminate when only some permissions are given for sharee with special characters', function () {
shareModel.set('shares', [{
id: 100,
item_source: 123,
permissions: 1 | OC.PERMISSION_UPDATE,
share_type: OC.Share.SHARE_TYPE_USER,
share_with: 'user _.@-\'',
share_with_displayname: 'User One',
uid_owner: oc_current_user,
itemType: 'folder'
}]);
shareModel.set('itemType', 'folder');
listView.render();
expect(listView.$el.find("input[name='edit']").is(':indeterminate')).toEqual(true);
});
it('Checks edit box when all permissions are given', function () {
shareModel.set('shares', [{
id: 100,
item_source: 123,
permissions: 1 | OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE,
share_type: OC.Share.SHARE_TYPE_USER,
share_with: 'user1',
share_with_displayname: 'User One',
uid_owner: oc_current_user,
itemType: 'folder'
}]);
shareModel.set('itemType', 'folder');
listView.render();
expect(listView.$el.find("input[name='edit']").is(':checked')).toEqual(true);
});
it('Checks edit box when all permissions are given for sharee with special characters', function () {
shareModel.set('shares', [{
id: 100,
item_source: 123,
permissions: 1 | OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE,
share_type: OC.Share.SHARE_TYPE_USER,
share_with: 'user _.@-\'',
share_with_displayname: 'User One',
uid_owner: oc_current_user,
itemType: 'folder'
}]);
shareModel.set('itemType', 'folder');
listView.render();
expect(listView.$el.find("input[name='edit']").is(':checked')).toEqual(true);
});
});
describe('Manages checkbox events correctly', function () {
it('Checks cruds boxes when edit box checked', function () {
shareModel.set('shares', [{
id: 100,
item_source: 123,
permissions: 1,
share_type: OC.Share.SHARE_TYPE_USER,
share_with: 'user1',
share_with_displayname: 'User One',
uid_owner: oc_current_user,
}]);
shareModel.set('itemType', 'folder');
listView.render();
listView.$el.find("input[name='edit']").click();
expect(listView.$el.find("input[name='update']").is(':checked')).toEqual(true);
expect(updateShareStub.calledOnce).toEqual(true);
});
it('marks edit box as indeterminate when some of create/update/delete are checked', function () {
shareModel.set('shares', [{
id: 100,
item_source: 123,
permissions: 1,
share_type: OC.Share.SHARE_TYPE_USER,
share_with: 'user1',
share_with_displayname: 'User One',
uid_owner: oc_current_user,
itemType: 'folder'
}]);
shareModel.set('itemType', 'folder');
listView.render();
listView.$el.find("input[name='update']").click();
expect(listView.$el.find("input[name='edit']").is(':indeterminate')).toEqual(true);
expect(updateShareStub.calledOnce).toEqual(true);
});
it('Checks edit box when all of create/update/delete are checked', function () {
shareModel.set('shares', [{
id: 100,
item_source: 123,
permissions: 1 | OC.PERMISSION_CREATE | OC.PERMISSION_DELETE,
share_type: OC.Share.SHARE_TYPE_USER,
share_with: 'user1',
share_with_displayname: 'User One',
uid_owner: oc_current_user,
itemType: 'folder'
}]);
shareModel.set('itemType', 'folder');
listView.render();
listView.$el.find("input[name='update']").click();
expect(listView.$el.find("input[name='edit']").is(':checked')).toEqual(true);
expect(updateShareStub.calledOnce).toEqual(true);
});
});
});