feat(assets): 素材选择器 - 支持按媒体类型筛选并覆盖远程项目资产
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import { resolve } from "node:path";
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
import { assetPickerItemsToInsertPayloads } from "@/components/canvas/asset-picker-modal";
|
||||
import type { AssetLibraryPickerItem } from "@/components/assets/asset-library-picker-modal";
|
||||
import { pickerItemMediaKind, type AssetLibraryPickerItem } from "@/components/assets/asset-library-picker-modal";
|
||||
import type { ImageAsset, TextAsset } from "@/stores/use-asset-store";
|
||||
|
||||
const timestamp = "2026-08-28T00:00:00.000Z";
|
||||
@@ -59,6 +59,36 @@ describe("canvas asset picker", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("asset picker media kind", () => {
|
||||
const base: AssetLibraryPickerItem = { id: "item", title: "素材", category: "other", kindLabel: "图片" };
|
||||
const image: ImageAsset = {
|
||||
id: "asset",
|
||||
kind: "image",
|
||||
title: "图",
|
||||
coverUrl: "",
|
||||
tags: [],
|
||||
createdAt: timestamp,
|
||||
updatedAt: timestamp,
|
||||
data: { dataUrl: "", width: 1, height: 1, bytes: 1, mimeType: "image/png" },
|
||||
};
|
||||
|
||||
test("prefers the declared media kind over the underlying record", () => {
|
||||
expect(pickerItemMediaKind({ ...base, mediaKind: "video", asset: image })).toBe("video");
|
||||
expect(pickerItemMediaKind({ ...base, asset: image })).toBe("image");
|
||||
});
|
||||
|
||||
test("resolves external plugin items and skips records without a media kind", () => {
|
||||
const external: AssetLibraryPickerItem = {
|
||||
...base,
|
||||
external: { sourceId: "eagle", sourceName: "Eagle", item: { id: "audio-1", title: "外部音频", kind: "audio" } },
|
||||
};
|
||||
|
||||
expect(pickerItemMediaKind(external)).toBe("audio");
|
||||
// 角色卡、3D 模型这类条目没有媒体类型,媒体筛选生效时不应被当成图片留在列表里。
|
||||
expect(pickerItemMediaKind(base)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("canvas context menu motion", () => {
|
||||
test("keeps hover feedback stationary while retaining spotlight surfaces", () => {
|
||||
const styles = readFileSync(resolve(import.meta.dir, "../src/styles/globals.css"), "utf8");
|
||||
|
||||
Reference in New Issue
Block a user