2016-04-17 18:02:33 +02:00
|
|
|
// Plugin tests
|
|
|
|
describe('Test the plugin system', function() {
|
2016-05-27 01:22:11 +02:00
|
|
|
var oldPlugins;
|
|
|
|
|
|
|
|
beforeAll(function() {
|
2016-06-10 22:26:35 +02:00
|
|
|
oldPlugins = Chart.plugins._plugins;
|
2016-05-27 01:22:11 +02:00
|
|
|
});
|
2016-06-10 22:26:35 +02:00
|
|
|
|
2016-05-27 01:22:11 +02:00
|
|
|
afterAll(function() {
|
2016-06-10 22:26:35 +02:00
|
|
|
Chart.plugins._plugins = oldPlugins;
|
2016-05-27 01:22:11 +02:00
|
|
|
});
|
|
|
|
|
2016-04-17 18:02:33 +02:00
|
|
|
beforeEach(function() {
|
2016-06-10 22:26:35 +02:00
|
|
|
Chart.plugins._plugins = [];
|
2016-04-17 18:02:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it ('Should register plugins', function() {
|
|
|
|
var myplugin = {};
|
2016-06-10 22:26:35 +02:00
|
|
|
Chart.plugins.register(myplugin);
|
|
|
|
expect(Chart.plugins._plugins.length).toBe(1);
|
2016-04-17 18:02:33 +02:00
|
|
|
|
|
|
|
// Should only add plugin once
|
2016-06-10 22:26:35 +02:00
|
|
|
Chart.plugins.register(myplugin);
|
|
|
|
expect(Chart.plugins._plugins.length).toBe(1);
|
2016-04-17 18:02:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it ('Should allow unregistering plugins', function() {
|
|
|
|
var myplugin = {};
|
2016-06-10 22:26:35 +02:00
|
|
|
Chart.plugins.register(myplugin);
|
|
|
|
expect(Chart.plugins._plugins.length).toBe(1);
|
2016-04-17 18:02:33 +02:00
|
|
|
|
|
|
|
// Should only add plugin once
|
2016-06-10 22:26:35 +02:00
|
|
|
Chart.plugins.remove(myplugin);
|
|
|
|
expect(Chart.plugins._plugins.length).toBe(0);
|
2016-04-17 18:02:33 +02:00
|
|
|
|
|
|
|
// Removing a plugin that doesn't exist should not error
|
2016-06-10 22:26:35 +02:00
|
|
|
Chart.plugins.remove(myplugin);
|
2016-04-17 18:02:33 +02:00
|
|
|
});
|
|
|
|
|
2016-06-10 22:26:55 +02:00
|
|
|
describe('Chart.plugins.notify', function() {
|
|
|
|
it ('should call plugins with arguments', function() {
|
|
|
|
var myplugin = {
|
|
|
|
count: 0,
|
|
|
|
trigger: function(chart) {
|
|
|
|
myplugin.count = chart.count;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Chart.plugins.register(myplugin);
|
|
|
|
Chart.plugins.notify('trigger', [{ count: 10 }]);
|
|
|
|
expect(myplugin.count).toBe(10);
|
|
|
|
});
|
2016-06-10 22:26:35 +02:00
|
|
|
|
2016-06-10 22:26:55 +02:00
|
|
|
it('should return TRUE if no plugin explicitly returns FALSE', function() {
|
|
|
|
Chart.plugins.register({ check: function() {} });
|
|
|
|
Chart.plugins.register({ check: function() { return; } });
|
|
|
|
Chart.plugins.register({ check: function() { return null; } });
|
|
|
|
Chart.plugins.register({ check: function() { return 42 } });
|
|
|
|
var res = Chart.plugins.notify('check');
|
|
|
|
expect(res).toBeTruthy();
|
|
|
|
});
|
2016-04-17 18:02:33 +02:00
|
|
|
|
2016-06-10 22:26:55 +02:00
|
|
|
it('should return FALSE if no plugin explicitly returns FALSE', function() {
|
|
|
|
Chart.plugins.register({ check: function() {} });
|
|
|
|
Chart.plugins.register({ check: function() { return; } });
|
|
|
|
Chart.plugins.register({ check: function() { return false; } });
|
|
|
|
Chart.plugins.register({ check: function() { return 42 } });
|
|
|
|
var res = Chart.plugins.notify('check');
|
|
|
|
expect(res).toBeFalsy();
|
|
|
|
});
|
2016-04-17 18:02:33 +02:00
|
|
|
});
|
|
|
|
});
|