Files
Genarrative/src/components/common/squareImageCropModel.test.ts
kdletters 1ad25e30f8 收口前端平台组件库能力
新增 PlatformUiKit 通用弹窗、按钮、状态、空态、媒体、表单和标签等公共组件
迁移结果页、创作工作台、认证入口、RPG 暗色面板和运行态弹窗的重复 UI chrome
补充组件测试、页面回归测试、技术文档和 Hermes 共享决策记录
2026-06-10 10:24:18 +08:00

39 lines
777 B
TypeScript

import { expect, test } from 'vitest';
import {
buildCenteredSquareImageCropRect,
clampSquareImageCropRect,
} from './squareImageCropModel';
test('builds a centered square crop from a rectangular image', () => {
expect(buildCenteredSquareImageCropRect({ width: 1200, height: 800 })).toEqual({
x: 200,
y: 0,
size: 800,
});
});
test('clamps square crop size and position inside image bounds', () => {
expect(
clampSquareImageCropRect(
{ width: 300, height: 200 },
{ x: 260, y: -30, size: 500 },
),
).toEqual({
x: 100,
y: 0,
size: 200,
});
expect(
clampSquareImageCropRect(
{ width: 300, height: 200 },
{ x: 120, y: 90, size: 10 },
),
).toEqual({
x: 120,
y: 90,
size: 48,
});
});