import { describe, test, expect } from 'vitest'; import { purifyHtml } from './HtmlBlock'; // Vite/Vitest `?raw` import -- ships the exact bytes of the file as a // string, declared by node_modules/vite/client.d.ts. This is a checked-in // copy of the reference acceptance fixture used for Task 24 (widening the // Custom HTML block's sanitiser allow-list); keep it byte-identical to the // external fixture used to drive this task so these tests cannot silently // drift from the thing they are supposed to be testing against. import fixtureHtml from './__fixtures__/html-block-test-body.html?raw'; /** * Task 24: the site owner tested a broad HTML fixture against the shipped * sanitiser config and found 38% of it silently deleted -- merged table * cells collapsing (colspan/rowspan/scope stripped),
//
/ * inline /
    flattened. The fix widens * ALLOWED_TAGS/ALLOWED_ATTR in HtmlBlock.tsx. These tests run the *actual* * reference fixture through the *actual* purifyHtml() and assert the * previously-broken constructs now survive with their meaningful * attributes intact, while re-confirming (with attack payloads spliced * into the newly-widened surface -- forms, media, inline svg) that the * four non-negotiable security properties still hold. */ describe('purifyHtml -- Task 24 fixture regression (formerly-dropped constructs survive)', () => { const out = purifyHtml(fixtureHtml); test('table merged cells keep colspan/rowspan/scope', () => { expect(out).toContain(''); expect(out).toContain(''); expect(out).toContain(''); expect(out).toContain(''); }); test('definition list keeps its dl/dt/dd structure (was flattened to "TermDef")', () => { expect(out).toMatch(/
    [\s\S]*
    Term one<\/dt>[\s\S]*
    Definition of the first term\.<\/dd>[\s\S]*<\/dl>/); }); test('menu list survives with nested buttons', () => { expect(out).toMatch(/[\s\S]*