c5295a619c
空生成任务列表不再保持四秒轮询 读取资源字节优先通过read-url直连OSS 保留read-bytes作为OSS读取失败兜底 更新资产导出与项目记忆文档口径
180 lines
5.2 KiB
TypeScript
180 lines
5.2 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
|
|
import { createMiniGameDraftGenerationState } from '../../services/miniGameDraftGenerationProgress';
|
|
import {
|
|
buildExternalGenerationQueuePresentation,
|
|
buildExternalGenerationQueueStatus,
|
|
shouldUseFastExternalGenerationTaskPolling,
|
|
} from './platformExternalGenerationQueueStatusModel';
|
|
import {
|
|
resolveFinishedMiniGameDraftGenerationState,
|
|
resolveMiniGameGenerationProgressTickState,
|
|
resolveMiniGameGenerationViewBusy,
|
|
} from './platformMiniGameDraftGenerationStateModel';
|
|
|
|
describe('resolveMiniGameGenerationProgressTickState', () => {
|
|
test('returns jump hop and wooden fish generation states for progress ticking', () => {
|
|
const jumpHopState = createMiniGameDraftGenerationState('jump-hop');
|
|
const woodenFishState = createMiniGameDraftGenerationState('wooden-fish');
|
|
|
|
expect(
|
|
resolveMiniGameGenerationProgressTickState('jump-hop-generating', {
|
|
'jump-hop': jumpHopState,
|
|
}),
|
|
).toBe(jumpHopState);
|
|
expect(
|
|
resolveMiniGameGenerationProgressTickState('wooden-fish-generating', {
|
|
'wooden-fish': woodenFishState,
|
|
}),
|
|
).toBe(woodenFishState);
|
|
});
|
|
|
|
test('returns null when the stage does not need generation ticking', () => {
|
|
expect(
|
|
resolveMiniGameGenerationProgressTickState('platform', {
|
|
'jump-hop': createMiniGameDraftGenerationState('jump-hop'),
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('resolveMiniGameGenerationViewBusy', () => {
|
|
test('敲木鱼恢复生成中草稿时继续隐藏重新生成按钮', () => {
|
|
const woodenFishGeneratingState =
|
|
createMiniGameDraftGenerationState('wooden-fish');
|
|
|
|
expect(
|
|
resolveMiniGameGenerationViewBusy(false, woodenFishGeneratingState),
|
|
).toBe(true);
|
|
});
|
|
|
|
test('生成态结束后只保留真实 busy', () => {
|
|
const woodenFishReadyState = resolveFinishedMiniGameDraftGenerationState(
|
|
createMiniGameDraftGenerationState('wooden-fish'),
|
|
'ready',
|
|
);
|
|
|
|
expect(resolveMiniGameGenerationViewBusy(false, woodenFishReadyState)).toBe(
|
|
false,
|
|
);
|
|
expect(resolveMiniGameGenerationViewBusy(true, woodenFishReadyState)).toBe(
|
|
true,
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('buildExternalGenerationQueueStatus', () => {
|
|
test('合并队列概览和当前任务状态', () => {
|
|
expect(
|
|
buildExternalGenerationQueueStatus(
|
|
{
|
|
pendingCount: 7,
|
|
runningCount: 3,
|
|
unacknowledgedTerminalCount: 1,
|
|
updatedAtMicros: 1_781_222_400_000_000,
|
|
},
|
|
{
|
|
operationId: 'extgen-1',
|
|
status: 'running',
|
|
phaseLabel: '正在生成。',
|
|
phaseDetail: '正在生成。',
|
|
progress: 35,
|
|
updatedAtMicros: 1_781_222_400_000_000,
|
|
},
|
|
),
|
|
).toEqual({
|
|
currentStatus: 'running',
|
|
currentProgress: 35,
|
|
pendingCount: 7,
|
|
runningCount: 3,
|
|
unacknowledgedTerminalCount: 1,
|
|
tasks: null,
|
|
});
|
|
});
|
|
|
|
test('没有队列或任务信息时不显示状态条', () => {
|
|
expect(buildExternalGenerationQueueStatus(null, null)).toBeNull();
|
|
});
|
|
|
|
test('构造我的页生成队列展示状态', () => {
|
|
expect(
|
|
buildExternalGenerationQueuePresentation({
|
|
currentStatus: 'running',
|
|
currentProgress: 42.4,
|
|
pendingCount: 2,
|
|
runningCount: 1,
|
|
unacknowledgedTerminalCount: 0,
|
|
}),
|
|
).toEqual({
|
|
statusLabel: '生成中',
|
|
progressLabel: '42%',
|
|
pendingLabel: '2',
|
|
runningLabel: '1',
|
|
pendingCount: 2,
|
|
runningCount: 1,
|
|
unacknowledgedTerminalCount: 0,
|
|
progress: 42,
|
|
tasks: [],
|
|
shouldShow: true,
|
|
});
|
|
|
|
expect(buildExternalGenerationQueuePresentation(null).shouldShow).toBe(
|
|
false,
|
|
);
|
|
expect(
|
|
buildExternalGenerationQueuePresentation({
|
|
currentStatus: 'completed',
|
|
currentProgress: 100,
|
|
pendingCount: 0,
|
|
runningCount: 0,
|
|
}).shouldShow,
|
|
).toBe(false);
|
|
});
|
|
|
|
test('只在队列活跃或存在未确认终态任务时使用快速轮询', () => {
|
|
expect(
|
|
shouldUseFastExternalGenerationTaskPolling({
|
|
pendingCount: 0,
|
|
runningCount: 0,
|
|
unacknowledgedTerminalCount: 0,
|
|
tasks: [],
|
|
}),
|
|
).toBe(false);
|
|
|
|
expect(
|
|
shouldUseFastExternalGenerationTaskPolling({
|
|
currentStatus: 'queued',
|
|
pendingCount: 0,
|
|
runningCount: 0,
|
|
unacknowledgedTerminalCount: 0,
|
|
tasks: [],
|
|
}),
|
|
).toBe(true);
|
|
|
|
expect(
|
|
shouldUseFastExternalGenerationTaskPolling({
|
|
pendingCount: 0,
|
|
runningCount: 0,
|
|
unacknowledgedTerminalCount: 0,
|
|
tasks: [
|
|
{
|
|
jobId: 'extgen-completed',
|
|
jobKind: 'editor_image_generation',
|
|
sourceModule: 'editor',
|
|
sourceEntityId: 'project-1',
|
|
requestLabel: '图片生成',
|
|
status: 'completed',
|
|
phaseLabel: '已完成',
|
|
phaseDetail: '已完成',
|
|
progress: 100,
|
|
priceMudPoints: 1,
|
|
createdAt: '2026-06-25T00:00:00.000Z',
|
|
updatedAt: '2026-06-25T00:00:00.000Z',
|
|
updatedAtMicros: 1_782_348_800_000_000,
|
|
},
|
|
],
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
});
|