// @vitest-environment jsdom
import { describe, expect, it } from 'vitest';
import { importXml } from '../../src/importers/xml-importer';
import { browserMarkupDocumentAdapter } from '../../src/platform/browser/import-runtime-adapters';
import { ImportError } from '../../src/shared/errors';
import { sourceMetadata } from './import-source-fixtures';
describe('XML importer', () => {
it('extracts element paths, attributes and direct text', () => {
const text = `
Weak policy
High
`;
const source = sourceMetadata('report.xml', text.length, 'application/xml');
const imported = importXml(source, text, browserMarkupDocumentAdapter);
expect(imported.format).toBe('XML');
expect(imported.sheets[0].name).toBe('report');
expect(imported.sheets[0].rows).toContainEqual(['report', 'tool="SyntheticScanner"', '']);
expect(imported.sheets[0].rows).toContainEqual(['report/finding[1]', 'id="RULE-1"', '']);
expect(imported.sheets[0].rows).toContainEqual(['report/finding[1]/title[1]', '', 'Weak policy']);
expect(imported.sheets[0].rows).toContainEqual(['report/finding[1]/severity[2]', '', 'High']);
});
it('rejects malformed XML with a controlled import error', () => {
const text = '';
const source = sourceMetadata('broken.xml', text.length, 'application/xml');
expect(() => importXml(source, text, browserMarkupDocumentAdapter)).toThrow(ImportError);
expect(() => importXml(source, text, browserMarkupDocumentAdapter)).toThrow('XML konnte nicht geparst werden.');
});
});