diff options
author | Morris Jobke <hey@morrisjobke.de> | 2014-06-27 15:03:21 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2014-06-27 15:03:21 +0200 |
commit | 3b2fd5e4e6aad769f656c473f1a1fe53f5936c47 (patch) | |
tree | 5e75f4c443c3590f2086b2088f2e0c623ca547a1 /apps/files/tests | |
parent | b975f0e7184f769d9bc857c1e6db90006b45e2c8 (diff) | |
parent | 586b3a9683421181b7cd66aff2d3fabd0f34531e (diff) | |
download | nextcloud-server-3b2fd5e4e6aad769f656c473f1a1fe53f5936c47.tar.gz nextcloud-server-3b2fd5e4e6aad769f656c473f1a1fe53f5936c47.zip |
Merge pull request #9254 from owncloud/fileactions-deferred
Sync file list with file actions
Diffstat (limited to 'apps/files/tests')
-rw-r--r-- | apps/files/tests/js/fileactionsSpec.js | 53 | ||||
-rw-r--r-- | apps/files/tests/js/filelistSpec.js | 32 |
2 files changed, 84 insertions, 1 deletions
diff --git a/apps/files/tests/js/fileactionsSpec.js b/apps/files/tests/js/fileactionsSpec.js index 355761afa01..f464800730a 100644 --- a/apps/files/tests/js/fileactionsSpec.js +++ b/apps/files/tests/js/fileactionsSpec.js @@ -21,7 +21,7 @@ describe('OCA.Files.FileActions tests', function() { var $filesTable, fileList; - var FileActions; + var FileActions; beforeEach(function() { // init horrible parameters @@ -36,6 +36,7 @@ describe('OCA.Files.FileActions tests', function() { }); afterEach(function() { FileActions = null; + fileList.destroy(); fileList = undefined; $('#dir, #permissions, #filestable').remove(); }); @@ -192,4 +193,54 @@ describe('OCA.Files.FileActions tests', function() { context = actionStub.getCall(0).args[1]; expect(context.dir).toEqual('/somepath'); }); + describe('events', function() { + var clock; + beforeEach(function() { + clock = sinon.useFakeTimers(); + }); + afterEach(function() { + clock.restore(); + }); + it('notifies update event handlers once after multiple changes', function() { + var actionStub = sinon.stub(); + var handler = sinon.stub(); + FileActions.addUpdateListener(handler); + FileActions.register( + 'all', + 'Test', + OC.PERMISSION_READ, + OC.imagePath('core', 'actions/test'), + actionStub + ); + FileActions.register( + 'all', + 'Test2', + OC.PERMISSION_READ, + OC.imagePath('core', 'actions/test'), + actionStub + ); + expect(handler.calledTwice).toEqual(true); + }); + it('does not notifies update event handlers after unregistering', function() { + var actionStub = sinon.stub(); + var handler = sinon.stub(); + FileActions.addUpdateListener(handler); + FileActions.removeUpdateListener(handler); + FileActions.register( + 'all', + 'Test', + OC.PERMISSION_READ, + OC.imagePath('core', 'actions/test'), + actionStub + ); + FileActions.register( + 'all', + 'Test2', + OC.PERMISSION_READ, + OC.imagePath('core', 'actions/test'), + actionStub + ); + expect(handler.notCalled).toEqual(true); + }); + }); }); diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js index 318f66825a6..a699177767a 100644 --- a/apps/files/tests/js/filelistSpec.js +++ b/apps/files/tests/js/filelistSpec.js @@ -1628,6 +1628,38 @@ describe('OCA.Files.FileList tests', function() { expect(context.fileActions).toBeDefined(); expect(context.dir).toEqual('/subdir'); }); + it('redisplays actions when new actions have been registered', function() { + var actionStub = sinon.stub(); + var clock = sinon.useFakeTimers(); + var debounceStub = sinon.stub(_, 'debounce', function(callback) { + return function() { + // defer instead of debounce, to make it work with clock + _.defer(callback); + }; + }); + // need to reinit the list to make the debounce call + fileList.destroy(); + fileList = new OCA.Files.FileList($('#app-content-files')); + + fileList.setFiles(testFiles); + fileList.fileActions.register( + 'text/plain', + 'Test', + OC.PERMISSION_ALL, + function() { + // Specify icon for hitory button + return OC.imagePath('core','actions/history'); + }, + actionStub + ); + var $tr = fileList.findFileEl('One.txt'); + expect($tr.find('.action-test').length).toEqual(0); + // update is delayed + clock.tick(100); + expect($tr.find('.action-test').length).toEqual(1); + clock.restore(); + debounceStub.restore(); + }); }); describe('Sorting files', function() { it('Sorts by name by default', function() { |