/**
* Tests for dashboard-renderer.cjs
* XSS protection, progress ring, plan card generation, and dashboard rendering
*/
const assert = require('assert');
const {
renderDashboard,
generatePlanCard,
generateProgressRing,
generateProgressBar,
generateStatusCounts,
generateEmptyState,
generatePlansGrid,
escapeHtml,
formatDate
} = require('../scripts/lib/dashboard-renderer.cjs');
describe('escapeHtml', () => {
it('should escape HTML special characters', () => {
assert.strictEqual(escapeHtml(''), '<script>alert("xss")</script>');
});
it('should handle ampersands', () => {
assert.strictEqual(escapeHtml('Tom & Jerry'), 'Tom & Jerry');
});
it('should handle single quotes', () => {
assert.strictEqual(escapeHtml("it's"), 'it's');
});
it('should handle double quotes', () => {
assert.strictEqual(escapeHtml('He said "hello"'), 'He said "hello"');
});
it('should handle null/undefined', () => {
assert.strictEqual(escapeHtml(null), '');
assert.strictEqual(escapeHtml(undefined), '');
});
it('should handle empty string', () => {
assert.strictEqual(escapeHtml(''), '');
});
it('should escape multiple occurrences', () => {
const result = escapeHtml('
Hello & "goodbye"
');
assert.strictEqual(result, '<div class="test">Hello & "goodbye"</div>');
});
});
describe('formatDate', () => {
it('should format ISO date string', () => {
const result = formatDate('2025-12-11T10:30:00Z');
assert(result.includes('Dec'));
assert(result.includes('11'));
assert(result.includes('2025'));
});
it('should handle null/undefined', () => {
assert.strictEqual(formatDate(null), '');
assert.strictEqual(formatDate(undefined), '');
});
it('should handle empty string', () => {
assert.strictEqual(formatDate(''), '');
});
it('should format different dates correctly', () => {
const result1 = formatDate('2025-01-01T00:00:00Z');
const result2 = formatDate('2025-12-31T23:59:59Z');
// Check for month indicator - could be "Jan" or "1" depending on locale
assert(result1.length > 0, 'Date 1 should format');
assert(result2.length > 0, 'Date 2 should format');
assert(result1 !== result2, 'Different dates should format differently');
});
});
describe('generateProgressRing', () => {
it('should generate SVG with correct progress percentage', () => {
const svg = generateProgressRing(50);
assert(svg.includes('50%'));
assert(svg.includes('stroke-dasharray'));
});
it('should generate valid SVG structure', () => {
const svg = generateProgressRing(75);
assert(svg.includes('