Browse Source

Add tests for mouseover events

pull/2151/head
nbdavies 7 years ago
parent
commit
81ac0e0176
  1. 53
      spec/interaction-spec.js

53
spec/interaction-spec.js

@ -1,3 +1,5 @@
var setMouseEvent = window.setMouseEvent;
describe('c3 chart interaction', function () {
'use strict';
@ -34,6 +36,57 @@ describe('c3 chart interaction', function () {
});
});
describe('mouseover', function () {
beforeAll(function () {
window.mouseoverCounter = 0;
args = {
data: {
columns: [
['data1', 30, 200, 100, 400, -150, 250],
['data2', 50, 20, 10, 40, 15, 25],
['data3', -150, 120, 110, 140, 115, 125]
],
type: 'bar',
mouseover: function(){
window.mouseoverCounter += 1;
}
},
axis: {
rotated: false
}
};
});
it('should be false when not within bar', function () {
setMouseEvent(chart, 'mousemove', 0, 0);
expect(chart.internal.mouseover).toBeFalsy();
});
it('should be data value when within bar', function () {
setMouseEvent(chart, 'mousemove', 31, 280);
expect(chart.internal.mouseover).toBe({
x: 0,
value: 30,
id: 'data1',
name: 'data1'
});
});
it('should be false after leaving chart', function () {
setMouseEvent(chart, 'mousemove', 31, 280);
setMouseEvent(chart, 'mouseout', 0, 0);
expect(chart.internal.mouseover).toBeFalsy();
});
it('should retrigger mouseover event when returning to same value', function () {
setMouseEvent(chart, 'mousemove', 31, 280);
setMouseEvent(chart, 'mouseout', 0, 0);
setMouseEvent(chart, 'mousemove', 31, 280);
expect(window.mouseoverCounter).toBe(2);
});
});
describe('should generate bar chart with only one data', function () {
beforeAll(function(){
args = {

Loading…
Cancel
Save