/** * HTML preview vocabulary tests: the srcdoc delivery path needs the previewed * document's relative references to resolve back into its own * `/sidebar/html/…` route (a srcdoc document has no URL of its own — the * browser would otherwise resolve `./style.css` against the GUI page). * * Pure module, plain node environment. */ import { describe, expect, it } from 'vitest' import { previewBaseOf, withPreviewBase } from '../src/client/html-preview.ts' const URL_ = '/sidebar/html/s1/p/a/index.html' describe('previewBaseOf', () => { it('keeps everything up to the last slash', () => { expect(previewBaseOf(URL_)).toBe('/sidebar/html/s1/p/a/') }) it('keeps the UNC double slash intact (the route encodes it that way)', () => { expect(previewBaseOf('/sidebar/html/s1//server/share/a.html')).toBe('/sidebar/html/s1//server/share/') }) it('returns the input unchanged when it has no slash', () => { expect(previewBaseOf('s1')).toBe('s1') }) }) describe('withPreviewBase', () => { it('injects the base as the first child of , ahead of the document’s own elements', () => { const out = withPreviewBase('t', URL_) expect(out).toBe('t') }) it('falls back to when the document declares no head', () => { const out = withPreviewBase('x', URL_) expect(out).toBe('x') }) it('prepends for a headless fragment', () => { expect(withPreviewBase('

x

', URL_)).toBe('

x

') }) it('leaves a document that declares its own base alone (the author owns it)', () => { const doc = '' expect(withPreviewBase(doc, URL_)).toBe(doc) }) it('quotes the injected href', () => { expect(withPreviewBase('', '/x/"y/')).toBe('') }) })