aboutsummaryrefslogtreecommitdiffstats
path: root/core/js/tests/specs/shareSpec.js
blob: 19e9a92ca9ed483584177f89595cf123bad1b668 (plain)
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/**
* ownCloud
*
* @author Vincent Petry
* @copyright 2014 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/>.
*
*/

/* global oc_appconfig */
describe('OC.Share tests', function() {
	describe('markFileAsShared', function() {
		var $file;
		var tooltipStub;

		beforeEach(function() {
			tooltipStub = sinon.stub($.fn, 'tooltip');
			$file = $('<tr><td class="filename"><div class="thumbnail"></div><span class="name">File name</span></td></tr>');
			$file.find('.filename').append(
				'<span class="fileactions">' +
				'<a href="#" class="action action-share" data-action="Share">' +
				'<img></img><span> Share</span>' +
				'</a>' +
				'</span>'
			);
		});
		afterEach(function() {
			$file = null;
			tooltipStub.restore();
		});
		describe('displaying the share owner', function() {
			function checkOwner(input, output, title) {
				var $action;

				$file.attr('data-share-owner', input);
				$file.attr('data-share-owner-id', input);
				OC.Share.markFileAsShared($file);

				$action = $file.find('.action-share>span').parent();
				expect($action.text().trim()).toEqual(output);
				if (_.isString(title)) {
					expect($action.find('.remoteAddress').attr('title')).toEqual(title);
				} else {
					expect($action.find('.remoteAddress').attr('title')).not.toBeDefined();
				}
				expect(tooltipStub.calledOnce).toEqual(true);
				tooltipStub.reset();
			}

			it('displays the local share owner with "Shared by" prefix', function() {
				checkOwner('User One', 'Shared by User One', null);
			});
			it('displays the user name part of a remote share owner', function() {
				checkOwner(
					'User One@someserver.com',
					'User One@…',
					'Shared by User One@someserver.com'
				);
				checkOwner(
					'User One@someserver.com/',
					'User One@…',
					'Shared by User One@someserver.com'
				);
				checkOwner(
					'User One@someserver.com/root/of/owncloud',
					'User One@…',
					'Shared by User One@someserver.com'
				);
			});
			it('displays the user name part with domain of a remote share owner', function() {
				checkOwner(
					'User One@example.com@someserver.com',
					'User One@example.com',
					'Shared by User One@example.com@someserver.com'
				);
				checkOwner(
					'User One@example.com@someserver.com/',
					'User One@example.com',
					'Shared by User One@example.com@someserver.com'
				);
				checkOwner(
					'User One@example.com@someserver.com/root/of/owncloud',
					'User One@example.com',
					'Shared by User One@example.com@someserver.com'
				);
			});
		});

		describe('displaying the folder icon', function() {
			function checkIcon(expectedImage) {
				var imageUrl = OC.TestUtil.getImageUrl($file.find('.filename .thumbnail'));
				expectedIcon = OC.imagePath('core', expectedImage);
				expect(imageUrl).toEqual(expectedIcon);
			}

			it('shows a plain folder icon for non-shared folders', function() {
				$file.attr('data-type', 'dir');
				OC.Share.markFileAsShared($file);

				checkIcon('filetypes/folder');
			});
			it('shows a shared folder icon for folders shared with another user', function() {
				$file.attr('data-type', 'dir');
				OC.Share.markFileAsShared($file, true);

				checkIcon('filetypes/folder-shared');
			});
			it('shows a shared folder icon for folders shared with the current user', function() {
				$file.attr('data-type', 'dir');
				$file.attr('data-share-owner', 'someoneelse');
				$file.attr('data-share-owner-id', 'someoneelse');
				OC.Share.markFileAsShared($file);

				checkIcon('filetypes/folder-shared');
			});
			it('shows a link folder icon for folders shared with link', function() {
				$file.attr('data-type', 'dir');
				OC.Share.markFileAsShared($file, false, true);

				checkIcon('filetypes/folder-public');
			});
			it('shows a link folder icon for folders shared with both link and another user', function() {
				$file.attr('data-type', 'dir');
				OC.Share.markFileAsShared($file, true, true);

				checkIcon('filetypes/folder-public');
			});
			it('shows a link folder icon for folders reshared with link', function() {
				$file.attr('data-type', 'dir');
				$file.attr('data-share-owner', 'someoneelse');
				OC.Share.markFileAsShared($file, false, true);

				checkIcon('filetypes/folder-public');
			});
			it('shows external storage icon if external mount point', function() {
				$file.attr('data-type', 'dir');
				$file.attr('data-mountType', 'external');
				OC.Share.markFileAsShared($file, false, false);

				checkIcon('filetypes/folder-external');
			});
		});

		describe('displaying the recipients', function() {
			function checkRecipients(input, output, title) {
				var $action;

				var concatenated = _.values(input).join(', ');
				$file.attr('data-share-recipients', concatenated);
				$file.attr('data-share-recipient-data', JSON.stringify(input));
				OC.Share.markFileAsShared($file, true);

				$action = $file.find('.action-share>span').parent();
				expect($action.text().trim()).toEqual(output);
				if (_.isString(title)) {
					expect($action.find('.remoteAddress').attr('title')).toEqual(title);
				} else if (_.isArray(title)) {
					var tooltips = $action.find('.remoteAddress');
					expect(tooltips.length).toEqual(title.length);

					tooltips.each(function(i) {
						expect($(this).attr('title')).toEqual(title[i]);
					});
				} else {
						expect($action.find('.remoteAddress').attr('title')).not.toBeDefined();
				}
				expect(tooltipStub.calledOnce).toEqual(true);
				tooltipStub.reset();
			}

			it('displays the local share owner as is', function() {
				checkRecipients({'User One': 'User One'}, 'Shared with User One', null);
			});
			it('displays the user name part of a remote recipient', function() {
				checkRecipients(
					{'User One@someserver.com': 'User One@someserver.com'},
					'User One@…',
					'Shared with User One@someserver.com'
				);
				checkRecipients(
					'{User One@someserver.com/: User One@someserver.com/}',
					'User One@…',
					'Shared with User One@someserver.com'
				);
				checkRecipients(
					{'User One@someserver.com/root/of/owncloud': 'User One@someserver.com/root/of/owncloud'},
					'User One@…',
					'Shared with User One@someserver.com'
				);
			});
			it('displays the user name part with domain of a remote share owner', function() {
				checkRecipients(
					{'User One@example.com@someserver.com': 'User One@example.com@someserver.com'},
					'User One@example.com',
					'Shared with User One@example.com@someserver.com'
				);
				checkRecipients(
					{'User One@example.com@someserver.com/': 'User One@example.com@someserver.com/'},
					'User One@example.com',
					'Shared with User One@example.com@someserver.com'
				);
				checkRecipients(
					{'User One@example.com@someserver.com/root/of/nextcloud': 'User One@example.com@someserver.com/root/of/nextcloud'},
					'User One@example.com',
					'Shared with User One@example.com@someserver.com'
				);
			});
			it('display multiple remote recipients', function() {
				checkRecipients(
					{
						'One@someserver.com': 'One@someserver.com',
						'two@otherserver.com': 'two@otherserver.com'
					},
					'One@… two@…',
					['Shared with One@someserver.com', 'Shared with two@otherserver.com']
				);
				checkRecipients(
					{
						'One@someserver.com/': 'One@someserver.com/',
						'two@otherserver.com': 'two@otherserver.com'
					},
					'One@… two@…',
					['Shared with One@someserver.com', 'Shared with two@otherserver.com']
				);
				checkRecipients(
					{
						'One@someserver.com/root/of/owncloud': 'One@someserver.com/root/of/owncloud',
						'two@otherserver.com': 'two@otherserver.com'
					},
					'One@… two@…',
					['Shared with One@someserver.com', 'Shared with two@otherserver.com']
				);
			});
			it('display mixed recipients', function() {
				checkRecipients(
					{
						'One': 'One',
						'two@otherserver.com': 'two@otherserver.com'
					},
					'Shared with One two@…',
					['Shared with two@otherserver.com']
				);
			});
			it('display multiple with divergent displaynames', function() {
				checkRecipients(
					{
						'One': 'Yoko Ono',
						'two@otherserver.com': 'two@otherserver.com',
						'Three': 'Green, Mina'
					},
					'Shared with Yoko Ono two@… Shared with Green, Mina',
					['Shared with two@otherserver.com']
				);
			});
		});
	});
});