Files
Genarrative/apps/ai-game-creator-shell/tests/resourceCanvasLayoutContract.test.ts
menghao 8a4b71bf8e
Project CI / Backend tests (pull_request) Failing after 10s
Project CI / Repository checks (pull_request) Failing after 10s
Project CI / Frontend tests (pull_request) Successful in 3m3s
Project CI / Native shell tests (pull_request) Successful in 10m23s
修复资源画布溢出与模板资源投影
闭合资源画布横向收缩链并增加内部滚动条

过滤任务产物通配模板避免生成无效资源卡

补充布局与资源投影回归测试

同步工作台文档与共享排障记忆
2026-08-07 10:53:41 +08:00

63 lines
2.4 KiB
TypeScript

import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { describe, expect, it } from 'vitest';
import {
GAME_CREATION_RESOURCE_LAYOUT_MAX_SAFE_REVISION,
isSafeProjectResourceCanvasLayoutRevision,
} from '../../../packages/shared/src/contracts/gameCreationApp';
describe('resource canvas layout contract', () => {
it('keeps wide resource content inside an explicitly scrollable stage column', () => {
const styles = readFileSync(
resolve(process.cwd(), 'apps/ai-game-creator-shell/src/styles.css'),
'utf8',
);
const stageRule = styles.match(
/\.game-workbench-stage\s*\{([^}]*)\}/s,
);
const managerRule = styles.match(
/\.game-resource-manager\s*\{([^}]*)\}/s,
);
const canvasRule = styles.match(
/\.game-resource-canvas\s*\{([^}]*)\}/s,
);
expect(stageRule?.[1]).toContain(
'grid-template-columns: minmax(0, 1fr);',
);
expect(managerRule?.[1]).toContain('min-width: 0;');
expect(managerRule?.[1]).toContain('overflow: hidden;');
expect(canvasRule?.[1]).toContain('width: 100%;');
expect(canvasRule?.[1]).toContain('min-width: 0;');
expect(canvasRule?.[1]).toContain('overflow-x: auto;');
expect(canvasRule?.[1]).toContain('overflow-y: auto;');
expect(styles).toMatch(
/\.game-resource-canvas::-webkit-scrollbar\s*\{[^}]*height:\s*12px/s,
);
expect(styles).toMatch(
/\.game-resource-canvas::-webkit-scrollbar-thumb\s*\{[^}]*background:\s*#d5a089/s,
);
});
it('keeps revisions inside the JSON safe integer range', () => {
const maxRevision = GAME_CREATION_RESOURCE_LAYOUT_MAX_SAFE_REVISION;
expect(JSON.parse(JSON.stringify({ revision: maxRevision }))).toEqual({
revision: maxRevision,
});
expect(isSafeProjectResourceCanvasLayoutRevision(0)).toBe(true);
expect(isSafeProjectResourceCanvasLayoutRevision(maxRevision)).toBe(true);
expect(isSafeProjectResourceCanvasLayoutRevision(maxRevision + 1)).toBe(
false,
);
expect(isSafeProjectResourceCanvasLayoutRevision(-1)).toBe(false);
expect(isSafeProjectResourceCanvasLayoutRevision(1.5)).toBe(false);
expect(isSafeProjectResourceCanvasLayoutRevision(Number.NaN)).toBe(false);
expect(
isSafeProjectResourceCanvasLayoutRevision(Number.POSITIVE_INFINITY),
).toBe(false);
expect(isSafeProjectResourceCanvasLayoutRevision('1')).toBe(false);
});
});