64 lines
2.9 KiB
TypeScript
64 lines
2.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
||
|
||
import {
|
||
buildSeedreamInteractivePrompt,
|
||
buildSeedreamLayerPrompt,
|
||
missingSeedreamAnnotationTokens,
|
||
seedreamAnnotationReferences,
|
||
type SeedreamAnnotation
|
||
} from "@/lib/seedream/creation";
|
||
|
||
const annotations: SeedreamAnnotation[] = [
|
||
{ id: "box", index: 1, kind: "box", box: { left: 100, top: 200, right: 700, bottom: 800 } },
|
||
{ id: "point", index: 3, kind: "point", point: { x: 456, y: 321 } }
|
||
];
|
||
|
||
describe("Seedream interactive prompt", () => {
|
||
it("offers existing canvas annotations as @ input references", () => {
|
||
expect(seedreamAnnotationReferences([
|
||
...annotations,
|
||
{ id: "mark", index: 4, kind: "stroke", points: [{ x: 1, y: 1 }, { x: 2, y: 2 }] }
|
||
], "标")).toEqual([
|
||
{ token: "@标注1", label: "框选区域 1", caption: "画布标注" },
|
||
{ token: "@标注3", label: "点选位置 3", caption: "画布标注" },
|
||
{ token: "@标记4", label: "蓝色标记 4", caption: "画布标注" }
|
||
]);
|
||
});
|
||
|
||
it("replaces visible annotation tokens with normalized provider tags", () => {
|
||
expect(buildSeedreamInteractivePrompt("把 @标注1 改成蓝色", annotations)).toBe(
|
||
"把 图1<bbox>100 200 700 800</bbox> 改成蓝色\n编辑位置:标注3 图1<point>456 321</point>。"
|
||
);
|
||
});
|
||
|
||
it("supports cross-image coordinates and visible mark references", () => {
|
||
const crossImageAnnotations: SeedreamAnnotation[] = [
|
||
{ id: "subject", index: 1, kind: "box", sourceKey: "image-a", box: { left: 50, top: 60, right: 400, bottom: 500 } },
|
||
{ id: "target", index: 2, kind: "point", sourceKey: "image-b", point: { x: 720, y: 310 } },
|
||
{ id: "mark", index: 4, kind: "stroke", sourceKey: "image-b", points: [{ x: 500, y: 500 }, { x: 650, y: 610 }] }
|
||
];
|
||
expect(buildSeedreamInteractivePrompt("把 @标注1 移到 @标注2,并清除 @标记4", crossImageAnnotations, ["image-a", "image-b"])).toBe(
|
||
"把 图1<bbox>50 60 400 500</bbox> 移到 图2<point>720 310</point>,并清除 图2中的蓝色标记区域"
|
||
);
|
||
});
|
||
|
||
it("detects references to annotations that were removed", () => {
|
||
expect(missingSeedreamAnnotationTokens("修改 @标注3 和 @标注2", annotations)).toEqual(["@标注2"]);
|
||
});
|
||
});
|
||
|
||
describe("Seedream layer prompt", () => {
|
||
it("supports optional region instructions for layer decomposition", () => {
|
||
expect(buildSeedreamLayerPrompt("拆出 @标注1 内的标题", annotations)).toBe(
|
||
"拆出 <bbox>100 200 700 800</bbox> 内的标题\n需拆分区域:<point>456 321</point>。"
|
||
);
|
||
});
|
||
|
||
it("can describe a blue mark when the prompt is left empty", () => {
|
||
const marks: SeedreamAnnotation[] = [
|
||
{ id: "mark", index: 1, kind: "stroke", points: [{ x: 100, y: 100 }, { x: 200, y: 250 }] }
|
||
];
|
||
expect(buildSeedreamLayerPrompt("", marks)).toBe("需拆分区域:图片中的蓝色标记区域。");
|
||
});
|
||
});
|