Fix fileActionsReady event after deferred file actions update

remotes/origin/ldap_group_count
Vincent Petry 11 years ago
parent 19a6dc5420
commit 509cdebab7
  1. 3
      apps/files/js/filelist.js
  2. 9
      apps/files/tests/js/filelistSpec.js

@ -519,8 +519,9 @@
_onFileActionsUpdated: function() { _onFileActionsUpdated: function() {
var self = this; var self = this;
this.$fileList.find('tr td.filename').each(function() { this.$fileList.find('tr td.filename').each(function() {
self.fileActions.display($(this), true, self); self.fileActions.display($(this), false, self);
}); });
this.$fileList.trigger($.Event('fileActionsReady', {fileList: this}));
}, },
/** /**

@ -1630,6 +1630,7 @@ describe('OCA.Files.FileList tests', function() {
}); });
it('redisplays actions when new actions have been registered', function() { it('redisplays actions when new actions have been registered', function() {
var actionStub = sinon.stub(); var actionStub = sinon.stub();
var readyHandler = sinon.stub();
var clock = sinon.useFakeTimers(); var clock = sinon.useFakeTimers();
var debounceStub = sinon.stub(_, 'debounce', function(callback) { var debounceStub = sinon.stub(_, 'debounce', function(callback) {
return function() { return function() {
@ -1637,11 +1638,15 @@ describe('OCA.Files.FileList tests', function() {
_.defer(callback); _.defer(callback);
}; };
}); });
// need to reinit the list to make the debounce call // need to reinit the list to make the debounce call
fileList.destroy(); fileList.destroy();
fileList = new OCA.Files.FileList($('#app-content-files')); fileList = new OCA.Files.FileList($('#app-content-files'));
fileList.setFiles(testFiles); fileList.setFiles(testFiles);
fileList.$fileList.on('fileActionsReady', readyHandler);
fileList.fileActions.register( fileList.fileActions.register(
'text/plain', 'text/plain',
'Test', 'Test',
@ -1654,9 +1659,13 @@ describe('OCA.Files.FileList tests', function() {
); );
var $tr = fileList.findFileEl('One.txt'); var $tr = fileList.findFileEl('One.txt');
expect($tr.find('.action-test').length).toEqual(0); expect($tr.find('.action-test').length).toEqual(0);
expect(readyHandler.notCalled).toEqual(true);
// update is delayed // update is delayed
clock.tick(100); clock.tick(100);
expect($tr.find('.action-test').length).toEqual(1); expect($tr.find('.action-test').length).toEqual(1);
expect(readyHandler.calledOnce).toEqual(true);
clock.restore(); clock.restore();
debounceStub.restore(); debounceStub.restore();
}); });

Loading…
Cancel
Save