refactor: 收口公开作品详情策略
This commit is contained in:
@@ -0,0 +1,229 @@
|
||||
import { expect, test } from 'vitest';
|
||||
|
||||
import type { CustomWorldGalleryCard } from '../../../packages/shared/src/contracts/runtime';
|
||||
import {
|
||||
EDUTAINMENT_BABY_OBJECT_MATCH_TEMPLATE_ID,
|
||||
EDUTAINMENT_BABY_OBJECT_MATCH_TEMPLATE_NAME,
|
||||
type PlatformPublicGalleryCard,
|
||||
} from '../rpg-entry/rpgEntryWorldPresentation';
|
||||
import {
|
||||
getPlatformPublicWorkDetailKind,
|
||||
type PlatformPublicWorkDetailKind,
|
||||
type PlatformPublicWorkDetailOpenStrategy,
|
||||
resolvePlatformPublicWorkActionMode,
|
||||
resolvePlatformPublicWorkDetailOpenStrategy,
|
||||
} from './platformPublicWorkDetailFlow';
|
||||
|
||||
type TypedPlatformPublicGalleryCard = Extract<
|
||||
PlatformPublicGalleryCard,
|
||||
{ sourceType: string }
|
||||
>;
|
||||
type PlatformGallerySourceType = TypedPlatformPublicGalleryCard['sourceType'];
|
||||
type TypedPlatformPublicGalleryCardOverrides = Partial<
|
||||
Omit<TypedPlatformPublicGalleryCard, 'sourceType'>
|
||||
>;
|
||||
|
||||
function buildRpgEntry(
|
||||
overrides: Partial<CustomWorldGalleryCard> = {},
|
||||
): CustomWorldGalleryCard {
|
||||
return {
|
||||
ownerUserId: 'user-1',
|
||||
profileId: 'rpg-profile',
|
||||
publicWorkCode: 'CW-RPG',
|
||||
authorPublicUserCode: null,
|
||||
visibility: 'published',
|
||||
publishedAt: '2026-06-01T00:00:00.000Z',
|
||||
updatedAt: '2026-06-01T01:00:00.000Z',
|
||||
authorDisplayName: '玩家',
|
||||
worldName: 'RPG 世界',
|
||||
subtitle: '公开作品',
|
||||
summaryText: '公开作品摘要',
|
||||
coverImageSrc: null,
|
||||
themeMode: 'martial',
|
||||
playableNpcCount: 1,
|
||||
landmarkCount: 1,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function buildTypedEntry(
|
||||
sourceType: PlatformGallerySourceType,
|
||||
overrides: TypedPlatformPublicGalleryCardOverrides = {},
|
||||
): PlatformPublicGalleryCard {
|
||||
const common = {
|
||||
workId: `${sourceType}-work`,
|
||||
profileId: `${sourceType}-profile`,
|
||||
publicWorkCode: `${sourceType}-code`,
|
||||
ownerUserId: 'user-1',
|
||||
authorDisplayName: '玩家',
|
||||
worldName: `${sourceType} 作品`,
|
||||
subtitle: '公开作品',
|
||||
summaryText: '公开作品摘要',
|
||||
coverImageSrc: null,
|
||||
themeTags: [sourceType],
|
||||
visibility: 'published' as const,
|
||||
publishedAt: '2026-06-01T00:00:00.000Z',
|
||||
updatedAt: '2026-06-01T01:00:00.000Z',
|
||||
};
|
||||
|
||||
switch (sourceType) {
|
||||
case 'puzzle':
|
||||
return { ...common, ...overrides, sourceType };
|
||||
case 'big-fish':
|
||||
return { ...common, ...overrides, sourceType };
|
||||
case 'match3d':
|
||||
return { ...common, ...overrides, sourceType };
|
||||
case 'square-hole':
|
||||
return { ...common, ...overrides, sourceType };
|
||||
case 'visual-novel':
|
||||
return { ...common, ...overrides, sourceType };
|
||||
case 'jump-hop':
|
||||
return { ...common, ...overrides, sourceType };
|
||||
case 'wooden-fish':
|
||||
return { ...common, ...overrides, sourceType };
|
||||
case 'edutainment':
|
||||
return {
|
||||
...common,
|
||||
...overrides,
|
||||
sourceType,
|
||||
templateId: EDUTAINMENT_BABY_OBJECT_MATCH_TEMPLATE_ID,
|
||||
templateName: EDUTAINMENT_BABY_OBJECT_MATCH_TEMPLATE_NAME,
|
||||
};
|
||||
case 'bark-battle':
|
||||
return {
|
||||
...common,
|
||||
...overrides,
|
||||
sourceType,
|
||||
authorPublicUserCode: null,
|
||||
coverRenderMode: 'image',
|
||||
coverCharacterImageSrcs: [],
|
||||
themeMode: 'martial',
|
||||
playableNpcCount: 1,
|
||||
landmarkCount: 1,
|
||||
};
|
||||
default: {
|
||||
const exhaustive: never = sourceType;
|
||||
return exhaustive;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test('platform public work detail flow resolves detail kind for every play kind', () => {
|
||||
const cases: Array<
|
||||
[sourceType: PlatformGallerySourceType, kind: PlatformPublicWorkDetailKind]
|
||||
> = [
|
||||
['big-fish', 'big-fish'],
|
||||
['puzzle', 'puzzle'],
|
||||
['jump-hop', 'jump-hop'],
|
||||
['wooden-fish', 'wooden-fish'],
|
||||
['match3d', 'match3d'],
|
||||
['square-hole', 'square-hole'],
|
||||
['visual-novel', 'visual-novel'],
|
||||
['bark-battle', 'bark-battle'],
|
||||
['edutainment', 'edutainment'],
|
||||
];
|
||||
|
||||
cases.forEach(([sourceType, kind]) => {
|
||||
expect(getPlatformPublicWorkDetailKind(buildTypedEntry(sourceType))).toBe(
|
||||
kind,
|
||||
);
|
||||
});
|
||||
|
||||
expect(getPlatformPublicWorkDetailKind(buildRpgEntry())).toBe('rpg');
|
||||
});
|
||||
|
||||
test('platform public work detail flow resolves open strategy', () => {
|
||||
const rpgEntry = buildRpgEntry();
|
||||
const cases: Array<
|
||||
[
|
||||
entry: PlatformPublicGalleryCard,
|
||||
strategy: PlatformPublicWorkDetailOpenStrategy,
|
||||
]
|
||||
> = [
|
||||
[
|
||||
buildTypedEntry('big-fish'),
|
||||
{
|
||||
type: 'use-entry',
|
||||
kind: 'big-fish',
|
||||
},
|
||||
],
|
||||
[
|
||||
buildTypedEntry('match3d'),
|
||||
{
|
||||
type: 'use-entry',
|
||||
kind: 'match3d',
|
||||
},
|
||||
],
|
||||
[
|
||||
buildTypedEntry('square-hole'),
|
||||
{
|
||||
type: 'use-entry',
|
||||
kind: 'square-hole',
|
||||
},
|
||||
],
|
||||
[
|
||||
buildTypedEntry('bark-battle'),
|
||||
{
|
||||
type: 'use-entry',
|
||||
kind: 'bark-battle',
|
||||
},
|
||||
],
|
||||
[
|
||||
buildTypedEntry('edutainment'),
|
||||
{
|
||||
type: 'use-entry',
|
||||
kind: 'edutainment',
|
||||
},
|
||||
],
|
||||
[
|
||||
buildTypedEntry('puzzle'),
|
||||
{
|
||||
type: 'load-puzzle-detail',
|
||||
profileId: 'puzzle-profile',
|
||||
},
|
||||
],
|
||||
[
|
||||
buildTypedEntry('jump-hop'),
|
||||
{
|
||||
type: 'load-jump-hop-detail',
|
||||
profileId: 'jump-hop-profile',
|
||||
},
|
||||
],
|
||||
[
|
||||
buildTypedEntry('wooden-fish'),
|
||||
{
|
||||
type: 'load-wooden-fish-detail',
|
||||
profileId: 'wooden-fish-profile',
|
||||
},
|
||||
],
|
||||
[
|
||||
buildTypedEntry('visual-novel'),
|
||||
{
|
||||
type: 'load-visual-novel-detail',
|
||||
profileId: 'visual-novel-profile',
|
||||
},
|
||||
],
|
||||
[
|
||||
rpgEntry,
|
||||
{
|
||||
type: 'load-rpg-detail',
|
||||
entry: rpgEntry,
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
cases.forEach(([entry, strategy]) => {
|
||||
expect(resolvePlatformPublicWorkDetailOpenStrategy(entry)).toEqual(
|
||||
strategy,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('platform public work detail flow resolves edit mode only for owned works', () => {
|
||||
const entry = buildTypedEntry('puzzle');
|
||||
|
||||
expect(resolvePlatformPublicWorkActionMode(entry, 'user-1')).toBe('edit');
|
||||
expect(resolvePlatformPublicWorkActionMode(entry, ' user-1 ')).toBe('edit');
|
||||
expect(resolvePlatformPublicWorkActionMode(entry, 'user-2')).toBe('remix');
|
||||
expect(resolvePlatformPublicWorkActionMode(entry, null)).toBe('remix');
|
||||
});
|
||||
Reference in New Issue
Block a user