html2canvas-pro
Version:
Screenshots with JavaScript. Next generation!
143 lines • 6.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const globals_1 = require("@jest/globals");
const image_rendering_1 = require("../image-rendering");
/**
* Integration tests for image-rendering CSS property
* Tests actual DOM and canvas rendering behavior
*/
(0, globals_1.describe)('image-rendering integration', () => {
let container;
let canvas;
let ctx = null;
(0, globals_1.beforeEach)(() => {
// Create test DOM elements
container = document.createElement('div');
document.body.appendChild(container);
// Create canvas for testing
canvas = document.createElement('canvas');
canvas.width = 100;
canvas.height = 100;
try {
ctx = canvas.getContext('2d');
}
catch {
// JSDOM does not implement getContext('2d') unless canvas npm package is installed
ctx = null;
}
});
(0, globals_1.afterEach)(() => {
// Cleanup
if (container.parentNode) {
container.parentNode.removeChild(container);
}
});
(0, globals_1.describe)('Canvas context imageSmoothingEnabled', () => {
(0, globals_1.it)('should default to true', () => {
if (!ctx)
return; // Skip if canvas not available
(0, globals_1.expect)(ctx.imageSmoothingEnabled).toBe(true);
});
(0, globals_1.it)('should be settable to false', () => {
if (!ctx)
return; // Skip if canvas not available
ctx.imageSmoothingEnabled = false;
(0, globals_1.expect)(ctx.imageSmoothingEnabled).toBe(false);
});
(0, globals_1.it)('should be settable to true', () => {
if (!ctx)
return; // Skip if canvas not available
ctx.imageSmoothingEnabled = false;
ctx.imageSmoothingEnabled = true;
(0, globals_1.expect)(ctx.imageSmoothingEnabled).toBe(true);
});
});
(0, globals_1.describe)('Canvas context imageSmoothingQuality', () => {
(0, globals_1.it)('should accept "low" value', () => {
if (!ctx)
return; // Skip if canvas not available
ctx.imageSmoothingQuality = 'low';
(0, globals_1.expect)(ctx.imageSmoothingQuality).toBe('low');
});
(0, globals_1.it)('should accept "medium" value', () => {
if (!ctx)
return; // Skip if canvas not available
ctx.imageSmoothingQuality = 'medium';
(0, globals_1.expect)(ctx.imageSmoothingQuality).toBe('medium');
});
(0, globals_1.it)('should accept "high" value', () => {
if (!ctx)
return; // Skip if canvas not available
ctx.imageSmoothingQuality = 'high';
(0, globals_1.expect)(ctx.imageSmoothingQuality).toBe('high');
});
});
(0, globals_1.describe)('CSS image-rendering property', () => {
(0, globals_1.it)('should apply pixelated style to img element', () => {
const img = document.createElement('img');
img.style.imageRendering = 'pixelated';
container.appendChild(img);
(0, globals_1.expect)(img.style.imageRendering).toBe('pixelated');
});
(0, globals_1.it)('should apply crisp-edges style to img element', () => {
const img = document.createElement('img');
img.style.imageRendering = 'crisp-edges';
container.appendChild(img);
(0, globals_1.expect)(img.style.imageRendering).toBe('crisp-edges');
});
(0, globals_1.it)('should apply smooth style to img element', () => {
const img = document.createElement('img');
img.style.imageRendering = 'smooth';
container.appendChild(img);
// Note: Some browsers may normalize this value
(0, globals_1.expect)(['smooth', 'auto', '']).toContain(img.style.imageRendering);
});
});
(0, globals_1.describe)('IMAGE_RENDERING enum values', () => {
(0, globals_1.it)('should have correct enum values', () => {
(0, globals_1.expect)(image_rendering_1.IMAGE_RENDERING.AUTO).toBe(0);
(0, globals_1.expect)(image_rendering_1.IMAGE_RENDERING.CRISP_EDGES).toBe(1);
(0, globals_1.expect)(image_rendering_1.IMAGE_RENDERING.PIXELATED).toBe(2);
(0, globals_1.expect)(image_rendering_1.IMAGE_RENDERING.SMOOTH).toBe(3);
});
(0, globals_1.it)('should have distinct values', () => {
const values = [
image_rendering_1.IMAGE_RENDERING.AUTO,
image_rendering_1.IMAGE_RENDERING.CRISP_EDGES,
image_rendering_1.IMAGE_RENDERING.PIXELATED,
image_rendering_1.IMAGE_RENDERING.SMOOTH
];
const uniqueValues = new Set(values);
(0, globals_1.expect)(uniqueValues.size).toBe(values.length);
});
});
(0, globals_1.describe)('Smoothing state preservation', () => {
(0, globals_1.it)('should preserve and restore smoothing state', () => {
if (!ctx)
return; // Skip if canvas not available
const originalState = ctx.imageSmoothingEnabled;
// Save state
ctx.save();
ctx.imageSmoothingEnabled = false;
(0, globals_1.expect)(ctx.imageSmoothingEnabled).toBe(false);
// Restore state
ctx.restore();
(0, globals_1.expect)(ctx.imageSmoothingEnabled).toBe(originalState);
});
(0, globals_1.it)('should handle multiple save/restore cycles', () => {
if (!ctx)
return; // Skip if canvas not available
ctx.imageSmoothingEnabled = true;
ctx.save();
ctx.imageSmoothingEnabled = false;
ctx.save();
ctx.imageSmoothingEnabled = true;
(0, globals_1.expect)(ctx.imageSmoothingEnabled).toBe(true);
ctx.restore();
(0, globals_1.expect)(ctx.imageSmoothingEnabled).toBe(false);
ctx.restore();
(0, globals_1.expect)(ctx.imageSmoothingEnabled).toBe(true);
});
});
});
//# sourceMappingURL=image-rendering-integration.test.js.map