/** @jest-environment jsdom */ // Load sanitizer and highlight utils used by the UI require('../sanitizer.js'); require('../highlight.js'); describe('Search highlight integration (server snippet rendering)', () => { const { formatSnippet, highlight, buildTokens } = window.highlightUtils; test('formatSnippet preserves server and sanitizes dangerous HTML', () => { const tokens = buildTokens('alpha'); const serverSnippet = 'Hello Alpha link'; const html = formatSnippet(serverSnippet, tokens); // Server-provided strong is preserved expect(html).toContain('Alpha'); // Dangerous attributes removed expect(html).not.toContain('onerror='); // javascript: protocol removed expect(html.toLowerCase()).not.toContain('href="javascript:'); // Image tag should remain but sanitized (no onerror) expect(html).toContain(' { const container = document.createElement('div'); const rawHtml = '
Text bold
'; // Using global helper installed by sanitizer.js window.setSafeHTML(container, rawHtml); // Script tags removed expect(container.innerHTML).not.toContain('