Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mountsfilelistSpec.js « js « tests « files_external « apps - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 663574481477e98a0d1ab0bd760a7a76e9400762 (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
/**
 * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
 *
 * @author Christoph Wurst <christoph@winzerhof-wurst.at>
 * @author Joas Schilling <coding@schilljs.com>
 * @author Vincent Petry <vincent@nextcloud.com>
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program 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 program. If not, see <http://www.gnu.org/licenses/>.
 *
 */

describe('OCA.Files_External.FileList tests', function() {
	var testFiles, alertStub, notificationStub, fileList;

	beforeEach(function() {
		alertStub = sinon.stub(OC.dialogs, 'alert');
		notificationStub = sinon.stub(OC.Notification, 'show');

		// init parameters and test table elements
		$('#testArea').append(
			'<div id="app-content-container">' +
			// init horrible parameters
			'<input type="hidden" id="dir" value="/"></input>' +
			'<input type="hidden" id="permissions" value="31"></input>' +
			// dummy controls
			'<div id="controls">' +
			'   <div class="actions creatable"></div>' +
			'   <div class="notCreatable"></div>' +
			'</div>' +
			// dummy table
			// TODO: at some point this will be rendered by the fileList class itself!
			'<table id="filestable">' +
			'<thead><tr>' +
			'<th id="headerName" class="hidden column-name">' +
			'	<div id="headerName-container">' +
			'		<a class="name sort columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' +
			'	</div>' +
			'</th>' +
			'<th id="headerBackend" class="hidden column-backend">' +
			'	<a class="backend sort columntitle" data-sort="backend"><span>Storage type</span><span class="sort-indicator"></span></a>' +
			'</th>' +
			'<th id="headerScope" class="hidden column-scope column-last">' +
			'	<a class="scope sort columntitle" data-sort="scope"><span>Scope</span><span class="sort-indicator"></span></a>' +
			'</th>' +
			'</tr></thead>' +
			'<tbody id="fileList"></tbody>' +
			'<tfoot></tfoot>' +
			'</table>' +
			'<div id="emptycontent">Empty content message</div>' +
			'</div>'
		);
	});
	afterEach(function() {
		testFiles = undefined;
		fileList.destroy();
		fileList = undefined;

		notificationStub.restore();
		alertStub.restore();
	});

	describe('loading file list for external storage', function() {
		var ocsResponse;
		var reloading;

		beforeEach(function() {
			fileList = new OCA.Files_External.FileList(
				$('#app-content-container')
			);

			reloading = fileList.reload();

			/* jshint camelcase: false */
			ocsResponse = {
				ocs: {
					meta: {
						status: 'ok',
						statuscode: 100,
						message: null
					},
					data: [{
						name: 'smb mount',
						path: '/mount points',
						type: 'dir',
						backend: 'SMB',
						scope: 'personal',
						permissions: OC.PERMISSION_READ | OC.PERMISSION_DELETE
					}, {
						name: 'sftp mount',
						path: '/another mount points',
						type: 'dir',
						backend: 'SFTP',
						scope: 'system',
						permissions: OC.PERMISSION_READ
					}]
				}
			};
		});
		it('render storage list', function(done) {
			var request;
			var $rows;
			var $tr;

			expect(fakeServer.requests.length).toEqual(1);
			request = fakeServer.requests[0];
			expect(request.url).toEqual(
				OC.linkToOCS('apps/files_external/api/v1/mounts?format=json')
			);

			fakeServer.requests[0].respond(
				200,
				{ 'Content-Type': 'application/json' },
				JSON.stringify(ocsResponse)
			);

			return reloading.then(function() {
				$rows = fileList.$el.find('tbody tr');
				expect($rows.length).toEqual(2);

				$tr = $rows.eq(0);
				expect($tr.attr('data-id')).not.toBeDefined();
				expect($tr.attr('data-type')).toEqual('dir');
				expect($tr.attr('data-file')).toEqual('sftp mount');
				expect($tr.attr('data-path')).toEqual('/another mount points');
				expect($tr.attr('data-size')).not.toBeDefined();
				expect($tr.attr('data-permissions')).toEqual('1'); // read only
				expect($tr.find('a.name').attr('href')).toEqual(
					OC.getRootPath() +
					'/index.php/apps/files' +
					'?dir=/another%20mount%20points/sftp%20mount'
				);
				expect($tr.find('.nametext').text().trim()).toEqual('sftp mount');
				expect($tr.find('.column-scope > span').text().trim()).toEqual('System');
				expect($tr.find('.column-backend').text().trim()).toEqual('SFTP');

				$tr = $rows.eq(1);
				expect($tr.attr('data-id')).not.toBeDefined();
				expect($tr.attr('data-type')).toEqual('dir');
				expect($tr.attr('data-file')).toEqual('smb mount');
				expect($tr.attr('data-path')).toEqual('/mount points');
				expect($tr.attr('data-size')).not.toBeDefined();
				expect($tr.attr('data-permissions')).toEqual('9'); // read and delete
				expect($tr.find('a.name').attr('href')).toEqual(
					OC.getRootPath() +
					'/index.php/apps/files' +
					'?dir=/mount%20points/smb%20mount'
				);
				expect($tr.find('.nametext').text().trim()).toEqual('smb mount');
				expect($tr.find('.column-scope > span').text().trim()).toEqual('Personal');
				expect($tr.find('.column-backend').text().trim()).toEqual('SMB');
			}).then(done, done);
		});
	});
});