From 81ac0e01766ad9db56a18a616598d2480d79f825 Mon Sep 17 00:00:00 2001 From: nbdavies Date: Fri, 8 Sep 2017 16:29:54 -0500 Subject: [PATCH] Add tests for mouseover events --- spec/interaction-spec.js | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/spec/interaction-spec.js b/spec/interaction-spec.js index aec686a..780dda0 100644 --- a/spec/interaction-spec.js +++ b/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 = {