diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-11-24 16:26:50 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-11-24 16:26:50 +0100 |
commit | e689bc745fc94d9760976e40522ddf96eb5c645c (patch) | |
tree | 8e4f24c0b42a08d4aa39e57f11380714f953164c /apps/files/tests | |
parent | 13b06aa6dfeb7c63750461529b27494ed035707d (diff) | |
download | nextcloud-server-e689bc745fc94d9760976e40522ddf96eb5c645c.tar.gz nextcloud-server-e689bc745fc94d9760976e40522ddf96eb5c645c.zip |
Improve FileActions JS to allow for custom rendering
This improves the OCA.Files.FileActions class to support passing a
"render" function in the action object.
The default function "_defaultRenderFunction" is used by default and
renders actions in the usual actions container.
Moved "Rename" and "Delete" to custom render functions.
Diffstat (limited to 'apps/files/tests')
-rw-r--r-- | apps/files/tests/js/fileactionsSpec.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/apps/files/tests/js/fileactionsSpec.js b/apps/files/tests/js/fileactionsSpec.js index f5f18a45a75..828aec9b6b9 100644 --- a/apps/files/tests/js/fileactionsSpec.js +++ b/apps/files/tests/js/fileactionsSpec.js @@ -193,6 +193,54 @@ describe('OCA.Files.FileActions tests', function() { context = actionStub.getCall(0).args[1]; expect(context.dir).toEqual('/somepath'); }); + describe('custom rendering', function() { + var $tr; + beforeEach(function() { + var fileData = { + id: 18, + type: 'file', + name: 'testName.txt', + mimetype: 'text/plain', + size: '1234', + etag: 'a01234c', + mtime: '123456' + }; + $tr = fileList.add(fileData); + }); + it('regular function', function() { + var actionStub = sinon.stub(); + FileActions.registerAction({ + name: 'Test', + displayName: '', + mime: 'all', + permissions: OC.PERMISSION_READ, + render: function(actionSpec, isDefault, context) { + expect(actionSpec.name).toEqual('Test'); + expect(actionSpec.displayName).toEqual(''); + expect(actionSpec.permissions).toEqual(OC.PERMISSION_READ); + expect(actionSpec.mime).toEqual('all'); + expect(isDefault).toEqual(false); + + expect(context.fileList).toEqual(fileList); + expect(context.$file[0]).toEqual($tr[0]); + + var $customEl = $('<a href="#"><span>blabli</span><span>blabla</span></a>'); + $tr.find('td:first').append($customEl); + return $customEl; + }, + actionHandler: actionStub + }); + FileActions.display($tr.find('td.filename'), true, fileList); + + var $actionEl = $tr.find('td:first .action-test'); + expect($actionEl.length).toEqual(1); + expect($actionEl.hasClass('action')).toEqual(true); + + $actionEl.click(); + expect(actionStub.calledOnce).toEqual(true); + expect(actionStub.getCall(0).args[0]).toEqual('testName.txt'); + }); + }); describe('merging', function() { var $tr; beforeEach(function() { |