refactor: 收口作品架 Source Adapter registry
This commit is contained in:
@@ -5,10 +5,11 @@ import { expect, test, vi } from 'vitest';
|
||||
import type { BabyObjectMatchDraft } from '../../../packages/shared/src/contracts/edutainmentBabyObject';
|
||||
import {
|
||||
buildCreationWorkShelfItems,
|
||||
buildCreationWorkShelfItemsFromSources,
|
||||
type CreationWorkShelfItem,
|
||||
getCreationWorkShelfItemTime,
|
||||
hasBarkBattleRequiredImages,
|
||||
isPersistedBarkBattleDraftGenerating,
|
||||
type CreationWorkShelfItem,
|
||||
} from './creationWorkShelf';
|
||||
import { CustomWorldWorkCard } from './CustomWorldWorkCard';
|
||||
|
||||
@@ -56,6 +57,86 @@ test('buildCreationWorkShelfItems maps visual novel items with VN public code',
|
||||
expect(items[1]?.publicWorkCode).toBeNull();
|
||||
});
|
||||
|
||||
test('buildCreationWorkShelfItemsFromSources flattens source adapters and applies runtime state', () => {
|
||||
const [staleRpgItem] = buildCreationWorkShelfItems({
|
||||
rpgItems: [
|
||||
{
|
||||
workId: 'draft:rpg-source-adapter',
|
||||
sourceType: 'agent_session',
|
||||
status: 'draft',
|
||||
title: '旧 RPG 草稿',
|
||||
subtitle: '待完善',
|
||||
summary: '通过 source adapter 输入。',
|
||||
coverImageSrc: null,
|
||||
updatedAt: '2026-05-01T00:00:00.000Z',
|
||||
publishedAt: null,
|
||||
stage: 'clarifying',
|
||||
stageLabel: '待完善',
|
||||
playableNpcCount: 0,
|
||||
landmarkCount: 0,
|
||||
sessionId: 'rpg-source-adapter',
|
||||
profileId: null,
|
||||
canResume: true,
|
||||
canEnterWorld: false,
|
||||
},
|
||||
],
|
||||
bigFishItems: [],
|
||||
puzzleItems: [],
|
||||
});
|
||||
const [freshPuzzleItem] = buildCreationWorkShelfItems({
|
||||
rpgItems: [],
|
||||
bigFishItems: [],
|
||||
puzzleItems: [
|
||||
{
|
||||
workId: 'puzzle:source-adapter',
|
||||
profileId: 'puzzle-source-adapter',
|
||||
ownerUserId: 'user-1',
|
||||
authorDisplayName: '拼图作者',
|
||||
levelName: '新拼图',
|
||||
summary: '新近拼图。',
|
||||
themeTags: ['灯塔'],
|
||||
coverImageSrc: null,
|
||||
publicationStatus: 'draft',
|
||||
updatedAt: '2026-05-03T00:00:00.000Z',
|
||||
publishedAt: null,
|
||||
playCount: 0,
|
||||
remixCount: 0,
|
||||
likeCount: 0,
|
||||
publishReady: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const items = buildCreationWorkShelfItemsFromSources({
|
||||
sources: [
|
||||
{
|
||||
kind: 'rpg',
|
||||
buildItems: () => (staleRpgItem ? [staleRpgItem] : []),
|
||||
},
|
||||
{
|
||||
kind: 'puzzle',
|
||||
buildItems: () => (freshPuzzleItem ? [freshPuzzleItem] : []),
|
||||
},
|
||||
],
|
||||
getItemState: (item) =>
|
||||
item.id === staleRpgItem?.id
|
||||
? {
|
||||
isGenerating: true,
|
||||
hasUnreadUpdate: true,
|
||||
titleOverride: '生成中 RPG 草稿',
|
||||
}
|
||||
: null,
|
||||
});
|
||||
|
||||
expect(items.map((item) => item.id)).toEqual([
|
||||
'puzzle:source-adapter',
|
||||
'draft:rpg-source-adapter',
|
||||
]);
|
||||
expect(items[1]?.title).toBe('生成中 RPG 草稿');
|
||||
expect(items[1]?.isGenerating).toBe(true);
|
||||
expect(items[1]?.hasUnreadUpdate).toBe(true);
|
||||
});
|
||||
|
||||
test('buildCreationWorkShelfItems maps wooden fish items with WF public code', () => {
|
||||
const onOpenWoodenFishDetail = vi.fn();
|
||||
const woodenFishWork = {
|
||||
|
||||
Reference in New Issue
Block a user