deckhearth/test/lib/scanner-video-layout.test.js
varutasu 6fab22d315
Add manual tap-to-scan with shutter button on mobile. (#167)
Default mobile to manual scan mode with guide tap and center shutter for explicit feedback. Split auto-detect pause from hard verification pause and fall back to guide bounds when shape detection misses.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-15 20:11:54 -05:00

61 lines
2 KiB
JavaScript

import { describe, expect, it } from 'vitest';
import {
cardGuideToContainerStyle,
computeCardGuideBounds,
computeObjectCoverLayout,
layoutGuideToVideoBounds,
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(/%$/);
});
});
describe('layoutGuideToVideoBounds', () => {
it('maps the centered guide back to video pixel space', () => {
const layout = computeObjectCoverLayout(1280, 720, 390, 844);
const bounds = layoutGuideToVideoBounds(layout);
expect(bounds.width).toBeGreaterThan(0);
expect(bounds.height).toBeGreaterThan(0);
expect(bounds.x).toBeGreaterThanOrEqual(0);
expect(bounds.y).toBeGreaterThanOrEqual(0);
});
});