2014-01-12 21:57:53 +04:00
|
|
|
/**
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
*/
|
2014-01-30 13:41:04 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
describe('OCA.Files.FileList tests', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
var FileInfo = OC.Files.FileInfo;
|
|
|
|
var testFiles, testRoot, notificationStub, fileList, pageSizeStub;
|
2014-05-23 21:02:50 +04:00
|
|
|
var bcResizeStub;
|
2015-07-13 18:38:13 +03:00
|
|
|
var filesClient;
|
|
|
|
var redirectStub;
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2014-04-04 20:46:08 +04:00
|
|
|
/**
|
|
|
|
* Generate test file data
|
|
|
|
*/
|
|
|
|
function generateFiles(startIndex, endIndex) {
|
|
|
|
var files = [];
|
|
|
|
var name;
|
|
|
|
for (var i = startIndex; i <= endIndex; i++) {
|
|
|
|
name = 'File with index ';
|
|
|
|
if (i < 10) {
|
|
|
|
// do not rely on localeCompare here
|
|
|
|
// and make the sorting predictable
|
|
|
|
// cross-browser
|
|
|
|
name += '0';
|
|
|
|
}
|
|
|
|
name += i + '.txt';
|
2015-07-13 18:38:13 +03:00
|
|
|
files.push(new FileInfo({
|
2014-04-04 20:46:08 +04:00
|
|
|
id: i,
|
|
|
|
type: 'file',
|
|
|
|
name: name,
|
|
|
|
mimetype: 'text/plain',
|
|
|
|
size: i * 2,
|
|
|
|
etag: 'abc'
|
2015-07-13 18:38:13 +03:00
|
|
|
}));
|
2014-04-04 20:46:08 +04:00
|
|
|
}
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
2014-01-12 21:57:53 +04:00
|
|
|
beforeEach(function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
filesClient = new OC.Files.Client({
|
|
|
|
host: 'localhost',
|
|
|
|
port: 80,
|
|
|
|
// FIXME: uncomment after fixing the test OC.webroot
|
|
|
|
//root: OC.webroot + '/remote.php/webdav',
|
|
|
|
root: '/remote.php/webdav',
|
|
|
|
useHTTPS: false
|
|
|
|
});
|
|
|
|
redirectStub = sinon.stub(OC, 'redirect');
|
|
|
|
notificationStub = sinon.stub(OC.Notification, 'showTemporary');
|
2014-05-23 21:02:50 +04:00
|
|
|
// prevent resize algo to mess up breadcrumb order while
|
|
|
|
// testing
|
|
|
|
bcResizeStub = sinon.stub(OCA.Files.BreadCrumb.prototype, '_resize');
|
2013-10-28 23:22:06 +04:00
|
|
|
|
|
|
|
// init parameters and test table elements
|
|
|
|
$('#testArea').append(
|
2014-05-09 00:06:30 +04:00
|
|
|
'<div id="app-content-files">' +
|
2014-05-12 21:54:20 +04:00
|
|
|
// init horrible parameters
|
2015-01-09 12:49:22 +03:00
|
|
|
'<input type="hidden" id="dir" value="/subdir"/>' +
|
|
|
|
'<input type="hidden" id="permissions" value="31"/>' +
|
2013-10-28 23:22:06 +04:00
|
|
|
// dummy controls
|
|
|
|
'<div id="controls">' +
|
|
|
|
' <div class="actions creatable"></div>' +
|
|
|
|
' <div class="notCreatable"></div>' +
|
|
|
|
'</div>' +
|
2014-05-21 17:55:29 +04:00
|
|
|
// uploader
|
|
|
|
'<input type="file" id="file_upload_start" name="files[]" multiple="multiple">' +
|
2013-10-28 23:22:06 +04:00
|
|
|
// dummy table
|
2014-05-09 00:06:30 +04:00
|
|
|
// TODO: at some point this will be rendered by the fileList class itself!
|
2013-10-28 23:22:06 +04:00
|
|
|
'<table id="filestable">' +
|
2014-04-03 22:57:06 +04:00
|
|
|
'<thead><tr>' +
|
|
|
|
'<th id="headerName" class="hidden column-name">' +
|
2016-02-15 16:58:44 +03:00
|
|
|
'<input type="checkbox" id="select_all_files" class="select-all checkbox">' +
|
2014-04-03 22:57:06 +04:00
|
|
|
'<a class="name columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' +
|
2015-06-29 16:55:46 +03:00
|
|
|
'<span id="selectedActionsList" class="selectedActions hidden">' +
|
|
|
|
'<a href class="download"><img src="actions/download.svg">Download</a>' +
|
2014-02-12 17:50:23 +04:00
|
|
|
'<a href class="delete-selected">Delete</a></span>' +
|
2014-04-03 22:57:06 +04:00
|
|
|
'</th>' +
|
|
|
|
'<th class="hidden column-size"><a class="columntitle" data-sort="size"><span class="sort-indicator"></span></a></th>' +
|
|
|
|
'<th class="hidden column-mtime"><a class="columntitle" data-sort="mtime"><span class="sort-indicator"></span></a></th>' +
|
|
|
|
'</tr></thead>' +
|
2014-05-12 21:54:20 +04:00
|
|
|
'<tbody id="fileList"></tbody>' +
|
2014-02-11 19:52:56 +04:00
|
|
|
'<tfoot></tfoot>' +
|
2013-10-28 23:22:06 +04:00
|
|
|
'</table>' +
|
2015-04-21 12:57:29 +03:00
|
|
|
// TODO: move to handlebars template
|
|
|
|
'<div id="emptycontent"><h2>Empty content message</h2><p class="uploadmessage">Upload message</p></div>' +
|
2015-01-09 12:49:22 +03:00
|
|
|
'<div class="nofilterresults hidden"></div>' +
|
2014-05-09 00:06:30 +04:00
|
|
|
'</div>'
|
2013-10-28 23:22:06 +04:00
|
|
|
);
|
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
testRoot = new FileInfo({
|
|
|
|
// root entry
|
|
|
|
id: 99,
|
|
|
|
type: 'dir',
|
|
|
|
name: '/subdir',
|
|
|
|
mimetype: 'httpd/unix-directory',
|
|
|
|
size: 1200000,
|
|
|
|
etag: 'a0b0c0d0',
|
|
|
|
permissions: OC.PERMISSION_ALL
|
|
|
|
});
|
|
|
|
testFiles = [new FileInfo({
|
2013-10-28 23:22:06 +04:00
|
|
|
id: 1,
|
|
|
|
type: 'file',
|
|
|
|
name: 'One.txt',
|
|
|
|
mimetype: 'text/plain',
|
2015-08-24 18:16:20 +03:00
|
|
|
mtime: 123456789,
|
2014-02-12 17:50:23 +04:00
|
|
|
size: 12,
|
2014-11-25 19:16:23 +03:00
|
|
|
etag: 'abc',
|
|
|
|
permissions: OC.PERMISSION_ALL
|
2015-07-13 18:38:13 +03:00
|
|
|
}), new FileInfo({
|
2013-10-28 23:22:06 +04:00
|
|
|
id: 2,
|
|
|
|
type: 'file',
|
|
|
|
name: 'Two.jpg',
|
|
|
|
mimetype: 'image/jpeg',
|
2015-08-24 18:16:20 +03:00
|
|
|
mtime: 234567890,
|
2014-02-12 17:50:23 +04:00
|
|
|
size: 12049,
|
|
|
|
etag: 'def',
|
2014-11-25 19:16:23 +03:00
|
|
|
permissions: OC.PERMISSION_ALL
|
2015-07-13 18:38:13 +03:00
|
|
|
}), new FileInfo({
|
2013-10-28 23:22:06 +04:00
|
|
|
id: 3,
|
|
|
|
type: 'file',
|
|
|
|
name: 'Three.pdf',
|
|
|
|
mimetype: 'application/pdf',
|
2015-08-24 18:16:20 +03:00
|
|
|
mtime: 234560000,
|
2014-02-12 17:50:23 +04:00
|
|
|
size: 58009,
|
|
|
|
etag: '123',
|
2014-11-25 19:16:23 +03:00
|
|
|
permissions: OC.PERMISSION_ALL
|
2015-07-13 18:38:13 +03:00
|
|
|
}), new FileInfo({
|
2013-10-28 23:22:06 +04:00
|
|
|
id: 4,
|
|
|
|
type: 'dir',
|
|
|
|
name: 'somedir',
|
|
|
|
mimetype: 'httpd/unix-directory',
|
2015-08-24 18:16:20 +03:00
|
|
|
mtime: 134560000,
|
2014-02-12 17:50:23 +04:00
|
|
|
size: 250,
|
2014-11-25 19:16:23 +03:00
|
|
|
etag: '456',
|
|
|
|
permissions: OC.PERMISSION_ALL
|
2015-07-13 18:38:13 +03:00
|
|
|
})];
|
2014-10-15 21:17:21 +04:00
|
|
|
pageSizeStub = sinon.stub(OCA.Files.FileList.prototype, 'pageSize').returns(20);
|
2015-07-13 18:38:13 +03:00
|
|
|
fileList = new OCA.Files.FileList($('#app-content-files'), {
|
|
|
|
filesClient: filesClient
|
|
|
|
});
|
2014-01-12 21:57:53 +04:00
|
|
|
});
|
|
|
|
afterEach(function() {
|
2013-10-28 23:22:06 +04:00
|
|
|
testFiles = undefined;
|
2015-09-25 13:23:28 +03:00
|
|
|
if (fileList) {
|
|
|
|
fileList.destroy();
|
|
|
|
}
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList = undefined;
|
2013-10-28 23:22:06 +04:00
|
|
|
|
|
|
|
notificationStub.restore();
|
2014-05-23 21:02:50 +04:00
|
|
|
bcResizeStub.restore();
|
2014-10-15 17:09:01 +04:00
|
|
|
pageSizeStub.restore();
|
2015-07-13 18:38:13 +03:00
|
|
|
redirectStub.restore();
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
describe('Getters', function() {
|
|
|
|
it('Returns the current directory', function() {
|
|
|
|
$('#dir').val('/one/two/three');
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.getCurrentDirectory()).toEqual('/one/two/three');
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('Returns the directory permissions as int', function() {
|
|
|
|
$('#permissions').val('23');
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.getDirectoryPermissions()).toEqual(23);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('Adding files', function() {
|
|
|
|
var clock, now;
|
|
|
|
beforeEach(function() {
|
|
|
|
// to prevent date comparison issues
|
|
|
|
clock = sinon.useFakeTimers();
|
|
|
|
now = new Date();
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
clock.restore();
|
|
|
|
});
|
|
|
|
it('generates file element with correct attributes when calling add() with file data', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
var fileData = new FileInfo({
|
2013-10-28 23:22:06 +04:00
|
|
|
id: 18,
|
|
|
|
name: 'testName.txt',
|
2014-05-12 21:54:20 +04:00
|
|
|
mimetype: 'text/plain',
|
2015-07-13 18:38:13 +03:00
|
|
|
size: 1234,
|
2013-10-28 23:22:06 +04:00
|
|
|
etag: 'a01234c',
|
2015-07-13 18:38:13 +03:00
|
|
|
mtime: 123456
|
|
|
|
});
|
2014-05-09 00:06:30 +04:00
|
|
|
var $tr = fileList.add(fileData);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
|
|
|
expect($tr).toBeDefined();
|
|
|
|
expect($tr[0].tagName.toLowerCase()).toEqual('tr');
|
|
|
|
expect($tr.attr('data-id')).toEqual('18');
|
|
|
|
expect($tr.attr('data-type')).toEqual('file');
|
|
|
|
expect($tr.attr('data-file')).toEqual('testName.txt');
|
|
|
|
expect($tr.attr('data-size')).toEqual('1234');
|
|
|
|
expect($tr.attr('data-etag')).toEqual('a01234c');
|
|
|
|
expect($tr.attr('data-permissions')).toEqual('31');
|
2014-05-12 21:54:20 +04:00
|
|
|
expect($tr.attr('data-mime')).toEqual('text/plain');
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($tr.attr('data-mtime')).toEqual('123456');
|
2014-05-12 21:54:20 +04:00
|
|
|
expect($tr.find('a.name').attr('href'))
|
2015-07-13 18:38:13 +03:00
|
|
|
.toEqual(OC.webroot + '/remote.php/webdav/subdir/testName.txt');
|
2014-05-12 21:54:20 +04:00
|
|
|
expect($tr.find('.nametext').text().trim()).toEqual('testName.txt');
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2016-01-19 12:51:57 +03:00
|
|
|
expect($tr.find('.filesize').text()).toEqual('1 KB');
|
2014-12-05 16:54:43 +03:00
|
|
|
expect($tr.find('.date').text()).not.toEqual('?');
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('testName.txt')[0]).toEqual($tr[0]);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('generates dir element with correct attributes when calling add() with dir data', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
var fileData = new FileInfo({
|
2013-10-28 23:22:06 +04:00
|
|
|
id: 19,
|
|
|
|
name: 'testFolder',
|
|
|
|
mimetype: 'httpd/unix-directory',
|
2015-07-13 18:38:13 +03:00
|
|
|
size: 1234,
|
2013-10-28 23:22:06 +04:00
|
|
|
etag: 'a01234c',
|
2015-07-13 18:38:13 +03:00
|
|
|
mtime: 123456
|
|
|
|
});
|
2014-05-09 00:06:30 +04:00
|
|
|
var $tr = fileList.add(fileData);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
|
|
|
expect($tr).toBeDefined();
|
|
|
|
expect($tr[0].tagName.toLowerCase()).toEqual('tr');
|
|
|
|
expect($tr.attr('data-id')).toEqual('19');
|
|
|
|
expect($tr.attr('data-type')).toEqual('dir');
|
|
|
|
expect($tr.attr('data-file')).toEqual('testFolder');
|
|
|
|
expect($tr.attr('data-size')).toEqual('1234');
|
|
|
|
expect($tr.attr('data-etag')).toEqual('a01234c');
|
|
|
|
expect($tr.attr('data-permissions')).toEqual('31');
|
|
|
|
expect($tr.attr('data-mime')).toEqual('httpd/unix-directory');
|
|
|
|
expect($tr.attr('data-mtime')).toEqual('123456');
|
|
|
|
|
2016-01-19 12:51:57 +03:00
|
|
|
expect($tr.find('.filesize').text()).toEqual('1 KB');
|
2014-12-05 16:54:43 +03:00
|
|
|
expect($tr.find('.date').text()).not.toEqual('?');
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('testFolder')[0]).toEqual($tr[0]);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('generates file element with default attributes when calling add() with minimal data', function() {
|
|
|
|
var fileData = {
|
|
|
|
type: 'file',
|
|
|
|
name: 'testFile.txt'
|
|
|
|
};
|
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
clock.tick(123456);
|
|
|
|
var $tr = fileList.add(fileData);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
|
|
|
expect($tr).toBeDefined();
|
|
|
|
expect($tr[0].tagName.toLowerCase()).toEqual('tr');
|
2014-11-04 12:37:16 +03:00
|
|
|
expect($tr.attr('data-id')).toBeUndefined();
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($tr.attr('data-type')).toEqual('file');
|
|
|
|
expect($tr.attr('data-file')).toEqual('testFile.txt');
|
2014-11-04 12:37:16 +03:00
|
|
|
expect($tr.attr('data-size')).toBeUndefined();
|
|
|
|
expect($tr.attr('data-etag')).toBeUndefined();
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($tr.attr('data-permissions')).toEqual('31');
|
2014-11-04 12:37:16 +03:00
|
|
|
expect($tr.attr('data-mime')).toBeUndefined();
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($tr.attr('data-mtime')).toEqual('123456');
|
|
|
|
|
|
|
|
expect($tr.find('.filesize').text()).toEqual('Pending');
|
2014-12-05 16:54:43 +03:00
|
|
|
expect($tr.find('.date').text()).not.toEqual('?');
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('generates dir element with default attributes when calling add() with minimal data', function() {
|
|
|
|
var fileData = {
|
|
|
|
type: 'dir',
|
|
|
|
name: 'testFolder'
|
|
|
|
};
|
2014-05-09 00:06:30 +04:00
|
|
|
clock.tick(123456);
|
|
|
|
var $tr = fileList.add(fileData);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
|
|
|
expect($tr).toBeDefined();
|
|
|
|
expect($tr[0].tagName.toLowerCase()).toEqual('tr');
|
2014-11-04 12:37:16 +03:00
|
|
|
expect($tr.attr('data-id')).toBeUndefined();
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($tr.attr('data-type')).toEqual('dir');
|
|
|
|
expect($tr.attr('data-file')).toEqual('testFolder');
|
2014-11-04 12:37:16 +03:00
|
|
|
expect($tr.attr('data-size')).toBeUndefined();
|
|
|
|
expect($tr.attr('data-etag')).toBeUndefined();
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($tr.attr('data-permissions')).toEqual('31');
|
|
|
|
expect($tr.attr('data-mime')).toEqual('httpd/unix-directory');
|
|
|
|
expect($tr.attr('data-mtime')).toEqual('123456');
|
|
|
|
|
|
|
|
expect($tr.find('.filesize').text()).toEqual('Pending');
|
2014-12-05 16:54:43 +03:00
|
|
|
expect($tr.find('.date').text()).not.toEqual('?');
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('generates file element with zero size when size is explicitly zero', function() {
|
|
|
|
var fileData = {
|
|
|
|
type: 'dir',
|
|
|
|
name: 'testFolder',
|
|
|
|
size: '0'
|
|
|
|
};
|
2014-05-09 00:06:30 +04:00
|
|
|
var $tr = fileList.add(fileData);
|
2016-01-19 12:51:57 +03:00
|
|
|
expect($tr.find('.filesize').text()).toEqual('0 KB');
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
2014-12-05 16:54:43 +03:00
|
|
|
it('generates file element with unknown date when mtime invalid', function() {
|
|
|
|
var fileData = {
|
|
|
|
type: 'dir',
|
|
|
|
name: 'testFolder',
|
|
|
|
mtime: -1
|
|
|
|
};
|
|
|
|
var $tr = fileList.add(fileData);
|
2014-12-18 03:27:58 +03:00
|
|
|
expect($tr.find('.date .modified').text()).toEqual('?');
|
2014-12-05 16:54:43 +03:00
|
|
|
});
|
2014-02-11 19:52:56 +04:00
|
|
|
it('adds new file to the end of the list', function() {
|
2014-04-04 16:34:07 +04:00
|
|
|
var $tr;
|
2013-10-28 23:22:06 +04:00
|
|
|
var fileData = {
|
|
|
|
type: 'file',
|
2014-04-04 18:11:31 +04:00
|
|
|
name: 'ZZZ.txt'
|
2013-10-28 23:22:06 +04:00
|
|
|
};
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
$tr = fileList.add(fileData);
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($tr.index()).toEqual(4);
|
|
|
|
});
|
2014-04-04 16:34:07 +04:00
|
|
|
it('inserts files in a sorted manner when insert option is enabled', function() {
|
|
|
|
for (var i = 0; i < testFiles.length; i++) {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.add(testFiles[i]);
|
2014-04-04 16:34:07 +04:00
|
|
|
}
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.files[0].name).toEqual('somedir');
|
|
|
|
expect(fileList.files[1].name).toEqual('One.txt');
|
|
|
|
expect(fileList.files[2].name).toEqual('Three.pdf');
|
|
|
|
expect(fileList.files[3].name).toEqual('Two.jpg');
|
2014-04-04 16:34:07 +04:00
|
|
|
});
|
|
|
|
it('inserts new file at correct position', function() {
|
|
|
|
var $tr;
|
2013-10-28 23:22:06 +04:00
|
|
|
var fileData = {
|
|
|
|
type: 'file',
|
|
|
|
name: 'P comes after O.txt'
|
|
|
|
};
|
2014-04-04 16:34:07 +04:00
|
|
|
for (var i = 0; i < testFiles.length; i++) {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.add(testFiles[i]);
|
2014-04-04 16:34:07 +04:00
|
|
|
}
|
2014-05-09 00:06:30 +04:00
|
|
|
$tr = fileList.add(fileData);
|
2013-10-28 23:22:06 +04:00
|
|
|
// after "One.txt"
|
2014-04-04 16:34:07 +04:00
|
|
|
expect($tr.index()).toEqual(2);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.files[2]).toEqual(fileData);
|
2014-04-04 16:34:07 +04:00
|
|
|
});
|
|
|
|
it('inserts new folder at correct position in insert mode', function() {
|
|
|
|
var $tr;
|
|
|
|
var fileData = {
|
|
|
|
type: 'dir',
|
|
|
|
name: 'somedir2 comes after somedir'
|
|
|
|
};
|
|
|
|
for (var i = 0; i < testFiles.length; i++) {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.add(testFiles[i]);
|
2014-04-04 16:34:07 +04:00
|
|
|
}
|
2014-05-09 00:06:30 +04:00
|
|
|
$tr = fileList.add(fileData);
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($tr.index()).toEqual(1);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.files[1]).toEqual(fileData);
|
2014-04-04 16:34:07 +04:00
|
|
|
});
|
|
|
|
it('inserts new file at the end correctly', function() {
|
|
|
|
var $tr;
|
|
|
|
var fileData = {
|
|
|
|
type: 'file',
|
|
|
|
name: 'zzz.txt'
|
|
|
|
};
|
|
|
|
for (var i = 0; i < testFiles.length; i++) {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.add(testFiles[i]);
|
2014-04-04 16:34:07 +04:00
|
|
|
}
|
2014-05-09 00:06:30 +04:00
|
|
|
$tr = fileList.add(fileData);
|
2014-04-04 16:34:07 +04:00
|
|
|
expect($tr.index()).toEqual(4);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.files[4]).toEqual(fileData);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('removes empty content message and shows summary when adding first file', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
var $summary;
|
2013-10-28 23:22:06 +04:00
|
|
|
var fileData = {
|
|
|
|
type: 'file',
|
|
|
|
name: 'first file.txt',
|
|
|
|
size: 12
|
|
|
|
};
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles([]);
|
|
|
|
expect(fileList.isEmpty).toEqual(true);
|
|
|
|
fileList.add(fileData);
|
2014-02-11 19:52:56 +04:00
|
|
|
$summary = $('#filestable .summary');
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(false);
|
2013-10-28 23:22:06 +04:00
|
|
|
// yes, ugly...
|
|
|
|
expect($summary.find('.info').text()).toEqual('0 folders and 1 file');
|
|
|
|
expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(true);
|
|
|
|
expect($summary.find('.fileinfo').hasClass('hidden')).toEqual(false);
|
|
|
|
expect($summary.find('.filesize').text()).toEqual('12 B');
|
|
|
|
expect($('#filestable thead th').hasClass('hidden')).toEqual(false);
|
|
|
|
expect($('#emptycontent').hasClass('hidden')).toEqual(true);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.isEmpty).toEqual(false);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
2015-03-26 12:29:01 +03:00
|
|
|
it('correctly adds the extension markup and show hidden files completely in gray', function() {
|
|
|
|
var $tr;
|
|
|
|
var testDataAndExpectedResult = [
|
|
|
|
{file: {type: 'file', name: 'ZZZ.txt'}, extension: '.txt'},
|
|
|
|
{file: {type: 'file', name: 'ZZZ.tar.gz'}, extension: '.gz'},
|
|
|
|
{file: {type: 'file', name: 'test.with.some.dots.in.it.txt'}, extension: '.txt'},
|
|
|
|
// we render hidden files completely in gray
|
|
|
|
{file: {type: 'file', name: '.test.with.some.dots.in.it.txt'}, extension: '.test.with.some.dots.in.it.txt'},
|
|
|
|
{file: {type: 'file', name: '.hidden'}, extension: '.hidden'},
|
|
|
|
];
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
|
|
|
|
for(var i = 0; i < testDataAndExpectedResult.length; i++) {
|
|
|
|
var testSet = testDataAndExpectedResult[i];
|
|
|
|
var fileData = testSet['file'];
|
|
|
|
$tr = fileList.add(fileData);
|
|
|
|
expect($tr.find('.nametext .extension').text()).toEqual(testSet['extension']);
|
|
|
|
}
|
|
|
|
});
|
2014-01-12 21:57:53 +04:00
|
|
|
});
|
2013-10-28 23:22:06 +04:00
|
|
|
describe('Removing files from the list', function() {
|
|
|
|
it('Removes file from list when calling remove() and updates summary', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
var $summary;
|
2013-10-28 23:22:06 +04:00
|
|
|
var $removedEl;
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
$removedEl = fileList.remove('One.txt');
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($removedEl).toBeDefined();
|
|
|
|
expect($removedEl.attr('data-file')).toEqual('One.txt');
|
2014-02-11 19:52:56 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(3);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.files.length).toEqual(3);
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(0);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2014-02-11 19:52:56 +04:00
|
|
|
$summary = $('#filestable .summary');
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(false);
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($summary.find('.info').text()).toEqual('1 folder and 2 files');
|
|
|
|
expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(false);
|
|
|
|
expect($summary.find('.fileinfo').hasClass('hidden')).toEqual(false);
|
2016-01-19 12:51:57 +03:00
|
|
|
expect($summary.find('.filesize').text()).toEqual('69 KB');
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.isEmpty).toEqual(false);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('Shows empty content when removing last file', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
var $summary;
|
|
|
|
fileList.setFiles([testFiles[0]]);
|
|
|
|
fileList.remove('One.txt');
|
2014-02-11 19:52:56 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(0);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.files.length).toEqual(0);
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(0);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2014-02-11 19:52:56 +04:00
|
|
|
$summary = $('#filestable .summary');
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(true);
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($('#filestable thead th').hasClass('hidden')).toEqual(true);
|
|
|
|
expect($('#emptycontent').hasClass('hidden')).toEqual(false);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.isEmpty).toEqual(true);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
2014-01-12 21:57:53 +04:00
|
|
|
});
|
2013-10-28 23:22:06 +04:00
|
|
|
describe('Deleting files', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
var deferredDelete;
|
|
|
|
var deleteStub;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
deferredDelete = $.Deferred();
|
|
|
|
deleteStub = sinon.stub(filesClient, 'remove').returns(deferredDelete.promise());
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
deleteStub.restore();
|
|
|
|
});
|
|
|
|
|
2013-10-28 23:22:06 +04:00
|
|
|
function doDelete() {
|
|
|
|
// note: normally called from FileActions
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.do_delete(['One.txt', 'Two.jpg']);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(deleteStub.calledTwice).toEqual(true);
|
|
|
|
expect(deleteStub.getCall(0).args[0]).toEqual('/subdir/One.txt');
|
|
|
|
expect(deleteStub.getCall(1).args[0]).toEqual('/subdir/Two.jpg');
|
2013-10-28 23:22:06 +04:00
|
|
|
}
|
|
|
|
it('calls delete.php, removes the deleted entries and updates summary', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
var $summary;
|
|
|
|
fileList.setFiles(testFiles);
|
2013-10-28 23:22:06 +04:00
|
|
|
doDelete();
|
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredDelete.resolve(200);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(0);
|
|
|
|
expect(fileList.findFileEl('Two.jpg').length).toEqual(0);
|
|
|
|
expect(fileList.findFileEl('Three.pdf').length).toEqual(1);
|
|
|
|
expect(fileList.$fileList.find('tr').length).toEqual(2);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2014-02-11 19:52:56 +04:00
|
|
|
$summary = $('#filestable .summary');
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(false);
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($summary.find('.info').text()).toEqual('1 folder and 1 file');
|
|
|
|
expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(false);
|
|
|
|
expect($summary.find('.fileinfo').hasClass('hidden')).toEqual(false);
|
2016-01-19 12:51:57 +03:00
|
|
|
expect($summary.find('.filesize').text()).toEqual('57 KB');
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.isEmpty).toEqual(false);
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($('#filestable thead th').hasClass('hidden')).toEqual(false);
|
|
|
|
expect($('#emptycontent').hasClass('hidden')).toEqual(true);
|
|
|
|
|
|
|
|
expect(notificationStub.notCalled).toEqual(true);
|
|
|
|
});
|
2015-08-05 13:48:42 +03:00
|
|
|
it('shows busy state on files to be deleted', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles(testFiles);
|
2014-04-29 19:59:30 +04:00
|
|
|
doDelete();
|
|
|
|
|
2015-08-05 13:48:42 +03:00
|
|
|
expect(fileList.findFileEl('One.txt').hasClass('busy')).toEqual(true);
|
|
|
|
expect(fileList.findFileEl('Three.pdf').hasClass('busy')).toEqual(false);
|
2014-04-29 19:59:30 +04:00
|
|
|
});
|
2015-08-05 13:48:42 +03:00
|
|
|
it('shows busy state on all files when deleting all', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles(testFiles);
|
2014-04-29 19:59:30 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.do_delete();
|
2014-04-29 19:59:30 +04:00
|
|
|
|
2015-08-05 13:48:42 +03:00
|
|
|
expect(fileList.$fileList.find('tr.busy').length).toEqual(4);
|
2014-04-29 19:59:30 +04:00
|
|
|
});
|
2013-10-28 23:22:06 +04:00
|
|
|
it('updates summary when deleting last file', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
var $summary;
|
|
|
|
fileList.setFiles([testFiles[0], testFiles[1]]);
|
2013-10-28 23:22:06 +04:00
|
|
|
doDelete();
|
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredDelete.resolve(200);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.$fileList.find('tr').length).toEqual(0);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2014-02-11 19:52:56 +04:00
|
|
|
$summary = $('#filestable .summary');
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(true);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.isEmpty).toEqual(true);
|
|
|
|
expect(fileList.files.length).toEqual(0);
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($('#filestable thead th').hasClass('hidden')).toEqual(true);
|
|
|
|
expect($('#emptycontent').hasClass('hidden')).toEqual(false);
|
|
|
|
});
|
|
|
|
it('bring back deleted item when delete call failed', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles(testFiles);
|
2013-10-28 23:22:06 +04:00
|
|
|
doDelete();
|
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredDelete.reject(403);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
|
|
|
// files are still in the list
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
|
|
|
expect(fileList.findFileEl('Two.jpg').length).toEqual(1);
|
|
|
|
expect(fileList.$fileList.find('tr').length).toEqual(4);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(notificationStub.calledTwice).toEqual(true);
|
|
|
|
});
|
|
|
|
it('remove file from list if delete call returned 404 not found', function() {
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
doDelete();
|
|
|
|
|
|
|
|
deferredDelete.reject(404);
|
|
|
|
|
|
|
|
// files are still in the list
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(0);
|
|
|
|
expect(fileList.findFileEl('Two.jpg').length).toEqual(0);
|
|
|
|
expect(fileList.$fileList.find('tr').length).toEqual(2);
|
|
|
|
|
|
|
|
expect(notificationStub.notCalled).toEqual(true);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('Renaming files', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
var deferredRename;
|
|
|
|
var renameStub;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
deferredRename = $.Deferred();
|
|
|
|
renameStub = sinon.stub(filesClient, 'move').returns(deferredRename.promise());
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
renameStub.restore();
|
|
|
|
});
|
|
|
|
|
2014-05-16 14:43:36 +04:00
|
|
|
function doCancelRename() {
|
|
|
|
var $input;
|
|
|
|
for (var i = 0; i < testFiles.length; i++) {
|
|
|
|
fileList.add(testFiles[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// trigger rename prompt
|
|
|
|
fileList.rename('One.txt');
|
|
|
|
$input = fileList.$fileList.find('input.filename');
|
|
|
|
// keep same name
|
|
|
|
$input.val('One.txt');
|
|
|
|
// trigger submit because triggering blur doesn't work in all browsers
|
|
|
|
$input.closest('form').trigger('submit');
|
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(renameStub.notCalled).toEqual(true);
|
2014-05-16 14:43:36 +04:00
|
|
|
}
|
2013-10-28 23:22:06 +04:00
|
|
|
function doRename() {
|
2015-07-13 18:38:13 +03:00
|
|
|
var $input;
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2014-04-04 16:34:07 +04:00
|
|
|
for (var i = 0; i < testFiles.length; i++) {
|
2014-06-06 17:13:02 +04:00
|
|
|
var file = testFiles[i];
|
|
|
|
file.path = '/some/subdir';
|
|
|
|
fileList.add(file, {silent: true});
|
2014-04-04 16:34:07 +04:00
|
|
|
}
|
2013-10-28 23:22:06 +04:00
|
|
|
|
|
|
|
// trigger rename prompt
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.rename('One.txt');
|
|
|
|
$input = fileList.$fileList.find('input.filename');
|
2014-05-12 21:54:20 +04:00
|
|
|
$input.val('Tu_after_three.txt');
|
|
|
|
// trigger submit because triggering blur doesn't work in all browsers
|
|
|
|
$input.closest('form').trigger('submit');
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(renameStub.calledOnce).toEqual(true);
|
|
|
|
expect(renameStub.getCall(0).args[0]).toEqual('/some/subdir/One.txt');
|
|
|
|
expect(renameStub.getCall(0).args[1]).toEqual('/some/subdir/Tu_after_three.txt');
|
2013-10-28 23:22:06 +04:00
|
|
|
}
|
2014-04-04 16:34:07 +04:00
|
|
|
it('Inserts renamed file entry at correct position if rename ajax call suceeded', function() {
|
2013-10-28 23:22:06 +04:00
|
|
|
doRename();
|
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredRename.resolve(201);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
|
|
|
// element stays renamed
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(0);
|
|
|
|
expect(fileList.findFileEl('Tu_after_three.txt').length).toEqual(1);
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(fileList.findFileEl('Tu_after_three.txt').index()).toEqual(2); // after Two.jpg
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(notificationStub.notCalled).toEqual(true);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('Reverts file entry if rename ajax call failed', function() {
|
|
|
|
doRename();
|
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredRename.reject(403);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
|
|
|
// element was reverted
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
|
|
|
expect(fileList.findFileEl('One.txt').index()).toEqual(1); // after somedir
|
|
|
|
expect(fileList.findFileEl('Tu_after_three.txt').length).toEqual(0);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(notificationStub.calledOnce).toEqual(true);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('Correctly updates file link after rename', function() {
|
|
|
|
var $tr;
|
|
|
|
doRename();
|
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredRename.resolve(201);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
$tr = fileList.findFileEl('Tu_after_three.txt');
|
2015-07-13 18:38:13 +03:00
|
|
|
expect($tr.find('a.name').attr('href'))
|
|
|
|
.toEqual(OC.webroot + '/remote.php/webdav/some/subdir/Tu_after_three.txt');
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
2014-05-16 14:43:36 +04:00
|
|
|
it('Triggers "fileActionsReady" event after rename', function() {
|
|
|
|
var handler = sinon.stub();
|
|
|
|
fileList.$fileList.on('fileActionsReady', handler);
|
|
|
|
doRename();
|
|
|
|
expect(handler.notCalled).toEqual(true);
|
2015-07-13 18:38:13 +03:00
|
|
|
|
|
|
|
deferredRename.resolve(201);
|
|
|
|
|
2014-05-16 14:43:36 +04:00
|
|
|
expect(handler.calledOnce).toEqual(true);
|
|
|
|
expect(fileList.$fileList.find('.test').length).toEqual(0);
|
|
|
|
});
|
|
|
|
it('Leaves the summary alone when reinserting renamed element', function() {
|
|
|
|
var $summary = $('#filestable .summary');
|
2013-10-28 23:22:06 +04:00
|
|
|
doRename();
|
2015-07-13 18:38:13 +03:00
|
|
|
|
|
|
|
deferredRename.resolve(201);
|
|
|
|
|
2014-05-16 14:43:36 +04:00
|
|
|
expect($summary.find('.info').text()).toEqual('1 folder and 3 files');
|
|
|
|
});
|
|
|
|
it('Leaves the summary alone when cancel renaming', function() {
|
|
|
|
var $summary = $('#filestable .summary');
|
|
|
|
doCancelRename();
|
|
|
|
expect($summary.find('.info').text()).toEqual('1 folder and 3 files');
|
|
|
|
});
|
2015-08-05 13:48:42 +03:00
|
|
|
it('Shows busy state while rename in progress', function() {
|
2014-05-16 14:43:36 +04:00
|
|
|
var $tr;
|
|
|
|
doRename();
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2014-05-16 14:43:36 +04:00
|
|
|
// element is renamed before the request finishes
|
2014-05-09 00:06:30 +04:00
|
|
|
$tr = fileList.findFileEl('Tu_after_three.txt');
|
2014-05-16 14:43:36 +04:00
|
|
|
expect($tr.length).toEqual(1);
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(0);
|
|
|
|
// file actions are hidden
|
2015-08-05 13:48:42 +03:00
|
|
|
expect($tr.hasClass('busy')).toEqual(true);
|
2014-05-16 14:43:36 +04:00
|
|
|
|
2014-06-23 18:35:11 +04:00
|
|
|
// input and form are gone
|
|
|
|
expect(fileList.$fileList.find('input.filename').length).toEqual(0);
|
|
|
|
expect(fileList.$fileList.find('form').length).toEqual(0);
|
|
|
|
});
|
|
|
|
it('Validates the file name', function() {
|
|
|
|
var $input, $tr;
|
|
|
|
|
|
|
|
for (var i = 0; i < testFiles.length; i++) {
|
|
|
|
fileList.add(testFiles[i], {silent: true});
|
|
|
|
}
|
|
|
|
|
|
|
|
// trigger rename prompt
|
|
|
|
fileList.rename('One.txt');
|
|
|
|
$input = fileList.$fileList.find('input.filename');
|
|
|
|
$input.val('Two.jpg');
|
|
|
|
|
|
|
|
// simulate key to trigger validation
|
|
|
|
$input.trigger(new $.Event('keyup', {keyCode: 97}));
|
|
|
|
|
|
|
|
// input is still there with error
|
|
|
|
expect(fileList.$fileList.find('input.filename').length).toEqual(1);
|
|
|
|
expect(fileList.$fileList.find('input.filename').hasClass('error')).toEqual(true);
|
|
|
|
|
|
|
|
// trigger submit does not send server request
|
|
|
|
$input.closest('form').trigger('submit');
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(renameStub.notCalled).toEqual(true);
|
2014-06-23 18:35:11 +04:00
|
|
|
|
|
|
|
// simulate escape key
|
|
|
|
$input.trigger(new $.Event('keyup', {keyCode: 27}));
|
|
|
|
|
|
|
|
// element is added back with the correct name
|
|
|
|
$tr = fileList.findFileEl('One.txt');
|
|
|
|
expect($tr.length).toEqual(1);
|
|
|
|
expect($tr.find('a .nametext').text().trim()).toEqual('One.txt');
|
|
|
|
expect($tr.find('a.name').is(':visible')).toEqual(true);
|
|
|
|
|
|
|
|
$tr = fileList.findFileEl('Two.jpg');
|
|
|
|
expect($tr.length).toEqual(1);
|
|
|
|
expect($tr.find('a .nametext').text().trim()).toEqual('Two.jpg');
|
|
|
|
expect($tr.find('a.name').is(':visible')).toEqual(true);
|
|
|
|
|
2014-05-16 14:43:36 +04:00
|
|
|
// input and form are gone
|
|
|
|
expect(fileList.$fileList.find('input.filename').length).toEqual(0);
|
|
|
|
expect(fileList.$fileList.find('form').length).toEqual(0);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
2014-12-17 15:12:57 +03:00
|
|
|
it('Restores thumbnail when rename was cancelled', function() {
|
|
|
|
doRename();
|
|
|
|
|
|
|
|
expect(OC.TestUtil.getImageUrl(fileList.findFileEl('Tu_after_three.txt').find('.thumbnail')))
|
|
|
|
.toEqual(OC.imagePath('core', 'loading.gif'));
|
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredRename.reject(409);
|
2014-12-17 15:12:57 +03:00
|
|
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
|
|
|
expect(OC.TestUtil.getImageUrl(fileList.findFileEl('One.txt').find('.thumbnail')))
|
2015-07-09 19:42:46 +03:00
|
|
|
.toEqual(OC.imagePath('core', 'filetypes/text.svg'));
|
2014-12-17 15:12:57 +03:00
|
|
|
});
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
2014-04-11 14:46:12 +04:00
|
|
|
describe('Moving files', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
var deferredMove;
|
|
|
|
var moveStub;
|
|
|
|
|
2014-04-11 14:46:12 +04:00
|
|
|
beforeEach(function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredMove = $.Deferred();
|
|
|
|
moveStub = sinon.stub(filesClient, 'move').returns(deferredMove.promise());
|
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles(testFiles);
|
2014-04-11 14:46:12 +04:00
|
|
|
});
|
2015-07-13 18:38:13 +03:00
|
|
|
afterEach(function() {
|
|
|
|
moveStub.restore();
|
|
|
|
});
|
|
|
|
|
2014-04-11 14:46:12 +04:00
|
|
|
it('Moves single file to target folder', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.move('One.txt', '/somedir');
|
2014-04-11 14:46:12 +04:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(moveStub.calledOnce).toEqual(true);
|
|
|
|
expect(moveStub.getCall(0).args[0]).toEqual('/subdir/One.txt');
|
|
|
|
expect(moveStub.getCall(0).args[1]).toEqual('/somedir/One.txt');
|
2014-04-11 14:46:12 +04:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredMove.resolve(201);
|
2014-04-11 14:46:12 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(0);
|
2014-04-11 14:46:12 +04:00
|
|
|
|
|
|
|
// folder size has increased
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('somedir').data('size')).toEqual(262);
|
|
|
|
expect(fileList.findFileEl('somedir').find('.filesize').text()).toEqual('262 B');
|
2014-04-11 14:46:12 +04:00
|
|
|
|
|
|
|
expect(notificationStub.notCalled).toEqual(true);
|
|
|
|
});
|
|
|
|
it('Moves list of files to target folder', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
var deferredMove1 = $.Deferred();
|
|
|
|
var deferredMove2 = $.Deferred();
|
|
|
|
moveStub.onCall(0).returns(deferredMove1.promise());
|
|
|
|
moveStub.onCall(1).returns(deferredMove2.promise());
|
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.move(['One.txt', 'Two.jpg'], '/somedir');
|
2014-04-11 14:46:12 +04:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(moveStub.calledTwice).toEqual(true);
|
|
|
|
expect(moveStub.getCall(0).args[0]).toEqual('/subdir/One.txt');
|
|
|
|
expect(moveStub.getCall(0).args[1]).toEqual('/somedir/One.txt');
|
|
|
|
expect(moveStub.getCall(1).args[0]).toEqual('/subdir/Two.jpg');
|
|
|
|
expect(moveStub.getCall(1).args[1]).toEqual('/somedir/Two.jpg');
|
2014-04-11 14:46:12 +04:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredMove1.resolve(201);
|
2014-04-11 14:46:12 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(0);
|
2014-04-11 14:46:12 +04:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
// folder size has increased during move
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('somedir').data('size')).toEqual(262);
|
|
|
|
expect(fileList.findFileEl('somedir').find('.filesize').text()).toEqual('262 B');
|
2014-04-11 14:46:12 +04:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredMove2.resolve(201);
|
2014-04-11 14:46:12 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('Two.jpg').length).toEqual(0);
|
2014-04-11 14:46:12 +04:00
|
|
|
|
|
|
|
// folder size has increased
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('somedir').data('size')).toEqual(12311);
|
2016-01-19 12:51:57 +03:00
|
|
|
expect(fileList.findFileEl('somedir').find('.filesize').text()).toEqual('12 KB');
|
2014-04-11 14:46:12 +04:00
|
|
|
|
|
|
|
expect(notificationStub.notCalled).toEqual(true);
|
|
|
|
});
|
|
|
|
it('Shows notification if a file could not be moved', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.move('One.txt', '/somedir');
|
2014-04-11 14:46:12 +04:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(moveStub.calledOnce).toEqual(true);
|
2014-04-11 14:46:12 +04:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredMove.reject(409);
|
2014-04-11 14:46:12 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
2014-04-11 14:46:12 +04:00
|
|
|
|
|
|
|
expect(notificationStub.calledOnce).toEqual(true);
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(notificationStub.getCall(0).args[0]).toEqual('Could not move "One.txt"');
|
2014-04-11 14:46:12 +04:00
|
|
|
});
|
2014-12-17 15:12:57 +03:00
|
|
|
it('Restores thumbnail if a file could not be moved', function() {
|
|
|
|
fileList.move('One.txt', '/somedir');
|
|
|
|
|
|
|
|
expect(OC.TestUtil.getImageUrl(fileList.findFileEl('One.txt').find('.thumbnail')))
|
|
|
|
.toEqual(OC.imagePath('core', 'loading.gif'));
|
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(moveStub.calledOnce).toEqual(true);
|
2014-12-17 15:12:57 +03:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredMove.reject(409);
|
2014-12-17 15:12:57 +03:00
|
|
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
|
|
|
|
|
|
|
expect(notificationStub.calledOnce).toEqual(true);
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(notificationStub.getCall(0).args[0]).toEqual('Could not move "One.txt"');
|
2014-12-17 15:12:57 +03:00
|
|
|
|
|
|
|
expect(OC.TestUtil.getImageUrl(fileList.findFileEl('One.txt').find('.thumbnail')))
|
2015-07-09 19:42:46 +03:00
|
|
|
.toEqual(OC.imagePath('core', 'filetypes/text.svg'));
|
2014-12-17 15:12:57 +03:00
|
|
|
});
|
2014-04-11 14:46:12 +04:00
|
|
|
});
|
2016-01-10 00:47:26 +03:00
|
|
|
describe('Update file', function() {
|
|
|
|
it('does not change summary', function() {
|
|
|
|
var $summary = $('#filestable .summary');
|
|
|
|
var fileData = new FileInfo({
|
|
|
|
type: 'file',
|
|
|
|
name: 'test file',
|
|
|
|
});
|
|
|
|
var $tr = fileList.add(fileData);
|
|
|
|
|
|
|
|
expect($summary.find('.info').text()).toEqual('0 folders and 1 file');
|
|
|
|
|
|
|
|
var model = fileList.getModelForFile('test file');
|
|
|
|
model.set({size: '100'});
|
|
|
|
expect($summary.find('.info').text()).toEqual('0 folders and 1 file');
|
|
|
|
});
|
|
|
|
})
|
2013-10-28 23:22:06 +04:00
|
|
|
describe('List rendering', function() {
|
|
|
|
it('renders a list of files using add()', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.files.length).toEqual(0);
|
|
|
|
expect(fileList.files).toEqual([]);
|
|
|
|
fileList.setFiles(testFiles);
|
2014-02-11 19:52:56 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(4);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.files.length).toEqual(4);
|
|
|
|
expect(fileList.files).toEqual(testFiles);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('updates summary using the file sizes', function() {
|
|
|
|
var $summary;
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles(testFiles);
|
2014-02-11 19:52:56 +04:00
|
|
|
$summary = $('#filestable .summary');
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(false);
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($summary.find('.info').text()).toEqual('1 folder and 3 files');
|
2016-01-19 12:51:57 +03:00
|
|
|
expect($summary.find('.filesize').text()).toEqual('69 KB');
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('shows headers, summary and hide empty content message after setting files', function(){
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles(testFiles);
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($('#filestable thead th').hasClass('hidden')).toEqual(false);
|
|
|
|
expect($('#emptycontent').hasClass('hidden')).toEqual(true);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.$el.find('.summary').hasClass('hidden')).toEqual(false);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('hides headers, summary and show empty content message after setting empty file list', function(){
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles([]);
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($('#filestable thead th').hasClass('hidden')).toEqual(true);
|
|
|
|
expect($('#emptycontent').hasClass('hidden')).toEqual(false);
|
2015-04-21 12:57:29 +03:00
|
|
|
expect($('#emptycontent .uploadmessage').hasClass('hidden')).toEqual(false);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.$el.find('.summary').hasClass('hidden')).toEqual(true);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
2015-04-21 12:57:29 +03:00
|
|
|
it('hides headers, upload message, and summary when list is empty and user has no creation permission', function(){
|
2013-10-28 23:22:06 +04:00
|
|
|
$('#permissions').val(0);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles([]);
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($('#filestable thead th').hasClass('hidden')).toEqual(true);
|
2015-04-21 12:57:29 +03:00
|
|
|
expect($('#emptycontent').hasClass('hidden')).toEqual(false);
|
|
|
|
expect($('#emptycontent .uploadmessage').hasClass('hidden')).toEqual(true);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.$el.find('.summary').hasClass('hidden')).toEqual(true);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('calling findFileEl() can find existing file element', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
expect(fileList.findFileEl('Two.jpg').length).toEqual(1);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('calling findFileEl() returns empty when file not found in file', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
expect(fileList.findFileEl('unexist.dat').length).toEqual(0);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('only add file if in same current directory', function() {
|
|
|
|
$('#dir').val('/current dir');
|
|
|
|
var fileData = {
|
|
|
|
type: 'file',
|
|
|
|
name: 'testFile.txt',
|
|
|
|
directory: '/current dir'
|
|
|
|
};
|
2015-07-13 18:38:13 +03:00
|
|
|
fileList.add(fileData);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('testFile.txt').length).toEqual(1);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('triggers "fileActionsReady" event after update', function() {
|
|
|
|
var handler = sinon.stub();
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.$fileList.on('fileActionsReady', handler);
|
|
|
|
fileList.setFiles(testFiles);
|
2013-10-28 23:22:06 +04:00
|
|
|
expect(handler.calledOnce).toEqual(true);
|
2014-07-01 23:32:04 +04:00
|
|
|
expect(handler.getCall(0).args[0].$files.length).toEqual(testFiles.length);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
2014-05-19 20:48:48 +04:00
|
|
|
it('triggers "fileActionsReady" event after single add', function() {
|
|
|
|
var handler = sinon.stub();
|
2014-07-01 23:32:04 +04:00
|
|
|
var $tr;
|
2014-05-19 20:48:48 +04:00
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
fileList.$fileList.on('fileActionsReady', handler);
|
2014-07-01 23:32:04 +04:00
|
|
|
$tr = fileList.add({name: 'test.txt'});
|
|
|
|
expect(handler.calledOnce).toEqual(true);
|
|
|
|
expect(handler.getCall(0).args[0].$files.is($tr)).toEqual(true);
|
|
|
|
});
|
|
|
|
it('triggers "fileActionsReady" event after next page load with the newly appended files', function() {
|
|
|
|
var handler = sinon.stub();
|
|
|
|
fileList.setFiles(generateFiles(0, 64));
|
|
|
|
fileList.$fileList.on('fileActionsReady', handler);
|
|
|
|
fileList._nextPage();
|
2014-05-19 20:48:48 +04:00
|
|
|
expect(handler.calledOnce).toEqual(true);
|
2014-10-15 21:18:35 +04:00
|
|
|
expect(handler.getCall(0).args[0].$files.length).toEqual(fileList.pageSize());
|
2014-05-19 20:48:48 +04:00
|
|
|
});
|
|
|
|
it('does not trigger "fileActionsReady" event after single add with silent argument', function() {
|
|
|
|
var handler = sinon.stub();
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
fileList.$fileList.on('fileActionsReady', handler);
|
|
|
|
fileList.add({name: 'test.txt'}, {silent: true});
|
|
|
|
expect(handler.notCalled).toEqual(true);
|
|
|
|
});
|
2013-10-28 23:22:06 +04:00
|
|
|
it('triggers "updated" event after update', function() {
|
|
|
|
var handler = sinon.stub();
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.$fileList.on('updated', handler);
|
|
|
|
fileList.setFiles(testFiles);
|
2013-10-28 23:22:06 +04:00
|
|
|
expect(handler.calledOnce).toEqual(true);
|
|
|
|
});
|
2014-02-12 17:50:23 +04:00
|
|
|
it('does not update summary when removing non-existing files', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
var $summary;
|
2014-02-12 17:50:23 +04:00
|
|
|
// single file
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles([testFiles[0]]);
|
2014-02-12 17:50:23 +04:00
|
|
|
$summary = $('#filestable .summary');
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(false);
|
|
|
|
expect($summary.find('.info').text()).toEqual('0 folders and 1 file');
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.remove('unexist.txt');
|
2014-02-12 17:50:23 +04:00
|
|
|
expect($summary.hasClass('hidden')).toEqual(false);
|
|
|
|
expect($summary.find('.info').text()).toEqual('0 folders and 1 file');
|
2014-04-04 18:11:31 +04:00
|
|
|
});
|
|
|
|
});
|
2015-01-09 12:49:22 +03:00
|
|
|
describe('Filtered list rendering', function() {
|
|
|
|
it('filters the list of files using filter()', function() {
|
|
|
|
expect(fileList.files.length).toEqual(0);
|
|
|
|
expect(fileList.files).toEqual([]);
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
var $summary = $('#filestable .summary');
|
|
|
|
var $nofilterresults = fileList.$el.find(".nofilterresults");
|
|
|
|
expect($nofilterresults.length).toEqual(1);
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(false);
|
|
|
|
|
|
|
|
expect($('#fileList tr:not(.hidden)').length).toEqual(4);
|
|
|
|
expect(fileList.files.length).toEqual(4);
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(false);
|
|
|
|
expect($nofilterresults.hasClass('hidden')).toEqual(true);
|
|
|
|
|
|
|
|
fileList.setFilter('e');
|
|
|
|
expect($('#fileList tr:not(.hidden)').length).toEqual(3);
|
|
|
|
expect(fileList.files.length).toEqual(4);
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(false);
|
|
|
|
expect($summary.find('.info').text()).toEqual("1 folder and 2 files match 'e'");
|
|
|
|
expect($nofilterresults.hasClass('hidden')).toEqual(true);
|
|
|
|
|
|
|
|
fileList.setFilter('ee');
|
|
|
|
expect($('#fileList tr:not(.hidden)').length).toEqual(1);
|
|
|
|
expect(fileList.files.length).toEqual(4);
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(false);
|
|
|
|
expect($summary.find('.info').text()).toEqual("0 folders and 1 file matches 'ee'");
|
|
|
|
expect($nofilterresults.hasClass('hidden')).toEqual(true);
|
|
|
|
|
|
|
|
fileList.setFilter('eee');
|
|
|
|
expect($('#fileList tr:not(.hidden)').length).toEqual(0);
|
|
|
|
expect(fileList.files.length).toEqual(4);
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(true);
|
|
|
|
expect($nofilterresults.hasClass('hidden')).toEqual(false);
|
|
|
|
|
|
|
|
fileList.setFilter('ee');
|
|
|
|
expect($('#fileList tr:not(.hidden)').length).toEqual(1);
|
|
|
|
expect(fileList.files.length).toEqual(4);
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(false);
|
|
|
|
expect($summary.find('.info').text()).toEqual("0 folders and 1 file matches 'ee'");
|
|
|
|
expect($nofilterresults.hasClass('hidden')).toEqual(true);
|
|
|
|
|
|
|
|
fileList.setFilter('e');
|
|
|
|
expect($('#fileList tr:not(.hidden)').length).toEqual(3);
|
|
|
|
expect(fileList.files.length).toEqual(4);
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(false);
|
|
|
|
expect($summary.find('.info').text()).toEqual("1 folder and 2 files match 'e'");
|
|
|
|
expect($nofilterresults.hasClass('hidden')).toEqual(true);
|
|
|
|
|
|
|
|
fileList.setFilter('');
|
|
|
|
expect($('#fileList tr:not(.hidden)').length).toEqual(4);
|
|
|
|
expect(fileList.files.length).toEqual(4);
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(false);
|
|
|
|
expect($summary.find('.info').text()).toEqual("1 folder and 3 files");
|
|
|
|
expect($nofilterresults.hasClass('hidden')).toEqual(true);
|
|
|
|
});
|
|
|
|
it('hides the emptyfiles notice when using filter()', function() {
|
|
|
|
expect(fileList.files.length).toEqual(0);
|
|
|
|
expect(fileList.files).toEqual([]);
|
|
|
|
fileList.setFiles([]);
|
|
|
|
var $summary = $('#filestable .summary');
|
|
|
|
var $emptycontent = fileList.$el.find("#emptycontent");
|
|
|
|
var $nofilterresults = fileList.$el.find(".nofilterresults");
|
|
|
|
expect($emptycontent.length).toEqual(1);
|
|
|
|
expect($nofilterresults.length).toEqual(1);
|
|
|
|
|
|
|
|
expect($('#fileList tr:not(.hidden)').length).toEqual(0);
|
|
|
|
expect(fileList.files.length).toEqual(0);
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(true);
|
|
|
|
expect($emptycontent.hasClass('hidden')).toEqual(false);
|
|
|
|
expect($nofilterresults.hasClass('hidden')).toEqual(true);
|
|
|
|
|
|
|
|
fileList.setFilter('e');
|
|
|
|
expect($('#fileList tr:not(.hidden)').length).toEqual(0);
|
|
|
|
expect(fileList.files.length).toEqual(0);
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(true);
|
|
|
|
expect($emptycontent.hasClass('hidden')).toEqual(true);
|
|
|
|
expect($nofilterresults.hasClass('hidden')).toEqual(false);
|
|
|
|
|
|
|
|
fileList.setFilter('');
|
|
|
|
expect($('#fileList tr:not(.hidden)').length).toEqual(0);
|
|
|
|
expect(fileList.files.length).toEqual(0);
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(true);
|
|
|
|
expect($emptycontent.hasClass('hidden')).toEqual(false);
|
|
|
|
expect($nofilterresults.hasClass('hidden')).toEqual(true);
|
|
|
|
});
|
|
|
|
it('does not show the emptyfiles or nofilterresults notice when the mask is active', function() {
|
|
|
|
expect(fileList.files.length).toEqual(0);
|
|
|
|
expect(fileList.files).toEqual([]);
|
|
|
|
fileList.showMask();
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
var $emptycontent = fileList.$el.find("#emptycontent");
|
|
|
|
var $nofilterresults = fileList.$el.find(".nofilterresults");
|
|
|
|
expect($emptycontent.length).toEqual(1);
|
|
|
|
expect($nofilterresults.length).toEqual(1);
|
|
|
|
|
|
|
|
expect($emptycontent.hasClass('hidden')).toEqual(true);
|
|
|
|
expect($nofilterresults.hasClass('hidden')).toEqual(true);
|
|
|
|
|
|
|
|
/*
|
|
|
|
fileList.setFilter('e');
|
|
|
|
expect($emptycontent.hasClass('hidden')).toEqual(true);
|
|
|
|
expect($nofilterresults.hasClass('hidden')).toEqual(false);
|
|
|
|
*/
|
|
|
|
|
|
|
|
fileList.setFilter('');
|
|
|
|
expect($emptycontent.hasClass('hidden')).toEqual(true);
|
|
|
|
expect($nofilterresults.hasClass('hidden')).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
2014-04-04 18:11:31 +04:00
|
|
|
describe('Rendering next page on scroll', function() {
|
|
|
|
beforeEach(function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles(generateFiles(0, 64));
|
2014-04-04 18:11:31 +04:00
|
|
|
});
|
|
|
|
it('renders only the first page', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.files.length).toEqual(65);
|
2014-04-04 18:11:31 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(20);
|
|
|
|
});
|
|
|
|
it('renders the second page when scrolling down (trigger nextPage)', function() {
|
|
|
|
// TODO: can't simulate scrolling here, so calling nextPage directly
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._nextPage(true);
|
2014-04-04 18:11:31 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(40);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._nextPage(true);
|
2014-04-04 18:11:31 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(60);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._nextPage(true);
|
2014-04-04 18:11:31 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(65);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._nextPage(true);
|
2014-04-04 18:11:31 +04:00
|
|
|
// stays at 65
|
|
|
|
expect($('#fileList tr').length).toEqual(65);
|
|
|
|
});
|
|
|
|
it('inserts into the DOM if insertion point is in the visible page ', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.add({
|
2014-04-04 18:11:31 +04:00
|
|
|
id: 2000,
|
|
|
|
type: 'file',
|
|
|
|
name: 'File with index 15b.txt'
|
|
|
|
});
|
|
|
|
expect($('#fileList tr').length).toEqual(21);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('File with index 15b.txt').index()).toEqual(16);
|
2014-04-04 18:11:31 +04:00
|
|
|
});
|
|
|
|
it('does not inserts into the DOM if insertion point is not the visible page ', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.add({
|
2014-04-04 18:11:31 +04:00
|
|
|
id: 2000,
|
|
|
|
type: 'file',
|
|
|
|
name: 'File with index 28b.txt'
|
|
|
|
});
|
|
|
|
expect($('#fileList tr').length).toEqual(20);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('File with index 28b.txt').length).toEqual(0);
|
|
|
|
fileList._nextPage(true);
|
2014-04-04 18:11:31 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(40);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('File with index 28b.txt').index()).toEqual(29);
|
2014-04-04 18:11:31 +04:00
|
|
|
});
|
|
|
|
it('appends into the DOM when inserting a file after the last visible element', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.add({
|
2014-04-04 18:11:31 +04:00
|
|
|
id: 2000,
|
|
|
|
type: 'file',
|
|
|
|
name: 'File with index 19b.txt'
|
|
|
|
});
|
|
|
|
expect($('#fileList tr').length).toEqual(21);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._nextPage(true);
|
2014-04-04 18:11:31 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(41);
|
|
|
|
});
|
|
|
|
it('appends into the DOM when inserting a file on the last page when visible', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._nextPage(true);
|
2014-04-04 18:11:31 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(40);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._nextPage(true);
|
2014-04-04 18:11:31 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(60);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._nextPage(true);
|
2014-04-04 18:11:31 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(65);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._nextPage(true);
|
|
|
|
fileList.add({
|
2014-04-04 18:11:31 +04:00
|
|
|
id: 2000,
|
|
|
|
type: 'file',
|
|
|
|
name: 'File with index 88.txt'
|
|
|
|
});
|
|
|
|
expect($('#fileList tr').length).toEqual(66);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._nextPage(true);
|
2014-04-04 18:11:31 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(66);
|
|
|
|
});
|
|
|
|
it('shows additional page when appending a page of files and scrolling down', function() {
|
|
|
|
var newFiles = generateFiles(66, 81);
|
|
|
|
for (var i = 0; i < newFiles.length; i++) {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.add(newFiles[i]);
|
2014-04-04 18:11:31 +04:00
|
|
|
}
|
|
|
|
expect($('#fileList tr').length).toEqual(20);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._nextPage(true);
|
2014-04-04 18:11:31 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(40);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._nextPage(true);
|
2014-04-04 18:11:31 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(60);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._nextPage(true);
|
2014-04-04 18:11:31 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(80);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._nextPage(true);
|
2014-04-04 18:11:31 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(81);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._nextPage(true);
|
2014-04-04 18:11:31 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(81);
|
2014-04-04 18:38:27 +04:00
|
|
|
});
|
|
|
|
it('automatically renders next page when there are not enough elements visible', function() {
|
|
|
|
// delete the 15 first elements
|
|
|
|
for (var i = 0; i < 15; i++) {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.remove(fileList.files[0].name);
|
2014-04-04 18:38:27 +04:00
|
|
|
}
|
|
|
|
// still makes sure that there are 20 elements visible, if any
|
|
|
|
expect($('#fileList tr').length).toEqual(25);
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
describe('file previews', function() {
|
|
|
|
var previewLoadStub;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
previewLoadStub = sinon.stub(OCA.Files.FileList.prototype, 'lazyLoadPreview');
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
previewLoadStub.restore();
|
|
|
|
});
|
2015-07-13 18:38:13 +03:00
|
|
|
it('renders default file icon when none provided and no mime type is set', function() {
|
2013-10-28 23:22:06 +04:00
|
|
|
var fileData = {
|
|
|
|
name: 'testFile.txt'
|
|
|
|
};
|
2014-05-09 00:06:30 +04:00
|
|
|
var $tr = fileList.add(fileData);
|
2014-12-11 19:36:14 +03:00
|
|
|
var $imgDiv = $tr.find('td.filename .thumbnail');
|
|
|
|
expect(OC.TestUtil.getImageUrl($imgDiv)).toEqual(OC.webroot + '/core/img/filetypes/file.svg');
|
2015-07-13 18:38:13 +03:00
|
|
|
// tries to load preview
|
|
|
|
expect(previewLoadStub.calledOnce).toEqual(true);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
2015-07-13 18:38:13 +03:00
|
|
|
it('renders default icon for folder when none provided', function() {
|
2013-10-28 23:22:06 +04:00
|
|
|
var fileData = {
|
2015-07-13 18:38:13 +03:00
|
|
|
name: 'test dir',
|
|
|
|
mimetype: 'httpd/unix-directory'
|
2013-10-28 23:22:06 +04:00
|
|
|
};
|
2015-07-13 18:38:13 +03:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
var $tr = fileList.add(fileData);
|
2014-12-11 19:36:14 +03:00
|
|
|
var $imgDiv = $tr.find('td.filename .thumbnail');
|
|
|
|
expect(OC.TestUtil.getImageUrl($imgDiv)).toEqual(OC.webroot + '/core/img/filetypes/folder.svg');
|
2015-07-13 18:38:13 +03:00
|
|
|
// no preview since it's a directory
|
2013-10-28 23:22:06 +04:00
|
|
|
expect(previewLoadStub.notCalled).toEqual(true);
|
|
|
|
});
|
|
|
|
it('renders provided icon for file when provided', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
var fileData = new FileInfo({
|
2013-10-28 23:22:06 +04:00
|
|
|
type: 'file',
|
2015-10-28 19:43:36 +03:00
|
|
|
name: 'test file',
|
2015-07-09 19:42:46 +03:00
|
|
|
icon: OC.webroot + '/core/img/filetypes/application-pdf.svg',
|
|
|
|
mimetype: 'application/pdf'
|
2015-07-13 18:38:13 +03:00
|
|
|
});
|
2014-05-09 00:06:30 +04:00
|
|
|
var $tr = fileList.add(fileData);
|
2014-12-11 19:36:14 +03:00
|
|
|
var $imgDiv = $tr.find('td.filename .thumbnail');
|
|
|
|
expect(OC.TestUtil.getImageUrl($imgDiv)).toEqual(OC.webroot + '/core/img/filetypes/application-pdf.svg');
|
2015-07-13 18:38:13 +03:00
|
|
|
// try loading preview
|
|
|
|
expect(previewLoadStub.calledOnce).toEqual(true);
|
|
|
|
});
|
|
|
|
it('renders provided icon for file when provided', function() {
|
|
|
|
var fileData = new FileInfo({
|
|
|
|
name: 'somefile.pdf',
|
|
|
|
icon: OC.webroot + '/core/img/filetypes/application-pdf.svg'
|
|
|
|
});
|
|
|
|
|
|
|
|
var $tr = fileList.add(fileData);
|
|
|
|
var $imgDiv = $tr.find('td.filename .thumbnail');
|
|
|
|
expect(OC.TestUtil.getImageUrl($imgDiv)).toEqual(OC.webroot + '/core/img/filetypes/application-pdf.svg');
|
|
|
|
// try loading preview
|
|
|
|
expect(previewLoadStub.calledOnce).toEqual(true);
|
|
|
|
});
|
|
|
|
it('renders provided icon for folder when provided', function() {
|
|
|
|
var fileData = new FileInfo({
|
|
|
|
name: 'some folder',
|
|
|
|
mimetype: 'httpd/unix-directory',
|
|
|
|
icon: OC.webroot + '/core/img/filetypes/folder-alt.svg'
|
|
|
|
});
|
|
|
|
|
|
|
|
var $tr = fileList.add(fileData);
|
|
|
|
var $imgDiv = $tr.find('td.filename .thumbnail');
|
|
|
|
expect(OC.TestUtil.getImageUrl($imgDiv)).toEqual(OC.webroot + '/core/img/filetypes/folder-alt.svg');
|
|
|
|
// do not load preview for folders
|
2013-10-28 23:22:06 +04:00
|
|
|
expect(previewLoadStub.notCalled).toEqual(true);
|
|
|
|
});
|
2015-07-13 18:38:13 +03:00
|
|
|
it('renders preview when no icon was provided', function() {
|
2013-10-28 23:22:06 +04:00
|
|
|
var fileData = {
|
|
|
|
type: 'file',
|
2015-07-13 18:38:13 +03:00
|
|
|
name: 'test file'
|
2013-10-28 23:22:06 +04:00
|
|
|
};
|
2014-05-09 00:06:30 +04:00
|
|
|
var $tr = fileList.add(fileData);
|
2013-10-28 23:22:06 +04:00
|
|
|
var $td = $tr.find('td.filename');
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(OC.TestUtil.getImageUrl($td.find('.thumbnail')))
|
|
|
|
.toEqual(OC.webroot + '/core/img/filetypes/file.svg');
|
2013-10-28 23:22:06 +04:00
|
|
|
expect(previewLoadStub.calledOnce).toEqual(true);
|
|
|
|
// third argument is callback
|
2014-05-09 00:06:30 +04:00
|
|
|
previewLoadStub.getCall(0).args[0].callback(OC.webroot + '/somepath.png');
|
2014-12-11 19:36:14 +03:00
|
|
|
expect(OC.TestUtil.getImageUrl($td.find('.thumbnail'))).toEqual(OC.webroot + '/somepath.png');
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
2015-10-28 19:43:36 +03:00
|
|
|
it('does not render preview for directories', function() {
|
|
|
|
var fileData = {
|
|
|
|
type: 'dir',
|
|
|
|
mimetype: 'httpd/unix-directory',
|
2015-07-13 18:38:13 +03:00
|
|
|
name: 'test dir'
|
2015-10-28 19:43:36 +03:00
|
|
|
};
|
|
|
|
var $tr = fileList.add(fileData);
|
|
|
|
var $td = $tr.find('td.filename');
|
|
|
|
expect(OC.TestUtil.getImageUrl($td.find('.thumbnail'))).toEqual(OC.webroot + '/core/img/filetypes/folder.svg');
|
|
|
|
expect(previewLoadStub.notCalled).toEqual(true);
|
|
|
|
});
|
|
|
|
it('render external storage icon for external storage root', function() {
|
|
|
|
var fileData = {
|
|
|
|
type: 'dir',
|
|
|
|
mimetype: 'httpd/unix-directory',
|
|
|
|
name: 'test dir',
|
|
|
|
mountType: 'external-root'
|
|
|
|
};
|
|
|
|
var $tr = fileList.add(fileData);
|
|
|
|
var $td = $tr.find('td.filename');
|
|
|
|
expect(OC.TestUtil.getImageUrl($td.find('.thumbnail'))).toEqual(OC.webroot + '/core/img/filetypes/folder-external.svg');
|
|
|
|
expect(previewLoadStub.notCalled).toEqual(true);
|
|
|
|
});
|
|
|
|
it('render external storage icon for external storage subdir', function() {
|
|
|
|
var fileData = {
|
|
|
|
type: 'dir',
|
|
|
|
mimetype: 'httpd/unix-directory',
|
|
|
|
name: 'test dir',
|
|
|
|
mountType: 'external'
|
|
|
|
};
|
|
|
|
var $tr = fileList.add(fileData);
|
|
|
|
var $td = $tr.find('td.filename');
|
|
|
|
expect(OC.TestUtil.getImageUrl($td.find('.thumbnail'))).toEqual(OC.webroot + '/core/img/filetypes/folder-external.svg');
|
|
|
|
expect(previewLoadStub.notCalled).toEqual(true);
|
|
|
|
// default icon override
|
|
|
|
expect($tr.attr('data-icon')).toEqual(OC.webroot + '/core/img/filetypes/folder-external.svg');
|
|
|
|
});
|
|
|
|
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
describe('viewer mode', function() {
|
|
|
|
it('enabling viewer mode hides files table and action buttons', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setViewerMode(true);
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($('#filestable').hasClass('hidden')).toEqual(true);
|
|
|
|
expect($('.actions').hasClass('hidden')).toEqual(true);
|
|
|
|
expect($('.notCreatable').hasClass('hidden')).toEqual(true);
|
|
|
|
});
|
|
|
|
it('disabling viewer mode restores files table and action buttons', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setViewerMode(true);
|
|
|
|
fileList.setViewerMode(false);
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($('#filestable').hasClass('hidden')).toEqual(false);
|
|
|
|
expect($('.actions').hasClass('hidden')).toEqual(false);
|
|
|
|
expect($('.notCreatable').hasClass('hidden')).toEqual(true);
|
|
|
|
});
|
|
|
|
it('disabling viewer mode restores files table and action buttons with correct permissions', function() {
|
|
|
|
$('#permissions').val(0);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setViewerMode(true);
|
|
|
|
fileList.setViewerMode(false);
|
2013-10-28 23:22:06 +04:00
|
|
|
expect($('#filestable').hasClass('hidden')).toEqual(false);
|
|
|
|
expect($('.actions').hasClass('hidden')).toEqual(true);
|
|
|
|
expect($('.notCreatable').hasClass('hidden')).toEqual(false);
|
|
|
|
});
|
2014-05-12 21:54:20 +04:00
|
|
|
it('toggling viewer mode triggers event', function() {
|
|
|
|
var handler = sinon.stub();
|
|
|
|
fileList.$el.on('changeViewerMode', handler);
|
|
|
|
fileList.setViewerMode(true);
|
|
|
|
expect(handler.calledOnce).toEqual(true);
|
|
|
|
expect(handler.getCall(0).args[0].viewerModeEnabled).toEqual(true);
|
|
|
|
|
|
|
|
handler.reset();
|
|
|
|
fileList.setViewerMode(false);
|
|
|
|
expect(handler.calledOnce).toEqual(true);
|
|
|
|
expect(handler.getCall(0).args[0].viewerModeEnabled).toEqual(false);
|
|
|
|
});
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
describe('loading file list', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
var deferredList;
|
|
|
|
var getFolderContentsStub;
|
|
|
|
|
2013-10-28 23:22:06 +04:00
|
|
|
beforeEach(function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredList = $.Deferred();
|
|
|
|
getFolderContentsStub = sinon.stub(filesClient, 'getFolderContents').returns(deferredList.promise());
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
getFolderContentsStub.restore();
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('fetches file list from server and renders it when reload() is called', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.reload();
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(getFolderContentsStub.calledOnce).toEqual(true);
|
|
|
|
expect(getFolderContentsStub.calledWith('/subdir')).toEqual(true);
|
|
|
|
deferredList.resolve(200, [testRoot].concat(testFiles));
|
2014-02-11 19:52:56 +04:00
|
|
|
expect($('#fileList tr').length).toEqual(4);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('switches dir and fetches file list when calling changeDirectory()', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.changeDirectory('/anothersubdir');
|
|
|
|
expect(fileList.getCurrentDirectory()).toEqual('/anothersubdir');
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(getFolderContentsStub.calledOnce).toEqual(true);
|
|
|
|
expect(getFolderContentsStub.calledWith('/anothersubdir')).toEqual(true);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
2015-02-19 19:12:29 +03:00
|
|
|
it('converts backslashes to slashes when calling changeDirectory()', function() {
|
|
|
|
fileList.changeDirectory('/another\\subdir');
|
|
|
|
expect(fileList.getCurrentDirectory()).toEqual('/another/subdir');
|
|
|
|
});
|
2013-10-28 23:22:06 +04:00
|
|
|
it('switches to root dir when current directory does not exist', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.changeDirectory('/unexist');
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredList.reject(404);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.getCurrentDirectory()).toEqual('/');
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
2015-06-19 17:31:22 +03:00
|
|
|
it('switches to root dir when current directory is forbidden', function() {
|
|
|
|
fileList.changeDirectory('/unexist');
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredList.reject(403);
|
2015-06-19 17:31:22 +03:00
|
|
|
expect(fileList.getCurrentDirectory()).toEqual('/');
|
|
|
|
});
|
2015-06-26 18:19:59 +03:00
|
|
|
it('switches to root dir when current directory is unavailable', function() {
|
|
|
|
fileList.changeDirectory('/unexist');
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredList.reject(500);
|
2015-06-26 18:19:59 +03:00
|
|
|
expect(fileList.getCurrentDirectory()).toEqual('/');
|
|
|
|
});
|
2013-10-28 23:22:06 +04:00
|
|
|
it('shows mask before loading file list then hides it at the end', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
var showMaskStub = sinon.stub(fileList, 'showMask');
|
|
|
|
var hideMaskStub = sinon.stub(fileList, 'hideMask');
|
|
|
|
fileList.changeDirectory('/anothersubdir');
|
2013-10-28 23:22:06 +04:00
|
|
|
expect(showMaskStub.calledOnce).toEqual(true);
|
|
|
|
expect(hideMaskStub.calledOnce).toEqual(false);
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredList.resolve(200, [testRoot].concat(testFiles));
|
2013-10-28 23:22:06 +04:00
|
|
|
expect(showMaskStub.calledOnce).toEqual(true);
|
|
|
|
expect(hideMaskStub.calledOnce).toEqual(true);
|
|
|
|
showMaskStub.restore();
|
|
|
|
hideMaskStub.restore();
|
|
|
|
});
|
2014-05-09 00:06:30 +04:00
|
|
|
it('triggers "changeDirectory" event when changing directory', function() {
|
|
|
|
var handler = sinon.stub();
|
|
|
|
$('#app-content-files').on('changeDirectory', handler);
|
|
|
|
fileList.changeDirectory('/somedir');
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredList.resolve(200, [testRoot].concat(testFiles));
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(handler.calledOnce).toEqual(true);
|
|
|
|
expect(handler.getCall(0).args[0].dir).toEqual('/somedir');
|
|
|
|
});
|
2016-05-04 12:17:53 +03:00
|
|
|
it('triggers "afterChangeDirectory" event with fileid after changing directory', function() {
|
|
|
|
var handler = sinon.stub();
|
|
|
|
$('#app-content-files').on('afterChangeDirectory', handler);
|
|
|
|
fileList.changeDirectory('/somedir');
|
|
|
|
deferredList.resolve(200, [testRoot].concat(testFiles));
|
|
|
|
expect(handler.calledOnce).toEqual(true);
|
|
|
|
expect(handler.getCall(0).args[0].dir).toEqual('/somedir');
|
|
|
|
expect(handler.getCall(0).args[0].fileId).toEqual(99);
|
|
|
|
});
|
2014-05-09 00:06:30 +04:00
|
|
|
it('changes the directory when receiving "urlChanged" event', function() {
|
|
|
|
$('#app-content-files').trigger(new $.Event('urlChanged', {view: 'files', dir: '/somedir'}));
|
|
|
|
expect(fileList.getCurrentDirectory()).toEqual('/somedir');
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('refreshes breadcrumb after update', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
var setDirSpy = sinon.spy(fileList.breadcrumb, 'setDirectory');
|
|
|
|
fileList.changeDirectory('/anothersubdir');
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredList.resolve(200, [testRoot].concat(testFiles));
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.breadcrumb.setDirectory.calledOnce).toEqual(true);
|
|
|
|
expect(fileList.breadcrumb.setDirectory.calledWith('/anothersubdir')).toEqual(true);
|
2013-10-28 23:22:06 +04:00
|
|
|
setDirSpy.restore();
|
2015-07-13 18:38:13 +03:00
|
|
|
getFolderContentsStub.restore();
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('breadcrumb events', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
var deferredList;
|
|
|
|
var getFolderContentsStub;
|
|
|
|
|
2013-10-28 23:22:06 +04:00
|
|
|
beforeEach(function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredList = $.Deferred();
|
|
|
|
getFolderContentsStub = sinon.stub(filesClient, 'getFolderContents').returns(deferredList.promise());
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
getFolderContentsStub.restore();
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('clicking on root breadcrumb changes directory to root', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.changeDirectory('/subdir/two/three with space/four/five');
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredList.resolve(200, [testRoot].concat(testFiles));
|
2014-05-09 00:06:30 +04:00
|
|
|
var changeDirStub = sinon.stub(fileList, 'changeDirectory');
|
2015-03-25 11:27:55 +03:00
|
|
|
fileList.breadcrumb.$el.find('.crumb:eq(0)').trigger({type: 'click', which: 1});
|
2013-10-28 23:22:06 +04:00
|
|
|
|
|
|
|
expect(changeDirStub.calledOnce).toEqual(true);
|
|
|
|
expect(changeDirStub.getCall(0).args[0]).toEqual('/');
|
|
|
|
changeDirStub.restore();
|
|
|
|
});
|
|
|
|
it('clicking on breadcrumb changes directory', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.changeDirectory('/subdir/two/three with space/four/five');
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredList.resolve(200, [testRoot].concat(testFiles));
|
2014-05-09 00:06:30 +04:00
|
|
|
var changeDirStub = sinon.stub(fileList, 'changeDirectory');
|
2015-03-25 11:27:55 +03:00
|
|
|
fileList.breadcrumb.$el.find('.crumb:eq(3)').trigger({type: 'click', which: 1});
|
2013-10-28 23:22:06 +04:00
|
|
|
|
|
|
|
expect(changeDirStub.calledOnce).toEqual(true);
|
|
|
|
expect(changeDirStub.getCall(0).args[0]).toEqual('/subdir/two/three with space');
|
|
|
|
changeDirStub.restore();
|
|
|
|
});
|
|
|
|
it('dropping files on breadcrumb calls move operation', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
var testDir = '/subdir/two/three with space/four/five';
|
|
|
|
var moveStub = sinon.stub(filesClient, 'move').returns($.Deferred().promise());
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.changeDirectory(testDir);
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredList.resolve(200, [testRoot].concat(testFiles));
|
2014-05-09 00:06:30 +04:00
|
|
|
var $crumb = fileList.breadcrumb.$el.find('.crumb:eq(3)');
|
2013-10-28 23:22:06 +04:00
|
|
|
// no idea what this is but is required by the handler
|
|
|
|
var ui = {
|
|
|
|
helper: {
|
|
|
|
find: sinon.stub()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// returns a list of tr that were dragged
|
|
|
|
ui.helper.find.returns([
|
2014-04-11 14:46:12 +04:00
|
|
|
$('<tr data-file="One.txt" data-dir="' + testDir + '"></tr>'),
|
|
|
|
$('<tr data-file="Two.jpg" data-dir="' + testDir + '"></tr>')
|
2013-10-28 23:22:06 +04:00
|
|
|
]);
|
|
|
|
// simulate drop event
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._onDropOnBreadCrumb(new $.Event('drop', {target: $crumb}), ui);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(moveStub.callCount).toEqual(2);
|
|
|
|
expect(moveStub.getCall(0).args[0]).toEqual(testDir + '/One.txt');
|
|
|
|
expect(moveStub.getCall(0).args[1]).toEqual('/subdir/two/three with space/One.txt');
|
|
|
|
expect(moveStub.getCall(1).args[0]).toEqual(testDir + '/Two.jpg');
|
|
|
|
expect(moveStub.getCall(1).args[1]).toEqual('/subdir/two/three with space/Two.jpg');
|
|
|
|
moveStub.restore();
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('dropping files on same dir breadcrumb does nothing', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
var testDir = '/subdir/two/three with space/four/five';
|
2015-07-13 18:38:13 +03:00
|
|
|
var moveStub = sinon.stub(filesClient, 'move').returns($.Deferred().promise());
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.changeDirectory(testDir);
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredList.resolve(200, [testRoot].concat(testFiles));
|
2014-05-09 00:06:30 +04:00
|
|
|
var $crumb = fileList.breadcrumb.$el.find('.crumb:last');
|
2013-10-28 23:22:06 +04:00
|
|
|
// no idea what this is but is required by the handler
|
|
|
|
var ui = {
|
|
|
|
helper: {
|
|
|
|
find: sinon.stub()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// returns a list of tr that were dragged
|
|
|
|
ui.helper.find.returns([
|
2014-04-11 14:46:12 +04:00
|
|
|
$('<tr data-file="One.txt" data-dir="' + testDir + '"></tr>'),
|
|
|
|
$('<tr data-file="Two.jpg" data-dir="' + testDir + '"></tr>')
|
2013-10-28 23:22:06 +04:00
|
|
|
]);
|
|
|
|
// simulate drop event
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList._onDropOnBreadCrumb(new $.Event('drop', {target: $crumb}), ui);
|
2013-10-28 23:22:06 +04:00
|
|
|
|
|
|
|
// no extra server request
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(moveStub.notCalled).toEqual(true);
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
2014-01-12 21:57:53 +04:00
|
|
|
});
|
2014-02-13 23:20:00 +04:00
|
|
|
describe('Download Url', function() {
|
|
|
|
it('returns correct download URL for single files', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(fileList.getDownloadUrl('some file.txt'))
|
|
|
|
.toEqual(OC.webroot + '/remote.php/webdav/subdir/some%20file.txt');
|
|
|
|
expect(fileList.getDownloadUrl('some file.txt', '/anotherpath/abc'))
|
|
|
|
.toEqual(OC.webroot + '/remote.php/webdav/anotherpath/abc/some%20file.txt');
|
2014-02-13 23:20:00 +04:00
|
|
|
$('#dir').val('/');
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(fileList.getDownloadUrl('some file.txt'))
|
|
|
|
.toEqual(OC.webroot + '/remote.php/webdav/some%20file.txt');
|
2014-02-13 23:20:00 +04:00
|
|
|
});
|
|
|
|
it('returns correct download URL for multiple files', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(fileList.getDownloadUrl(['a b c.txt', 'd e f.txt']))
|
|
|
|
.toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=%5B%22a%20b%20c.txt%22%2C%22d%20e%20f.txt%22%5D');
|
2013-10-28 23:22:06 +04:00
|
|
|
});
|
|
|
|
it('returns the correct ajax URL', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(fileList.getAjaxUrl('test', {a:1, b:'x y'}))
|
|
|
|
.toEqual(OC.webroot + '/index.php/apps/files/ajax/test.php?a=1&b=x%20y');
|
2014-02-13 23:20:00 +04:00
|
|
|
});
|
2014-01-24 16:32:31 +04:00
|
|
|
});
|
2014-02-12 17:50:23 +04:00
|
|
|
describe('File selection', function() {
|
|
|
|
beforeEach(function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles(testFiles);
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
|
|
|
it('Selects a file when clicking its checkbox', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
2014-02-12 17:50:23 +04:00
|
|
|
expect($tr.find('input:checkbox').prop('checked')).toEqual(false);
|
|
|
|
$tr.find('td.filename input:checkbox').click();
|
|
|
|
|
|
|
|
expect($tr.find('input:checkbox').prop('checked')).toEqual(true);
|
|
|
|
});
|
2014-04-04 20:46:08 +04:00
|
|
|
it('Selects/deselect a file when clicking on the name while holding Ctrl', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
|
|
|
var $tr2 = fileList.findFileEl('Three.pdf');
|
2014-04-04 20:46:08 +04:00
|
|
|
var e;
|
|
|
|
expect($tr.find('input:checkbox').prop('checked')).toEqual(false);
|
|
|
|
expect($tr2.find('input:checkbox').prop('checked')).toEqual(false);
|
|
|
|
e = new $.Event('click');
|
|
|
|
e.ctrlKey = true;
|
|
|
|
$tr.find('td.filename .name').trigger(e);
|
|
|
|
|
|
|
|
expect($tr.find('input:checkbox').prop('checked')).toEqual(true);
|
|
|
|
expect($tr2.find('input:checkbox').prop('checked')).toEqual(false);
|
|
|
|
|
|
|
|
// click on second entry, does not clear the selection
|
|
|
|
e = new $.Event('click');
|
|
|
|
e.ctrlKey = true;
|
|
|
|
$tr2.find('td.filename .name').trigger(e);
|
|
|
|
expect($tr.find('input:checkbox').prop('checked')).toEqual(true);
|
|
|
|
expect($tr2.find('input:checkbox').prop('checked')).toEqual(true);
|
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(_.pluck(fileList.getSelectedFiles(), 'name')).toEqual(['One.txt', 'Three.pdf']);
|
2014-04-04 20:46:08 +04:00
|
|
|
|
|
|
|
// deselect now
|
|
|
|
e = new $.Event('click');
|
|
|
|
e.ctrlKey = true;
|
|
|
|
$tr2.find('td.filename .name').trigger(e);
|
|
|
|
expect($tr.find('input:checkbox').prop('checked')).toEqual(true);
|
|
|
|
expect($tr2.find('input:checkbox').prop('checked')).toEqual(false);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(_.pluck(fileList.getSelectedFiles(), 'name')).toEqual(['One.txt']);
|
2014-04-04 20:46:08 +04:00
|
|
|
});
|
|
|
|
it('Selects a range when clicking on one file then Shift clicking on another one', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
|
|
|
var $tr2 = fileList.findFileEl('Three.pdf');
|
2014-04-04 20:46:08 +04:00
|
|
|
var e;
|
|
|
|
$tr.find('td.filename input:checkbox').click();
|
|
|
|
e = new $.Event('click');
|
|
|
|
e.shiftKey = true;
|
|
|
|
$tr2.find('td.filename .name').trigger(e);
|
|
|
|
|
|
|
|
expect($tr.find('input:checkbox').prop('checked')).toEqual(true);
|
|
|
|
expect($tr2.find('input:checkbox').prop('checked')).toEqual(true);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('Two.jpg').find('input:checkbox').prop('checked')).toEqual(true);
|
|
|
|
var selection = _.pluck(fileList.getSelectedFiles(), 'name');
|
2014-04-04 20:46:08 +04:00
|
|
|
expect(selection.length).toEqual(3);
|
|
|
|
expect(selection).toContain('One.txt');
|
|
|
|
expect(selection).toContain('Two.jpg');
|
|
|
|
expect(selection).toContain('Three.pdf');
|
|
|
|
});
|
|
|
|
it('Selects a range when clicking on one file then Shift clicking on another one that is above the first one', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
|
|
|
var $tr2 = fileList.findFileEl('Three.pdf');
|
2014-04-04 20:46:08 +04:00
|
|
|
var e;
|
|
|
|
$tr2.find('td.filename input:checkbox').click();
|
|
|
|
e = new $.Event('click');
|
|
|
|
e.shiftKey = true;
|
|
|
|
$tr.find('td.filename .name').trigger(e);
|
|
|
|
|
|
|
|
expect($tr.find('input:checkbox').prop('checked')).toEqual(true);
|
|
|
|
expect($tr2.find('input:checkbox').prop('checked')).toEqual(true);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('Two.jpg').find('input:checkbox').prop('checked')).toEqual(true);
|
|
|
|
var selection = _.pluck(fileList.getSelectedFiles(), 'name');
|
2014-04-04 20:46:08 +04:00
|
|
|
expect(selection.length).toEqual(3);
|
|
|
|
expect(selection).toContain('One.txt');
|
|
|
|
expect(selection).toContain('Two.jpg');
|
|
|
|
expect(selection).toContain('Three.pdf');
|
|
|
|
});
|
2014-02-12 17:50:23 +04:00
|
|
|
it('Selecting all files will automatically check "select all" checkbox', function() {
|
2014-05-12 21:54:20 +04:00
|
|
|
expect($('.select-all').prop('checked')).toEqual(false);
|
2014-02-12 17:50:23 +04:00
|
|
|
$('#fileList tr td.filename input:checkbox').click();
|
2014-05-12 21:54:20 +04:00
|
|
|
expect($('.select-all').prop('checked')).toEqual(true);
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
2014-04-04 20:46:08 +04:00
|
|
|
it('Selecting all files on the first visible page will not automatically check "select all" checkbox', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles(generateFiles(0, 41));
|
2014-05-12 21:54:20 +04:00
|
|
|
expect($('.select-all').prop('checked')).toEqual(false);
|
2014-04-04 20:46:08 +04:00
|
|
|
$('#fileList tr td.filename input:checkbox').click();
|
2014-05-12 21:54:20 +04:00
|
|
|
expect($('.select-all').prop('checked')).toEqual(false);
|
2014-04-04 20:46:08 +04:00
|
|
|
});
|
2014-02-12 17:50:23 +04:00
|
|
|
it('Clicking "select all" will select/deselect all files', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles(generateFiles(0, 41));
|
2014-05-12 21:54:20 +04:00
|
|
|
$('.select-all').click();
|
|
|
|
expect($('.select-all').prop('checked')).toEqual(true);
|
2014-02-12 17:50:23 +04:00
|
|
|
$('#fileList tr input:checkbox').each(function() {
|
|
|
|
expect($(this).prop('checked')).toEqual(true);
|
|
|
|
});
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(_.pluck(fileList.getSelectedFiles(), 'name').length).toEqual(42);
|
2014-02-12 17:50:23 +04:00
|
|
|
|
2014-05-12 21:54:20 +04:00
|
|
|
$('.select-all').click();
|
|
|
|
expect($('.select-all').prop('checked')).toEqual(false);
|
2014-02-12 17:50:23 +04:00
|
|
|
|
|
|
|
$('#fileList tr input:checkbox').each(function() {
|
|
|
|
expect($(this).prop('checked')).toEqual(false);
|
|
|
|
});
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(_.pluck(fileList.getSelectedFiles(), 'name').length).toEqual(0);
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
|
|
|
it('Clicking "select all" then deselecting a file will uncheck "select all"', function() {
|
2014-05-12 21:54:20 +04:00
|
|
|
$('.select-all').click();
|
|
|
|
expect($('.select-all').prop('checked')).toEqual(true);
|
2014-02-12 17:50:23 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
2014-02-12 17:50:23 +04:00
|
|
|
$tr.find('input:checkbox').click();
|
|
|
|
|
2014-05-12 21:54:20 +04:00
|
|
|
expect($('.select-all').prop('checked')).toEqual(false);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(_.pluck(fileList.getSelectedFiles(), 'name').length).toEqual(3);
|
2014-04-04 20:46:08 +04:00
|
|
|
});
|
2014-04-10 22:07:02 +04:00
|
|
|
it('Updates the selection summary when doing a few manipulations with "Select all"', function() {
|
2014-05-12 21:54:20 +04:00
|
|
|
$('.select-all').click();
|
|
|
|
expect($('.select-all').prop('checked')).toEqual(true);
|
2014-04-10 22:07:02 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
2014-04-10 22:07:02 +04:00
|
|
|
// unselect one
|
|
|
|
$tr.find('input:checkbox').click();
|
|
|
|
|
2014-05-12 21:54:20 +04:00
|
|
|
expect($('.select-all').prop('checked')).toEqual(false);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(_.pluck(fileList.getSelectedFiles(), 'name').length).toEqual(3);
|
2014-04-10 22:07:02 +04:00
|
|
|
|
|
|
|
// select all
|
2014-05-12 21:54:20 +04:00
|
|
|
$('.select-all').click();
|
|
|
|
expect($('.select-all').prop('checked')).toEqual(true);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(_.pluck(fileList.getSelectedFiles(), 'name').length).toEqual(4);
|
2014-04-10 22:07:02 +04:00
|
|
|
|
|
|
|
// unselect one
|
|
|
|
$tr.find('input:checkbox').click();
|
2014-05-12 21:54:20 +04:00
|
|
|
expect($('.select-all').prop('checked')).toEqual(false);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(_.pluck(fileList.getSelectedFiles(), 'name').length).toEqual(3);
|
2014-04-10 22:07:02 +04:00
|
|
|
|
|
|
|
// re-select it
|
|
|
|
$tr.find('input:checkbox').click();
|
2014-05-12 21:54:20 +04:00
|
|
|
expect($('.select-all').prop('checked')).toEqual(true);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(_.pluck(fileList.getSelectedFiles(), 'name').length).toEqual(4);
|
2014-04-10 22:07:02 +04:00
|
|
|
});
|
2014-04-04 20:46:08 +04:00
|
|
|
it('Auto-selects files on next page when "select all" is checked', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles(generateFiles(0, 41));
|
2014-05-12 21:54:20 +04:00
|
|
|
$('.select-all').click();
|
2014-04-04 20:46:08 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.$fileList.find('tr input:checkbox:checked').length).toEqual(20);
|
|
|
|
fileList._nextPage(true);
|
|
|
|
expect(fileList.$fileList.find('tr input:checkbox:checked').length).toEqual(40);
|
|
|
|
fileList._nextPage(true);
|
|
|
|
expect(fileList.$fileList.find('tr input:checkbox:checked').length).toEqual(42);
|
|
|
|
expect(_.pluck(fileList.getSelectedFiles(), 'name').length).toEqual(42);
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
|
|
|
it('Selecting files updates selection summary', function() {
|
2014-04-03 22:57:06 +04:00
|
|
|
var $summary = $('#headerName a.name>span:first');
|
2014-02-12 17:50:23 +04:00
|
|
|
expect($summary.text()).toEqual('Name');
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.findFileEl('One.txt').find('input:checkbox').click();
|
|
|
|
fileList.findFileEl('Three.pdf').find('input:checkbox').click();
|
|
|
|
fileList.findFileEl('somedir').find('input:checkbox').click();
|
2015-08-17 15:31:44 +03:00
|
|
|
expect($summary.text()).toEqual('1 folder and 2 files');
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
|
|
|
it('Unselecting files hides selection summary', function() {
|
2014-04-03 22:57:06 +04:00
|
|
|
var $summary = $('#headerName a.name>span:first');
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.findFileEl('One.txt').find('input:checkbox').click().click();
|
2014-02-12 17:50:23 +04:00
|
|
|
expect($summary.text()).toEqual('Name');
|
|
|
|
});
|
|
|
|
it('Select/deselect files shows/hides file actions', function() {
|
|
|
|
var $actions = $('#headerName .selectedActions');
|
2014-05-09 00:06:30 +04:00
|
|
|
var $checkbox = fileList.findFileEl('One.txt').find('input:checkbox');
|
2014-02-12 17:50:23 +04:00
|
|
|
expect($actions.hasClass('hidden')).toEqual(true);
|
|
|
|
$checkbox.click();
|
|
|
|
expect($actions.hasClass('hidden')).toEqual(false);
|
|
|
|
$checkbox.click();
|
|
|
|
expect($actions.hasClass('hidden')).toEqual(true);
|
|
|
|
});
|
|
|
|
it('Selection is cleared when switching dirs', function() {
|
2014-05-12 21:54:20 +04:00
|
|
|
$('.select-all').click();
|
2015-07-13 18:38:13 +03:00
|
|
|
var deferredList = $.Deferred();
|
|
|
|
var getFolderContentsStub = sinon.stub(filesClient, 'getFolderContents').returns(deferredList.promise());
|
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.changeDirectory('/');
|
2015-07-13 18:38:13 +03:00
|
|
|
|
|
|
|
deferredList.resolve(200, [testRoot].concat(testFiles));
|
|
|
|
|
2014-05-12 21:54:20 +04:00
|
|
|
expect($('.select-all').prop('checked')).toEqual(false);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(_.pluck(fileList.getSelectedFiles(), 'name')).toEqual([]);
|
2015-07-13 18:38:13 +03:00
|
|
|
|
|
|
|
getFolderContentsStub.restore();
|
2014-04-04 20:46:08 +04:00
|
|
|
});
|
|
|
|
it('getSelectedFiles returns the selected files even when they are on the next page', function() {
|
|
|
|
var selectedFiles;
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.setFiles(generateFiles(0, 41));
|
2014-05-12 21:54:20 +04:00
|
|
|
$('.select-all').click();
|
2014-04-04 20:46:08 +04:00
|
|
|
// unselect one to not have the "allFiles" case
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.$fileList.find('tr input:checkbox:first').click();
|
2014-04-04 20:46:08 +04:00
|
|
|
|
|
|
|
// only 20 files visible, must still return all the selected ones
|
2014-05-09 00:06:30 +04:00
|
|
|
selectedFiles = _.pluck(fileList.getSelectedFiles(), 'name');
|
2014-04-04 20:46:08 +04:00
|
|
|
|
|
|
|
expect(selectedFiles.length).toEqual(41);
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
2014-06-23 14:55:42 +04:00
|
|
|
describe('clearing the selection', function() {
|
|
|
|
it('clears selected files selected individually calling setFiles()', function() {
|
|
|
|
var selectedFiles;
|
|
|
|
|
|
|
|
fileList.setFiles(generateFiles(0, 41));
|
|
|
|
fileList.$fileList.find('tr:eq(5) input:checkbox:first').click();
|
|
|
|
fileList.$fileList.find('tr:eq(7) input:checkbox:first').click();
|
|
|
|
|
|
|
|
selectedFiles = _.pluck(fileList.getSelectedFiles(), 'name');
|
|
|
|
expect(selectedFiles.length).toEqual(2);
|
|
|
|
|
|
|
|
fileList.setFiles(generateFiles(0, 2));
|
|
|
|
|
|
|
|
selectedFiles = _.pluck(fileList.getSelectedFiles(), 'name');
|
|
|
|
expect(selectedFiles.length).toEqual(0);
|
|
|
|
});
|
|
|
|
it('clears selected files selected with select all when calling setFiles()', function() {
|
|
|
|
var selectedFiles;
|
|
|
|
|
|
|
|
fileList.setFiles(generateFiles(0, 41));
|
|
|
|
$('.select-all').click();
|
|
|
|
|
|
|
|
selectedFiles = _.pluck(fileList.getSelectedFiles(), 'name');
|
|
|
|
expect(selectedFiles.length).toEqual(42);
|
|
|
|
|
|
|
|
fileList.setFiles(generateFiles(0, 2));
|
|
|
|
|
|
|
|
selectedFiles = _.pluck(fileList.getSelectedFiles(), 'name');
|
|
|
|
expect(selectedFiles.length).toEqual(0);
|
|
|
|
});
|
|
|
|
});
|
2014-05-12 21:54:20 +04:00
|
|
|
describe('Selection overlay', function() {
|
2014-11-25 19:16:23 +03:00
|
|
|
it('show doesnt show the delete action if one or more files are not deletable', function () {
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
$('#permissions').val(OC.PERMISSION_READ | OC.PERMISSION_DELETE);
|
|
|
|
$('.select-all').click();
|
|
|
|
expect(fileList.$el.find('.delete-selected').hasClass('hidden')).toEqual(false);
|
|
|
|
testFiles[0].permissions = OC.PERMISSION_READ;
|
|
|
|
$('.select-all').click();
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
$('.select-all').click();
|
|
|
|
expect(fileList.$el.find('.delete-selected').hasClass('hidden')).toEqual(true);
|
|
|
|
});
|
2014-05-12 21:54:20 +04:00
|
|
|
});
|
2014-02-12 17:50:23 +04:00
|
|
|
describe('Actions', function() {
|
|
|
|
beforeEach(function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.findFileEl('One.txt').find('input:checkbox').click();
|
|
|
|
fileList.findFileEl('Three.pdf').find('input:checkbox').click();
|
|
|
|
fileList.findFileEl('somedir').find('input:checkbox').click();
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
2014-04-04 20:46:08 +04:00
|
|
|
it('getSelectedFiles returns the selected file data', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
var files = fileList.getSelectedFiles();
|
2014-02-12 17:50:23 +04:00
|
|
|
expect(files.length).toEqual(3);
|
|
|
|
expect(files[0]).toEqual({
|
|
|
|
id: 1,
|
|
|
|
name: 'One.txt',
|
|
|
|
mimetype: 'text/plain',
|
2015-08-24 18:16:20 +03:00
|
|
|
mtime: 123456789,
|
2014-02-12 17:50:23 +04:00
|
|
|
type: 'file',
|
|
|
|
size: 12,
|
2014-11-25 19:16:23 +03:00
|
|
|
etag: 'abc',
|
|
|
|
permissions: OC.PERMISSION_ALL
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
|
|
|
expect(files[1]).toEqual({
|
|
|
|
id: 3,
|
|
|
|
type: 'file',
|
|
|
|
name: 'Three.pdf',
|
|
|
|
mimetype: 'application/pdf',
|
2015-08-24 18:16:20 +03:00
|
|
|
mtime: 234560000,
|
2014-02-12 17:50:23 +04:00
|
|
|
size: 58009,
|
2014-11-25 19:16:23 +03:00
|
|
|
etag: '123',
|
|
|
|
permissions: OC.PERMISSION_ALL
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
|
|
|
expect(files[2]).toEqual({
|
|
|
|
id: 4,
|
|
|
|
type: 'dir',
|
|
|
|
name: 'somedir',
|
|
|
|
mimetype: 'httpd/unix-directory',
|
2015-08-24 18:16:20 +03:00
|
|
|
mtime: 134560000,
|
2014-02-12 17:50:23 +04:00
|
|
|
size: 250,
|
2014-11-25 19:16:23 +03:00
|
|
|
etag: '456',
|
|
|
|
permissions: OC.PERMISSION_ALL
|
2014-04-04 20:46:08 +04:00
|
|
|
});
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(files[0].id).toEqual(1);
|
|
|
|
expect(files[0].name).toEqual('One.txt');
|
|
|
|
expect(files[1].id).toEqual(3);
|
|
|
|
expect(files[1].name).toEqual('Three.pdf');
|
|
|
|
expect(files[2].id).toEqual(4);
|
|
|
|
expect(files[2].name).toEqual('somedir');
|
2014-04-04 20:46:08 +04:00
|
|
|
});
|
|
|
|
it('Removing a file removes it from the selection', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.remove('Three.pdf');
|
|
|
|
var files = fileList.getSelectedFiles();
|
2014-04-04 20:46:08 +04:00
|
|
|
expect(files.length).toEqual(2);
|
|
|
|
expect(files[0]).toEqual({
|
|
|
|
id: 1,
|
|
|
|
name: 'One.txt',
|
|
|
|
mimetype: 'text/plain',
|
2015-08-24 18:16:20 +03:00
|
|
|
mtime: 123456789,
|
2014-04-04 20:46:08 +04:00
|
|
|
type: 'file',
|
|
|
|
size: 12,
|
2014-11-25 19:16:23 +03:00
|
|
|
etag: 'abc',
|
|
|
|
permissions: OC.PERMISSION_ALL
|
2014-04-04 20:46:08 +04:00
|
|
|
});
|
|
|
|
expect(files[1]).toEqual({
|
|
|
|
id: 4,
|
|
|
|
type: 'dir',
|
|
|
|
name: 'somedir',
|
|
|
|
mimetype: 'httpd/unix-directory',
|
2015-08-24 18:16:20 +03:00
|
|
|
mtime: 134560000,
|
2014-04-04 20:46:08 +04:00
|
|
|
size: 250,
|
2014-11-25 19:16:23 +03:00
|
|
|
etag: '456',
|
|
|
|
permissions: OC.PERMISSION_ALL
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('Download', function() {
|
|
|
|
it('Opens download URL when clicking "Download"', function() {
|
|
|
|
$('.selectedActions .download').click();
|
|
|
|
expect(redirectStub.calledOnce).toEqual(true);
|
2015-06-29 16:55:46 +03:00
|
|
|
expect(redirectStub.getCall(0).args[0]).toContain(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=%5B%22One.txt%22%2C%22Three.pdf%22%2C%22somedir%22%5D');
|
2014-02-12 17:50:23 +04:00
|
|
|
redirectStub.restore();
|
|
|
|
});
|
|
|
|
it('Downloads root folder when all selected in root folder', function() {
|
|
|
|
$('#dir').val('/');
|
2014-05-12 21:54:20 +04:00
|
|
|
$('.select-all').click();
|
2014-02-12 17:50:23 +04:00
|
|
|
$('.selectedActions .download').click();
|
|
|
|
expect(redirectStub.calledOnce).toEqual(true);
|
2015-06-29 16:55:46 +03:00
|
|
|
expect(redirectStub.getCall(0).args[0]).toContain(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2F&files=');
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
|
|
|
it('Downloads parent folder when all selected in subfolder', function() {
|
2014-05-12 21:54:20 +04:00
|
|
|
$('.select-all').click();
|
2014-02-12 17:50:23 +04:00
|
|
|
$('.selectedActions .download').click();
|
|
|
|
expect(redirectStub.calledOnce).toEqual(true);
|
2015-06-29 16:55:46 +03:00
|
|
|
expect(redirectStub.getCall(0).args[0]).toContain(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2F&files=subdir');
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('Delete', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
var deleteStub, deferredDelete;
|
|
|
|
beforeEach(function() {
|
|
|
|
deferredDelete = $.Deferred();
|
|
|
|
deleteStub = sinon.stub(filesClient, 'remove').returns(deferredDelete.promise());
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
deleteStub.restore();
|
|
|
|
});
|
2014-02-12 17:50:23 +04:00
|
|
|
it('Deletes selected files when "Delete" clicked', function() {
|
|
|
|
$('.selectedActions .delete-selected').click();
|
2015-07-13 18:38:13 +03:00
|
|
|
|
|
|
|
expect(deleteStub.callCount).toEqual(3);
|
|
|
|
expect(deleteStub.getCall(0).args[0]).toEqual('/subdir/One.txt');
|
|
|
|
expect(deleteStub.getCall(1).args[0]).toEqual('/subdir/Three.pdf');
|
|
|
|
expect(deleteStub.getCall(2).args[0]).toEqual('/subdir/somedir');
|
|
|
|
|
|
|
|
deferredDelete.resolve(204);
|
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(0);
|
|
|
|
expect(fileList.findFileEl('Three.pdf').length).toEqual(0);
|
|
|
|
expect(fileList.findFileEl('somedir').length).toEqual(0);
|
|
|
|
expect(fileList.findFileEl('Two.jpg').length).toEqual(1);
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
|
|
|
it('Deletes all files when all selected when "Delete" clicked', function() {
|
2014-05-12 21:54:20 +04:00
|
|
|
$('.select-all').click();
|
2014-02-12 17:50:23 +04:00
|
|
|
$('.selectedActions .delete-selected').click();
|
2015-07-13 18:38:13 +03:00
|
|
|
|
|
|
|
expect(deleteStub.callCount).toEqual(4);
|
|
|
|
expect(deleteStub.getCall(0).args[0]).toEqual('/subdir/One.txt');
|
|
|
|
expect(deleteStub.getCall(1).args[0]).toEqual('/subdir/Two.jpg');
|
|
|
|
expect(deleteStub.getCall(2).args[0]).toEqual('/subdir/Three.pdf');
|
|
|
|
expect(deleteStub.getCall(3).args[0]).toEqual('/subdir/somedir');
|
|
|
|
|
|
|
|
deferredDelete.resolve(204);
|
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.isEmpty).toEqual(true);
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-04-29 20:49:11 +04:00
|
|
|
it('resets the file selection on reload', function() {
|
2014-05-12 21:54:20 +04:00
|
|
|
fileList.$el.find('.select-all').click();
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.reload();
|
2014-05-12 21:54:20 +04:00
|
|
|
expect(fileList.$el.find('.select-all').prop('checked')).toEqual(false);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.getSelectedFiles()).toEqual([]);
|
2014-04-29 20:49:11 +04:00
|
|
|
});
|
2015-01-15 20:16:27 +03:00
|
|
|
describe('Disabled selection', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
fileList._allowSelection = false;
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
});
|
|
|
|
it('Does not render checkboxes', function() {
|
|
|
|
expect(fileList.$fileList.find('.selectCheckBox').length).toEqual(0);
|
|
|
|
});
|
|
|
|
it('Does not select a file with Ctrl or Shift if selection is not allowed', function() {
|
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
|
|
|
var $tr2 = fileList.findFileEl('Three.pdf');
|
|
|
|
var e;
|
|
|
|
e = new $.Event('click');
|
|
|
|
e.ctrlKey = true;
|
|
|
|
$tr.find('td.filename .name').trigger(e);
|
|
|
|
|
|
|
|
// click on second entry, does not clear the selection
|
|
|
|
e = new $.Event('click');
|
|
|
|
e.ctrlKey = true;
|
|
|
|
$tr2.find('td.filename .name').trigger(e);
|
|
|
|
|
|
|
|
expect(fileList.getSelectedFiles().length).toEqual(0);
|
|
|
|
|
|
|
|
// deselect now
|
|
|
|
e = new $.Event('click');
|
|
|
|
e.shiftKey = true;
|
|
|
|
$tr2.find('td.filename .name').trigger(e);
|
|
|
|
expect(fileList.getSelectedFiles().length).toEqual(0);
|
|
|
|
});
|
2015-10-15 17:30:50 +03:00
|
|
|
});
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
2015-07-17 15:09:00 +03:00
|
|
|
describe('Details sidebar', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
fileList.setFiles(testFiles);
|
2015-09-25 13:23:28 +03:00
|
|
|
fileList.showDetailsView('Two.jpg');
|
2015-07-17 15:09:00 +03:00
|
|
|
});
|
2015-10-15 17:30:50 +03:00
|
|
|
describe('registering', function() {
|
|
|
|
var addTabStub;
|
|
|
|
var addDetailStub;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
addTabStub = sinon.stub(OCA.Files.DetailsView.prototype, 'addTabView');
|
|
|
|
addDetailStub = sinon.stub(OCA.Files.DetailsView.prototype, 'addDetailView');
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
addTabStub.restore();
|
|
|
|
addDetailStub.restore();
|
|
|
|
});
|
|
|
|
it('forward the registered views to the underlying DetailsView', function() {
|
|
|
|
fileList.destroy();
|
|
|
|
fileList = new OCA.Files.FileList($('#app-content-files'), {
|
|
|
|
detailsViewEnabled: true
|
|
|
|
});
|
|
|
|
fileList.registerTabView(new OCA.Files.DetailTabView());
|
|
|
|
fileList.registerDetailView(new OCA.Files.DetailFileInfoView());
|
|
|
|
|
|
|
|
expect(addTabStub.calledOnce).toEqual(true);
|
|
|
|
// twice because the filelist already registers one by default
|
|
|
|
expect(addDetailStub.calledTwice).toEqual(true);
|
|
|
|
});
|
|
|
|
it('does not error when registering panels when not details view configured', function() {
|
|
|
|
fileList.destroy();
|
|
|
|
fileList = new OCA.Files.FileList($('#app-content-files'), {
|
|
|
|
detailsViewEnabled: false
|
|
|
|
});
|
|
|
|
fileList.registerTabView(new OCA.Files.DetailTabView());
|
|
|
|
fileList.registerDetailView(new OCA.Files.DetailFileInfoView());
|
|
|
|
|
|
|
|
expect(addTabStub.notCalled).toEqual(true);
|
|
|
|
expect(addDetailStub.notCalled).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
2015-09-25 13:23:28 +03:00
|
|
|
it('triggers file action when clicking on row if no details view configured', function() {
|
2015-10-15 17:30:50 +03:00
|
|
|
fileList.destroy();
|
|
|
|
fileList = new OCA.Files.FileList($('#app-content-files'), {
|
|
|
|
detailsViewEnabled: false
|
|
|
|
});
|
2015-07-17 15:09:00 +03:00
|
|
|
var updateDetailsViewStub = sinon.stub(fileList, '_updateDetailsView');
|
|
|
|
var actionStub = sinon.stub();
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
fileList.fileActions.register(
|
|
|
|
'text/plain',
|
|
|
|
'Test',
|
|
|
|
OC.PERMISSION_ALL,
|
|
|
|
function() {
|
|
|
|
// Specify icon for hitory button
|
|
|
|
return OC.imagePath('core','actions/history');
|
|
|
|
},
|
|
|
|
actionStub
|
|
|
|
);
|
|
|
|
fileList.fileActions.setDefault('text/plain', 'Test');
|
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
|
|
|
$tr.find('td.filename>a.name').click();
|
|
|
|
expect(actionStub.calledOnce).toEqual(true);
|
|
|
|
expect(updateDetailsViewStub.notCalled).toEqual(true);
|
|
|
|
updateDetailsViewStub.restore();
|
|
|
|
});
|
2015-09-25 13:23:28 +03:00
|
|
|
it('highlights current file when clicked and updates sidebar', function() {
|
2015-07-17 15:09:00 +03:00
|
|
|
fileList.fileActions.setDefault('text/plain', 'Test');
|
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
|
|
|
$tr.find('td.filename>a.name').click();
|
|
|
|
expect($tr.hasClass('highlighted')).toEqual(true);
|
|
|
|
|
|
|
|
expect(fileList._detailsView.getFileInfo().id).toEqual(1);
|
|
|
|
});
|
2015-09-25 13:23:28 +03:00
|
|
|
it('keeps the last highlighted file when clicking outside', function() {
|
2015-07-17 15:09:00 +03:00
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
|
|
|
$tr.find('td.filename>a.name').click();
|
|
|
|
|
|
|
|
fileList.$el.find('tfoot').click();
|
|
|
|
|
2015-09-25 13:23:28 +03:00
|
|
|
expect($tr.hasClass('highlighted')).toEqual(true);
|
|
|
|
expect(fileList._detailsView.getFileInfo().id).toEqual(1);
|
|
|
|
});
|
2016-02-15 16:58:44 +03:00
|
|
|
it('removes last highlighted file when selecting via checkbox', function() {
|
2015-09-25 13:23:28 +03:00
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
2016-02-15 16:58:44 +03:00
|
|
|
|
|
|
|
// select
|
|
|
|
$tr.find('td.filename>a.name').click();
|
2015-09-25 13:23:28 +03:00
|
|
|
$tr.find('input:checkbox').click();
|
2016-02-15 16:58:44 +03:00
|
|
|
expect($tr.hasClass('highlighted')).toEqual(false);
|
|
|
|
|
|
|
|
// deselect
|
|
|
|
$tr.find('td.filename>a.name').click();
|
2015-09-25 13:23:28 +03:00
|
|
|
$tr.find('input:checkbox').click();
|
2016-02-15 16:58:44 +03:00
|
|
|
expect($tr.hasClass('highlighted')).toEqual(false);
|
2015-09-25 13:23:28 +03:00
|
|
|
|
2016-02-15 16:58:44 +03:00
|
|
|
expect(fileList._detailsView.getFileInfo()).toEqual(null);
|
|
|
|
});
|
|
|
|
it('removes last highlighted file when selecting all files via checkbox', function() {
|
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
|
|
|
|
|
|
|
// select
|
|
|
|
$tr.find('td.filename>a.name').click();
|
|
|
|
fileList.$el.find('.select-all.checkbox').click();
|
|
|
|
expect($tr.hasClass('highlighted')).toEqual(false);
|
|
|
|
|
|
|
|
// deselect
|
|
|
|
$tr.find('td.filename>a.name').click();
|
|
|
|
fileList.$el.find('.select-all.checkbox').click();
|
|
|
|
expect($tr.hasClass('highlighted')).toEqual(false);
|
|
|
|
|
|
|
|
expect(fileList._detailsView.getFileInfo()).toEqual(null);
|
2015-09-25 13:23:28 +03:00
|
|
|
});
|
|
|
|
it('closes sidebar whenever the currently highlighted file was removed from the list', function() {
|
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
|
|
|
$tr.find('td.filename>a.name').click();
|
|
|
|
expect($tr.hasClass('highlighted')).toEqual(true);
|
|
|
|
|
|
|
|
expect(fileList._detailsView.getFileInfo().id).toEqual(1);
|
|
|
|
|
|
|
|
expect($('#app-sidebar').hasClass('disappear')).toEqual(false);
|
|
|
|
fileList.remove('One.txt');
|
|
|
|
expect($('#app-sidebar').hasClass('disappear')).toEqual(true);
|
2015-07-17 15:09:00 +03:00
|
|
|
});
|
2015-08-12 18:30:20 +03:00
|
|
|
it('returns the currently selected model instance when calling getModelForFile', function() {
|
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
|
|
|
$tr.find('td.filename>a.name').click();
|
|
|
|
|
|
|
|
var model1 = fileList.getModelForFile('One.txt');
|
|
|
|
var model2 = fileList.getModelForFile('One.txt');
|
|
|
|
model1.set('test', true);
|
|
|
|
|
|
|
|
// it's the same model
|
|
|
|
expect(model2).toEqual(model1);
|
|
|
|
|
|
|
|
var model3 = fileList.getModelForFile($tr);
|
|
|
|
expect(model3).toEqual(model1);
|
|
|
|
});
|
2015-09-25 13:23:28 +03:00
|
|
|
it('closes the sidebar when switching folders', function() {
|
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
|
|
|
$tr.find('td.filename>a.name').click();
|
|
|
|
|
|
|
|
expect($('#app-sidebar').hasClass('disappear')).toEqual(false);
|
|
|
|
fileList.changeDirectory('/another');
|
|
|
|
expect($('#app-sidebar').hasClass('disappear')).toEqual(true);
|
|
|
|
});
|
2015-07-17 15:09:00 +03:00
|
|
|
});
|
2014-05-20 13:44:18 +04:00
|
|
|
describe('File actions', function() {
|
|
|
|
it('Clicking on a file name will trigger default action', function() {
|
|
|
|
var actionStub = sinon.stub();
|
|
|
|
fileList.setFiles(testFiles);
|
2015-08-05 13:48:42 +03:00
|
|
|
fileList.fileActions.registerAction({
|
|
|
|
mime: 'text/plain',
|
|
|
|
name: 'Test',
|
|
|
|
type: OCA.Files.FileActions.TYPE_INLINE,
|
|
|
|
permissions: OC.PERMISSION_ALL,
|
|
|
|
icon: function() {
|
2014-05-20 13:44:18 +04:00
|
|
|
// Specify icon for hitory button
|
|
|
|
return OC.imagePath('core','actions/history');
|
|
|
|
},
|
2015-08-05 13:48:42 +03:00
|
|
|
actionHandler: actionStub
|
|
|
|
});
|
2014-05-20 13:44:18 +04:00
|
|
|
fileList.fileActions.setDefault('text/plain', 'Test');
|
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
2015-07-17 15:09:00 +03:00
|
|
|
$tr.find('td.filename .nametext').click();
|
2014-05-20 13:44:18 +04:00
|
|
|
expect(actionStub.calledOnce).toEqual(true);
|
|
|
|
expect(actionStub.getCall(0).args[0]).toEqual('One.txt');
|
|
|
|
var context = actionStub.getCall(0).args[1];
|
|
|
|
expect(context.$file.is($tr)).toEqual(true);
|
|
|
|
expect(context.fileList).toBeDefined();
|
|
|
|
expect(context.fileActions).toBeDefined();
|
|
|
|
expect(context.dir).toEqual('/subdir');
|
|
|
|
});
|
2014-06-27 15:36:18 +04:00
|
|
|
it('redisplays actions when new actions have been registered', function() {
|
|
|
|
var actionStub = sinon.stub();
|
2014-07-01 20:50:54 +04:00
|
|
|
var readyHandler = sinon.stub();
|
2014-06-27 15:36:18 +04:00
|
|
|
var clock = sinon.useFakeTimers();
|
|
|
|
var debounceStub = sinon.stub(_, 'debounce', function(callback) {
|
|
|
|
return function() {
|
|
|
|
// defer instead of debounce, to make it work with clock
|
|
|
|
_.defer(callback);
|
|
|
|
};
|
|
|
|
});
|
2014-07-01 20:50:54 +04:00
|
|
|
|
2014-06-27 15:36:18 +04:00
|
|
|
// need to reinit the list to make the debounce call
|
|
|
|
fileList.destroy();
|
|
|
|
fileList = new OCA.Files.FileList($('#app-content-files'));
|
|
|
|
|
|
|
|
fileList.setFiles(testFiles);
|
2014-07-01 20:50:54 +04:00
|
|
|
|
|
|
|
fileList.$fileList.on('fileActionsReady', readyHandler);
|
|
|
|
|
2015-08-05 13:48:42 +03:00
|
|
|
fileList.fileActions.registerAction({
|
|
|
|
mime: 'text/plain',
|
|
|
|
name: 'Test',
|
|
|
|
type: OCA.Files.FileActions.TYPE_INLINE,
|
|
|
|
permissions: OC.PERMISSION_ALL,
|
|
|
|
icon: function() {
|
2014-06-27 15:36:18 +04:00
|
|
|
// Specify icon for hitory button
|
|
|
|
return OC.imagePath('core','actions/history');
|
|
|
|
},
|
2015-08-05 13:48:42 +03:00
|
|
|
actionHandler: actionStub
|
|
|
|
});
|
2014-06-27 15:36:18 +04:00
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
|
|
|
expect($tr.find('.action-test').length).toEqual(0);
|
2014-07-01 20:50:54 +04:00
|
|
|
expect(readyHandler.notCalled).toEqual(true);
|
|
|
|
|
2014-06-27 15:36:18 +04:00
|
|
|
// update is delayed
|
|
|
|
clock.tick(100);
|
|
|
|
expect($tr.find('.action-test').length).toEqual(1);
|
2014-07-01 20:50:54 +04:00
|
|
|
expect(readyHandler.calledOnce).toEqual(true);
|
|
|
|
|
2014-06-27 15:36:18 +04:00
|
|
|
clock.restore();
|
|
|
|
debounceStub.restore();
|
|
|
|
});
|
2014-05-20 13:44:18 +04:00
|
|
|
});
|
2014-04-03 22:57:06 +04:00
|
|
|
describe('Sorting files', function() {
|
|
|
|
it('Toggles the sort indicator when clicking on a column header', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
var ASC_CLASS = fileList.SORT_INDICATOR_ASC_CLASS;
|
|
|
|
var DESC_CLASS = fileList.SORT_INDICATOR_DESC_CLASS;
|
2016-04-12 12:51:50 +03:00
|
|
|
var request;
|
|
|
|
var sortingUrl = OC.generateUrl('/apps/files/api/v1/sorting');
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.$el.find('.column-size .columntitle').click();
|
2014-07-17 22:27:55 +04:00
|
|
|
// moves triangle to size column, check indicator on name is hidden
|
2014-04-03 22:57:06 +04:00
|
|
|
expect(
|
2014-07-17 22:27:55 +04:00
|
|
|
fileList.$el.find('.column-name .sort-indicator').hasClass('hidden')
|
|
|
|
).toEqual(true);
|
|
|
|
// check indicator on size is visible and defaults to descending
|
|
|
|
expect(
|
|
|
|
fileList.$el.find('.column-size .sort-indicator').hasClass('hidden')
|
2014-04-03 22:57:06 +04:00
|
|
|
).toEqual(false);
|
|
|
|
expect(
|
2014-07-17 22:27:55 +04:00
|
|
|
fileList.$el.find('.column-size .sort-indicator').hasClass(DESC_CLASS)
|
2014-04-03 22:57:06 +04:00
|
|
|
).toEqual(true);
|
2016-04-12 12:51:50 +03:00
|
|
|
// check if changes are persisted
|
|
|
|
expect(fakeServer.requests.length).toEqual(1);
|
|
|
|
request = fakeServer.requests[0];
|
|
|
|
expect(request.url).toEqual(sortingUrl);
|
2014-04-03 22:57:06 +04:00
|
|
|
|
|
|
|
// click again on size column, reverses direction
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.$el.find('.column-size .columntitle').click();
|
2014-04-03 22:57:06 +04:00
|
|
|
expect(
|
2014-07-17 22:27:55 +04:00
|
|
|
fileList.$el.find('.column-size .sort-indicator').hasClass('hidden')
|
|
|
|
).toEqual(false);
|
|
|
|
expect(
|
|
|
|
fileList.$el.find('.column-size .sort-indicator').hasClass(ASC_CLASS)
|
2014-04-03 22:57:06 +04:00
|
|
|
).toEqual(true);
|
2016-04-12 12:51:50 +03:00
|
|
|
// check if changes are persisted
|
|
|
|
expect(fakeServer.requests.length).toEqual(2);
|
|
|
|
request = fakeServer.requests[1];
|
|
|
|
expect(request.url).toEqual(sortingUrl);
|
2014-04-03 22:57:06 +04:00
|
|
|
|
|
|
|
// click again on size column, reverses direction
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.$el.find('.column-size .columntitle').click();
|
2014-04-03 22:57:06 +04:00
|
|
|
expect(
|
2014-07-17 22:27:55 +04:00
|
|
|
fileList.$el.find('.column-size .sort-indicator').hasClass('hidden')
|
|
|
|
).toEqual(false);
|
|
|
|
expect(
|
|
|
|
fileList.$el.find('.column-size .sort-indicator').hasClass(DESC_CLASS)
|
2014-04-03 22:57:06 +04:00
|
|
|
).toEqual(true);
|
2016-04-12 12:51:50 +03:00
|
|
|
expect(fakeServer.requests.length).toEqual(3);
|
|
|
|
request = fakeServer.requests[2];
|
|
|
|
expect(request.url).toEqual(sortingUrl);
|
2014-04-03 22:57:06 +04:00
|
|
|
|
|
|
|
// click on mtime column, moves indicator there
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.$el.find('.column-mtime .columntitle').click();
|
2014-04-03 22:57:06 +04:00
|
|
|
expect(
|
2014-07-17 22:27:55 +04:00
|
|
|
fileList.$el.find('.column-size .sort-indicator').hasClass('hidden')
|
|
|
|
).toEqual(true);
|
|
|
|
expect(
|
|
|
|
fileList.$el.find('.column-mtime .sort-indicator').hasClass('hidden')
|
2014-04-03 22:57:06 +04:00
|
|
|
).toEqual(false);
|
|
|
|
expect(
|
2014-07-17 22:27:55 +04:00
|
|
|
fileList.$el.find('.column-mtime .sort-indicator').hasClass(DESC_CLASS)
|
2014-04-03 22:57:06 +04:00
|
|
|
).toEqual(true);
|
2016-04-12 12:51:50 +03:00
|
|
|
expect(fakeServer.requests.length).toEqual(4);
|
|
|
|
request = fakeServer.requests[3];
|
|
|
|
expect(request.url).toEqual(sortingUrl);
|
2014-04-03 22:57:06 +04:00
|
|
|
});
|
|
|
|
it('Uses correct sort comparator when inserting files', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
testFiles.sort(OCA.Files.FileList.Comparators.size);
|
2014-07-17 22:27:55 +04:00
|
|
|
testFiles.reverse(); //default is descending
|
2015-07-13 18:38:13 +03:00
|
|
|
fileList.setFiles(testFiles);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.$el.find('.column-size .columntitle').click();
|
2015-07-13 18:38:13 +03:00
|
|
|
var newFileData = new FileInfo({
|
2014-04-03 22:57:06 +04:00
|
|
|
id: 999,
|
|
|
|
name: 'new file.txt',
|
|
|
|
mimetype: 'text/plain',
|
|
|
|
size: 40001,
|
|
|
|
etag: '999'
|
2015-07-13 18:38:13 +03:00
|
|
|
});
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.add(newFileData);
|
2014-07-17 22:27:55 +04:00
|
|
|
expect(fileList.findFileEl('Three.pdf').index()).toEqual(0);
|
|
|
|
expect(fileList.findFileEl('new file.txt').index()).toEqual(1);
|
|
|
|
expect(fileList.findFileEl('Two.jpg').index()).toEqual(2);
|
|
|
|
expect(fileList.findFileEl('somedir').index()).toEqual(3);
|
|
|
|
expect(fileList.findFileEl('One.txt').index()).toEqual(4);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.files.length).toEqual(5);
|
|
|
|
expect(fileList.$fileList.find('tr').length).toEqual(5);
|
2014-04-03 22:57:06 +04:00
|
|
|
});
|
|
|
|
it('Uses correct reversed sort comparator when inserting files', function() {
|
2014-05-09 00:06:30 +04:00
|
|
|
testFiles.sort(OCA.Files.FileList.Comparators.size);
|
2015-07-13 18:38:13 +03:00
|
|
|
fileList.setFiles(testFiles);
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.$el.find('.column-size .columntitle').click();
|
2015-07-13 18:38:13 +03:00
|
|
|
|
2014-04-03 22:57:06 +04:00
|
|
|
// reverse sort
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.$el.find('.column-size .columntitle').click();
|
2015-07-13 18:38:13 +03:00
|
|
|
var newFileData = new FileInfo({
|
2014-04-03 22:57:06 +04:00
|
|
|
id: 999,
|
|
|
|
name: 'new file.txt',
|
|
|
|
mimetype: 'text/plain',
|
|
|
|
size: 40001,
|
|
|
|
etag: '999'
|
2015-07-13 18:38:13 +03:00
|
|
|
});
|
2014-05-09 00:06:30 +04:00
|
|
|
fileList.add(newFileData);
|
2014-07-17 22:27:55 +04:00
|
|
|
expect(fileList.findFileEl('One.txt').index()).toEqual(0);
|
|
|
|
expect(fileList.findFileEl('somedir').index()).toEqual(1);
|
|
|
|
expect(fileList.findFileEl('Two.jpg').index()).toEqual(2);
|
|
|
|
expect(fileList.findFileEl('new file.txt').index()).toEqual(3);
|
|
|
|
expect(fileList.findFileEl('Three.pdf').index()).toEqual(4);
|
2014-05-09 00:06:30 +04:00
|
|
|
expect(fileList.files.length).toEqual(5);
|
|
|
|
expect(fileList.$fileList.find('tr').length).toEqual(5);
|
2014-04-03 22:57:06 +04:00
|
|
|
});
|
2015-09-29 14:24:33 +03:00
|
|
|
it('does not sort when clicking on header whenever multiselect is enabled', function() {
|
|
|
|
var sortStub = sinon.stub(OCA.Files.FileList.prototype, 'setSort');
|
|
|
|
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
fileList.findFileEl('One.txt').find('input:checkbox:first').click();
|
|
|
|
|
|
|
|
fileList.$el.find('.column-size .columntitle').click();
|
|
|
|
|
|
|
|
expect(sortStub.notCalled).toEqual(true);
|
|
|
|
|
|
|
|
// can sort again after deselecting
|
|
|
|
fileList.findFileEl('One.txt').find('input:checkbox:first').click();
|
|
|
|
|
|
|
|
fileList.$el.find('.column-size .columntitle').click();
|
|
|
|
|
|
|
|
expect(sortStub.calledOnce).toEqual(true);
|
|
|
|
|
|
|
|
sortStub.restore();
|
|
|
|
});
|
2014-02-12 17:50:23 +04:00
|
|
|
});
|
2015-09-03 13:17:35 +03:00
|
|
|
describe('create file', function() {
|
|
|
|
var deferredCreate;
|
2015-07-13 18:38:13 +03:00
|
|
|
var deferredInfo;
|
|
|
|
var createStub;
|
|
|
|
var getFileInfoStub;
|
2015-09-03 13:17:35 +03:00
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
deferredCreate = $.Deferred();
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredInfo = $.Deferred();
|
|
|
|
createStub = sinon.stub(filesClient, 'putFileContents')
|
|
|
|
.returns(deferredCreate.promise());
|
|
|
|
getFileInfoStub = sinon.stub(filesClient, 'getFileInfo')
|
|
|
|
.returns(deferredInfo.promise());
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
createStub.restore();
|
|
|
|
getFileInfoStub.restore();
|
2015-09-03 13:17:35 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('creates file with given name and adds it to the list', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
fileList.createFile('test.txt');
|
2015-09-03 13:17:35 +03:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(createStub.calledOnce).toEqual(true);
|
|
|
|
expect(createStub.getCall(0).args[0]).toEqual('/subdir/test.txt');
|
|
|
|
expect(createStub.getCall(0).args[2]).toEqual({
|
|
|
|
contentType: 'text/plain',
|
|
|
|
overwrite: true
|
|
|
|
});
|
2015-09-03 13:17:35 +03:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredCreate.resolve(200);
|
2015-09-03 13:17:35 +03:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
expect(getFileInfoStub.calledOnce).toEqual(true);
|
|
|
|
expect(getFileInfoStub.getCall(0).args[0]).toEqual('/subdir/test.txt');
|
2015-09-03 13:17:35 +03:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredInfo.resolve(
|
2015-09-03 13:17:35 +03:00
|
|
|
200,
|
2015-07-13 18:38:13 +03:00
|
|
|
new FileInfo({
|
|
|
|
path: '/subdir',
|
|
|
|
name: 'test.txt',
|
|
|
|
mimetype: 'text/plain'
|
2015-09-03 13:17:35 +03:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
var $tr = fileList.findFileEl('test.txt');
|
2015-09-03 13:17:35 +03:00
|
|
|
expect($tr.length).toEqual(1);
|
|
|
|
expect($tr.attr('data-mime')).toEqual('text/plain');
|
|
|
|
});
|
|
|
|
// TODO: error cases
|
|
|
|
// TODO: unique name cases
|
|
|
|
});
|
2015-07-13 18:38:13 +03:00
|
|
|
describe('create folder', function() {
|
|
|
|
var deferredCreate;
|
|
|
|
var deferredInfo;
|
|
|
|
var createStub;
|
|
|
|
var getFileInfoStub;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
deferredCreate = $.Deferred();
|
|
|
|
deferredInfo = $.Deferred();
|
|
|
|
createStub = sinon.stub(filesClient, 'createDirectory')
|
|
|
|
.returns(deferredCreate.promise());
|
|
|
|
getFileInfoStub = sinon.stub(filesClient, 'getFileInfo')
|
|
|
|
.returns(deferredInfo.promise());
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
createStub.restore();
|
|
|
|
getFileInfoStub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('creates folder with given name and adds it to the list', function() {
|
|
|
|
fileList.createDirectory('sub dir');
|
|
|
|
|
|
|
|
expect(createStub.calledOnce).toEqual(true);
|
|
|
|
expect(createStub.getCall(0).args[0]).toEqual('/subdir/sub dir');
|
2015-09-03 13:17:35 +03:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
deferredCreate.resolve(200);
|
|
|
|
|
|
|
|
expect(getFileInfoStub.calledOnce).toEqual(true);
|
|
|
|
expect(getFileInfoStub.getCall(0).args[0]).toEqual('/subdir/sub dir');
|
|
|
|
|
|
|
|
deferredInfo.resolve(
|
2015-09-03 13:17:35 +03:00
|
|
|
200,
|
2015-07-13 18:38:13 +03:00
|
|
|
new FileInfo({
|
|
|
|
path: '/subdir',
|
|
|
|
name: 'sub dir',
|
|
|
|
mimetype: 'httpd/unix-directory'
|
2015-09-03 13:17:35 +03:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
var $tr = fileList.findFileEl('sub dir');
|
2015-09-03 13:17:35 +03:00
|
|
|
expect($tr.length).toEqual(1);
|
|
|
|
expect($tr.attr('data-mime')).toEqual('httpd/unix-directory');
|
|
|
|
});
|
|
|
|
// TODO: error cases
|
|
|
|
// TODO: unique name cases
|
|
|
|
});
|
2014-05-21 17:55:29 +04:00
|
|
|
/**
|
|
|
|
* Test upload mostly by testing the code inside the event handlers
|
|
|
|
* that were registered on the magic upload object
|
|
|
|
*/
|
|
|
|
describe('file upload', function() {
|
|
|
|
var $uploader;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
// note: this isn't the real blueimp file uploader from jquery.fileupload
|
|
|
|
// but it makes it possible to simulate the event triggering to
|
|
|
|
// test the response of the handlers
|
|
|
|
$uploader = $('#file_upload_start');
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
$uploader = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('dropping external files', function() {
|
|
|
|
var uploadData;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Simulate drop event on the given target
|
|
|
|
*
|
|
|
|
* @param $target target element to drop on
|
|
|
|
* @return event object including the result
|
|
|
|
*/
|
|
|
|
function dropOn($target, data) {
|
|
|
|
var eventData = {
|
|
|
|
originalEvent: {
|
|
|
|
target: $target
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var ev = new $.Event('fileuploaddrop', eventData);
|
|
|
|
// using triggerHandler instead of trigger so we can pass
|
|
|
|
// extra data
|
|
|
|
$uploader.triggerHandler(ev, data || {});
|
|
|
|
return ev;
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
// simulate data structure from jquery.upload
|
|
|
|
uploadData = {
|
|
|
|
files: [{
|
|
|
|
relativePath: 'fileToUpload.txt'
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
uploadData = null;
|
|
|
|
});
|
|
|
|
it('drop on a tr or crumb outside file list does not trigger upload', function() {
|
|
|
|
var $anotherTable = $('<table><tbody><tr><td>outside<div class="crumb">crumb</div></td></tr></table>');
|
|
|
|
var ev;
|
|
|
|
$('#testArea').append($anotherTable);
|
|
|
|
ev = dropOn($anotherTable.find('tr'), uploadData);
|
|
|
|
expect(ev.result).toEqual(false);
|
|
|
|
|
|
|
|
ev = dropOn($anotherTable.find('.crumb'));
|
|
|
|
expect(ev.result).toEqual(false);
|
|
|
|
});
|
2014-05-22 13:16:42 +04:00
|
|
|
it('drop on an element outside file list container does not trigger upload', function() {
|
2014-05-21 17:55:29 +04:00
|
|
|
var $anotherEl = $('<div>outside</div>');
|
|
|
|
var ev;
|
|
|
|
$('#testArea').append($anotherEl);
|
|
|
|
ev = dropOn($anotherEl);
|
|
|
|
|
|
|
|
expect(ev.result).toEqual(false);
|
|
|
|
});
|
|
|
|
it('drop on an element inside the table triggers upload', function() {
|
|
|
|
var ev;
|
|
|
|
ev = dropOn(fileList.$fileList.find('th:first'), uploadData);
|
|
|
|
|
|
|
|
expect(ev.result).not.toEqual(false);
|
|
|
|
});
|
2014-05-22 13:16:42 +04:00
|
|
|
it('drop on an element on the table container triggers upload', function() {
|
|
|
|
var ev;
|
|
|
|
ev = dropOn($('#app-content-files'), uploadData);
|
|
|
|
|
|
|
|
expect(ev.result).not.toEqual(false);
|
|
|
|
});
|
2014-05-21 17:55:29 +04:00
|
|
|
it('drop on an element inside the table does not trigger upload if no upload permission', function() {
|
|
|
|
$('#permissions').val(0);
|
|
|
|
var ev;
|
|
|
|
ev = dropOn(fileList.$fileList.find('th:first'));
|
|
|
|
|
|
|
|
expect(ev.result).toEqual(false);
|
2014-09-04 21:58:49 +04:00
|
|
|
expect(notificationStub.calledOnce).toEqual(true);
|
|
|
|
});
|
|
|
|
it('drop on an folder does not trigger upload if no upload permission on that folder', function() {
|
|
|
|
var $tr = fileList.findFileEl('somedir');
|
|
|
|
var ev;
|
|
|
|
$tr.data('permissions', OC.PERMISSION_READ);
|
|
|
|
ev = dropOn($tr);
|
|
|
|
|
|
|
|
expect(ev.result).toEqual(false);
|
|
|
|
expect(notificationStub.calledOnce).toEqual(true);
|
2014-05-21 17:55:29 +04:00
|
|
|
});
|
|
|
|
it('drop on a file row inside the table triggers upload to current folder', function() {
|
|
|
|
var ev;
|
|
|
|
ev = dropOn(fileList.findFileEl('One.txt').find('td:first'), uploadData);
|
|
|
|
|
|
|
|
expect(ev.result).not.toEqual(false);
|
|
|
|
});
|
|
|
|
it('drop on a folder row inside the table triggers upload to target folder', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
var ev;
|
2014-05-21 17:55:29 +04:00
|
|
|
ev = dropOn(fileList.findFileEl('somedir').find('td:eq(2)'), uploadData);
|
|
|
|
|
|
|
|
expect(ev.result).not.toEqual(false);
|
2014-06-19 19:19:28 +04:00
|
|
|
expect(uploadData.targetDir).toEqual('/subdir/somedir');
|
2014-05-21 17:55:29 +04:00
|
|
|
});
|
|
|
|
it('drop on a breadcrumb inside the table triggers upload to target folder', function() {
|
2015-07-13 18:38:13 +03:00
|
|
|
var ev;
|
2014-05-21 17:55:29 +04:00
|
|
|
fileList.changeDirectory('a/b/c/d');
|
|
|
|
ev = dropOn(fileList.$el.find('.crumb:eq(2)'), uploadData);
|
|
|
|
|
|
|
|
expect(ev.result).not.toEqual(false);
|
2014-06-19 19:19:28 +04:00
|
|
|
expect(uploadData.targetDir).toEqual('/a/b');
|
2014-05-21 17:55:29 +04:00
|
|
|
});
|
2015-12-17 13:50:24 +03:00
|
|
|
it('renders upload indicator element for folders only', function() {
|
|
|
|
fileList.add({
|
|
|
|
name: 'afolder',
|
|
|
|
type: 'dir',
|
|
|
|
mime: 'httpd/unix-directory'
|
|
|
|
});
|
|
|
|
fileList.add({
|
|
|
|
name: 'afile.txt',
|
|
|
|
type: 'file',
|
|
|
|
mime: 'text/plain'
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(fileList.findFileEl('afolder').find('.uploadtext').length).toEqual(1);
|
|
|
|
expect(fileList.findFileEl('afile.txt').find('.uploadtext').length).toEqual(0);
|
|
|
|
});
|
2014-05-21 17:55:29 +04:00
|
|
|
});
|
|
|
|
});
|
2015-07-13 18:38:13 +03:00
|
|
|
describe('Handling errors', function () {
|
|
|
|
var deferredList;
|
|
|
|
var getFolderContentsStub;
|
2015-08-05 13:48:42 +03:00
|
|
|
|
2015-07-13 18:38:13 +03:00
|
|
|
beforeEach(function() {
|
|
|
|
deferredList = $.Deferred();
|
|
|
|
getFolderContentsStub =
|
|
|
|
sinon.stub(filesClient, 'getFolderContents');
|
|
|
|
getFolderContentsStub.onCall(0).returns(deferredList.promise());
|
|
|
|
getFolderContentsStub.onCall(1).returns($.Deferred().promise());
|
|
|
|
fileList.reload();
|
2014-07-04 16:08:48 +04:00
|
|
|
});
|
2015-07-13 18:38:13 +03:00
|
|
|
afterEach(function() {
|
|
|
|
getFolderContentsStub.restore();
|
2014-07-04 16:08:48 +04:00
|
|
|
fileList = undefined;
|
2015-07-13 18:38:13 +03:00
|
|
|
});
|
|
|
|
it('redirects to root folder in case of forbidden access', function () {
|
|
|
|
deferredList.reject(403);
|
|
|
|
|
|
|
|
expect(fileList.getCurrentDirectory()).toEqual('/');
|
|
|
|
expect(getFolderContentsStub.calledTwice).toEqual(true);
|
|
|
|
});
|
|
|
|
it('redirects to root folder and shows notification in case of internal server error', function () {
|
|
|
|
expect(notificationStub.notCalled).toEqual(true);
|
|
|
|
deferredList.reject(500);
|
|
|
|
|
|
|
|
expect(fileList.getCurrentDirectory()).toEqual('/');
|
|
|
|
expect(getFolderContentsStub.calledTwice).toEqual(true);
|
|
|
|
expect(notificationStub.calledOnce).toEqual(true);
|
|
|
|
});
|
|
|
|
it('redirects to root folder and shows notification in case of storage not available', function () {
|
|
|
|
expect(notificationStub.notCalled).toEqual(true);
|
|
|
|
deferredList.reject(503, 'Storage not available');
|
|
|
|
|
|
|
|
expect(fileList.getCurrentDirectory()).toEqual('/');
|
|
|
|
expect(getFolderContentsStub.calledTwice).toEqual(true);
|
|
|
|
expect(notificationStub.calledOnce).toEqual(true);
|
2014-07-04 16:08:48 +04:00
|
|
|
});
|
|
|
|
});
|
2015-08-05 13:48:42 +03:00
|
|
|
describe('showFileBusyState', function() {
|
|
|
|
var $tr;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
$tr = fileList.findFileEl('Two.jpg');
|
|
|
|
});
|
|
|
|
it('shows spinner on busy rows', function() {
|
|
|
|
fileList.showFileBusyState('Two.jpg', true);
|
|
|
|
expect($tr.hasClass('busy')).toEqual(true);
|
|
|
|
expect(OC.TestUtil.getImageUrl($tr.find('.thumbnail')))
|
|
|
|
.toEqual(OC.imagePath('core', 'loading.gif'));
|
|
|
|
|
|
|
|
fileList.showFileBusyState('Two.jpg', false);
|
|
|
|
expect($tr.hasClass('busy')).toEqual(false);
|
|
|
|
expect(OC.TestUtil.getImageUrl($tr.find('.thumbnail')))
|
|
|
|
.toEqual(OC.imagePath('core', 'filetypes/image.svg'));
|
|
|
|
});
|
|
|
|
it('accepts multiple input formats', function() {
|
|
|
|
_.each([
|
|
|
|
'Two.jpg',
|
|
|
|
['Two.jpg'],
|
|
|
|
$tr,
|
|
|
|
[$tr]
|
|
|
|
], function(testCase) {
|
|
|
|
fileList.showFileBusyState(testCase, true);
|
|
|
|
expect($tr.hasClass('busy')).toEqual(true);
|
|
|
|
fileList.showFileBusyState(testCase, false);
|
|
|
|
expect($tr.hasClass('busy')).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2015-08-24 18:16:20 +03:00
|
|
|
describe('elementToFile', function() {
|
|
|
|
var $tr;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
$tr = fileList.findFileEl('One.txt');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('converts data attributes to file info structure', function() {
|
|
|
|
var fileInfo = fileList.elementToFile($tr);
|
|
|
|
expect(fileInfo.id).toEqual(1);
|
|
|
|
expect(fileInfo.name).toEqual('One.txt');
|
|
|
|
expect(fileInfo.mtime).toEqual(123456789);
|
|
|
|
expect(fileInfo.etag).toEqual('abc');
|
|
|
|
expect(fileInfo.permissions).toEqual(OC.PERMISSION_ALL);
|
|
|
|
expect(fileInfo.size).toEqual(12);
|
|
|
|
expect(fileInfo.mimetype).toEqual('text/plain');
|
|
|
|
expect(fileInfo.type).toEqual('file');
|
2016-02-08 19:02:05 +03:00
|
|
|
expect(fileInfo.path).not.toBeDefined();
|
|
|
|
});
|
|
|
|
it('adds path attribute if available', function() {
|
|
|
|
$tr.attr('data-path', '/subdir');
|
|
|
|
var fileInfo = fileList.elementToFile($tr);
|
|
|
|
expect(fileInfo.path).toEqual('/subdir');
|
2015-08-24 18:16:20 +03:00
|
|
|
});
|
|
|
|
});
|
2015-09-03 13:17:35 +03:00
|
|
|
describe('new file menu', function() {
|
|
|
|
var newFileMenuStub;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
newFileMenuStub = sinon.stub(OCA.Files.NewFileMenu.prototype, 'showAt');
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
newFileMenuStub.restore();
|
|
|
|
})
|
|
|
|
it('renders new button when no legacy upload button exists', function() {
|
|
|
|
expect(fileList.$el.find('.button.upload').length).toEqual(0);
|
|
|
|
expect(fileList.$el.find('.button.new').length).toEqual(1);
|
|
|
|
});
|
|
|
|
it('does not render new button when no legacy upload button exists (public page)', function() {
|
|
|
|
fileList.destroy();
|
|
|
|
$('#controls').append('<input type="button" class="button upload" />');
|
|
|
|
fileList = new OCA.Files.FileList($('#app-content-files'));
|
|
|
|
expect(fileList.$el.find('.button.upload').length).toEqual(1);
|
|
|
|
expect(fileList.$el.find('.button.new').length).toEqual(0);
|
|
|
|
});
|
|
|
|
it('opens the new file menu when clicking on the "New" button', function() {
|
|
|
|
var $button = fileList.$el.find('.button.new');
|
|
|
|
$button.click();
|
|
|
|
expect(newFileMenuStub.calledOnce).toEqual(true);
|
|
|
|
});
|
|
|
|
it('does not open the new file menu when button is disabled', function() {
|
|
|
|
var $button = fileList.$el.find('.button.new');
|
|
|
|
$button.addClass('disabled');
|
|
|
|
$button.click();
|
|
|
|
expect(newFileMenuStub.notCalled).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
2015-12-14 12:44:47 +03:00
|
|
|
describe('mount type detection', function() {
|
|
|
|
function testMountType(dirInfoId, dirInfoMountType, inputMountType, expectedMountType) {
|
|
|
|
var $tr;
|
|
|
|
fileList.dirInfo.id = dirInfoId;
|
|
|
|
fileList.dirInfo.mountType = dirInfoMountType;
|
|
|
|
$tr = fileList.add({
|
|
|
|
type: 'dir',
|
|
|
|
mimetype: 'httpd/unix-directory',
|
|
|
|
name: 'test dir',
|
|
|
|
mountType: inputMountType
|
|
|
|
});
|
|
|
|
|
|
|
|
expect($tr.attr('data-mounttype')).toEqual(expectedMountType);
|
|
|
|
}
|
|
|
|
|
|
|
|
it('leaves mount type as is if no parent exists', function() {
|
|
|
|
testMountType(null, null, 'external', 'external');
|
|
|
|
testMountType(null, null, 'shared', 'shared');
|
|
|
|
});
|
|
|
|
it('detects share root if parent exists', function() {
|
|
|
|
testMountType(123, null, 'shared', 'shared-root');
|
|
|
|
testMountType(123, 'shared', 'shared', 'shared');
|
|
|
|
testMountType(123, 'shared-root', 'shared', 'shared');
|
|
|
|
});
|
|
|
|
it('detects external storage root if parent exists', function() {
|
|
|
|
testMountType(123, null, 'external', 'external-root');
|
|
|
|
testMountType(123, 'external', 'external', 'external');
|
|
|
|
testMountType(123, 'external-root', 'external', 'external');
|
|
|
|
});
|
|
|
|
});
|
2014-01-12 21:57:53 +04:00
|
|
|
});
|