summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/tests/js/filelistSpec.js
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-05-12 19:54:20 +0200
committerVincent Petry <pvince81@owncloud.com>2014-05-15 17:51:04 +0200
commit6fd084243b65a556d4775209ba3916145ef5912a (patch)
tree6162c2af1861d8e3b8bbf1340ac55c4affc5ad61 /apps/files_trashbin/tests/js/filelistSpec.js
parent9d38e3602b2faf37d861729c52690ce51b8fee97 (diff)
downloadnextcloud-server-6fd084243b65a556d4775209ba3916145ef5912a.tar.gz
nextcloud-server-6fd084243b65a556d4775209ba3916145ef5912a.zip
Fixed many issues, clean up
- fixed upload and storage statistics - fixed infinite scroll to use the correct contain for scroll detection - fixed unit test that sometimes fail for rename case - controls are now sticky again - fixed selection overlay to be aligned with the table - fixed "select all" checkbox that had id conflicts - fixed public page - fixed global actions permissions detection - fix when URL contains an invalid view id - viewer mode now hides the sidebar (ex: text editor) - added unit tests for trashbin - clean up storage info in template (most is retrieved via ajax call now)
Diffstat (limited to 'apps/files_trashbin/tests/js/filelistSpec.js')
-rw-r--r--apps/files_trashbin/tests/js/filelistSpec.js140
1 files changed, 115 insertions, 25 deletions
diff --git a/apps/files_trashbin/tests/js/filelistSpec.js b/apps/files_trashbin/tests/js/filelistSpec.js
index 291b2ffe14c..d41c24c3cc9 100644
--- a/apps/files_trashbin/tests/js/filelistSpec.js
+++ b/apps/files_trashbin/tests/js/filelistSpec.js
@@ -24,19 +24,16 @@ describe('OCA.Trashbin.FileList tests', function() {
var FileActions = OCA.Files.FileActions;
beforeEach(function() {
- // init horrible parameters
- var $body = $('body');
- $body.append('<input type="hidden" id="dir" value="/"></input>');
- // dummy files table
- $body.append('<table id="filestable"></table>');
-
alertStub = sinon.stub(OC.dialogs, 'alert');
notificationStub = sinon.stub(OC.Notification, 'show');
// init parameters and test table elements
$('#testArea').append(
'<div id="app-content-trashbin">' +
+ // init horrible parameters
'<input type="hidden" id="dir" value="/"></input>' +
+ // set this but it shouldn't be used (could be the one from the
+ // files app)
'<input type="hidden" id="permissions" value="31"></input>' +
// dummy controls
'<div id="controls">' +
@@ -47,13 +44,13 @@ describe('OCA.Trashbin.FileList tests', function() {
// TODO: at some point this will be rendered by the fileList class itself!
'<table id="filestable">' +
'<thead><tr><th id="headerName" class="hidden">' +
- '<input type="checkbox" id="select_all">' +
+ '<input type="checkbox" id="select_all_trash" class="select-all">' +
'<span class="name">Name</span>' +
'<span class="selectedActions hidden">' +
'<a href class="undelete">Restore</a>' +
'<a href class="delete-selected">Delete</a></span>' +
'</th></tr></thead>' +
- '<tbody id="fileList"></tbody>' +
+ '<tbody id="fileList"></tbody>' +
'<tfoot></tfoot>' +
'</table>' +
'<div id="emptycontent">Empty content message</div>' +
@@ -66,7 +63,6 @@ describe('OCA.Trashbin.FileList tests', function() {
name: 'One.txt',
mtime: 11111000,
mimetype: 'text/plain',
- size: 12,
etag: 'abc'
}, {
id: 2,
@@ -74,7 +70,6 @@ describe('OCA.Trashbin.FileList tests', function() {
name: 'Two.jpg',
mtime: 22222000,
mimetype: 'image/jpeg',
- size: 12049,
etag: 'def',
}, {
id: 3,
@@ -82,7 +77,6 @@ describe('OCA.Trashbin.FileList tests', function() {
name: 'Three.pdf',
mtime: 33333000,
mimetype: 'application/pdf',
- size: 58009,
etag: '123',
}, {
id: 4,
@@ -90,7 +84,6 @@ describe('OCA.Trashbin.FileList tests', function() {
mtime: 99999000,
name: 'somedir',
mimetype: 'httpd/unix-directory',
- size: 250,
etag: '456'
}];
@@ -106,10 +99,91 @@ describe('OCA.Trashbin.FileList tests', function() {
notificationStub.restore();
alertStub.restore();
});
+ describe('Initialization', function() {
+ it('Sorts by mtime by default', function() {
+ expect(fileList._sort).toEqual('mtime');
+ expect(fileList._sortDirection).toEqual('desc');
+ });
+ it('Always returns read and delete permission', function() {
+ expect(fileList.getDirectoryPermissions()).toEqual(OC.PERMISSION_READ | OC.PERMISSION_DELETE);
+ });
+ });
+ describe('Breadcrumbs', function() {
+ beforeEach(function() {
+ var data = {
+ status: 'success',
+ data: {
+ files: testFiles,
+ permissions: 1
+ }
+ };
+ fakeServer.respondWith(/\/index\.php\/apps\/files_trashbin\/ajax\/list.php\?dir=%2Fsubdir/, [
+ 200, {
+ "Content-Type": "application/json"
+ },
+ JSON.stringify(data)
+ ]);
+ });
+ it('links the breadcrumb to the trashbin view', function() {
+ fileList.changeDirectory('/subdir', false, true);
+ fakeServer.respond();
+ var $crumbs = fileList.$el.find('#controls .crumb');
+ expect($crumbs.length).toEqual(2);
+ expect($crumbs.eq(0).find('a').text()).toEqual('');
+ expect($crumbs.eq(0).find('a').attr('href'))
+ .toEqual(OC.webroot + '/index.php/apps/files?view=trashbin&dir=/');
+ expect($crumbs.eq(1).find('a').text()).toEqual('subdir');
+ expect($crumbs.eq(1).find('a').attr('href'))
+ .toEqual(OC.webroot + '/index.php/apps/files?view=trashbin&dir=/subdir');
+ });
+ });
describe('Rendering rows', function() {
- // TODO. test that rows show the correct name but
- // have the real file name with the ".d" suffix
- // TODO: with and without dir listing
+ it('renders rows with the correct data when in root', function() {
+ // dir listing is false when in root
+ $('#dir').val('/');
+ fileList.setFiles(testFiles);
+ var $rows = fileList.$el.find('tbody tr');
+ var $tr = $rows.eq(0);
+ expect($rows.length).toEqual(4);
+ expect($tr.attr('data-id')).toEqual('1');
+ expect($tr.attr('data-type')).toEqual('file');
+ expect($tr.attr('data-file')).toEqual('One.txt.d11111');
+ expect($tr.attr('data-size')).not.toBeDefined();
+ expect($tr.attr('data-etag')).toEqual('abc');
+ expect($tr.attr('data-permissions')).toEqual('9'); // read and delete
+ expect($tr.attr('data-mime')).toEqual('text/plain');
+ expect($tr.attr('data-mtime')).toEqual('11111000');
+ expect($tr.find('a.name').attr('href')).toEqual('#');
+
+ expect($tr.find('.nametext').text().trim()).toEqual('One.txt');
+
+ expect(fileList.findFileEl('One.txt.d11111')[0]).toEqual($tr[0]);
+ });
+ it('renders rows with the correct data when in subdirectory', function() {
+ // dir listing is true when in a subdir
+ $('#dir').val('/subdir');
+
+ fileList.setFiles(testFiles);
+ var $rows = fileList.$el.find('tbody tr');
+ var $tr = $rows.eq(0);
+ expect($rows.length).toEqual(4);
+ expect($tr.attr('data-id')).toEqual('1');
+ expect($tr.attr('data-type')).toEqual('file');
+ expect($tr.attr('data-file')).toEqual('One.txt');
+ expect($tr.attr('data-size')).not.toBeDefined();
+ expect($tr.attr('data-etag')).toEqual('abc');
+ expect($tr.attr('data-permissions')).toEqual('9'); // read and delete
+ expect($tr.attr('data-mime')).toEqual('text/plain');
+ expect($tr.attr('data-mtime')).toEqual('11111000');
+ expect($tr.find('a.name').attr('href')).toEqual('#');
+
+ expect($tr.find('.nametext').text().trim()).toEqual('One.txt');
+
+ expect(fileList.findFileEl('One.txt')[0]).toEqual($tr[0]);
+ });
+ it('does not render a size column', function() {
+ expect(fileList.$el.find('tbody tr .filesize').length).toEqual(0);
+ });
});
describe('File actions', function() {
describe('Deleting single files', function() {
@@ -142,7 +216,6 @@ describe('OCA.Trashbin.FileList tests', function() {
fileList.findFileEl('somedir.d99999').find('input:checkbox').click();
});
describe('Delete', function() {
- // TODO: also test with "allFiles"
it('Deletes selected files when "Delete" clicked', function() {
var request;
$('.selectedActions .delete-selected').click();
@@ -154,7 +227,16 @@ describe('OCA.Trashbin.FileList tests', function() {
fakeServer.requests[0].respond(
200,
{ 'Content-Type': 'application/json' },
- JSON.stringify({status: 'success'})
+ JSON.stringify({
+ status: 'success',
+ data: {
+ success: [
+ {filename: 'One.txt.d11111'},
+ {filename: 'Three.pdf.d33333'},
+ {filename: 'somedir.d99999'}
+ ]
+ }
+ })
);
expect(fileList.findFileEl('One.txt.d11111').length).toEqual(0);
expect(fileList.findFileEl('Three.pdf.d33333').length).toEqual(0);
@@ -163,7 +245,7 @@ describe('OCA.Trashbin.FileList tests', function() {
});
it('Deletes all files when all selected when "Delete" clicked', function() {
var request;
- $('#select_all').click();
+ $('.select-all').click();
$('.selectedActions .delete-selected').click();
expect(fakeServer.requests.length).toEqual(1);
request = fakeServer.requests[0];
@@ -179,7 +261,6 @@ describe('OCA.Trashbin.FileList tests', function() {
});
});
describe('Restore', function() {
- // TODO: also test with "allFiles"
it('Restores selected files when "Restore" clicked', function() {
var request;
$('.selectedActions .undelete').click();
@@ -191,16 +272,25 @@ describe('OCA.Trashbin.FileList tests', function() {
fakeServer.requests[0].respond(
200,
{ 'Content-Type': 'application/json' },
- JSON.stringify({status: 'success'})
+ JSON.stringify({
+ status: 'success',
+ data: {
+ success: [
+ {filename: 'One.txt.d11111'},
+ {filename: 'Three.pdf.d33333'},
+ {filename: 'somedir.d99999'}
+ ]
+ }
+ })
);
- 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);
+ expect(fileList.findFileEl('One.txt.d11111').length).toEqual(0);
+ expect(fileList.findFileEl('Three.pdf.d33333').length).toEqual(0);
+ expect(fileList.findFileEl('somedir.d99999').length).toEqual(0);
+ expect(fileList.findFileEl('Two.jpg.d22222').length).toEqual(1);
});
it('Restores all files when all selected when "Restore" clicked', function() {
var request;
- $('#select_all').click();
+ $('.select-all').click();
$('.selectedActions .undelete').click();
expect(fakeServer.requests.length).toEqual(1);
request = fakeServer.requests[0];