Defer metrics reporting until plugins are loaded
Cache all events reported via gr-reporting instances in closure in order
to share the cahce. Flush the cache on next reporting after plugins are
loaded.
This allows plugins to receive all reporting events and unlocks Google
Analytics integration.
Change-Id: Ic0c1d37667208bfd55bbf77e2138d0170f7fb097
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface_test.html b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface_test.html
index 97e0a18..2e7c53d 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface_test.html
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface_test.html
@@ -172,5 +172,49 @@
});
});
+ test('_setPluginsCount', function(done) {
+ stub('gr-reporting', {
+ pluginsLoaded: function() {
+ assert.equal(Gerrit._pluginsPending, 0);
+ done();
+ }
+ });
+ Gerrit._setPluginsCount(0);
+ });
+
+ test('_arePluginsLoaded', function() {
+ assert.isFalse(Gerrit._arePluginsLoaded());
+ Gerrit._setPluginsCount(1);
+ assert.isFalse(Gerrit._arePluginsLoaded());
+ Gerrit._setPluginsCount(0);
+ assert.isTrue(Gerrit._arePluginsLoaded());
+ });
+
+ test('_pluginInstalled', function(done) {
+ stub('gr-reporting', {
+ pluginsLoaded: function() {
+ done();
+ }
+ });
+ Gerrit._setPluginsCount(2);
+ Gerrit._pluginInstalled();
+ assert.equal(Gerrit._pluginsPending, 1);
+ Gerrit._pluginInstalled();
+ });
+
+ test('install calls _pluginInstalled', function() {
+ var stub = sinon.stub(Gerrit, '_pluginInstalled');
+ Gerrit.install(function(p) { plugin = p; }, '0.1',
+ 'http://test.com/plugins/testplugin/static/test.js');
+ assert.isTrue(stub.calledOnce);
+ stub.restore();
+ });
+
+ test('install calls _pluginInstalled on error', function() {
+ var stub = sinon.stub(Gerrit, '_pluginInstalled');
+ Gerrit.install(function() {}, '0.0pre-alpha');
+ assert.isTrue(stub.calledOnce);
+ stub.restore();
+ });
});
</script>