|
|
|
|
@ -522,7 +522,7 @@ describe('OCA.Files.FileList tests', function() {
|
|
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
|
deferredDelete = $.Deferred();
|
|
|
|
|
deleteStub = sinon.stub(filesClient, 'remove').returns(deferredDelete.promise());
|
|
|
|
|
deleteStub = sinon.stub(filesClient, 'remove');
|
|
|
|
|
});
|
|
|
|
|
afterEach(function() {
|
|
|
|
|
deleteStub.restore();
|
|
|
|
|
@ -530,92 +530,153 @@ describe('OCA.Files.FileList tests', function() {
|
|
|
|
|
|
|
|
|
|
function doDelete() {
|
|
|
|
|
// note: normally called from FileActions
|
|
|
|
|
fileList.do_delete(['One.txt', 'Two.jpg']);
|
|
|
|
|
return fileList.do_delete(['One.txt', 'Two.jpg']).then(function(){
|
|
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
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');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
it('calls delete.php, removes the deleted entries and updates summary', function() {
|
|
|
|
|
it('calls delete.php, removes the deleted entries and updates summary', function(done) {
|
|
|
|
|
var $summary;
|
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
|
doDelete();
|
|
|
|
|
deferredDelete1 = $.Deferred();
|
|
|
|
|
deferredDelete2 = $.Deferred();
|
|
|
|
|
deleteStub.onCall(0).callsFake(function(src){
|
|
|
|
|
expect(deleteStub.calledOnce).toEqual(true);
|
|
|
|
|
expect(src).toEqual('/subdir/One.txt');
|
|
|
|
|
return deferredDelete1.promise();
|
|
|
|
|
});
|
|
|
|
|
deleteStub.onCall(1).callsFake(function(src){
|
|
|
|
|
expect(deleteStub.calledTwice).toEqual(true);
|
|
|
|
|
expect(src).toEqual('/subdir/Two.jpg');
|
|
|
|
|
return deferredDelete2.promise();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
deferredDelete.resolve(200);
|
|
|
|
|
var promise = fileList.do_delete(['One.txt', 'Two.jpg']);
|
|
|
|
|
deferredDelete1.resolve(200);
|
|
|
|
|
deferredDelete2.resolve(200);
|
|
|
|
|
return promise.then(function(){
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
$summary = $('#filestable .summary');
|
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(false);
|
|
|
|
|
expect($summary.find('.dirinfo').text()).toEqual('1 folder');
|
|
|
|
|
expect($summary.find('.fileinfo').text()).toEqual('1 file');
|
|
|
|
|
expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(false);
|
|
|
|
|
expect($summary.find('.fileinfo').hasClass('hidden')).toEqual(false);
|
|
|
|
|
expect($summary.find('.filesize').text()).toEqual('57 KB');
|
|
|
|
|
expect(fileList.isEmpty).toEqual(false);
|
|
|
|
|
expect($('#filestable thead th').hasClass('hidden')).toEqual(false);
|
|
|
|
|
expect($('#emptycontent').hasClass('hidden')).toEqual(true);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
$summary = $('#filestable .summary');
|
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(false);
|
|
|
|
|
expect($summary.find('.dirinfo').text()).toEqual('1 folder');
|
|
|
|
|
expect($summary.find('.fileinfo').text()).toEqual('1 file');
|
|
|
|
|
expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(false);
|
|
|
|
|
expect($summary.find('.fileinfo').hasClass('hidden')).toEqual(false);
|
|
|
|
|
expect($summary.find('.filesize').text()).toEqual('57 KB');
|
|
|
|
|
expect(fileList.isEmpty).toEqual(false);
|
|
|
|
|
expect($('#filestable thead th').hasClass('hidden')).toEqual(false);
|
|
|
|
|
expect($('#emptycontent').hasClass('hidden')).toEqual(true);
|
|
|
|
|
|
|
|
|
|
expect(notificationStub.notCalled).toEqual(true);
|
|
|
|
|
expect(notificationStub.notCalled).toEqual(true);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
it('shows busy state on files to be deleted', function() {
|
|
|
|
|
it('shows busy state on files to be deleted', function(done) {
|
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
|
doDelete();
|
|
|
|
|
|
|
|
|
|
expect(fileList.findFileEl('One.txt').hasClass('busy')).toEqual(true);
|
|
|
|
|
expect(fileList.findFileEl('Three.pdf').hasClass('busy')).toEqual(false);
|
|
|
|
|
deferredDelete1 = $.Deferred();
|
|
|
|
|
deferredDelete2 = $.Deferred();
|
|
|
|
|
deleteStub.onCall(0).callsFake(function(src){
|
|
|
|
|
expect(fileList.findFileEl('One.txt').hasClass('busy')).toEqual(true);
|
|
|
|
|
expect(fileList.findFileEl('Three.pdf').hasClass('busy')).toEqual(false);
|
|
|
|
|
|
|
|
|
|
expect(deleteStub.calledOnce).toEqual(true);
|
|
|
|
|
expect(src).toEqual('/subdir/One.txt');
|
|
|
|
|
return deferredDelete1.promise();
|
|
|
|
|
});
|
|
|
|
|
deleteStub.onCall(1).callsFake(function(src){
|
|
|
|
|
expect(fileList.findFileEl('Two.jpg').hasClass('busy')).toEqual(true);
|
|
|
|
|
expect(fileList.findFileEl('Three.pdf').hasClass('busy')).toEqual(false);
|
|
|
|
|
|
|
|
|
|
expect(deleteStub.calledTwice).toEqual(true);
|
|
|
|
|
expect(src).toEqual('/subdir/Two.jpg');
|
|
|
|
|
return deferredDelete2.promise();
|
|
|
|
|
});
|
|
|
|
|
var promise = fileList.do_delete(['One.txt', 'Two.jpg']).then(function(){
|
|
|
|
|
expect(deleteStub.calledTwice).toEqual(true);
|
|
|
|
|
});
|
|
|
|
|
deferredDelete1.resolve(200);
|
|
|
|
|
deferredDelete2.resolve(200);
|
|
|
|
|
return promise.then(function(){
|
|
|
|
|
expect(fileList.findFileEl('One.txt').hasClass('busy')).toEqual(false);
|
|
|
|
|
expect(fileList.findFileEl('Two.jpg').hasClass('busy')).toEqual(false);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
it('shows busy state on all files when deleting all', function() {
|
|
|
|
|
it('shows busy state on all files when deleting all', function(done) {
|
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
|
|
|
|
|
|
fileList.do_delete();
|
|
|
|
|
|
|
|
|
|
expect(fileList.$fileList.find('tr.busy').length).toEqual(4);
|
|
|
|
|
var deferredDeleteArray = [];
|
|
|
|
|
var count = 0;
|
|
|
|
|
for (var i = 0; i < 4; i++) {
|
|
|
|
|
(function(i, fn){
|
|
|
|
|
deferredDeleteArray.push($.Deferred());
|
|
|
|
|
deleteStub.onCall(i).callsFake(function(src){
|
|
|
|
|
expect(fileList.findFileEl(fn).hasClass('busy')).toEqual(true);
|
|
|
|
|
count++;
|
|
|
|
|
return deferredDeleteArray[i].promise();
|
|
|
|
|
});
|
|
|
|
|
})(i, testFiles[i].name);
|
|
|
|
|
}
|
|
|
|
|
var promise = fileList.do_delete();
|
|
|
|
|
for (var i = 0; i < 4; i++) {
|
|
|
|
|
deferredDeleteArray[i].resolve(200);
|
|
|
|
|
}
|
|
|
|
|
return promise.then(function(){
|
|
|
|
|
expect(count).toEqual(4);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
it('updates summary when deleting last file', function() {
|
|
|
|
|
it('updates summary when deleting last file', function(done) {
|
|
|
|
|
var $summary;
|
|
|
|
|
fileList.setFiles([testFiles[0], testFiles[1]]);
|
|
|
|
|
doDelete();
|
|
|
|
|
|
|
|
|
|
deleteStub.returns(deferredDelete.promise());
|
|
|
|
|
deferredDelete.resolve(200);
|
|
|
|
|
|
|
|
|
|
expect(fileList.$fileList.find('tr').length).toEqual(0);
|
|
|
|
|
|
|
|
|
|
$summary = $('#filestable .summary');
|
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(true);
|
|
|
|
|
expect(fileList.isEmpty).toEqual(true);
|
|
|
|
|
expect(fileList.files.length).toEqual(0);
|
|
|
|
|
expect($('#filestable thead th').hasClass('hidden')).toEqual(true);
|
|
|
|
|
expect($('#emptycontent').hasClass('hidden')).toEqual(false);
|
|
|
|
|
return doDelete().then(function(){
|
|
|
|
|
expect(fileList.$fileList.find('tr').length).toEqual(0);
|
|
|
|
|
$summary = $('#filestable .summary');
|
|
|
|
|
expect($summary.hasClass('hidden')).toEqual(true);
|
|
|
|
|
expect(fileList.isEmpty).toEqual(true);
|
|
|
|
|
expect(fileList.files.length).toEqual(0);
|
|
|
|
|
expect($('#filestable thead th').hasClass('hidden')).toEqual(true);
|
|
|
|
|
expect($('#emptycontent').hasClass('hidden')).toEqual(false);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
it('bring back deleted item when delete call failed', function() {
|
|
|
|
|
it('bring back deleted item when delete call failed', function(done) {
|
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
|
doDelete();
|
|
|
|
|
|
|
|
|
|
deleteStub.returns(deferredDelete.promise());
|
|
|
|
|
var promise = doDelete();
|
|
|
|
|
deferredDelete.reject(403);
|
|
|
|
|
return promise.then(function(){
|
|
|
|
|
// files are still in the list
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
|
|
|
|
expect(fileList.findFileEl('Two.jpg').length).toEqual(1);
|
|
|
|
|
expect(fileList.$fileList.find('tr').length).toEqual(4);
|
|
|
|
|
|
|
|
|
|
// files are still in the list
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
|
|
|
|
expect(fileList.findFileEl('Two.jpg').length).toEqual(1);
|
|
|
|
|
expect(fileList.$fileList.find('tr').length).toEqual(4);
|
|
|
|
|
|
|
|
|
|
expect(notificationStub.calledTwice).toEqual(true);
|
|
|
|
|
expect(notificationStub.calledTwice).toEqual(true);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
it('remove file from list if delete call returned 404 not found', function() {
|
|
|
|
|
it('remove file from list if delete call returned 404 not found', function(done) {
|
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
|
doDelete();
|
|
|
|
|
|
|
|
|
|
deleteStub.returns(deferredDelete.promise());
|
|
|
|
|
var promise = doDelete();
|
|
|
|
|
deferredDelete.reject(404);
|
|
|
|
|
return promise.then(function(){
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(0);
|
|
|
|
|
expect(fileList.findFileEl('Two.jpg').length).toEqual(0);
|
|
|
|
|
expect(fileList.$fileList.find('tr').length).toEqual(2);
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
expect(notificationStub.notCalled).toEqual(true);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
describe('Renaming files', function() {
|
|
|
|
|
@ -831,7 +892,7 @@ describe('OCA.Files.FileList tests', function() {
|
|
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
|
deferredMove = $.Deferred();
|
|
|
|
|
moveStub = sinon.stub(filesClient, 'move').returns(deferredMove.promise());
|
|
|
|
|
moveStub = sinon.stub(filesClient, 'move');
|
|
|
|
|
|
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
|
});
|
|
|
|
|
@ -840,14 +901,18 @@ describe('OCA.Files.FileList tests', function() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Moves single file to target folder', function(done) {
|
|
|
|
|
return fileList.move('One.txt', '/somedir').then(function(){
|
|
|
|
|
var promise = fileList.move('One.txt', '/somedir');
|
|
|
|
|
|
|
|
|
|
moveStub.callsFake(function(src, dst){
|
|
|
|
|
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');
|
|
|
|
|
expect(src).toEqual('/subdir/One.txt');
|
|
|
|
|
expect(dst).toEqual('/somedir/One.txt');
|
|
|
|
|
return deferredMove.promise();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
deferredMove.resolve(201);
|
|
|
|
|
deferredMove.resolve(201);
|
|
|
|
|
|
|
|
|
|
return promise.then(function(){
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(0);
|
|
|
|
|
|
|
|
|
|
// folder size has increased
|
|
|
|
|
@ -861,26 +926,29 @@ describe('OCA.Files.FileList tests', function() {
|
|
|
|
|
it('Moves list of files to target folder', function(done) {
|
|
|
|
|
var deferredMove1 = $.Deferred();
|
|
|
|
|
var deferredMove2 = $.Deferred();
|
|
|
|
|
moveStub.onCall(0).returns(deferredMove1.promise());
|
|
|
|
|
moveStub.onCall(1).returns(deferredMove2.promise());
|
|
|
|
|
|
|
|
|
|
return fileList.move(['One.txt', 'Two.jpg'], '/somedir').then(function(){
|
|
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
|
|
|
|
|
deferredMove1.resolve(201);
|
|
|
|
|
|
|
|
|
|
moveStub.onCall(0).callsFake(function(src, dst){
|
|
|
|
|
expect(moveStub.calledOnce).toEqual(true);
|
|
|
|
|
expect(src).toEqual('/subdir/One.txt');
|
|
|
|
|
expect(dst).toEqual('/somedir/One.txt');
|
|
|
|
|
return deferredMove1.promise();
|
|
|
|
|
});
|
|
|
|
|
moveStub.onCall(1).callsFake(function(src, dst){
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(0);
|
|
|
|
|
|
|
|
|
|
// folder size has increased during move
|
|
|
|
|
expect(fileList.findFileEl('somedir').data('size')).toEqual(262);
|
|
|
|
|
expect(fileList.findFileEl('somedir').find('.filesize').text()).toEqual('262 B');
|
|
|
|
|
|
|
|
|
|
deferredMove2.resolve(201);
|
|
|
|
|
expect(src).toEqual('/subdir/Two.jpg');
|
|
|
|
|
expect(dst).toEqual('/somedir/Two.jpg');
|
|
|
|
|
return deferredMove2.promise();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var promise = fileList.move(['One.txt', 'Two.jpg'], '/somedir');
|
|
|
|
|
deferredMove1.resolve(201);
|
|
|
|
|
deferredMove2.resolve(201);
|
|
|
|
|
return promise.then(function(){
|
|
|
|
|
expect(moveStub.calledTwice).toEqual(true);
|
|
|
|
|
|
|
|
|
|
expect(fileList.findFileEl('Two.jpg').length).toEqual(0);
|
|
|
|
|
|
|
|
|
|
@ -893,34 +961,32 @@ describe('OCA.Files.FileList tests', function() {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
it('Shows notification if a file could not be moved', function(done) {
|
|
|
|
|
return fileList.move('One.txt', '/somedir').then(function(){
|
|
|
|
|
|
|
|
|
|
moveStub.callsFake(function(){
|
|
|
|
|
expect(moveStub.calledOnce).toEqual(true);
|
|
|
|
|
|
|
|
|
|
deferredMove.reject(409);
|
|
|
|
|
|
|
|
|
|
return deferredMove.promise();
|
|
|
|
|
});
|
|
|
|
|
var promise = fileList.move('One.txt', '/somedir');
|
|
|
|
|
deferredMove.reject(409);
|
|
|
|
|
return promise.then(function(){
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
|
|
|
|
|
|
|
|
|
expect(notificationStub.calledOnce).toEqual(true);
|
|
|
|
|
expect(notificationStub.getCall(0).args[0]).toEqual('Could not move "One.txt"');
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
it('Restores thumbnail if a file could not be moved', function(done) {
|
|
|
|
|
return fileList.move('One.txt', '/somedir').then(function(){
|
|
|
|
|
|
|
|
|
|
moveStub.callsFake(function(){
|
|
|
|
|
expect(fileList.findFileEl('One.txt').find('.thumbnail').parent().attr('class'))
|
|
|
|
|
.toContain('icon-loading-small');
|
|
|
|
|
|
|
|
|
|
expect(moveStub.calledOnce).toEqual(true);
|
|
|
|
|
|
|
|
|
|
deferredMove.reject(409);
|
|
|
|
|
|
|
|
|
|
return deferredMove.promise();
|
|
|
|
|
});
|
|
|
|
|
var promise = fileList.move('One.txt', '/somedir');
|
|
|
|
|
deferredMove.reject(409);
|
|
|
|
|
return promise.then(function(){
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
|
|
|
|
|
|
|
|
|
expect(notificationStub.calledOnce).toEqual(true);
|
|
|
|
|
expect(notificationStub.getCall(0).args[0]).toEqual('Could not move "One.txt"');
|
|
|
|
|
|
|
|
|
|
expect(OC.TestUtil.getImageUrl(fileList.findFileEl('One.txt').find('.thumbnail')))
|
|
|
|
|
.toEqual(OC.imagePath('core', 'filetypes/text.svg'));
|
|
|
|
|
done();
|
|
|
|
|
@ -934,7 +1000,7 @@ describe('OCA.Files.FileList tests', function() {
|
|
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
|
deferredCopy = $.Deferred();
|
|
|
|
|
copyStub = sinon.stub(filesClient, 'copy').returns(deferredCopy.promise());
|
|
|
|
|
copyStub = sinon.stub(filesClient, 'copy');
|
|
|
|
|
|
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
|
});
|
|
|
|
|
@ -942,86 +1008,100 @@ describe('OCA.Files.FileList tests', function() {
|
|
|
|
|
copyStub.restore();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Copies single file to target folder', function() {
|
|
|
|
|
fileList.copy('One.txt', '/somedir');
|
|
|
|
|
it('Copies single file to target folder', function(done) {
|
|
|
|
|
copyStub.callsFake(function(){
|
|
|
|
|
expect(copyStub.calledOnce).toEqual(true);
|
|
|
|
|
expect(copyStub.getCall(0).args[0]).toEqual('/subdir/One.txt');
|
|
|
|
|
expect(copyStub.getCall(0).args[1]).toEqual('/somedir/One.txt');
|
|
|
|
|
|
|
|
|
|
expect(copyStub.calledOnce).toEqual(true);
|
|
|
|
|
expect(copyStub.getCall(0).args[0]).toEqual('/subdir/One.txt');
|
|
|
|
|
expect(copyStub.getCall(0).args[1]).toEqual('/somedir/One.txt');
|
|
|
|
|
return deferredCopy.promise();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var promise = fileList.copy('One.txt', '/somedir');
|
|
|
|
|
deferredCopy.resolve(201);
|
|
|
|
|
return promise.then(function(){
|
|
|
|
|
// File is still here
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
|
|
|
|
|
|
|
|
|
// File is still here
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
|
|
|
|
|
|
|
|
|
// folder size has increased
|
|
|
|
|
expect(fileList.findFileEl('somedir').data('size')).toEqual(262);
|
|
|
|
|
expect(fileList.findFileEl('somedir').find('.filesize').text()).toEqual('262 B');
|
|
|
|
|
// folder size has increased
|
|
|
|
|
expect(fileList.findFileEl('somedir').data('size')).toEqual(262);
|
|
|
|
|
expect(fileList.findFileEl('somedir').find('.filesize').text()).toEqual('262 B');
|
|
|
|
|
|
|
|
|
|
// Copying sents a notification to tell that we've successfully copied file
|
|
|
|
|
expect(notificationStub.notCalled).toEqual(false);
|
|
|
|
|
// Copying sents a notification to tell that we've successfully copied file
|
|
|
|
|
expect(notificationStub.notCalled).toEqual(false);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
it('Copies list of files to target folder', function() {
|
|
|
|
|
it('Copies list of files to target folder', function(done) {
|
|
|
|
|
var deferredCopy1 = $.Deferred();
|
|
|
|
|
var deferredCopy2 = $.Deferred();
|
|
|
|
|
copyStub.onCall(0).returns(deferredCopy1.promise());
|
|
|
|
|
copyStub.onCall(1).returns(deferredCopy2.promise());
|
|
|
|
|
|
|
|
|
|
fileList.copy(['One.txt', 'Two.jpg'], '/somedir');
|
|
|
|
|
copyStub.onCall(0).callsFake(function(src, dst){
|
|
|
|
|
expect(src).toEqual('/subdir/One.txt');
|
|
|
|
|
expect(dst).toEqual('/somedir/One.txt');
|
|
|
|
|
return deferredCopy1.promise();
|
|
|
|
|
});
|
|
|
|
|
copyStub.onCall(1).callsFake(function(src, dst){
|
|
|
|
|
// folder size has increased during copy
|
|
|
|
|
expect(fileList.findFileEl('somedir').data('size')).toEqual(262);
|
|
|
|
|
expect(fileList.findFileEl('somedir').find('.filesize').text()).toEqual('262 B');
|
|
|
|
|
|
|
|
|
|
expect(copyStub.calledTwice).toEqual(true);
|
|
|
|
|
expect(copyStub.getCall(0).args[0]).toEqual('/subdir/One.txt');
|
|
|
|
|
expect(copyStub.getCall(0).args[1]).toEqual('/somedir/One.txt');
|
|
|
|
|
expect(copyStub.getCall(1).args[0]).toEqual('/subdir/Two.jpg');
|
|
|
|
|
expect(copyStub.getCall(1).args[1]).toEqual('/somedir/Two.jpg');
|
|
|
|
|
expect(src).toEqual('/subdir/Two.jpg');
|
|
|
|
|
expect(dst).toEqual('/somedir/Two.jpg');
|
|
|
|
|
return deferredCopy2.promise();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var promise = fileList.copy(['One.txt', 'Two.jpg'], '/somedir');
|
|
|
|
|
deferredCopy1.resolve(201);
|
|
|
|
|
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
|
|
|
|
|
|
|
|
|
// folder size has increased during copy
|
|
|
|
|
expect(fileList.findFileEl('somedir').data('size')).toEqual(262);
|
|
|
|
|
expect(fileList.findFileEl('somedir').find('.filesize').text()).toEqual('262 B');
|
|
|
|
|
|
|
|
|
|
deferredCopy2.resolve(201);
|
|
|
|
|
|
|
|
|
|
expect(fileList.findFileEl('Two.jpg').length).toEqual(1);
|
|
|
|
|
return promise.then(function(){
|
|
|
|
|
expect(copyStub.calledTwice).toEqual(true);
|
|
|
|
|
expect(fileList.findFileEl('Two.jpg').length).toEqual(1);
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
|
|
|
|
|
|
|
|
|
// folder size has increased
|
|
|
|
|
expect(fileList.findFileEl('somedir').data('size')).toEqual(12311);
|
|
|
|
|
expect(fileList.findFileEl('somedir').find('.filesize').text()).toEqual('12 KB');
|
|
|
|
|
// folder size has increased
|
|
|
|
|
expect(fileList.findFileEl('somedir').data('size')).toEqual(12311);
|
|
|
|
|
expect(fileList.findFileEl('somedir').find('.filesize').text()).toEqual('12 KB');
|
|
|
|
|
|
|
|
|
|
expect(notificationStub.notCalled).toEqual(false);
|
|
|
|
|
expect(notificationStub.notCalled).toEqual(false);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
it('Shows notification if a file could not be copied', function() {
|
|
|
|
|
fileList.copy('One.txt', '/somedir');
|
|
|
|
|
|
|
|
|
|
expect(copyStub.calledOnce).toEqual(true);
|
|
|
|
|
it('Shows notification if a file could not be copied', function(done) {
|
|
|
|
|
copyStub.callsFake(function(){
|
|
|
|
|
expect(copyStub.calledOnce).toEqual(true);
|
|
|
|
|
return deferredCopy.promise();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var promise = fileList.copy('One.txt', '/somedir');
|
|
|
|
|
deferredCopy.reject(409);
|
|
|
|
|
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
|
|
|
|
|
|
|
|
|
expect(notificationStub.calledOnce).toEqual(true);
|
|
|
|
|
expect(notificationStub.getCall(0).args[0]).toEqual('Could not copy "One.txt"');
|
|
|
|
|
return promise.then(function(){
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
|
|
|
|
expect(notificationStub.calledOnce).toEqual(true);
|
|
|
|
|
expect(notificationStub.getCall(0).args[0]).toEqual('Could not copy "One.txt"');
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
it('Restores thumbnail if a file could not be copied', function() {
|
|
|
|
|
fileList.copy('One.txt', '/somedir');
|
|
|
|
|
|
|
|
|
|
expect(fileList.findFileEl('One.txt').find('.thumbnail').parent().attr('class'))
|
|
|
|
|
.toContain('icon-loading-small');
|
|
|
|
|
|
|
|
|
|
expect(copyStub.calledOnce).toEqual(true);
|
|
|
|
|
it('Restores thumbnail if a file could not be copied', function(done) {
|
|
|
|
|
copyStub.callsFake(function(){
|
|
|
|
|
expect(fileList.findFileEl('One.txt').find('.thumbnail').parent().attr('class'))
|
|
|
|
|
.toContain('icon-loading-small');
|
|
|
|
|
expect(copyStub.calledOnce).toEqual(true);
|
|
|
|
|
return deferredCopy.promise();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var promise = fileList.copy('One.txt', '/somedir');
|
|
|
|
|
deferredCopy.reject(409);
|
|
|
|
|
return promise.then(function(){
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
|
|
|
|
|
|
|
|
|
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
|
|
|
|
|
|
|
|
|
expect(notificationStub.calledOnce).toEqual(true);
|
|
|
|
|
expect(notificationStub.getCall(0).args[0]).toEqual('Could not copy "One.txt"');
|
|
|
|
|
expect(notificationStub.calledOnce).toEqual(true);
|
|
|
|
|
expect(notificationStub.getCall(0).args[0]).toEqual('Could not copy "One.txt"');
|
|
|
|
|
|
|
|
|
|
expect(OC.TestUtil.getImageUrl(fileList.findFileEl('One.txt').find('.thumbnail')))
|
|
|
|
|
.toEqual(OC.imagePath('core', 'filetypes/text.svg'));
|
|
|
|
|
expect(OC.TestUtil.getImageUrl(fileList.findFileEl('One.txt').find('.thumbnail')))
|
|
|
|
|
.toEqual(OC.imagePath('core', 'filetypes/text.svg'));
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@ -2283,7 +2363,7 @@ describe('OCA.Files.FileList tests', function() {
|
|
|
|
|
var deleteStub, deferredDelete;
|
|
|
|
|
beforeEach(function() {
|
|
|
|
|
deferredDelete = $.Deferred();
|
|
|
|
|
deleteStub = sinon.stub(filesClient, 'remove').returns(deferredDelete.promise());
|
|
|
|
|
deleteStub = sinon.stub(filesClient, 'remove');
|
|
|
|
|
fileList.$el.find('.actions-selected').click();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@ -2292,34 +2372,54 @@ describe('OCA.Files.FileList tests', function() {
|
|
|
|
|
deleteStub.restore();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Deletes selected files when "Delete" clicked', function() {
|
|
|
|
|
it('Deletes selected files when "Delete" clicked', function(done) {
|
|
|
|
|
var deferred = $.Deferred();
|
|
|
|
|
|
|
|
|
|
deleteStub.returns(deferredDelete.promise());
|
|
|
|
|
deleteStub.onCall(2).callsFake(function(){
|
|
|
|
|
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');
|
|
|
|
|
return deferredDelete.promise();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
stub = sinon.stub(fileList._operationProgressBar, 'hideProgressBar').callsFake(function(){
|
|
|
|
|
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);
|
|
|
|
|
done();
|
|
|
|
|
deferred.resolve();
|
|
|
|
|
});
|
|
|
|
|
$('.selectedActions .filesSelectMenu .delete').click();
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
return deferred.promise();
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
it('Deletes all files when all selected when "Delete" clicked', function() {
|
|
|
|
|
it('Deletes all files when all selected when "Delete" clicked', function(done) {
|
|
|
|
|
var deferred = $.Deferred();
|
|
|
|
|
|
|
|
|
|
deleteStub.returns(deferredDelete.promise());
|
|
|
|
|
deleteStub.onCall(3).callsFake(function(){
|
|
|
|
|
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');
|
|
|
|
|
return deferredDelete.promise();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
stub = sinon.stub(fileList._operationProgressBar, 'hideProgressBar').callsFake(function(){
|
|
|
|
|
expect(fileList.isEmpty).toEqual(true);
|
|
|
|
|
expect(deleteStub.callCount).toEqual(4);
|
|
|
|
|
done();
|
|
|
|
|
deferred.resolve();
|
|
|
|
|
});
|
|
|
|
|
$('.select-all').click();
|
|
|
|
|
$('.selectedActions .filesSelectMenu .delete').click();
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
expect(fileList.isEmpty).toEqual(true);
|
|
|
|
|
return deferred.promise();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|