This commit is contained in:
谢宇宁
2026-11-06 00:13:27 +07:00
parent f65d10e998
commit 37411fcada
98 changed files with 958 additions and 4598 deletions
+5 -32
View File
@@ -1,3 +1,4 @@
import {linkShared} from './helpers/shared-modules.mjs';
import {routingModuleUrl} from './helpers/routing.mjs';
import {test} from 'node:test';
import assert from 'node:assert/strict';
@@ -7,7 +8,7 @@ import ts from 'typescript';
async function moduleUrl(file,replace=code=>code){
const filename=new URL(file,import.meta.url);
const {outputText}=ts.transpileModule(await readFile(filename,'utf8'),{compilerOptions:{target:ts.ScriptTarget.ES2022,module:ts.ModuleKind.ESNext}});
return 'data:text/javascript;base64,'+Buffer.from(replace(outputText).replace(/(['"])\.\.\/routing\1/g,JSON.stringify(routingModuleUrl))+'\n//# sourceURL='+filename.pathname).toString('base64');
return 'data:text/javascript;base64,'+Buffer.from(linkShared(replace(outputText)).replace(/(['"])\.\.\/routing\1/g,JSON.stringify(routingModuleUrl))+'\n//# sourceURL='+filename.pathname).toString('base64');
}
const routingUrl=await moduleUrl('../src/lib/routing.ts');
const {routeFromSegments,parseSitePath,paginationPath,internalPagePath,searchPath}=await import(routingUrl);
@@ -15,14 +16,10 @@ const protocolUrl=await moduleUrl('../src/lib/api/protocol.ts');
const renderUrl=await moduleUrl('../src/lib/client/render.ts',code=>code.replace('"../api/protocol"',JSON.stringify(protocolUrl)));
const {pagination}=await import(renderUrl);
const {bindPaginationJumps}=await import(await moduleUrl('../src/lib/client/navigation.ts'));
const authUrl=await moduleUrl('../src/lib/client/auth.ts');
const trackingUrl=await moduleUrl('../src/lib/tracking.ts');
const accountUrl=await moduleUrl('../src/lib/client/account.ts',code=>code.replace('"../api/protocol"',JSON.stringify(protocolUrl)).replace('"./render"',JSON.stringify(renderUrl)).replace("'./auth'",JSON.stringify(authUrl)).replace("'../tracking'",JSON.stringify(trackingUrl)));
const {renderMember,renderWallet}=await import(accountUrl);
test('every paginated page type resolves directly from the page suffix',()=>{
const keyword='都市 / page/7/?#%2F';
const bases=['/shorts/','/topics/','/topics/7/','/theme/8/','/tag/9/','/config/31/','/rank/','/rank/hot/','/rank/new/','/rank/follow/','/search/'+encodeURIComponent(keyword)+'/', '/member/favorites/','/member/history/','/member/likes/','/member/purchased/','/info/deposit/','/info/deposit/vip/','/detail/23456/','/play/23456/90001/'];
const bases=['/shorts/','/topics/','/topics/7/','/theme/8/','/tag/9/','/config/31/','/rank/','/rank/hot/','/rank/new/','/rank/follow/','/search/'+encodeURIComponent(keyword)+'/'];
for(const base of bases){
for(const page of [1,2,37]){
const path=base+'page/'+page+'/';
@@ -37,7 +34,8 @@ test('every paginated page type resolves directly from the page suffix',()=>{
test('invalid page numbers, nested page suffixes, and non-paginated sections are rejected',()=>{
for(const value of ['0','-1','1.5','02','NaN','9007199254740992'])assert.equal(parseSitePath(`/shorts/page/${value}/`),null,value);
for(const base of ['/','/apps/','/home-road/','/navigation/','/member/center/','/member/settings/','/info/about-us/'])assert.equal(parseSitePath(base+'page/2/'),null,base);
for(const base of ['/','/apps/','/home-road/','/navigation/','/info/about-us/','/detail/23456/','/play/23456/90001/'])assert.equal(parseSitePath(base+'page/2/'),null,base);
for(const base of ['/member/center/','/member/favorites/','/info/deposit/','/info/feedback/'])assert.equal(parseSitePath(base),null,base);
assert.equal(parseSitePath('/shorts/page/2/page/3/'),null);
assert.throws(()=>paginationPath('/shorts/',0));assert.throws(()=>paginationPath('/apps/',2));
});
@@ -50,7 +48,6 @@ test('page links retain filters and encoded search terms and sorting resets to t
assert.equal(paginationPath(base,2),searchPath('都市 / 爱情?#%',2));
const url=new URL(paginationPath(base,2),'https://drama.example');
assert.equal(parseSitePath(url.pathname,url.search).key,'都市 / 爱情?#%');
assert.equal(paginationPath('/play/7/90001/page/3/?commentSort=1',1,{commentSort:null}),'/play/7/90001/');
});
test('pagination renders real page links with correct boundaries, current page, and bounded page numbers',()=>{
@@ -94,27 +91,3 @@ test('jump forms navigate to independent routes, retain canonical slugs and filt
if(previousInput===undefined)delete globalThis.HTMLInputElement;else globalThis.HTMLInputElement=previousInput;
}
});
test('personal library and wallet requests and page links use the route page',async()=>{
const previousDocument=globalThis.document,calls=[];
const root={innerHTML:'',querySelector:()=>null,addEventListener(){}};
const user={userId:7,nickName:'测试用户'};
const api={user,ensureSession:async()=>user,async get(path,query){
calls.push({path,...query});
if(path==='user/center/data')return {};
if(path==='recharge/package/list')return {coinList:[],vipList:[]};
return {list:[],totalCount:120};
}};
const app={api,signal:new AbortController().signal};
globalThis.document={getElementById:()=>root};
try{
for(const [tab,endpoint] of [['favorites','playlet/collect/list'],['history','playlet/history/list'],['likes','playlet/like/list'],['purchased','playlet/bought/list']]){
await renderMember(app,tab,3,page=>paginationPath(`/member/${tab}/page/3/`,page));
const call=calls.at(-1);assert.equal(call.path,endpoint);assert.equal(call.pageNum,3);
assert.ok(root.innerHTML.includes(`href="/member/${tab}/page/2/"`));
}
await renderWallet(app,true,3,page=>paginationPath('/info/deposit/vip/page/3/',page));
assert.equal(calls.at(-1).path,'coin/trans/list');assert.equal(calls.at(-1).page,3);
assert.ok(root.innerHTML.includes('href="/info/deposit/vip/page/4/"'));
}finally{if(previousDocument===undefined)delete globalThis.document;else globalThis.document=previousDocument;}
});