feat(runtime): 即梦本机运行时 - 接入安全生成闭环与桌面本机渠道
Refs #225 Co-authored-by: zkhyww <127009345+zkhyww@users.noreply.github.com>
This commit is contained in:
@@ -2,30 +2,36 @@ import { describe, expect, test } from "bun:test";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
function compactSource(source: string) {
|
||||
return source.replace(/\s+/g, " ").trim();
|
||||
}
|
||||
|
||||
describe("creation library button", () => {
|
||||
test("places a library control beside the generation mode picker", () => {
|
||||
const source = readFileSync(resolve(import.meta.dir, "../src/pages/create/index.tsx"), "utf8");
|
||||
const modePickerIndex = source.indexOf("<ModePicker mode={props.mode} onModeChange={props.onModeChange} />");
|
||||
const libraryButtonIndex = source.indexOf('className="creation-chat-control" onClick={props.onOpenLibrary} disabled={props.busy || !referencesSupported} aria-label="打开素材库选择参考内容"');
|
||||
const dockStart = source.indexOf('<footer className="creation-chat-dock">');
|
||||
const dockEnd = source.indexOf("</footer>", dockStart);
|
||||
|
||||
expect(modePickerIndex).toBeGreaterThanOrEqual(0);
|
||||
expect(libraryButtonIndex).toBeGreaterThan(modePickerIndex);
|
||||
expect(source.slice(libraryButtonIndex, libraryButtonIndex + 180)).toContain("<FolderOpen />");
|
||||
expect(source.slice(libraryButtonIndex, libraryButtonIndex + 180)).toContain("<span>素材库</span>");
|
||||
expect(dockStart).toBeGreaterThanOrEqual(0);
|
||||
expect(dockEnd).toBeGreaterThan(dockStart);
|
||||
expect(compactSource(source.slice(dockStart, dockEnd))).toMatch(
|
||||
/<ModePicker mode=\{props\.mode\} onModeChange=\{props\.onModeChange\} \/> <Tooltip\b[^>]*>\s*<button(?=[^>]*className="creation-chat-control")(?=[^>]*onClick=\{props\.onOpenLibrary\})(?=[^>]*disabled=\{props\.busy \|\| !referencesSupported\})(?=[^>]*aria-label="打开素材库选择参考内容")[^>]*>\s*<FolderOpen \/>\s*<span>素材库<\/span>\s*<\/button>\s*<\/Tooltip>/,
|
||||
);
|
||||
});
|
||||
|
||||
test("uploads from the library without adding a reference before confirmation", () => {
|
||||
const source = readFileSync(resolve(import.meta.dir, "../src/pages/create/index.tsx"), "utf8");
|
||||
const pickerSource = readFileSync(resolve(import.meta.dir, "../src/components/assets/asset-library-picker-modal.tsx"), "utf8");
|
||||
const uploadStart = source.indexOf("const uploadLibraryAssets = async");
|
||||
const uploadEnd = source.indexOf("const handleFileChange", uploadStart);
|
||||
|
||||
expect(uploadStart).toBeGreaterThanOrEqual(0);
|
||||
expect(uploadEnd).toBeGreaterThan(uploadStart);
|
||||
expect(source.slice(uploadStart, uploadEnd)).not.toContain("setAttachments");
|
||||
expect(source).toContain("onUpload={uploadLibraryAssets}");
|
||||
expect(source).toContain("onUpload: uploadLibraryAssets");
|
||||
expect(source).not.toContain("onUpload={() => fileInputRef.current?.click()}");
|
||||
expect(source).toContain("上传后保存到素材库");
|
||||
expect(source).toContain("正在保存到素材库,完成后会自动选中");
|
||||
expect(pickerSource).toContain("保存完成后会自动选中");
|
||||
expect(source).toContain("个素材已上传到素材库并自动选中");
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user