fix: polish bark battle creation flow
This commit is contained in:
@@ -4,6 +4,7 @@ import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { afterEach, expect, test, vi } from 'vitest';
|
||||
|
||||
import type { BarkBattleWorkSummary } from '../../../packages/shared/src/contracts/barkBattle';
|
||||
import type { CustomWorldWorkSummary } from '../../../packages/shared/src/contracts/customWorldAgent';
|
||||
import type { BabyObjectMatchDraft } from '../../../packages/shared/src/contracts/edutainmentBabyObject';
|
||||
import type { SquareHoleWorkSummary } from '../../../packages/shared/src/contracts/squareHoleWorks';
|
||||
@@ -226,6 +227,42 @@ const babyObjectMatchDraftItem: BabyObjectMatchDraft = {
|
||||
publishedAt: null,
|
||||
};
|
||||
|
||||
const barkBattleDraftItem: BarkBattleWorkSummary = {
|
||||
workId: 'bark-battle-work-draft-visible',
|
||||
draftId: 'bark-battle-draft-visible',
|
||||
ownerUserId: 'user-1',
|
||||
authorDisplayName: '声浪作者',
|
||||
title: '竖屏声浪草稿',
|
||||
summary: '生成完成后也必须留在我的草稿里。',
|
||||
themeDescription: '霓虹竖屏擂台',
|
||||
playerImageDescription: '红围巾选手',
|
||||
opponentImageDescription: '蓝头带对手',
|
||||
onomatopoeia: ['炸场', '破阵'],
|
||||
playerCharacterImageSrc: '/bark/player.png',
|
||||
opponentCharacterImageSrc: '/bark/opponent.png',
|
||||
uiBackgroundImageSrc: '/bark/background.png',
|
||||
difficultyPreset: 'normal',
|
||||
status: 'draft',
|
||||
generationStatus: 'ready',
|
||||
publishReady: true,
|
||||
playCount: 0,
|
||||
updatedAt: '2026-05-21T10:00:00.000Z',
|
||||
publishedAt: null,
|
||||
};
|
||||
|
||||
const barkBattlePublishedItem: BarkBattleWorkSummary = {
|
||||
...barkBattleDraftItem,
|
||||
workId: 'bark-battle-work-published-visible',
|
||||
draftId: 'bark-battle-draft-published-visible',
|
||||
title: '竖屏声浪已发布',
|
||||
summary: '发布完成后必须留在已发布作品里。',
|
||||
authorDisplayName: '发布作者',
|
||||
status: 'published',
|
||||
playCount: 9,
|
||||
updatedAt: '2026-05-21T10:10:00.000Z',
|
||||
publishedAt: '2026-05-21T10:10:00.000Z',
|
||||
};
|
||||
|
||||
test('creation hub reflects updated draft title summary and counts after rerender', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onCreateType = vi.fn();
|
||||
@@ -592,6 +629,47 @@ test('creation hub shows delete action for baby object match drafts', async () =
|
||||
expect(onOpenBabyObjectMatchDetail).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('creation hub works-only tab filters bark battle draft and published works', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onOpenBarkBattleDetail = vi.fn();
|
||||
|
||||
render(
|
||||
<CustomWorldCreationHub
|
||||
mode="works-only"
|
||||
items={[]}
|
||||
barkBattleItems={[barkBattleDraftItem, barkBattlePublishedItem]}
|
||||
loading={false}
|
||||
error={null}
|
||||
onRetry={() => {}}
|
||||
onCreateType={noopCreateType}
|
||||
onOpenDraft={() => {}}
|
||||
onEnterPublished={() => {}}
|
||||
onOpenBarkBattleDetail={onOpenBarkBattleDetail}
|
||||
entryConfig={testEntryConfig}
|
||||
creationTypes={testCreationTypes}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getByRole('button', { name: '全部 2' })).toBeTruthy();
|
||||
expect(screen.getByRole('button', { name: '草稿 1' })).toBeTruthy();
|
||||
expect(screen.getByRole('button', { name: '已发布 1' })).toBeTruthy();
|
||||
expect(screen.getByText('竖屏声浪草稿')).toBeTruthy();
|
||||
expect(screen.getByText('竖屏声浪已发布')).toBeTruthy();
|
||||
|
||||
await user.click(screen.getByRole('button', { name: '草稿 1' }));
|
||||
expect(screen.getByText('竖屏声浪草稿')).toBeTruthy();
|
||||
expect(screen.queryByText('竖屏声浪已发布')).toBeNull();
|
||||
|
||||
await user.click(screen.getByRole('button', { name: '已发布 1' }));
|
||||
expect(screen.queryByText('竖屏声浪草稿')).toBeNull();
|
||||
expect(screen.getByText('竖屏声浪已发布')).toBeTruthy();
|
||||
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: /查看详情《竖屏声浪已发布》/u }),
|
||||
);
|
||||
expect(onOpenBarkBattleDetail).toHaveBeenCalledWith(barkBattlePublishedItem);
|
||||
});
|
||||
|
||||
test('creation hub published work delete action is revealed without opening card', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onDeletePuzzle = vi.fn();
|
||||
|
||||
Reference in New Issue
Block a user