fix: restore puzzle runtime url state
This commit is contained in:
85
src/services/creationUrlState.test.ts
Normal file
85
src/services/creationUrlState.test.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import {
|
||||
clearCreationUrlState,
|
||||
readCreationUrlState,
|
||||
writeCreationUrlState,
|
||||
} from './creationUrlState';
|
||||
|
||||
describe('creationUrlState', () => {
|
||||
it('writes and reads restore state on creation restore paths', () => {
|
||||
const replaceState = vi.fn();
|
||||
const env = {
|
||||
location: {
|
||||
pathname: '/creation/puzzle/result',
|
||||
search: '?clientRuntime=wechat_mini_program',
|
||||
},
|
||||
history: { replaceState },
|
||||
};
|
||||
|
||||
writeCreationUrlState(
|
||||
{
|
||||
sessionId: ' session-1 ',
|
||||
profileId: 'profile-1',
|
||||
draftId: 'draft-1',
|
||||
workId: 'work-1',
|
||||
},
|
||||
env,
|
||||
);
|
||||
|
||||
expect(replaceState).toHaveBeenCalledWith(
|
||||
null,
|
||||
'',
|
||||
'/creation/puzzle/result?clientRuntime=wechat_mini_program&sessionId=session-1&profileId=profile-1&draftId=draft-1&workId=work-1',
|
||||
);
|
||||
expect(
|
||||
readCreationUrlState({
|
||||
location: {
|
||||
pathname: '/creation/puzzle/result',
|
||||
search:
|
||||
'?sessionId=session-1&profileId=profile-1&draftId=draft-1&workId=work-1',
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
sessionId: 'session-1',
|
||||
profileId: 'profile-1',
|
||||
draftId: 'draft-1',
|
||||
workId: 'work-1',
|
||||
});
|
||||
});
|
||||
|
||||
it('ignores writes and clears outside creation restore paths', () => {
|
||||
const replaceState = vi.fn();
|
||||
const env = {
|
||||
location: {
|
||||
pathname: '/works/detail',
|
||||
search: '?work=PZ-123&sessionId=session-1',
|
||||
},
|
||||
history: { replaceState },
|
||||
};
|
||||
|
||||
writeCreationUrlState({ sessionId: 'session-2' }, env);
|
||||
clearCreationUrlState(env);
|
||||
|
||||
expect(replaceState).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('clears only private restore params on creation restore paths', () => {
|
||||
const replaceState = vi.fn();
|
||||
const env = {
|
||||
location: {
|
||||
pathname: '/creation/bark-battle/result',
|
||||
search: '?draftId=draft-1&workId=work-1&clientRuntime=wechat',
|
||||
},
|
||||
history: { replaceState },
|
||||
};
|
||||
|
||||
clearCreationUrlState(env);
|
||||
|
||||
expect(replaceState).toHaveBeenCalledWith(
|
||||
null,
|
||||
'',
|
||||
'/creation/bark-battle/result?clientRuntime=wechat',
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user