import { renderUrlset } from '../../render/renderUrlset.js'; import { SitemapUrlRecord } from '../../types.js'; describe('renderUrlset', () => { it('renders from record.loc and a valid XML prolog', () => { const xml = renderUrlset([{ loc: 'https://shop.com/shoes' }]); expect(xml.startsWith('')).toBe(true); expect(xml).toContain('https://shop.com/shoes'); }); it('omits optional tags when absent', () => { const xml = renderUrlset([{ loc: 'https://shop.com/a' }]); expect(xml).not.toContain(''); expect(xml).not.toContain(''); expect(xml).not.toContain(''); }); it('renders optional tags when present', () => { const record: SitemapUrlRecord = { loc: 'https://shop.com/a', lastmod: '2026-01-01T00:00:00.000Z', changefreq: 'daily', priority: 0.7 }; const xml = renderUrlset([record]); expect(xml).toContain('2026-01-01T00:00:00.000Z'); expect(xml).toContain('daily'); expect(xml).toContain('0.7'); }); it('declares xmlns:xhtml and renders only when a record has alternates', () => { const without = renderUrlset([{ loc: 'https://shop.com/a' }]); expect(without).not.toContain('xmlns:xhtml'); expect(without).not.toContain('' ); }); it('entity-escapes the loc', () => { const xml = renderUrlset([{ loc: 'https://shop.com/a?x=1&y=2' }]); expect(xml).toContain('https://shop.com/a?x=1&y=2'); }); it('renders an empty namespace-free urlset for no records', () => { const xml = renderUrlset([]); expect(xml).toContain( '' ); expect(xml).toContain(''); expect(xml).not.toContain(''); expect(xml).not.toContain('xmlns:xhtml'); }); it('clamps priority to one decimal within [0,1]', () => { expect(renderUrlset([{ loc: 'x', priority: 1 }])).toContain( '1.0' ); expect(renderUrlset([{ loc: 'x', priority: 5 }])).toContain( '1.0' ); expect(renderUrlset([{ loc: 'x', priority: -1 }])).toContain( '0.0' ); }); });