31 lines
3.1 KiB
TypeScript
31 lines
3.1 KiB
TypeScript
import {test} from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {staticEntries,getEntry,entryText} from '../src/lib/explore';
|
|
import {pageId,previewUrl} from '../src/content/page-links';
|
|
import {guidanceDocuments} from '../src/content/skills/guidance';
|
|
import {getServerSideProps} from '../src/pages/explore/[id]';
|
|
test('every public document has a distinct persisted ID and canonical entry',async()=>{assert.equal(new Set(staticEntries.map(e=>e.id)).size,staticEntries.length);for(const e of staticEntries){assert.match(e.id,/^[a-f0-9]{24}$/);assert.equal((await getEntry(e.id))?.title,e.title);}for(const doc of guidanceDocuments)assert.ok(pageId('guidance:'+doc.path));assert.equal(await getEntry('unknown'),null);});
|
|
test('agent_mode on the canonical URL emits text with media links and no HTML',async()=>{const entry=staticEntries.find(e=>e.media.length)!;let body='';const headers:Record<string,string>={};const response={setHeader:(k:string,v:string)=>headers[k]=v,end:(value:string)=>{body=value}};await getServerSideProps({params:{id:entry.id},query:{agent_mode:'True'},res:response,req:{method:'GET'}} as never);assert.match(headers['Content-Type'],/text\/plain/);assert.ok(body.includes(entry.title));assert.ok(body.includes(entry.media[0].url));assert.ok(body.startsWith('# '+entry.title));assert.ok(!body.includes('!['));assert.equal(body,entryText((await getEntry(entry.id))!));});
|
|
test('preview URLs always use bounded image endpoints',()=>{const url=new URL(previewUrl('/api/media/id?variant=poster',480),'http://test');assert.equal(url.pathname,'/api/preview');assert.equal(url.searchParams.get('source'),'/api/media/id?variant=poster');assert.equal(url.searchParams.get('width'),'480');});
|
|
|
|
test('independent notes expose their own description, tags and complete image counts',async()=>{
|
|
for(const entry of staticEntries){assert.ok(entry.description.trim());assert.equal(entry.imageCount,entry.media.filter(m=>m.kind==='image').length);assert.equal(new Set(entry.media.map(m=>m.url)).size,entry.media.length);}
|
|
const note=(await getEntry(pageId('guidance:shadow-puppet')))!;
|
|
assert.equal(note.imageCount,2);assert.ok(note.categories.includes('照片入皮影'));assert.ok(entryText(note).includes('Description: '+note.description));
|
|
const workflow=(await getEntry(pageId('guidance:shadow-puppet/workflow')))!;
|
|
assert.notEqual(workflow.description,note.description);assert.notEqual(workflow.id,note.id);
|
|
});
|
|
|
|
test('agent text preserves tutorial HTML and TSX code without returning an HTML page',async()=>{
|
|
const entry=(await getEntry(pageId('guidance:premium-layout/ref-01')))!;
|
|
let body='';const headers:Record<string,string>={};
|
|
const response={setHeader:(k:string,v:string)=>headers[k]=v,end:(value:string)=>{body=value}};
|
|
await getServerSideProps({params:{id:entry.id},query:{agent_mode:'True'},res:response,req:{method:'GET'}} as never);
|
|
assert.match(headers['Content-Type'],/text\/plain/);
|
|
assert.ok(body.startsWith('# '+entry.title));
|
|
assert.match(body,/```\n<!doctype html>\n<html lang="zh-CN">/);
|
|
assert.ok(body.includes('export default function Example'));
|
|
assert.ok(body.includes('app/designs/ref-01/page.tsx'));
|
|
assert.equal(body,entryText(entry));
|
|
});
|