@spoolcms/nextjs
Version:
The beautiful headless CMS for Next.js developers
39 lines (38 loc) • 2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const image_1 = require("../utils/image");
describe('Image utilities', () => {
const mockImageSizes = {
original: 'https://example.com/image.jpg',
thumb: 'https://example.com/image_thumb.webp',
small: 'https://example.com/image_small.webp',
};
const mockLegacyUrl = 'https://example.com/legacy-image.jpg';
describe('img()', () => {
it('should return empty string for null/undefined values', () => {
expect((0, image_1.img)(null)).toBe('');
expect((0, image_1.img)(undefined)).toBe('');
});
it('should return the original URL for legacy string values', () => {
expect((0, image_1.img)(mockLegacyUrl)).toBe(mockLegacyUrl);
expect((0, image_1.img)(mockLegacyUrl, 'thumb')).toBe(mockLegacyUrl);
expect((0, image_1.img)(mockLegacyUrl, 'small')).toBe(mockLegacyUrl);
expect((0, image_1.img)(mockLegacyUrl, 'original')).toBe(mockLegacyUrl);
});
it('should return the correct size for image objects', () => {
expect((0, image_1.img)(mockImageSizes, 'thumb')).toBe(mockImageSizes.thumb);
expect((0, image_1.img)(mockImageSizes, 'small')).toBe(mockImageSizes.small);
expect((0, image_1.img)(mockImageSizes, 'original')).toBe(mockImageSizes.original);
});
it('should default to original size when no size specified', () => {
expect((0, image_1.img)(mockImageSizes)).toBe(mockImageSizes.original);
});
it('should fallback to original if requested size is missing', () => {
const partialSizes = { original: 'https://example.com/image.jpg' };
expect((0, image_1.img)(partialSizes, 'thumb')).toBe(partialSizes.original);
});
it('should return empty string for invalid objects', () => {
expect((0, image_1.img)({})).toBe('');
});
});
});