summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/tests/js/shareSpec.js
blob: 604a4bb2bb60d1412d8d9b7dd570885ff85016da (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
/*
 * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
 *
 * This file is licensed under the Affero General Public License version 3
 * or later.
 *
 * See the COPYING-README file.
 *
 */

describe('OCA.Sharing.Util tests', function() {
	var oldFileListPrototype;
	var fileList;
	var testFiles;

	beforeEach(function() {
		// back up prototype, as it will be extended by
		// the sharing code
		oldFileListPrototype = _.extend({}, OCA.Files.FileList.prototype);

		var $content = $('<div id="content"></div>');
		$('#testArea').append($content);
		// dummy file list
		var $div = $(
			'<div>' +
			'<table id="filestable">' +
			'<thead></thead>' +
			'<tbody id="fileList"></tbody>' +
			'</table>' +
			'</div>');
		$('#content').append($div);

		var fileActions = new OCA.Files.FileActions();
		OCA.Sharing.Util.initialize(fileActions);
		fileList = new OCA.Files.FileList(
			$div, {
				fileActions : fileActions
			}
		);

		testFiles = [{
			id: 1,
			type: 'file',
			name: 'One.txt',
			path: '/subdir',
			mimetype: 'text/plain',
			size: 12,
			permissions: 31,
			etag: 'abc',
			shareOwner: 'User One',
			isShareMountPoint: false
		}];

		OCA.Sharing.sharesLoaded = true;
		OC.Share.statuses = {
			1: {link: false, path: '/subdir'}
		};
	});
	afterEach(function() {
		OCA.Files.FileList.prototype = oldFileListPrototype;
		delete OCA.Sharing.sharesLoaded;
		OC.Share.statuses = {};
	});

	describe('Sharing data in table row', function() {
		// TODO: test data-permissions, data-share-owner, etc
	});
	describe('Share action icon', function() {
		it('do not shows share text when not shared', function() {
			var $action;
			OC.Share.statuses = {};
			fileList.setFiles([{
				id: 1,
				type: 'file',
				name: 'One.txt',
				path: '/subdir',
				mimetype: 'text/plain',
				size: 12,
				permissions: 31,
				etag: 'abc'
			}]);
			$action = fileList.$el.find('tbody tr:first .action-share');
			expect($action.hasClass('permanent')).toEqual(false);
			expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
		});
		it('shows simple share text with share icon', function() {
			var $action;
			fileList.setFiles([{
				id: 1,
				type: 'file',
				name: 'One.txt',
				path: '/subdir',
				mimetype: 'text/plain',
				size: 12,
				permissions: 31,
				etag: 'abc'
			}]);
			$action = fileList.$el.find('tbody tr:first .action-share');
			expect($action.hasClass('permanent')).toEqual(true);
			expect($action.find('>span').text()).toEqual('Shared');
			expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
		});
		it('shows simple share text with public icon when shared with link', function() {
			var $action;
			OC.Share.statuses = {1: {link: true, path: '/subdir'}};
			fileList.setFiles([{
				id: 1,
				type: 'file',
				name: 'One.txt',
				path: '/subdir',
				mimetype: 'text/plain',
				size: 12,
				permissions: 31,
				etag: 'abc'
			}]);
			$action = fileList.$el.find('tbody tr:first .action-share');
			expect($action.hasClass('permanent')).toEqual(true);
			expect($action.find('>span').text()).toEqual('Shared');
			expect(OC.basename($action.find('img').attr('src'))).toEqual('public.svg');
		});
		it('shows owner name when owner is available', function() {
			var $action;
			fileList.setFiles([{
				id: 1,
				type: 'file',
				name: 'One.txt',
				path: '/subdir',
				mimetype: 'text/plain',
				size: 12,
				permissions: 31,
				shareOwner: 'User One',
				etag: 'abc'
			}]);
			$action = fileList.$el.find('tbody tr:first .action-share');
			expect($action.hasClass('permanent')).toEqual(true);
			expect($action.find('>span').text()).toEqual('Shared by User One');
			expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
		});
		it('shows recipients when recipients are available', function() {
			var $action;
			fileList.setFiles([{
				id: 1,
				type: 'file',
				name: 'One.txt',
				path: '/subdir',
				mimetype: 'text/plain',
				size: 12,
				permissions: 31,
				recipientsDisplayName: 'User One, User Two',
				etag: 'abc'
			}]);
			$action = fileList.$el.find('tbody tr:first .action-share');
			expect($action.hasClass('permanent')).toEqual(true);
			expect($action.find('>span').text()).toEqual('Shared with User One, User Two');
			expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
		});
	});
	describe('Share action', function() {
		// TODO: test file action / dropdown trigger
		it('updates share icon when shares were changed in dropdown', function() {
			fileList.setFiles(testFiles);
			fileList.$el.find('tr:first .action-share').click();
		});
	});
	describe('formatRecipients', function() {
		it('returns a single recipient when one passed', function() {
			expect(OCA.Sharing.Util.formatRecipients(['User one']))
				.toEqual('User one');
		});
		it('returns two recipients when two passed', function() {
			expect(OCA.Sharing.Util.formatRecipients(['User one', 'User two']))
				.toEqual('User one, User two');
		});
		it('returns four recipients with plus when five passed', function() {
			var recipients = [
				'User one',
				'User two',
				'User three',
				'User four',
				'User five'
			];
			expect(OCA.Sharing.Util.formatRecipients(recipients))
				.toEqual('User four, User one, User three, User two, +1');
		});
		it('returns four recipients with plus when ten passed', function() {
			var recipients = [
				'User one',
				'User two',
				'User three',
				'User four',
				'User five',
				'User six',
				'User seven',
				'User eight',
				'User nine',
				'User ten'
			];
			expect(OCA.Sharing.Util.formatRecipients(recipients))
				.toEqual('User four, User one, User three, User two, +6');
		});
		it('returns four recipients with plus when four passed with counter', function() {
			var recipients = [
				'User one',
				'User two',
				'User three',
				'User four'
			];
			expect(OCA.Sharing.Util.formatRecipients(recipients, 10))
				.toEqual('User four, User one, User three, User two, +6');
		});
	});
	
});