Files
ttstd-infinite-canvas/web/test/canvas-node-copy.test.ts

28 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, test } from "bun:test";
import { nextCopiedNodeTitle } from "@/lib/canvas/canvas-node-copy";
describe("canvas node copy title", () => {
test("首次复制使用 copy1,后续按已有最大序号递增", () => {
expect(nextCopiedNodeTitle("女明星角色三视图", ["女明星角色三视图"])).toBe("女明星角色三视图_copy1");
expect(nextCopiedNodeTitle("女明星角色三视图", ["女明星角色三视图", "女明星角色三视图_copy1"])).toBe("女明星角色三视图_copy2");
expect(nextCopiedNodeTitle("女明星角色三视图", ["女明星角色三视图_copy1", "女明星角色三视图_copy3"])).toBe("女明星角色三视图_copy4");
});
test("复制已有副本时仍使用原始名称计算下一序号", () => {
expect(nextCopiedNodeTitle("女明星角色三视图_copy1", ["女明星角色三视图", "女明星角色三视图_copy1"])).toBe("女明星角色三视图_copy2");
});
test("兼容旧版空格 Copy 后缀", () => {
expect(nextCopiedNodeTitle("女明星角色三视图 Copy", ["女明星角色三视图", "女明星角色三视图 Copy"])).toBe("女明星角色三视图_copy1");
});
test("同一批粘贴可以通过预留标题连续分配序号", () => {
const titles = new Set(["节点", "节点_copy1"]);
const first = nextCopiedNodeTitle("节点", titles);
titles.add(first);
const second = nextCopiedNodeTitle("节点", titles);
expect([first, second]).toEqual(["节点_copy2", "节点_copy3"]);
});
});