Something went wrong. Try again.
tiny REST API that resolves AT Protocol Lexicon schemas from NSIDs lex.desertthunder.dev
lexicon atproto rest jsx dns hono htmx
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152import { describe, expect, it } from 'vitest';import { renderToString } from 'hono/jsx/dom/server';import { JSONView } from '../src/view/partials';import { Resolver } from '../src/view/partials/form';import { Helmet } from '../src/view/partials/helmet';
describe('View helpers', () => { it('escapes JSON before rendering the Prism partial', () => { const html = renderToString(JSONView({ value: '<script>alert("x")</script>' }, 'com.example.foo'));
expect(html).toContain('x-data='); expect(html).toContain('x-init="Prism.highlightAllUnder($el)"'); expect(html).toContain('language-json'); expect(html).toContain('Lexicon: com.example.foo'); expect(html).toContain('<script>alert(\\"x\\")</script>'); expect(html).not.toContain('<script>alert("x")</script>'); });
it('escapes the lexicon label', () => { const html = renderToString(JSONView({}, '<script>'));
expect(html).toContain('Lexicon: <script>'); expect(html).not.toContain('Lexicon: <script>'); });
it('marks error JSON results', () => { const html = renderToString(JSONView({ error: { code: 'bad_request', message: 'Invalid NSID' } }, 'com.example'));
expect(html).toContain('json-result--error'); expect(html).toContain('Error: com.example'); });
it('renders a copyable usage command', () => { const html = renderToString(Resolver({ baseUrl: 'https://lexdns.example' }));
expect(html).toContain('Usage'); expect(html).toContain('curl https://lexdns.example/api/resolve/site.standard.publication | jq '.lexicon''); expect(html).toContain('x-ref="usage"'); expect(html).toContain('copyUsage()'); });
it('renders canonical and social preview metadata', () => { const html = renderToString(Helmet());
expect(html).toContain('rel="canonical" href="https://lex.desertthunder.dev/"'); expect(html).toContain('property="og:url" content="https://lex.desertthunder.dev/"'); expect(html).toContain('property="og:image" content="https://lex.desertthunder.dev/og.png"'); expect(html).toContain('name="twitter:card" content="summary_large_image"'); expect(html).toContain('name="twitter:image" content="https://lex.desertthunder.dev/og.png"'); });});