mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-07 04:39:06 +02:00
Merge pull request #1428 from etimberg/feature/unit-test
Core.element unit tests
This commit is contained in:
commit
0813924a7e
@ -2,6 +2,6 @@ module.exports = function(config) {
|
||||
config.set({
|
||||
browsers: ['Chrome', 'Firefox'],
|
||||
frameworks: ['jasmine'],
|
||||
reporters: ['progress'],
|
||||
reporters: ['progress', 'html'],
|
||||
});
|
||||
};
|
@ -30,6 +30,7 @@
|
||||
"karma-coverage": "^0.5.1",
|
||||
"karma-firefox-launcher": "^0.1.6",
|
||||
"karma-jasmine": "^0.3.6",
|
||||
"karma-jasmine-html-reporter": "^0.1.8",
|
||||
"onecolor": "^2.5.0",
|
||||
"semver": "^3.0.1"
|
||||
},
|
||||
|
45
test/core.element.tests.js
Normal file
45
test/core.element.tests.js
Normal file
@ -0,0 +1,45 @@
|
||||
// Test the core element functionality
|
||||
describe('Core element tests', function() {
|
||||
it ('should transition model properties', function() {
|
||||
var element = new Chart.Element({
|
||||
_model: {
|
||||
numberProp: 0,
|
||||
numberProp2: 100,
|
||||
_underscoreProp: 0,
|
||||
stringProp: 'abc',
|
||||
objectProp: {
|
||||
myObject: true
|
||||
},
|
||||
colorProp: 'rgb(0, 0, 0)'
|
||||
}
|
||||
});
|
||||
|
||||
// First transition clones model into view
|
||||
element.transition(0.25);
|
||||
expect(element._view).toEqual(element._model);
|
||||
expect(element._start).toEqual(element._model); // also cloned
|
||||
|
||||
expect(element._view.objectProp).toBe(element._model.objectProp); // not cloned
|
||||
expect(element._start.objectProp).toEqual(element._model.objectProp); // not cloned
|
||||
|
||||
element._model.numberProp = 100;
|
||||
element._model.numberProp2 = 250;
|
||||
element._model._underscoreProp = 200;
|
||||
element._model.stringProp = 'def'
|
||||
element._model.newStringProp = 'newString';
|
||||
element._model.colorProp = 'rgb(255, 255, 0)'
|
||||
|
||||
element.transition(0.25);
|
||||
expect(element._view).toEqual({
|
||||
numberProp: 25,
|
||||
numberProp2: 137.5,
|
||||
_underscoreProp: 0, // underscore props are not transition to a new value
|
||||
stringProp: 'def',
|
||||
newStringProp: 'newString',
|
||||
objectProp: {
|
||||
myObject: true
|
||||
},
|
||||
colorProp: 'rgb(64, 64, 0)',
|
||||
});
|
||||
});
|
||||
});
|
@ -380,6 +380,59 @@ describe('Core helper tests', function() {
|
||||
expect(helpers.previousItem(testData, 0, true)).toEqual(2);
|
||||
expect(helpers.previousItem(testData, 2, false)).toEqual(1);
|
||||
expect(helpers.previousItem(testData, 1, true)).toEqual(0);
|
||||
});
|
||||
|
||||
it ('should clear a canvas', function() {
|
||||
var context = window.createMockContext();
|
||||
helpers.clear({
|
||||
width: 100,
|
||||
height: 150,
|
||||
ctx: context
|
||||
});
|
||||
|
||||
expect(context.getCalls()).toEqual([{
|
||||
name: 'clearRect',
|
||||
args: [0, 0, 100, 150]
|
||||
}]);
|
||||
});
|
||||
|
||||
it ('should draw a rounded rectangle', function() {
|
||||
var context = window.createMockContext();
|
||||
helpers.drawRoundedRectangle(context, 10, 20, 30, 40, 5);
|
||||
|
||||
expect(context.getCalls()).toEqual([{
|
||||
name: 'beginPath',
|
||||
args: []
|
||||
}, {
|
||||
name: 'moveTo',
|
||||
args: [15, 20]
|
||||
}, {
|
||||
name: 'lineTo',
|
||||
args: [35, 20]
|
||||
}, {
|
||||
name: 'quadraticCurveTo',
|
||||
args: [40, 20, 40, 25]
|
||||
}, {
|
||||
name: 'lineTo',
|
||||
args: [40, 55]
|
||||
}, {
|
||||
name: 'quadraticCurveTo',
|
||||
args: [40, 60, 35, 60]
|
||||
}, {
|
||||
name: 'lineTo',
|
||||
args: [15, 60]
|
||||
}, {
|
||||
name: 'quadraticCurveTo',
|
||||
args: [10, 60, 10, 55]
|
||||
}, {
|
||||
name: 'lineTo',
|
||||
args: [10, 25]
|
||||
}, {
|
||||
name: 'quadraticCurveTo',
|
||||
args: [10, 20, 15, 20]
|
||||
}, {
|
||||
name: 'closePath',
|
||||
args: []
|
||||
}])
|
||||
});
|
||||
});
|
@ -65,10 +65,12 @@
|
||||
arc: function() {},
|
||||
beginPath: function() {},
|
||||
bezierCurveTo: function() {},
|
||||
clearRect: function() {},
|
||||
closePath: function() {},
|
||||
fill: function() {},
|
||||
lineTo: function(x, y) {},
|
||||
moveTo: function(x, y) {},
|
||||
quadraticCurveTo: function() {},
|
||||
restore: function() {},
|
||||
save: function() {},
|
||||
setLineDash: function() {},
|
||||
|
Loading…
Reference in New Issue
Block a user