Fixed failing test cases for the new actions menu.

Signed-off-by: Abijeet <abijeetpatro@gmail.com>
This commit is contained in:
Abijeet 2018-06-06 23:30:56 +05:30 committed by John Molakvoæ (skjnldsv)
parent 0ca9ce0f84
commit e89f6590e2
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
2 changed files with 74 additions and 31 deletions

View File

@ -94,9 +94,7 @@ describe('OCA.Files.FileList tests', function() {
'<input type="checkbox" id="select_all_files" class="select-all checkbox">' + '<input type="checkbox" id="select_all_files" class="select-all checkbox">' +
'<a class="name columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' + '<a class="name columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' +
'<span id="selectedActionsList" class="selectedActions hidden">' + '<span id="selectedActionsList" class="selectedActions hidden">' +
'<a href class="copy-move"><span class="label">Move or copy</span></a>' + '<a href="" class="actions-selected"><span class="icon icon-more"></span><span>Actions</span></a>' +
'<a href class="download"><img src="actions/download.svg">Download</a>' +
'<a href class="delete-selected">Delete</a></span>' +
'</th>' + '</th>' +
'<th class="hidden column-size"><a class="columntitle" data-sort="size"><span class="sort-indicator"></span></a></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>' + '<th class="hidden column-mtime"><a class="columntitle" data-sort="mtime"><span class="sort-indicator"></span></a></th>' +
@ -161,7 +159,22 @@ describe('OCA.Files.FileList tests', function() {
fileList = new OCA.Files.FileList($('#app-content-files'), { fileList = new OCA.Files.FileList($('#app-content-files'), {
filesClient: filesClient, filesClient: filesClient,
config: filesConfig, config: filesConfig,
enableUpload: true enableUpload: true,
multiSelectMenu: [{
name: 'copyMove',
displayName: t('files', 'Move or copy'),
iconClass: 'icon-external',
},
{
name: 'download',
displayName: t('files', 'Download'),
iconClass: 'icon-download',
},
{
name: 'delete',
displayName: t('files', 'Delete'),
iconClass: 'icon-delete',
}]
}); });
}); });
afterEach(function() { afterEach(function() {
@ -2100,41 +2113,41 @@ describe('OCA.Files.FileList tests', function() {
fileList.setFiles(testFiles); fileList.setFiles(testFiles);
$('#permissions').val(OC.PERMISSION_READ | OC.PERMISSION_UPDATE); $('#permissions').val(OC.PERMISSION_READ | OC.PERMISSION_UPDATE);
$('.select-all').click(); $('.select-all').click();
expect(fileList.$el.find('.selectedActions .copy-move').hasClass('hidden')).toEqual(false); expect(fileList.$el.find('.selectedActions .item-copyMove').hasClass('hidden')).toEqual(false);
expect(fileList.$el.find('.selectedActions .copy-move .label').text()).toEqual('Move or copy'); expect(fileList.$el.find('.selectedActions .item-copyMove .label').text()).toEqual('Move or copy');
testFiles[0].permissions = OC.PERMISSION_READ; testFiles[0].permissions = OC.PERMISSION_READ;
$('.select-all').click(); $('.select-all').click();
fileList.setFiles(testFiles); fileList.setFiles(testFiles);
$('.select-all').click(); $('.select-all').click();
expect(fileList.$el.find('.selectedActions .copy-move').hasClass('hidden')).toEqual(false); expect(fileList.$el.find('.selectedActions .item-copyMove').hasClass('hidden')).toEqual(false);
expect(fileList.$el.find('.selectedActions .copy-move .label').text()).toEqual('Copy'); expect(fileList.$el.find('.selectedActions .item-copyMove .label').text()).toEqual('Copy');
testFiles[0].permissions = OC.PERMISSION_NONE; testFiles[0].permissions = OC.PERMISSION_NONE;
$('.select-all').click(); $('.select-all').click();
fileList.setFiles(testFiles); fileList.setFiles(testFiles);
$('.select-all').click(); $('.select-all').click();
expect(fileList.$el.find('.selectedActions .copy-move').hasClass('hidden')).toEqual(true); expect(fileList.$el.find('.selectedActions .item-copyMove').hasClass('hidden')).toEqual(true);
}); });
it('show doesnt show the download action if one or more files are not downloadable', function () { it('show doesnt show the download action if one or more files are not downloadable', function () {
fileList.setFiles(testFiles); fileList.setFiles(testFiles);
$('#permissions').val(OC.PERMISSION_READ | OC.PERMISSION_UPDATE); $('#permissions').val(OC.PERMISSION_READ | OC.PERMISSION_UPDATE);
$('.select-all').click(); $('.select-all').click();
expect(fileList.$el.find('.selectedActions .download').hasClass('hidden')).toEqual(false); expect(fileList.$el.find('.selectedActions .item-download').hasClass('hidden')).toEqual(false);
testFiles[0].permissions = OC.PERMISSION_UPDATE; testFiles[0].permissions = OC.PERMISSION_UPDATE;
$('.select-all').click(); $('.select-all').click();
fileList.setFiles(testFiles); fileList.setFiles(testFiles);
$('.select-all').click(); $('.select-all').click();
expect(fileList.$el.find('.selectedActions .download').hasClass('hidden')).toEqual(true); expect(fileList.$el.find('.selectedActions .item-download').hasClass('hidden')).toEqual(true);
}); });
it('show doesnt show the delete action if one or more files are not deletable', function () { it('show doesnt show the delete action if one or more files are not deletable', function () {
fileList.setFiles(testFiles); fileList.setFiles(testFiles);
$('#permissions').val(OC.PERMISSION_READ | OC.PERMISSION_DELETE); $('#permissions').val(OC.PERMISSION_READ | OC.PERMISSION_DELETE);
$('.select-all').click(); $('.select-all').click();
expect(fileList.$el.find('.delete-selected').hasClass('hidden')).toEqual(false); expect(fileList.$el.find('.selectedActions .item-delete').hasClass('hidden')).toEqual(false);
testFiles[0].permissions = OC.PERMISSION_READ; testFiles[0].permissions = OC.PERMISSION_READ;
$('.select-all').click(); $('.select-all').click();
fileList.setFiles(testFiles); fileList.setFiles(testFiles);
$('.select-all').click(); $('.select-all').click();
expect(fileList.$el.find('.delete-selected').hasClass('hidden')).toEqual(true); expect(fileList.$el.find('.selectedActions .item-delete').hasClass('hidden')).toEqual(true);
}); });
}); });
describe('Actions', function() { describe('Actions', function() {
@ -2219,8 +2232,12 @@ describe('OCA.Files.FileList tests', function() {
}); });
}); });
describe('Download', function() { describe('Download', function() {
beforeEach(function() {
fileList.$el.find('.actions-selected').click();
});
it('Opens download URL when clicking "Download"', function() { it('Opens download URL when clicking "Download"', function() {
$('.selectedActions .download').click(); $('.selectedActions .filesSelectMenu .download').click();
expect(redirectStub.calledOnce).toEqual(true); expect(redirectStub.calledOnce).toEqual(true);
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'); 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');
redirectStub.restore(); redirectStub.restore();
@ -2228,28 +2245,37 @@ describe('OCA.Files.FileList tests', function() {
it('Downloads root folder when all selected in root folder', function() { it('Downloads root folder when all selected in root folder', function() {
$('#dir').val('/'); $('#dir').val('/');
$('.select-all').click(); $('.select-all').click();
$('.selectedActions .download').click(); $('.selectedActions .filesSelectMenu .download').click();
expect(redirectStub.calledOnce).toEqual(true); expect(redirectStub.calledOnce).toEqual(true);
expect(redirectStub.getCall(0).args[0]).toContain(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2F&files='); expect(redirectStub.getCall(0).args[0]).toContain(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2F&files=');
}); });
it('Downloads parent folder when all selected in subfolder', function() { it('Downloads parent folder when all selected in subfolder', function() {
$('.select-all').click(); $('.select-all').click();
$('.selectedActions .download').click(); $('.selectedActions .filesSelectMenu .download').click();
expect(redirectStub.calledOnce).toEqual(true); expect(redirectStub.calledOnce).toEqual(true);
expect(redirectStub.getCall(0).args[0]).toContain(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2F&files=subdir'); expect(redirectStub.getCall(0).args[0]).toContain(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2F&files=subdir');
}); });
afterEach(function() {
fileList.$el.find('.actions-selected').click();
});
}); });
describe('Delete', function() { describe('Delete', function() {
var deleteStub, deferredDelete; var deleteStub, deferredDelete;
beforeEach(function() { beforeEach(function() {
deferredDelete = $.Deferred(); deferredDelete = $.Deferred();
deleteStub = sinon.stub(filesClient, 'remove').returns(deferredDelete.promise()); deleteStub = sinon.stub(filesClient, 'remove').returns(deferredDelete.promise());
fileList.$el.find('.actions-selected').click();
}); });
afterEach(function() { afterEach(function() {
fileList.$el.find('.actions-selected').click();
deleteStub.restore(); deleteStub.restore();
}); });
it('Deletes selected files when "Delete" clicked', function() { it('Deletes selected files when "Delete" clicked', function() {
$('.selectedActions .delete-selected').click(); $('.selectedActions .filesSelectMenu .delete').click();
expect(deleteStub.callCount).toEqual(3); expect(deleteStub.callCount).toEqual(3);
expect(deleteStub.getCall(0).args[0]).toEqual('/subdir/One.txt'); expect(deleteStub.getCall(0).args[0]).toEqual('/subdir/One.txt');
@ -2265,7 +2291,7 @@ describe('OCA.Files.FileList tests', function() {
}); });
it('Deletes all files when all selected when "Delete" clicked', function() { it('Deletes all files when all selected when "Delete" clicked', function() {
$('.select-all').click(); $('.select-all').click();
$('.selectedActions .delete-selected').click(); $('.selectedActions .filesSelectMenu .delete').click();
expect(deleteStub.callCount).toEqual(4); expect(deleteStub.callCount).toEqual(4);
expect(deleteStub.getCall(0).args[0]).toEqual('/subdir/One.txt'); expect(deleteStub.getCall(0).args[0]).toEqual('/subdir/One.txt');

View File

@ -46,8 +46,8 @@ describe('OCA.Trashbin.FileList tests', function() {
'<input type="checkbox" id="select_all_trash" class="select-all">' + '<input type="checkbox" id="select_all_trash" class="select-all">' +
'<span class="name">Name</span>' + '<span class="name">Name</span>' +
'<span class="selectedActions hidden">' + '<span class="selectedActions hidden">' +
'<a href class="undelete">Restore</a>' + '<a href="" class="actions-selected"><span class="icon icon-more"></span><span>Actions</span>' +
'<a href class="delete-selected">Delete</a></span>' + '</span>' +
'</th></tr></thead>' + '</th></tr></thead>' +
'<tbody id="fileList"></tbody>' + '<tbody id="fileList"></tbody>' +
'<tfoot></tfoot>' + '<tfoot></tfoot>' +
@ -90,7 +90,18 @@ describe('OCA.Trashbin.FileList tests', function() {
var fileActions = OCA.Trashbin.App._createFileActions(fileList); var fileActions = OCA.Trashbin.App._createFileActions(fileList);
fileList = new OCA.Trashbin.FileList( fileList = new OCA.Trashbin.FileList(
$('#app-content-trashbin'), { $('#app-content-trashbin'), {
fileActions: fileActions fileActions: fileActions,
multiSelectMenu: [{
name: 'restore',
displayName: t('files', 'Restore'),
iconClass: 'icon-history',
},
{
name: 'delete',
displayName: t('files', 'Delete'),
iconClass: 'icon-delete',
}
]
} }
); );
}); });
@ -260,33 +271,39 @@ describe('OCA.Trashbin.FileList tests', function() {
fileList.findFileEl('One.txt.d11111').find('input:checkbox').click(); fileList.findFileEl('One.txt.d11111').find('input:checkbox').click();
fileList.findFileEl('Three.pdf.d33333').find('input:checkbox').click(); fileList.findFileEl('Three.pdf.d33333').find('input:checkbox').click();
fileList.findFileEl('somedir.d99999').find('input:checkbox').click(); fileList.findFileEl('somedir.d99999').find('input:checkbox').click();
fileList.$el.find('.actions-selected').click();
}); });
afterEach(function() {
fileList.$el.find('.actions-selected').click();
});
describe('Delete', function() { describe('Delete', function() {
it('Shows trashbin actions', function() { it('Shows trashbin actions', function() {
// visible because a few files were selected // visible because a few files were selected
expect($('.selectedActions').is(':visible')).toEqual(true); expect($('.selectedActions').is(':visible')).toEqual(true);
expect($('.selectedActions .delete-selected').is(':visible')).toEqual(true); expect($('.selectedActions .item-delete').is(':visible')).toEqual(true);
expect($('.selectedActions .undelete').is(':visible')).toEqual(true); expect($('.selectedActions .item-restore').is(':visible')).toEqual(true);
// check // check
fileList.$el.find('.select-all').click(); fileList.$el.find('.select-all').click();
// stays visible // stays visible
expect($('.selectedActions').is(':visible')).toEqual(true); expect($('.selectedActions').is(':visible')).toEqual(true);
expect($('.selectedActions .delete-selected').is(':visible')).toEqual(true); expect($('.selectedActions .item-delete').is(':visible')).toEqual(true);
expect($('.selectedActions .undelete').is(':visible')).toEqual(true); expect($('.selectedActions .item-restore').is(':visible')).toEqual(true);
// uncheck // uncheck
fileList.$el.find('.select-all').click(); fileList.$el.find('.select-all').click();
// becomes hidden now // becomes hidden now
expect($('.selectedActions').is(':visible')).toEqual(false); expect($('.selectedActions').is(':visible')).toEqual(false);
expect($('.selectedActions .delete-selected').is(':visible')).toEqual(false); expect($('.selectedActions .item-delete').is(':visible')).toEqual(false);
expect($('.selectedActions .undelete').is(':visible')).toEqual(false); expect($('.selectedActions .item-restore').is(':visible')).toEqual(false);
}); });
it('Deletes selected files when "Delete" clicked', function() { it('Deletes selected files when "Delete" clicked', function() {
var request; var request;
$('.selectedActions .delete-selected').click(); $('.selectedActions .filesSelectMenu .delete').click();
expect(fakeServer.requests.length).toEqual(1); expect(fakeServer.requests.length).toEqual(1);
request = fakeServer.requests[0]; request = fakeServer.requests[0];
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/delete.php'); expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/delete.php');
@ -314,7 +331,7 @@ describe('OCA.Trashbin.FileList tests', function() {
it('Deletes all files when all selected when "Delete" clicked', function() { it('Deletes all files when all selected when "Delete" clicked', function() {
var request; var request;
$('.select-all').click(); $('.select-all').click();
$('.selectedActions .delete-selected').click(); $('.selectedActions .filesSelectMenu .delete').click();
expect(fakeServer.requests.length).toEqual(1); expect(fakeServer.requests.length).toEqual(1);
request = fakeServer.requests[0]; request = fakeServer.requests[0];
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/delete.php'); expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/delete.php');
@ -331,7 +348,7 @@ describe('OCA.Trashbin.FileList tests', function() {
describe('Restore', function() { describe('Restore', function() {
it('Restores selected files when "Restore" clicked', function() { it('Restores selected files when "Restore" clicked', function() {
var request; var request;
$('.selectedActions .undelete').click(); $('.selectedActions .filesSelectMenu .restore').click();
expect(fakeServer.requests.length).toEqual(1); expect(fakeServer.requests.length).toEqual(1);
request = fakeServer.requests[0]; request = fakeServer.requests[0];
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/undelete.php'); expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/undelete.php');
@ -359,7 +376,7 @@ describe('OCA.Trashbin.FileList tests', function() {
it('Restores all files when all selected when "Restore" clicked', function() { it('Restores all files when all selected when "Restore" clicked', function() {
var request; var request;
$('.select-all').click(); $('.select-all').click();
$('.selectedActions .undelete').click(); $('.selectedActions .filesSelectMenu .restore').click();
expect(fakeServer.requests.length).toEqual(1); expect(fakeServer.requests.length).toEqual(1);
request = fakeServer.requests[0]; request = fakeServer.requests[0];
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/undelete.php'); expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/undelete.php');