Skip to content

Commit

Permalink
test: validate the canvas style too
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaron committed Dec 15, 2022
1 parent 7525e89 commit bf4fdcf
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions test/specs/helpers.dom.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,27 +254,28 @@ describe('DOM helpers tests', function() {
expect(canvas.style.width).toBe('400px');
});

it ('retinaScale should not change chart size', function() {
it ('should handle devicePixelRatio correctly', function() {
const chartWidth = 800;
const chartHeight = 400;
let devicePixelRatio = 0.8999999761581421; // 1.7999999523162842;
var chart = window.acquireChart({}, {
canvas: {
width: chartWidth,
height: chartHeight,
style: `width: ${chartWidth}px; height: ${chartHeight}px;`
}
});

helpers.retinaScale(chart, devicePixelRatio, false);
helpers.retinaScale(chart, devicePixelRatio, true);

var canvas = chart.canvas;

expect(canvas.width).toBe(Math.floor(chartWidth * devicePixelRatio));
expect(canvas.height).toBe(Math.floor(chartHeight * devicePixelRatio));

expect(chart.width).toBe(chartWidth);
expect(chart.height).toBe(chartHeight);

expect(canvas.style.width).toBe(`${chartWidth}px`);
expect(canvas.style.height).toBe(`${chartHeight}px`);
});

describe('getRelativePosition', function() {
Expand Down

0 comments on commit bf4fdcf

Please sign in to comment.