Merge "Wait for all plugins to load before sending plugin events"
This commit is contained in:
commit
62f911698d
@ -48,23 +48,26 @@
|
|||||||
EventType: EventType,
|
EventType: EventType,
|
||||||
|
|
||||||
handleEvent: function(type, detail) {
|
handleEvent: function(type, detail) {
|
||||||
switch (type) {
|
Gerrit.awaitPluginsLoaded().then(function() {
|
||||||
case EventType.HISTORY:
|
switch (type) {
|
||||||
this._handleHistory(detail);
|
case EventType.HISTORY:
|
||||||
break;
|
this._handleHistory(detail);
|
||||||
case EventType.SHOW_CHANGE:
|
break;
|
||||||
this._handleShowChange(detail);
|
case EventType.SHOW_CHANGE:
|
||||||
break;
|
this._handleShowChange(detail);
|
||||||
case EventType.COMMENT:
|
break;
|
||||||
this._handleComment(detail);
|
case EventType.COMMENT:
|
||||||
break;
|
this._handleComment(detail);
|
||||||
case EventType.LABEL_CHANGE:
|
break;
|
||||||
this._handleLabelChange(detail);
|
case EventType.LABEL_CHANGE:
|
||||||
break;
|
this._handleLabelChange(detail);
|
||||||
default:
|
break;
|
||||||
console.warn('handleEvent called with unsupported event type:', type);
|
default:
|
||||||
break;
|
console.warn('handleEvent called with unsupported event type:',
|
||||||
}
|
type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
addElement: function(key, el) {
|
addElement: function(key, el) {
|
||||||
|
@ -45,6 +45,7 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
element = fixture('basic');
|
element = fixture('basic');
|
||||||
errorStub = sinon.stub(console, 'error');
|
errorStub = sinon.stub(console, 'error');
|
||||||
|
Gerrit._setPluginsCount(1);
|
||||||
Gerrit.install(function(p) { plugin = p; }, '0.1',
|
Gerrit.install(function(p) { plugin = p; }, '0.1',
|
||||||
'http://test.com/plugins/testplugin/static/test.js');
|
'http://test.com/plugins/testplugin/static/test.js');
|
||||||
});
|
});
|
||||||
@ -75,10 +76,7 @@ limitations under the License.
|
|||||||
test('showchange event', function(done) {
|
test('showchange event', function(done) {
|
||||||
var testChange = {
|
var testChange = {
|
||||||
_number: 42,
|
_number: 42,
|
||||||
revisions: {
|
revisions: {def: {_number: 2}, abc: {_number: 1}},
|
||||||
def: {_number: 2},
|
|
||||||
abc: {_number: 1},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
plugin.on(element.EventType.SHOW_CHANGE, throwErrFn);
|
plugin.on(element.EventType.SHOW_CHANGE, throwErrFn);
|
||||||
plugin.on(element.EventType.SHOW_CHANGE, function(change, revision) {
|
plugin.on(element.EventType.SHOW_CHANGE, function(change, revision) {
|
||||||
@ -91,6 +89,24 @@ limitations under the License.
|
|||||||
{change: testChange, patchNum: 1});
|
{change: testChange, patchNum: 1});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('handleEvent awaits plugins load', function(done) {
|
||||||
|
var testChange = {
|
||||||
|
_number: 42,
|
||||||
|
revisions: {def: {_number: 2}, abc: {_number: 1}},
|
||||||
|
};
|
||||||
|
var spy = sinon.spy();
|
||||||
|
Gerrit._setPluginsCount(1);
|
||||||
|
plugin.on(element.EventType.SHOW_CHANGE, spy);
|
||||||
|
element.handleEvent(element.EventType.SHOW_CHANGE,
|
||||||
|
{change: testChange, patchNum: 1});
|
||||||
|
assert.isFalse(spy.called);
|
||||||
|
Gerrit._setPluginsCount(0);
|
||||||
|
flush(function() {
|
||||||
|
assert.isTrue(spy.called);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('comment event', function(done) {
|
test('comment event', function(done) {
|
||||||
var testCommentNode = {foo: 'bar'};
|
var testCommentNode = {foo: 'bar'};
|
||||||
plugin.on(element.EventType.COMMENT, throwErrFn);
|
plugin.on(element.EventType.COMMENT, throwErrFn);
|
||||||
@ -196,7 +212,7 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('_arePluginsLoaded', function() {
|
test('_arePluginsLoaded', function() {
|
||||||
assert.isFalse(Gerrit._arePluginsLoaded());
|
assert.isTrue(Gerrit._arePluginsLoaded());
|
||||||
Gerrit._setPluginsCount(1);
|
Gerrit._setPluginsCount(1);
|
||||||
assert.isFalse(Gerrit._arePluginsLoaded());
|
assert.isFalse(Gerrit._arePluginsLoaded());
|
||||||
Gerrit._setPluginsCount(0);
|
Gerrit._setPluginsCount(0);
|
||||||
|
@ -111,10 +111,29 @@
|
|||||||
Gerrit._pluginInstalled();
|
Gerrit._pluginInstalled();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Gerrit._allPluginsPromise = null;
|
||||||
|
Gerrit._resolveAllPluginsLoaded = null;
|
||||||
|
|
||||||
|
Gerrit.awaitPluginsLoaded = function() {
|
||||||
|
if (!Gerrit._allPluginsPromise) {
|
||||||
|
if (Gerrit._arePluginsLoaded()) {
|
||||||
|
Gerrit._allPluginsPromise = Promise.resolve();
|
||||||
|
} else {
|
||||||
|
Gerrit._allPluginsPromise = new Promise(function(resolve) {
|
||||||
|
Gerrit._resolveAllPluginsLoaded = resolve;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Gerrit._allPluginsPromise;
|
||||||
|
};
|
||||||
|
|
||||||
Gerrit._setPluginsCount = function(count) {
|
Gerrit._setPluginsCount = function(count) {
|
||||||
Gerrit._pluginsPending = count;
|
Gerrit._pluginsPending = count;
|
||||||
if (Gerrit._arePluginsLoaded()) {
|
if (Gerrit._arePluginsLoaded()) {
|
||||||
document.createElement('gr-reporting').pluginsLoaded();
|
document.createElement('gr-reporting').pluginsLoaded();
|
||||||
|
if (Gerrit._resolveAllPluginsLoaded) {
|
||||||
|
Gerrit._resolveAllPluginsLoaded();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user