Files
Genarrative/packages/shared/src/components/PlatformGameLoadingSurface.test.tsx
T
suzmii d7c4f82d7d
Project CI / AI game creator shell Rust crates (pull_request) Successful in 4m48s
Project CI / AI game creator shell Rust lane 1/2 (pull_request) Successful in 7m3s
Project CI / AI game creator shell Rust lane 2/2 (pull_request) Successful in 6m33s
Project CI / Frontend tests (pull_request) Successful in 3m24s
Project CI / Backend tests (pull_request) Successful in 7m29s
Project CI / AI game creator shell web tests (pull_request) Successful in 2m55s
Project CI / Repository checks (pull_request) Successful in 6m33s
Project CI / Native shell tests (pull_request) Successful in 9m0s
修复自查发现的门禁与体验问题:格式、超时态语义、压缩 CPU 边界
- 新增 Rust 测试补齐 cargo fmt;ESLint 按仓库约定收口:常量与解析函数拆到 platformGameLoadingSurfaceModel.ts,删除 GAME_PLAY_STARTUP_TIMEOUT_MS 常量别名(测试直接用共享常量)
- 共享加载面新增 stalled:宿主判定等待不再推进时停掉进度动画并把 aria-busy 置回 false(去掉与 role=status 重复的 aria-live)
- 后台试玩超时时传入 stalled,避免「一边转圈一边说超时」
- Accept-Encoding 权重参数名改为大小写不敏感(RFC 9110 §12.5.3),GZIP;Q=0 视为拒绝并补用例
- 发行资源压缩分级:≥2 MiB 改用 level 1(zlib 端实测约 1/3 耗时、压缩比差约 3%),小文件仍用 level 6
- 文档:主规范补压缩与条件请求契约(并写明 60 秒窗口与撤销窗口不放宽)、nginx README 修正 Pingora 压缩关闭时的口径、pitfalls 补 CPU 边界与措辞修正
2026-10-05 18:02:48 +08:00

107 lines
3.6 KiB
TypeScript

/* @vitest-environment jsdom */
import { act, render, screen } from '@testing-library/react';
import { afterEach, describe, expect, test, vi } from 'vitest';
import { PlatformGameLoadingSurface } from './PlatformGameLoadingSurface';
import {
PLATFORM_GAME_LOADING_ASSET_PHASE_MS,
PLATFORM_GAME_LOADING_ENGINE_PHASE_MS,
PLATFORM_GAME_LOADING_SLOW_PHASE_MS,
resolvePlatformGameLoadingMessage,
} from './platformGameLoadingSurfaceModel';
function readMessage() {
return screen
.getByRole('status')
.querySelector('.platform-game-loading__message')?.textContent;
}
afterEach(() => {
vi.useRealTimers();
});
describe('PlatformGameLoadingSurface', () => {
test('阶段文案随等待时长推进,慢加载才追加提示行', () => {
vi.useFakeTimers();
render(<PlatformGameLoadingSurface title="星尘防线" />);
const surface = screen.getByRole('status');
expect(surface.getAttribute('aria-busy')).toBe('true');
expect(surface.getAttribute('aria-label')).toContain('星尘防线');
expect(readMessage()).toBe(resolvePlatformGameLoadingMessage(0));
expect(surface.querySelector('.platform-game-loading__hint')).toBeNull();
act(() => {
vi.advanceTimersByTime(PLATFORM_GAME_LOADING_ASSET_PHASE_MS);
});
expect(readMessage()).toBe(
resolvePlatformGameLoadingMessage(PLATFORM_GAME_LOADING_ASSET_PHASE_MS),
);
expect(
screen.getByRole('status').querySelector('.platform-game-loading__hint'),
).toBeNull();
act(() => {
vi.advanceTimersByTime(
PLATFORM_GAME_LOADING_ENGINE_PHASE_MS -
PLATFORM_GAME_LOADING_ASSET_PHASE_MS,
);
});
expect(readMessage()).toBe(
resolvePlatformGameLoadingMessage(PLATFORM_GAME_LOADING_ENGINE_PHASE_MS),
);
act(() => {
vi.advanceTimersByTime(
PLATFORM_GAME_LOADING_SLOW_PHASE_MS -
PLATFORM_GAME_LOADING_ENGINE_PHASE_MS,
);
});
expect(
screen.getByRole('status').querySelector('.platform-game-loading__hint')
?.textContent,
).toBeTruthy();
});
test('宿主文案与提示覆盖默认阶段文案,封面按宿主给的内容渲染', () => {
render(
<PlatformGameLoadingSurface
title="待审版本试玩"
tone="panel"
message="正在创建试玩会话…"
hint="会话过期后请重新创建"
cover={<img alt="封面" src="data:image/gif;base64,R0lGOD" />}
/>,
);
const surface = screen.getByRole('status');
expect(surface.className).toContain('platform-game-loading--panel');
expect(readMessage()).toBe('正在创建试玩会话…');
expect(
surface.querySelector('.platform-game-loading__hint')?.textContent,
).toBe('会话过期后请重新创建');
expect(screen.getByRole('img', { name: '封面' })).toBeTruthy();
});
test('宿主判定停止推进时不再声明 busy,并停掉进度动画', () => {
render(<PlatformGameLoadingSurface title="待审版本试玩" stalled />);
const surface = screen.getByRole('status');
expect(surface.getAttribute('aria-busy')).toBe('false');
expect(surface.className).toContain('platform-game-loading--stalled');
});
test('没有封面时渲染图标占位而不是空白区块', () => {
const { container } = render(
<PlatformGameLoadingSurface title="加载中" tone="player" />,
);
const surface = container.querySelector('.platform-game-loading');
expect(surface?.className).toContain('platform-game-loading--player');
expect(
surface?.querySelector('.platform-game-loading__cover svg'),
).toBeTruthy();
});
});