diff options
Diffstat (limited to 'apps/files/tests/js/fileactionsSpec.js')
-rw-r--r-- | apps/files/tests/js/fileactionsSpec.js | 78 |
1 files changed, 60 insertions, 18 deletions
diff --git a/apps/files/tests/js/fileactionsSpec.js b/apps/files/tests/js/fileactionsSpec.js index ef7ddcb874a..3c22c84b866 100644 --- a/apps/files/tests/js/fileactionsSpec.js +++ b/apps/files/tests/js/fileactionsSpec.js @@ -22,6 +22,7 @@ /* global OC, FileActions, FileList */ describe('FileActions tests', function() { var $filesTable; + beforeEach(function() { // init horrible parameters var $body = $('body'); @@ -34,42 +35,83 @@ describe('FileActions tests', function() { $('#dir, #permissions, #filestable').remove(); }); it('calling display() sets file actions', function() { - // note: download_url is actually the link target, not the actual download URL... - var $tr = FileList.addFile('testName.txt', 1234, new Date(), false, false, {download_url: 'test/download/url'}); - - // no actions before call - expect($tr.find('.action[data-action=Download]').length).toEqual(0); - expect($tr.find('.action[data-action=Rename]').length).toEqual(0); - expect($tr.find('.action.delete').length).toEqual(0); + var fileData = { + id: 18, + type: 'file', + name: 'testName.txt', + mimetype: 'plain/text', + size: '1234', + etag: 'a01234c', + mtime: '123456' + }; - FileActions.display($tr.find('td.filename'), true); + // note: FileActions.display() is called implicitly + var $tr = FileList.add(fileData); - // actions defined after cal - expect($tr.find('.action[data-action=Download]').length).toEqual(1); - expect($tr.find('.nametext .action[data-action=Rename]').length).toEqual(1); + // actions defined after call + expect($tr.find('.action.action-download').length).toEqual(1); + expect($tr.find('.action.action-download').attr('data-action')).toEqual('Download'); + expect($tr.find('.nametext .action.action-rename').length).toEqual(1); + expect($tr.find('.nametext .action.action-rename').attr('data-action')).toEqual('Rename'); expect($tr.find('.action.delete').length).toEqual(1); }); it('calling display() twice correctly replaces file actions', function() { - var $tr = FileList.addFile('testName.txt', 1234, new Date(), false, false, {download_url: 'test/download/url'}); + var fileData = { + id: 18, + type: 'file', + name: 'testName.txt', + mimetype: 'plain/text', + size: '1234', + etag: 'a01234c', + mtime: '123456' + }; + var $tr = FileList.add(fileData); FileActions.display($tr.find('td.filename'), true); FileActions.display($tr.find('td.filename'), true); // actions defined after cal - expect($tr.find('.action[data-action=Download]').length).toEqual(1); - expect($tr.find('.nametext .action[data-action=Rename]').length).toEqual(1); + expect($tr.find('.action.action-download').length).toEqual(1); + expect($tr.find('.nametext .action.action-rename').length).toEqual(1); expect($tr.find('.action.delete').length).toEqual(1); }); it('redirects to download URL when clicking download', function() { var redirectStub = sinon.stub(OC, 'redirect'); - // note: download_url is actually the link target, not the actual download URL... - var $tr = FileList.addFile('test download File.txt', 1234, new Date(), false, false, {download_url: 'test/download/url'}); + var fileData = { + id: 18, + type: 'file', + name: 'testName.txt', + mimetype: 'plain/text', + size: '1234', + etag: 'a01234c', + mtime: '123456' + }; + var $tr = FileList.add(fileData); FileActions.display($tr.find('td.filename'), true); - $tr.find('.action[data-action=Download]').click(); + $tr.find('.action-download').click(); expect(redirectStub.calledOnce).toEqual(true); - expect(redirectStub.getCall(0).args[0]).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=test%20download%20File.txt'); + expect(redirectStub.getCall(0).args[0]).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=testName.txt'); redirectStub.restore(); }); + it('deletes file when clicking delete', function() { + var deleteStub = sinon.stub(FileList, 'do_delete'); + var fileData = { + id: 18, + type: 'file', + name: 'testName.txt', + mimetype: 'plain/text', + size: '1234', + etag: 'a01234c', + mtime: '123456' + }; + var $tr = FileList.add(fileData); + FileActions.display($tr.find('td.filename'), true); + + $tr.find('.action.delete').click(); + + expect(deleteStub.calledOnce).toEqual(true); + deleteStub.restore(); + }); }); |