fix: route recommend puzzle next through feed

This commit is contained in:
2026-06-07 14:14:16 +08:00
parent e56a25243c
commit 8f460feb41
11 changed files with 84 additions and 126 deletions

View File

@@ -1039,7 +1039,7 @@ function renderStatefulLoggedOutHomeView(
function StatefulLoggedOutHomeView() {
const [activeTab, setActiveTab] =
useState<RpgEntryHomeViewProps['activeTab']>('category');
useState<RpgEntryHomeViewProps['activeTab']>('home');
return (
<AuthUiContext.Provider
@@ -3640,24 +3640,19 @@ test('public gallery cards hide phone masked author and public user code', async
expect(within(card).queryByText('SY-00000003')).toBeNull();
});
test('logged out mobile shell defaults to discover tab', () => {
test('logged out mobile shell defaults to recommend tab', () => {
const { container } = renderStatefulLoggedOutHomeView({
latestEntries: [puzzlePublicEntry],
});
const activePanel = container.querySelector('.platform-tab-panel--active');
expect(activePanel?.id).toBe('platform-tab-panel-category');
expect(
screen.getByPlaceholderText('搜索作品号、名称、作者、描述'),
).toBeTruthy();
expect(container.querySelector('.platform-mobile-topbar')).toBeTruthy();
expect(activePanel?.id).toBe('platform-tab-panel-home');
expect(
container.querySelector('.platform-mobile-entry-shell--recommend'),
).toBeNull();
).toBeTruthy();
});
test('logged out recommend tab opens embedded runtime without login modal', async () => {
const user = userEvent.setup();
const { container, openLoginModal } = renderStatefulLoggedOutHomeView({
latestEntries: [puzzlePublicEntry],
activeRecommendEntryKey: 'puzzle:user-2:puzzle-profile-public-1',
@@ -3667,10 +3662,6 @@ test('logged out recommend tab opens embedded runtime without login modal', asyn
throw new Error('缺少底部导航');
}
await user.click(
within(bottomNav as HTMLElement).getByRole('button', { name: '推荐' }),
);
expect(openLoginModal).not.toHaveBeenCalled();
expect(container.querySelector('.platform-recommend-cover-only')).toBeNull();
expect(container.querySelector('.platform-mobile-topbar')).toBeNull();
@@ -3683,7 +3674,6 @@ test('logged out recommend tab opens embedded runtime without login modal', asyn
});
test('logged out recommend runtime keeps detail callback idle', async () => {
const user = userEvent.setup();
const onOpenGalleryDetail = vi.fn();
const { openLoginModal } = renderStatefulLoggedOutHomeView({
latestEntries: [puzzlePublicEntry],
@@ -3695,10 +3685,6 @@ test('logged out recommend runtime keeps detail callback idle', async () => {
throw new Error('缺少底部导航');
}
await user.click(
within(bottomNav as HTMLElement).getByRole('button', { name: '推荐' }),
);
expect(openLoginModal).not.toHaveBeenCalled();
expect(screen.getByTestId('recommend-runtime')).toBeTruthy();
expect(onOpenGalleryDetail).not.toHaveBeenCalled();
@@ -3920,7 +3906,7 @@ test('mobile recommend startup keeps cover visible without loading copy', () =>
expect(screen.getAllByText('奇幻拼图').length).toBeGreaterThan(0);
});
test('mobile recommend next level keeps runtime visual stable when active work changes', async () => {
test('mobile recommend keeps runtime visual stable when active entry changes', async () => {
const animationCallbacks: FrameRequestCallback[] = [];
Object.defineProperty(window, 'requestAnimationFrame', {
configurable: true,
@@ -3944,18 +3930,18 @@ test('mobile recommend next level keeps runtime visual stable when active work c
worldName: '当前拼图',
coverImageSrc: 'current-cover.png',
} satisfies PlatformPublicGalleryCard;
const similarEntry = {
const nextEntry = {
...puzzlePublicEntry,
workId: 'puzzle-work-similar-1',
profileId: 'puzzle-profile-similar-1',
workId: 'puzzle-work-next-1',
profileId: 'puzzle-profile-next-1',
ownerUserId: 'user-feed-2',
publicWorkCode: 'PZ-SIMILAR1',
worldName: '相似拼图',
coverImageSrc: 'similar-cover.png',
publicWorkCode: 'PZ-NEXT1',
worldName: '下一张拼图',
coverImageSrc: 'next-cover.png',
} satisfies PlatformPublicGalleryCard;
const { rerender } = renderLoggedOutHomeView(vi.fn(), {
latestEntries: [firstEntry, similarEntry],
latestEntries: [firstEntry, nextEntry],
activeRecommendEntryKey: 'puzzle:user-feed-1:puzzle-profile-feed-1',
isRecommendRuntimeReady: true,
});
@@ -3998,7 +3984,7 @@ test('mobile recommend next level keeps runtime visual stable when active work c
saveEntries={[]}
saveError={null}
featuredEntries={[]}
latestEntries={[firstEntry, similarEntry]}
latestEntries={[firstEntry, nextEntry]}
myEntries={[]}
historyEntries={[]}
profileDashboard={null}
@@ -4013,7 +3999,7 @@ test('mobile recommend next level keeps runtime visual stable when active work c
onOpenCreateTypePicker={vi.fn()}
onOpenGalleryDetail={vi.fn()}
recommendRuntimeContent={<div data-testid="recommend-runtime" />}
activeRecommendEntryKey="puzzle:user-feed-2:puzzle-profile-similar-1"
activeRecommendEntryKey="puzzle:user-feed-2:puzzle-profile-next-1"
isRecommendRuntimeReady
onOpenLibraryDetail={vi.fn()}
onSearchPublicCode={vi.fn()}
@@ -4026,7 +4012,7 @@ test('mobile recommend next level keeps runtime visual stable when active work c
) as HTMLElement | null;
expect(rail?.className).toContain('platform-recommend-swipe-rail--settled');
expect(rail?.style.transform).toBe('translate3d(0, 0px, 0)');
expect(screen.getByLabelText('相似拼图 作品信息')).toBeTruthy();
expect(screen.getByLabelText('下一张拼图 作品信息')).toBeTruthy();
expect(
document.querySelector('.platform-recommend-runtime-cover')?.className,
).toContain('platform-recommend-runtime-cover--hidden');
@@ -4394,6 +4380,7 @@ test('mobile discover recommend feed only rotates the card closest to screen cen
});
test('mobile discover recommend feed renders cover fallback for legacy browsers', async () => {
const user = userEvent.setup();
renderStatefulLoggedOutHomeView({
latestEntries: [
{
@@ -4403,6 +4390,7 @@ test('mobile discover recommend feed renders cover fallback for legacy browsers'
},
],
});
await user.click(screen.getByRole('button', { name: '发现' }));
const discoverPanel = document.getElementById('platform-tab-panel-category');
if (!discoverPanel) {