fix(create): 创作素材库 - 上传素材仅在确认后回填参考 (#194)

This commit is contained in:
ahyang
2026-08-09 09:00:35 +08:00
committed by GitHub
parent 1084fdef9f
commit ee95fbf1dd
2 changed files with 75 additions and 11 deletions

View File

@@ -0,0 +1,28 @@
import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
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="打开素材库选择参考内容"');
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>");
});
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 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).not.toContain("onUpload={() => fileInputRef.current?.click()}");
});
});