Files
Genarrative/src/components/image-editor/ImageCanvasRasterEditModel.test.ts
T
JenkenB ea29887d9c 完善快速编辑参考图与生成占位
- 快速编辑支持最多8张额外参考图,并将原图自动作为最后一张参考图提交

- 快速编辑尺寸和模型沿用原图配置,按禁用态参数胶囊展示

- 快速编辑提交前同步改写原图引用为实际图序号

- 快速编辑生成改为创建独立画布生成占位,并支持键盘删除生成中对象

- 对齐生成类面板参考图图标、规范类固定参数和相关文档测试
2026-06-18 22:50:42 +08:00

98 lines
2.2 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
buildCropExpandInsetsFromFrame,
buildCropExpandGeometry,
buildCropExpandLayerPatch,
parseCropExpandInsetValue,
} from './ImageCanvasRasterEditModel';
describe('ImageCanvasRasterEditModel', () => {
it('builds transparent expansion geometry around the source image', () => {
expect(
buildCropExpandGeometry({
width: 100,
height: 80,
insets: { left: 10, top: 6, right: 12, bottom: 8 },
}),
).toEqual({
outputWidth: 122,
outputHeight: 94,
sourceX: 0,
sourceY: 0,
sourceWidth: 100,
sourceHeight: 80,
targetX: 10,
targetY: 6,
});
});
it('builds crop geometry and moves the layer origin to the cropped bounds', () => {
const insets = { left: -10, top: -6, right: -12, bottom: -8 };
expect(
buildCropExpandGeometry({
width: 100,
height: 80,
insets,
}),
).toMatchObject({
outputWidth: 78,
outputHeight: 66,
sourceX: 10,
sourceY: 6,
sourceWidth: 78,
sourceHeight: 66,
targetX: 0,
targetY: 0,
});
expect(
buildCropExpandLayerPatch({
layerX: 50,
layerY: 40,
insets,
outputWidth: 78,
outputHeight: 66,
}),
).toEqual({
x: 60,
y: 46,
width: 78,
height: 66,
originalWidth: 78,
originalHeight: 66,
});
});
it('parses integer crop-expand values and rejects invalid input', () => {
expect(parseCropExpandInsetValue(' 12 ')).toBe(12);
expect(parseCropExpandInsetValue('')).toBe(0);
expect(() => parseCropExpandInsetValue('左')).toThrow('裁扩数值必须是整数');
});
it('converts a dragged canvas frame into transparent crop-expand insets', () => {
expect(
buildCropExpandInsetsFromFrame({
layer: {
x: 100,
y: 80,
width: 200,
height: 120,
originalWidth: 400,
originalHeight: 240,
},
frame: {
x: 90,
y: 90,
width: 240,
height: 90,
},
}),
).toEqual({
left: 20,
top: -20,
right: 60,
bottom: -40,
});
});
});