summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2017-09-15 18:14:34 +0200
committerThomas Citharel <tcit@tcit.fr>2017-09-15 18:14:34 +0200
commit8c576a8d6374cabaa8807455b412603f0e8f1d45 (patch)
treef6903d1e8ee0ae5539dacee85b1770f04aa00015
parent98ee32b91c7111aa9b73f72950350819b591d39c (diff)
downloadnextcloud-server-8c576a8d6374cabaa8807455b412603f0e8f1d45.tar.gz
nextcloud-server-8c576a8d6374cabaa8807455b412603f0e8f1d45.zip
Add tests for FileList
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
-rw-r--r--apps/files/tests/js/filelistSpec.js98
1 files changed, 98 insertions, 0 deletions
diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js
index a12c0ff49b6..5061d70c4c7 100644
--- a/apps/files/tests/js/filelistSpec.js
+++ b/apps/files/tests/js/filelistSpec.js
@@ -853,6 +853,104 @@ describe('OCA.Files.FileList tests', function() {
.toEqual(OC.imagePath('core', 'filetypes/text.svg'));
});
});
+
+ describe('Copying files', function() {
+ var deferredCopy;
+ var copyStub;
+
+ beforeEach(function() {
+ deferredCopy = $.Deferred();
+ copyStub = sinon.stub(filesClient, 'copy').returns(deferredCopy.promise());
+
+ fileList.setFiles(testFiles);
+ });
+ afterEach(function() {
+ copyStub.restore();
+ });
+
+ it('Copies single file to target folder', function() {
+ fileList.copy('One.txt', '/somedir');
+
+ 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');
+
+ deferredCopy.resolve(201);
+
+ // 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');
+
+ // Copying sents a notification to tell that we've successfully copied file
+ expect(notificationStub.notCalled).toEqual(false);
+ });
+ it('Copies list of files to target folder', function() {
+ 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');
+
+ 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');
+
+ 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);
+
+ // 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);
+ });
+ it('Shows notification if a file could not be copied', function() {
+ fileList.copy('One.txt', '/somedir');
+
+ expect(copyStub.calledOnce).toEqual(true);
+
+ 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"');
+ });
+ it('Restores thumbnail if a file could not be copied', function() {
+ fileList.copy('One.txt', '/somedir');
+
+ expect(OC.TestUtil.getImageUrl(fileList.findFileEl('One.txt').find('.thumbnail')))
+ .toEqual(OC.imagePath('core', 'loading.gif'));
+
+ expect(copyStub.calledOnce).toEqual(true);
+
+ 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"');
+
+ expect(OC.TestUtil.getImageUrl(fileList.findFileEl('One.txt').find('.thumbnail')))
+ .toEqual(OC.imagePath('core', 'filetypes/text.svg'));
+ });
+ });
+
describe('Update file', function() {
it('does not change summary', function() {
var $summary = $('#filestable .summary');