refactor: 收口拼图表单草稿判定
This commit is contained in:
@@ -531,6 +531,8 @@ import {
|
||||
buildPuzzleFormPayloadFromAction,
|
||||
buildPuzzleFormPayloadFromSession,
|
||||
buildPuzzleFormPayloadFromWork,
|
||||
isEmptyPuzzleFormOnlyDraft,
|
||||
isPuzzleFormOnlyDraft,
|
||||
} from './platformMiniGameDraftPayloadModel';
|
||||
import {
|
||||
buildJumpHopPendingSession,
|
||||
@@ -1054,28 +1056,6 @@ function openPuzzleRuntimeStage(
|
||||
writePuzzleRuntimeUrlState(state);
|
||||
}
|
||||
|
||||
function isPuzzleFormOnlyDraft(session: PuzzleAgentSessionSnapshot | null) {
|
||||
return Boolean(
|
||||
session?.stage === 'collecting_anchors' && session.draft?.formDraft,
|
||||
);
|
||||
}
|
||||
|
||||
function isEmptyPuzzleFormOnlyDraft(
|
||||
session: PuzzleAgentSessionSnapshot | null,
|
||||
) {
|
||||
if (!isPuzzleFormOnlyDraft(session)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const formDraft = session?.draft?.formDraft;
|
||||
return !(
|
||||
session?.seedText?.trim() ||
|
||||
formDraft?.workTitle?.trim() ||
|
||||
formDraft?.workDescription?.trim() ||
|
||||
formDraft?.pictureDescription?.trim()
|
||||
);
|
||||
}
|
||||
|
||||
const CustomWorldGenerationView = lazy(async () => {
|
||||
const module = await import('../CustomWorldGenerationView');
|
||||
return {
|
||||
|
||||
@@ -24,6 +24,8 @@ import {
|
||||
buildPuzzleFormPayloadFromAction,
|
||||
buildPuzzleFormPayloadFromSession,
|
||||
buildPuzzleFormPayloadFromWork,
|
||||
isEmptyPuzzleFormOnlyDraft,
|
||||
isPuzzleFormOnlyDraft,
|
||||
} from './platformMiniGameDraftPayloadModel';
|
||||
|
||||
function buildPuzzleAnchorPack(): PuzzleAnchorPack {
|
||||
@@ -244,6 +246,29 @@ describe('platformMiniGameDraftPayloadModel', () => {
|
||||
).toBe('关卡优先');
|
||||
});
|
||||
|
||||
test('resolves puzzle form-only draft state for empty and filled forms', () => {
|
||||
const baseDraft = buildPuzzleSession().draft!;
|
||||
const emptySession = buildPuzzleSession({
|
||||
seedText: ' ',
|
||||
draft: {
|
||||
...baseDraft,
|
||||
formDraft: {
|
||||
workTitle: ' ',
|
||||
workDescription: ' ',
|
||||
pictureDescription: ' ',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(isPuzzleFormOnlyDraft(emptySession)).toBe(true);
|
||||
expect(isEmptyPuzzleFormOnlyDraft(emptySession)).toBe(true);
|
||||
expect(isPuzzleFormOnlyDraft(buildPuzzleSession())).toBe(true);
|
||||
expect(isEmptyPuzzleFormOnlyDraft(buildPuzzleSession())).toBe(false);
|
||||
expect(
|
||||
isPuzzleFormOnlyDraft(buildPuzzleSession({ stage: 'ready_to_publish' })),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
test('builds puzzle compile action and restores form payload from action', () => {
|
||||
const payload: CreatePuzzleAgentSessionRequest = {
|
||||
seedText: '种子',
|
||||
|
||||
@@ -151,6 +151,30 @@ export function buildPuzzleFormPayloadFromSession(
|
||||
};
|
||||
}
|
||||
|
||||
export function isPuzzleFormOnlyDraft(
|
||||
session: PuzzleAgentSessionSnapshot | null,
|
||||
) {
|
||||
return Boolean(
|
||||
session?.stage === 'collecting_anchors' && session.draft?.formDraft,
|
||||
);
|
||||
}
|
||||
|
||||
export function isEmptyPuzzleFormOnlyDraft(
|
||||
session: PuzzleAgentSessionSnapshot | null,
|
||||
) {
|
||||
if (!isPuzzleFormOnlyDraft(session)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const formDraft = session?.draft?.formDraft;
|
||||
return !(
|
||||
session?.seedText?.trim() ||
|
||||
formDraft?.workTitle?.trim() ||
|
||||
formDraft?.workDescription?.trim() ||
|
||||
formDraft?.pictureDescription?.trim()
|
||||
);
|
||||
}
|
||||
|
||||
export function buildPendingPuzzleDraftMetadata(
|
||||
payload: CreatePuzzleAgentSessionRequest | null | undefined,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user