SHA256
HEADER v3, primary аккаунты и подтверждения
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import vm from 'node:vm';
|
||||
const source = fs.readFileSync(new URL('../js/router.js', import.meta.url), 'utf8').replace(/^import .*$/gm, '').replace(/^export /gm, '');
|
||||
function setup(path) {
|
||||
const url = new URL(path, 'https://t2.shineup.me');
|
||||
const calls = [];
|
||||
const window = { location: url, history: { state: { shineFrom: '/messages' }, replaceState(state, _, value) { calls.push([state, value]); url.href = new URL(value, url).href; }, pushState(state, _, value) { url.href = new URL(value, url).href; } }, dispatchEvent() {} };
|
||||
const router = vm.runInNewContext(source + '\n({toPrettyPath,getRoute,navigate})', { window, PopStateEvent: class {}, parseShineRouteParts: () => null });
|
||||
return { router, window, calls };
|
||||
}
|
||||
test('chat navigation keeps @ visible; other escapes unchanged', () => {
|
||||
const {router, window} = setup('/messages');
|
||||
assert.equal(router.toPrettyPath('chat-view/qwer1%40free'), 'chat/qwer1@free');
|
||||
assert.equal(router.toPrettyPath('chat/qwer1%40free/media'), 'chat/qwer1@free/media');
|
||||
assert.equal(router.toPrettyPath('chat/a%40b%2Fc'), 'chat/a@b%2Fc');
|
||||
assert.equal(router.toPrettyPath('settings/a%40b'), 'settings/a%40b');
|
||||
router.navigate('chat-view/qwer1%40free');
|
||||
assert.equal(window.location.pathname, '/chat/qwer1@free');
|
||||
assert.equal(router.getRoute().params.chatId, 'qwer1@free');
|
||||
});
|
||||
test('direct legacy URL canonicalizes without new history entry and retains query/hash', () => {
|
||||
const {router, window, calls} = setup('/chat/qwer1%40free/media?x=1#anchor');
|
||||
const route = router.getRoute();
|
||||
assert.equal(route.pageId, 'chat-media-view');
|
||||
assert.equal(route.params.chatId, 'qwer1@free');
|
||||
assert.equal(window.location.pathname, '/chat/qwer1@free/media');
|
||||
assert.deepEqual(calls, [[{shineFrom:'/messages'}, '/chat/qwer1@free/media?x=1#anchor']]);
|
||||
router.getRoute();
|
||||
assert.equal(calls.length, 1);
|
||||
});
|
||||
Reference in New Issue
Block a user