2015-08-29 04:32:56 +02:00
|
|
|
describe('Core helper tests', function() {
|
|
|
|
|
|
|
|
var helpers;
|
|
|
|
|
|
|
|
beforeAll(function() {
|
|
|
|
helpers = window.Chart.helpers;
|
|
|
|
});
|
|
|
|
|
2016-04-26 22:44:53 +02:00
|
|
|
it('should generate integer ids', function() {
|
|
|
|
var uid = helpers.uid();
|
|
|
|
expect(uid).toEqual(jasmine.any(Number));
|
|
|
|
expect(helpers.uid()).toBe(uid + 1);
|
|
|
|
expect(helpers.uid()).toBe(uid + 2);
|
|
|
|
expect(helpers.uid()).toBe(uid + 3);
|
2015-08-29 04:32:56 +02:00
|
|
|
});
|
|
|
|
|
2016-04-12 17:36:56 +02:00
|
|
|
describe('Color helper', function() {
|
|
|
|
function isColorInstance(obj) {
|
2020-02-08 01:24:29 +01:00
|
|
|
return typeof obj === 'object' && Object.prototype.hasOwnProperty.call(obj, 'valid');
|
2016-04-12 17:36:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
it('should return a color when called with a color', function() {
|
|
|
|
expect(isColorInstance(helpers.color('rgb(1, 2, 3)'))).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-09 08:24:32 +02:00
|
|
|
describe('Background hover color helper', function() {
|
|
|
|
it('should return a CanvasPattern when called with a CanvasPattern', function(done) {
|
2016-05-07 23:24:00 +02:00
|
|
|
var dots = new Image();
|
|
|
|
dots.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAMAAAAolt3jAAAAD1BMVEUAAAD///////////////+PQt5oAAAABXRSTlMAHlFhZsfk/BEAAAAqSURBVHgBY2BgZGJmYmSAAUYWEIDzmcBcJhiXGcxlRpPFrhdmMiqgvX0AcGIBEUAo6UAAAAAASUVORK5CYII=';
|
|
|
|
dots.onload = function() {
|
|
|
|
var chartContext = document.createElement('canvas').getContext('2d');
|
|
|
|
var patternCanvas = document.createElement('canvas');
|
|
|
|
var patternContext = patternCanvas.getContext('2d');
|
|
|
|
var pattern = patternContext.createPattern(dots, 'repeat');
|
|
|
|
patternContext.fillStyle = pattern;
|
|
|
|
|
2016-05-09 08:24:32 +02:00
|
|
|
var backgroundColor = helpers.getHoverColor(chartContext.createPattern(patternCanvas, 'repeat'));
|
2016-05-07 23:24:00 +02:00
|
|
|
|
|
|
|
expect(backgroundColor instanceof CanvasPattern).toBe(true);
|
|
|
|
|
|
|
|
done();
|
2016-10-16 23:34:59 +02:00
|
|
|
};
|
2016-05-07 23:24:00 +02:00
|
|
|
});
|
|
|
|
|
2018-11-28 01:54:03 +01:00
|
|
|
it('should return a CanvasGradient when called with a CanvasGradient', function() {
|
|
|
|
var context = document.createElement('canvas').getContext('2d');
|
|
|
|
var gradient = context.createLinearGradient(0, 1, 2, 3);
|
|
|
|
|
|
|
|
expect(helpers.getHoverColor(gradient) instanceof CanvasGradient).toBe(true);
|
|
|
|
});
|
|
|
|
|
2016-05-09 08:24:32 +02:00
|
|
|
it('should return a modified version of color when called with a color', function() {
|
2016-05-07 23:24:00 +02:00
|
|
|
var originalColorRGB = 'rgb(70, 191, 189)';
|
|
|
|
|
2016-05-09 08:24:32 +02:00
|
|
|
expect(helpers.getHoverColor('#46BFBD')).not.toEqual(originalColorRGB);
|
2016-05-07 23:24:00 +02:00
|
|
|
});
|
|
|
|
});
|
2015-10-17 05:14:07 +02:00
|
|
|
});
|