import { createElement } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { readFileSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
import { PathText, isWholePath } from '../../src/components/PathText/PathText';
import { RichTextValue } from '../../src/components/RichTextValue/RichTextValue';
const render = (value: string, label?: string, search?: string) => renderToStaticMarkup(createElement(PathText, { value, label, search }));
describe('shared path presentation', () => {
it.each(['C:\\Program Files\\Synthetic\\report.xml', '\\\\synthetic.invalid\\Reports\\scan.xml', 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Synthetic', 'SOFTWARE\\Policies\\Synthetic', '/var/log/synthetic.log', '../Synthetic/report.xml'])('boxes a complete path without changing it: %s', value => {
expect(render(value)).toBe(`${value}`);
});
it('isolates path lines from labels, metadata and audit guidance', () => {
const html = render('Source 1\nSource path: {synthetic}/DomainSysvol/GPO/Machine/windows nt/report.inf#lines=9\nScope: computer\nKey: SOFTWARE\\Synthetic\nData: 0\nComputer policy: system audit subcategory · synthetic');
expect(html.match(/class="technical-path"/g)).toHaveLength(2);
expect(html).toContain('\nScope: computer');
expect(html).toContain('\nData: 0');
expect(html).toContain('Computer policy: system audit subcategory · synthetic');
});
it('preserves spaces, full long paths and search highlighting', () => {
const path = 'Root folder/' + 'segment/'.repeat(100) + 'Synthetic.xml';
expect(render(path, 'Source path', 'synthetic')).toContain('Root folder/');
expect(render(path, 'Source path', 'synthetic')).toContain('Synthetic.xml');
expect(render(path, 'Source path')).toContain(path);
});
it('separates a registry finding title from its complete technical path', () => {
const path = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Office\\15.0\\Outlook\\Forms\\TrustedFormScriptList\\IPM.Appointment.LSW.Raumreservierung';
const html = render(`registry \u00b7 ${path}`);
expect(html).toBe(`registry \u00b7 ${path}`);
});
it('separates a Security Template Registry Values title from its MACHINE path', () => {
const path = 'MACHINE\\System\\CurrentControlSet\\Services\\NTDS\\Parameters\\SyntheticChannelBinding';
const html = render(`Registry Values \u00b7 ${path}`, undefined, 'SyntheticChannelBinding');
expect(html).toBe(`Registry Values \u00b7 MACHINE\\System\\CurrentControlSet\\Services\\NTDS\\Parameters\\SyntheticChannelBinding`);
});
it('escapes path content and never introduces links or active markup', () => {
const html = render('
', 'Source path');
expect(html).toContain('<img');
expect(html).not.toContain('
synthetic' }))).toContain('<b>');
});
it('leaves empty values, placeholders, identifiers and URLs alone', () => {
for (const value of ['', 'Not configured', '–', 'backup-synthetic', 'Scope: computer', 'https://example.invalid/page']) {
expect(isWholePath(value)).toBe(false);
expect(render(value)).not.toContain('technical-path');
}
expect(render('Not configured', 'Registry path')).toBe('Not configured');
expect(render('MACHINE\\System\\Synthetic')).toBe('MACHINE\\System\\Synthetic');
});
it('uses path styling in ordinary report text as well', () => {
for (const value of ['Source path: Synthetic/report.xml\nScope: computer', 'Source path: Synthetic/report.xml']) {
const html = renderToStaticMarkup(createElement(RichTextValue, { value }));
expect(html).toContain('Source path: Synthetic/report.xml');
}
});
it('uses shared theme colors and a path-only font exception without clipping', () => {
const css = readFileSync(new URL('../../src/styles/components.css', import.meta.url), 'utf8');
const rule = css.slice(css.indexOf('.technical-path,')).split('}')[0];
expect(rule).toContain('font-family: var(--font-path)');
expect(rule).toContain('font-size: inherit');
expect(rule).toContain('background: var(--surface-inset)');
expect(rule).toContain('overflow-wrap: anywhere');
expect(rule).toContain('white-space: pre-wrap');
expect(rule).not.toMatch(/hidden|ellipsis|nowrap/);
});
});