import { parseFailureSummary, escapeHtml } from '../public/logic.js';
describe('HTML and Summary Parsers', () => {
describe('parseFailureSummary', () => {
it('should return a default message for empty or null summary', () => {
expect(parseFailureSummary(null as any)).toBe('No suggestions available.');
expect(parseFailureSummary('')).toBe('No suggestions available.');
});
it('should correctly parse a multi-line summary', () => {
const summary = 'Fix all of the following:\n- Element has insufficient color contrast\n- Element has a role of "presentation"';
const expectedHtml = '<h6>Fix all of the following:</h6><ul><li>Element has insufficient color contrast</li><li>Element has a role of "presentation"</li></ul>';
expect(parseFailureSummary(summary)).toBe(expectedHtml);
});
it('should handle summaries with no line items', () => {
const summary = 'Just do this one thing.';
const expectedHtml = '<h6>Just do this one thing.</h6>';
expect(parseFailureSummary(summary)).toBe(expectedHtml);
});
it('should remove duplicate suggestions', () => {
const summary = 'Suggestions:\n- Do this\n- Do this\n- Do that';
const expectedHtml = '<h6>Suggestions:</h6><ul><li>Do this</li><li>Do that</li></ul>';
expect(parseFailureSummary(summary)).toBe(expectedHtml);
});
});
describe('escapeHtml', () => {
it('should escape less than and greater than characters', () => {
const input = '<div class="test">Hello</div>';
const expected = '<div class="test">Hello</div>';
expect(escapeHtml(input)).toBe(expected);
});
it('should return an empty string for non-string inputs', () => {
expect(escapeHtml(null as any)).toBe('');
expect(escapeHtml(undefined as any)).toBe('');
expect(escapeHtml(123 as any)).toBe('');
});
it('should handle strings with no special characters', () => {
const input = 'Just a regular string.';
expect(escapeHtml(input)).toBe(input);
});
});
});