Skip to content

Commit

Permalink
Updated controller.scatter.test.js to test default tooltip callbacks
Browse files Browse the repository at this point in the history
- This moves the mouse over the drawn point and verifies that there is
  no title in the tooltip and that the body contains expected content.
  • Loading branch information
darless committed Jan 8, 2019
1 parent b7139db commit 4ca06b3
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/specs/controller.scatter.test.js
Expand Up @@ -3,6 +3,43 @@ describe('Chart.controllers.scatter', function() {
expect(typeof Chart.controllers.scatter).toBe('function');
});

it('should test default tooltip callbacks', function() {
var chart = window.acquireChart({
type: 'scatter',
data: {
datasets: [{
data: [{
x: 10,
y: 15
}],
label: 'dataset1'
}],
},
options: {}
});
var meta = chart.getDatasetMeta(0);
var point = meta.data[0];
var node = chart.canvas;
var rect = node.getBoundingClientRect();
var evt = new MouseEvent('mousemove', {
view: window,
bubbles: true,
cancelable: true,
clientX: rect.left + point._model.x,
clientY: rect.top + point._model.y,
});

// Manually trigger rather than having an async test
node.dispatchEvent(evt);

// Check and see if tooltip was displayed
var tooltip = chart.tooltip;

// Title should be empty
expect(tooltip._view.title.length).toBe(0);
expect(tooltip._view.body[0].lines).toEqual(['(10, 15)']);
});

describe('showLines option', function() {
it('should not draw a line if undefined', function() {
var chart = window.acquireChart({
Expand Down

0 comments on commit 4ca06b3

Please sign in to comment.