const { chunkReport } = require('../utils/chunkReport'); describe('chunkReport', () => { it('returns [] for empty input', () => { expect(chunkReport('')).toEqual([]); expect(chunkReport(null)).toEqual([]); }); it('returns a single chunk when under the limit', () => { const report = '**🌐 Network**\n- Switch online\n- AP online'; expect(chunkReport(report, 1000)).toEqual([report]); }); it('trims surrounding whitespace from the single-chunk case', () => { const report = '\n\n**A**\nhello\n\n'; expect(chunkReport(report, 1000)).toEqual(['**A**\nhello']); }); it('splits on section boundaries when over the limit', () => { const a = '**A** ' + 'x'.repeat(60); const b = '**B** ' + 'y'.repeat(60); const c = '**C** ' + 'z'.repeat(60); const report = `${a}\n\n${b}\n\n${c}`; const chunks = chunkReport(report, 100); // Each section is ~66 chars so two sections per chunk is just over the // limit. Expect 3 chunks, one per section. expect(chunks).toHaveLength(3); expect(chunks[0]).toContain('**A**'); expect(chunks[1]).toContain('**B**'); expect(chunks[2]).toContain('**C**'); chunks.forEach(c => expect(c.length).toBeLessThanOrEqual(100)); }); it('packs multiple small sections into one chunk when they fit', () => { const sections = ['**A** short', '**B** short', '**C** short', '**D** short']; const report = sections.join('\n\n'); const chunks = chunkReport(report, 1000); expect(chunks).toHaveLength(1); expect(chunks[0]).toBe(report); }); it('hard-splits when a single section exceeds the limit', () => { const huge = '**Huge** ' + 'x'.repeat(500); const chunks = chunkReport(huge, 100); chunks.forEach(c => expect(c.length).toBeLessThanOrEqual(100)); expect(chunks.join('')).toBe(huge); }); it('keeps each chunk under the default 7000-char limit', () => { const section = '**Section ' + 'x'.repeat(50) + '**\n' + 'y'.repeat(3500); const report = Array.from({ length: 5 }, () => section).join('\n\n'); const chunks = chunkReport(report); chunks.forEach(c => expect(c.length).toBeLessThanOrEqual(7000)); }); });