Files
Genarrative/src/components/MapModal.test.tsx
T
kdletters 193e4f0e96 继续收口首页导航行与暗色弹窗底栏
将首页排行行与分类行切换为 PlatformNavigableListItem
将 NPC 交易详情与地图切场确认底栏收口到 PlatformDarkModalFooter
补充首页与弹窗回归测试并更新 PlatformUiKit 收口计划与共享决策记录
2026-06-11 05:06:07 +08:00

138 lines
4.5 KiB
TypeScript

/* @vitest-environment jsdom */
import { fireEvent, render, screen, within } from '@testing-library/react';
import type { HTMLAttributes, ReactNode } from 'react';
import { expect, test, vi } from 'vitest';
import { getCustomWorldSceneRelativePositionLabel } from '../data/customWorldSceneGraph';
import {
getConnectedScenePresets,
getWorldCampScenePreset,
} from '../data/scenePresets';
import { WorldType } from '../types';
import { MapModal } from './MapModal';
vi.mock('motion/react', () => ({
AnimatePresence: ({ children }: { children: ReactNode }) => <>{children}</>,
motion: {
div: ({
animate: _animate,
children,
exit: _exit,
initial: _initial,
transition: _transition,
...props
}: HTMLAttributes<HTMLDivElement> & {
animate?: unknown;
exit?: unknown;
initial?: unknown;
transition?: unknown;
}) => <div {...props}>{children}</div>,
},
}));
test('目标场景确认面板复用暗色琥珀 PlatformSubpanel 和胶囊标签', () => {
const currentScene = getWorldCampScenePreset(WorldType.WUXIA);
if (!currentScene) {
throw new Error('测试需要武侠营地场景');
}
const destination = getConnectedScenePresets(
WorldType.WUXIA,
currentScene.id,
)[0];
if (!destination) {
throw new Error('测试需要至少一个相邻场景');
}
const connection = currentScene.connections.find(
(item) => item.sceneId === destination.id,
);
const destinationLabel = connection
? getCustomWorldSceneRelativePositionLabel(connection.relativePosition)
: '前方';
render(
<MapModal
isOpen
currentScenePreset={currentScene}
worldType={WorldType.WUXIA}
onClose={vi.fn()}
onTravelToScene={vi.fn()}
/>,
);
const destinationNameNode = screen.getAllByText(destination.name)[0];
if (!destinationNameNode) {
throw new Error('测试需要展示目标场景名称');
}
const destinationButton = destinationNameNode.closest('button');
if (!destinationButton) {
throw new Error('测试需要可点击的目标场景节点');
}
const mapNodeLabelBadge =
within(destinationButton).getByText(destinationLabel);
expect(mapNodeLabelBadge.className).toContain('bg-emerald-500/10');
expect(mapNodeLabelBadge.className).toContain('rounded-full');
fireEvent.click(destinationButton);
const panel = screen.getByTestId('map-target-scene-panel');
const currentSummary = screen.getByTestId('map-current-scene-summary');
const nextSummary = screen.getByTestId('map-next-scene-summary');
const footer = screen.getByTestId('map-travel-footer');
const labelBadge = within(panel).getByText(destinationLabel);
const cancelButton = screen.getByRole('button', { name: '取消' });
const confirmButton = screen.getByRole('button', { name: '确认前往' });
expect(panel.className).toContain('border-amber-300/18');
expect(panel.className).toContain('bg-amber-500/8');
expect(panel.className).toContain('rounded-xl');
expect(panel.className).toContain('p-4');
expect(labelBadge.className).toContain('rounded-full');
expect(labelBadge.className).toContain('bg-amber-500/10');
expect(currentSummary.className).toContain('border-white/10');
expect(currentSummary.className).toContain('bg-black/25');
expect(nextSummary.className).toContain('border-white/10');
expect(nextSummary.className).toContain('bg-black/25');
expect(footer.className).toContain('platform-dark-modal-footer');
expect(footer.className).toContain('border-t');
expect(cancelButton.className).toContain(
'platform-action-button--editor-dark',
);
expect(cancelButton.className).toContain('bg-black/20');
expect(confirmButton.className).toContain(
'platform-action-button--editor-dark',
);
expect(confirmButton.className).toContain('bg-amber-500/20');
});
test('地图右上关闭按钮复用共享像素关闭按钮能力', () => {
const currentScene = getWorldCampScenePreset(WorldType.WUXIA);
if (!currentScene) {
throw new Error('测试需要武侠营地场景');
}
const onClose = vi.fn();
render(
<MapModal
isOpen
currentScenePreset={currentScene}
worldType={WorldType.WUXIA}
onClose={onClose}
onTravelToScene={vi.fn()}
/>,
);
const closeButton = screen.getByRole('button', { name: '关闭地图' });
fireEvent.click(closeButton);
expect(closeButton.className).toContain('absolute');
expect(closeButton.className).toContain('right-4');
expect(closeButton.getAttribute('title')).toBe('关闭地图');
expect(onClose).toHaveBeenCalledTimes(1);
});