Fix move related tests

Signed-off-by: Tomasz Grobelny <tomasz@grobelny.net>
This commit is contained in:
Tomasz Grobelny 2018-11-03 23:01:32 +00:00
parent 68a27debd1
commit 41687ef00f
2 changed files with 73 additions and 60 deletions

View File

@ -989,7 +989,7 @@
});
}
this.move(_.pluck(files, 'name'), targetPath);
var movePromise = this.move(_.pluck(files, 'name'), targetPath);
// re-enable td elements to be droppable
// sometimes the filename drop handler is still called after re-enable,
@ -997,6 +997,8 @@
setTimeout(function() {
self.$el.find('td.filename.ui-droppable').droppable('enable');
}, 10);
return movePromise;
},
/**
@ -2229,8 +2231,8 @@
var mcSemaphore = new Semaphore(10);
var counter = 0;
_.each(fileNames, function(arg) {
mcSemaphore.acquire().then(function(){
var promises = _.map(fileNames, function(arg) {
return mcSemaphore.acquire().then(function(){
moveFileFunction(arg).then(function(){
mcSemaphore.release();
counter++;
@ -2238,9 +2240,11 @@
});
});
return Promise.all(promises).then(function(){
if (callback) {
callback();
}
});
},
/**

View File

@ -838,8 +838,8 @@ describe('OCA.Files.FileList tests', function() {
moveStub.restore();
});
it('Moves single file to target folder', function() {
fileList.move('One.txt', '/somedir');
it('Moves single file to target folder', function(done) {
return fileList.move('One.txt', '/somedir').then(function(){
expect(moveStub.calledOnce).toEqual(true);
expect(moveStub.getCall(0).args[0]).toEqual('/subdir/One.txt');
@ -854,14 +854,16 @@ describe('OCA.Files.FileList tests', function() {
expect(fileList.findFileEl('somedir').find('.filesize').text()).toEqual('262 B');
expect(notificationStub.notCalled).toEqual(true);
done();
});
it('Moves list of files to target folder', 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());
fileList.move(['One.txt', 'Two.jpg'], '/somedir');
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');
@ -886,9 +888,11 @@ describe('OCA.Files.FileList tests', function() {
expect(fileList.findFileEl('somedir').find('.filesize').text()).toEqual('12 KB');
expect(notificationStub.notCalled).toEqual(true);
done();
});
it('Shows notification if a file could not be moved', function() {
fileList.move('One.txt', '/somedir');
});
it('Shows notification if a file could not be moved', function(done) {
return fileList.move('One.txt', '/somedir').then(function(){
expect(moveStub.calledOnce).toEqual(true);
@ -898,9 +902,11 @@ describe('OCA.Files.FileList tests', function() {
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() {
fileList.move('One.txt', '/somedir');
return fileList.move('One.txt', '/somedir').then(function(){
expect(fileList.findFileEl('One.txt').find('.thumbnail').parent().attr('class'))
.toContain('icon-loading-small');
@ -918,6 +924,7 @@ describe('OCA.Files.FileList tests', function() {
.toEqual(OC.imagePath('core', 'filetypes/text.svg'));
});
});
});
describe('Copying files', function() {
var deferredCopy;
@ -1757,7 +1764,7 @@ describe('OCA.Files.FileList tests', function() {
expect(changeDirStub.getCall(0).args[0]).toEqual('/subdir/two/three with space');
changeDirStub.restore();
});
it('dropping files on breadcrumb calls move operation', function() {
it('dropping files on breadcrumb calls move operation', function(done) {
var testDir = '/subdir/two/three with space/four/five';
var moveStub = sinon.stub(filesClient, 'move').returns($.Deferred().promise());
fileList.changeDirectory(testDir);
@ -1775,7 +1782,7 @@ describe('OCA.Files.FileList tests', function() {
$('<tr data-file="Two.jpg" data-dir="' + testDir + '"></tr>')
]);
// simulate drop event
fileList._onDropOnBreadCrumb(new $.Event('drop', {target: $crumb}), ui);
return fileList._onDropOnBreadCrumb(new $.Event('drop', {target: $crumb}), ui).then(function(){
expect(moveStub.callCount).toEqual(2);
expect(moveStub.getCall(0).args[0]).toEqual(testDir + '/One.txt');
@ -1783,6 +1790,8 @@ describe('OCA.Files.FileList tests', function() {
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();
done();
});
});
it('dropping files on same dir breadcrumb does nothing', function() {
var testDir = '/subdir/two/three with space/four/five';