refactor match3d runtime adapters

This commit is contained in:
2026-05-12 14:02:42 +08:00
parent 5cb5329f4e
commit 22810245f5
8 changed files with 358 additions and 43 deletions

View File

@@ -54,6 +54,7 @@ import {
import { match3dCreationClient } from '../../services/match3d-creation';
import {
clickMatch3DItem,
createServerMatch3DRuntimeAdapter,
finishMatch3DTimeUp,
restartMatch3DRun,
startMatch3DRun,
@@ -348,14 +349,35 @@ vi.mock('../../services/match3d-works', () => ({
listMatch3DWorks: vi.fn(),
}));
vi.mock('../../services/match3d-runtime', () => ({
const match3dRuntimeServiceMocks = vi.hoisted(() => ({
clickMatch3DItem: vi.fn(),
createServerMatch3DRuntimeAdapter: vi.fn(),
finishMatch3DTimeUp: vi.fn(),
restartMatch3DRun: vi.fn(),
startMatch3DRun: vi.fn(),
stopMatch3DRun: vi.fn(),
}));
const match3dServerRuntimeAdapterMock = vi.hoisted(() => ({
clickItem: vi.fn(),
finishTimeUp: vi.fn(),
getRun: vi.fn(),
restartRun: vi.fn(),
startRun: vi.fn(),
stopRun: vi.fn(),
}));
vi.mock('../../services/match3d-runtime', async () => {
const actual = await vi.importActual<
typeof import('../../services/match3d-runtime')
>('../../services/match3d-runtime');
return {
...actual,
...match3dRuntimeServiceMocks,
};
});
vi.mock('../../services/square-hole-creation', () => ({
squareHoleCreationClient: {
createSession: vi.fn(),
@@ -1453,6 +1475,24 @@ function TestWrapper({
beforeEach(() => {
vi.resetAllMocks();
vi.mocked(createServerMatch3DRuntimeAdapter).mockReturnValue(
match3dServerRuntimeAdapterMock,
);
match3dServerRuntimeAdapterMock.startRun.mockRejectedValue(
new Error('未启动抓大鹅运行态'),
);
match3dServerRuntimeAdapterMock.clickItem.mockRejectedValue(
new Error('未执行抓大鹅点击'),
);
match3dServerRuntimeAdapterMock.restartRun.mockRejectedValue(
new Error('未重新开始抓大鹅运行态'),
);
match3dServerRuntimeAdapterMock.finishTimeUp.mockResolvedValue({
run: buildMockMatch3DRun('match3d-profile-time-up'),
});
match3dServerRuntimeAdapterMock.stopRun.mockResolvedValue({
run: buildMockMatch3DRun('match3d-profile-stopped'),
});
window.history.replaceState(null, '', '/');
window.sessionStorage.clear();
window.localStorage.clear();
@@ -4465,7 +4505,7 @@ test('public code search opens a published Match3D work by M3 code and starts ru
vi.mocked(listMatch3DGallery).mockResolvedValue({
items: [match3dWork],
});
vi.mocked(startMatch3DRun).mockResolvedValue({
match3dServerRuntimeAdapterMock.startRun.mockResolvedValue({
run: buildMockMatch3DRun(match3dWork.profileId),
});
@@ -4483,7 +4523,9 @@ test('public code search opens a published Match3D work by M3 code and starts ru
await user.click(screen.getByRole('button', { name: '启动' }));
await waitFor(() => {
expect(startMatch3DRun).toHaveBeenCalledWith('match3d-profile-public-1');
expect(match3dServerRuntimeAdapterMock.startRun).toHaveBeenCalledWith(
'match3d-profile-public-1',
);
});
expect(
await screen.findByText('抓大鹅运行态match3d-run-match3d-profile-public-1'),