Move big fish runtime to frontend
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
2026-04-27 21:12:43 +08:00
parent dc619817a1
commit 2792df03a6
42 changed files with 1058 additions and 1895 deletions

View File

@@ -1,7 +1,7 @@
// @vitest-environment jsdom
import { fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, test, vi } from 'vitest';
import { act, fireEvent, render, screen } from '@testing-library/react';
import { afterEach, describe, expect, test, vi } from 'vitest';
import type { BigFishRuntimeSnapshotResponse } from '../../../packages/shared/src/contracts/bigFish';
import { BigFishRuntimeShell } from './BigFishRuntimeShell';
@@ -38,7 +38,21 @@ function createRun(
};
}
function dispatchPointerEvent(
target: HTMLElement,
type: string,
options: { pointerId: number; clientX: number; clientY: number },
) {
const event = new Event(type, { bubbles: true, cancelable: true });
Object.assign(event, options);
target.dispatchEvent(event);
}
describe('BigFishRuntimeShell', () => {
afterEach(() => {
vi.useRealTimers();
});
test('renders restart and exit actions after a failed run', () => {
const onBack = vi.fn();
const onRestart = vi.fn();
@@ -96,4 +110,51 @@ describe('BigFishRuntimeShell', () => {
expect(screen.queryByRole('dialog', { name: '玩法规则' })).toBeNull();
});
test('keeps moving in the last sampled direction after drag ends', () => {
vi.useFakeTimers();
const onSubmitInput = vi.fn();
const { container } = render(
<BigFishRuntimeShell
run={createRun('running')}
onBack={() => {}}
onSubmitInput={onSubmitInput}
/>,
);
const stage = container.querySelector('.touch-none');
if (!(stage instanceof HTMLElement)) {
throw new Error('Missing big fish stage');
}
act(() => {
dispatchPointerEvent(stage, 'pointerdown', {
pointerId: 1,
clientX: 100,
clientY: 100,
});
});
act(() => {
dispatchPointerEvent(stage, 'pointermove', {
pointerId: 1,
clientX: 140,
clientY: 100,
});
});
act(() => {
vi.advanceTimersByTime(100);
});
act(() => {
dispatchPointerEvent(stage, 'pointerup', {
pointerId: 1,
clientX: 140,
clientY: 100,
});
});
act(() => {
vi.advanceTimersByTime(220);
});
expect(onSubmitInput).toHaveBeenLastCalledWith({ x: 1, y: 0 });
});
});