deckhearth/test/lib/scanner-video-layout.test.js

50 lines
1.6 KiB
JavaScript
Raw Normal View History

import { describe, expect, it } from 'vitest';
import {
cardGuideToContainerStyle,
computeCardGuideBounds,
computeObjectCoverLayout,
videoBoundsToContainerStyle,
} from '../../lib/scanner-video-layout.js';
describe('computeObjectCoverLayout', () => {
it('computes horizontal crop when video is wider than container', () => {
const layout = computeObjectCoverLayout(1280, 720, 390, 844);
expect(layout).not.toBeNull();
expect(layout.renderedHeight).toBe(844);
expect(layout.renderedWidth).toBeGreaterThan(390);
expect(layout.offsetX).toBeLessThan(0);
});
});
describe('videoBoundsToContainerStyle', () => {
it('maps full-frame video bounds to full container percentages', () => {
const layout = computeObjectCoverLayout(1000, 1000, 500, 500);
const style = videoBoundsToContainerStyle(
{ x: 0, y: 0, width: 1000, height: 1000 },
layout
);
expect(style).toEqual({
left: '0%',
top: '0%',
width: '100%',
height: '100%',
});
});
});
describe('card guide layout', () => {
it('centers a 5:7 guide within the container', () => {
const guide = computeCardGuideBounds(400, 800);
expect(guide.width / guide.height).toBeCloseTo(5 / 7, 5);
expect(guide.left).toBeGreaterThan(0);
expect(guide.top).toBeGreaterThan(0);
});
it('returns percentage styles for the guide overlay', () => {
const layout = computeObjectCoverLayout(1280, 720, 390, 844);
const style = cardGuideToContainerStyle(layout);
expect(style.left).toMatch(/%$/);
expect(style.width).toMatch(/%$/);
});
});