|
| 1 | +import assert from 'node:assert'; |
| 2 | +import { describe, it } from 'node:test'; |
| 3 | +import { paginate } from '../src/utils/paginate.js'; |
| 4 | +import { extract } from '../src/utils/extract.js'; |
| 5 | +import { processURL } from '../src/utils/process-url.js'; |
| 6 | + |
| 7 | +describe('Utility Functions', () => { |
| 8 | + describe('paginate', () => { |
| 9 | + it('should correctly paginate content', () => { |
| 10 | + const content = 'Hello World!'; |
| 11 | + const result = paginate('test-url', content, '', 0, 5); |
| 12 | + assert.ok(result.includes('Hello')); |
| 13 | + assert.ok(result.includes('truncated')); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should handle start index beyond content length', () => { |
| 17 | + const content = 'Hello World!'; |
| 18 | + const result = paginate('test-url', content, '', 20, 5); |
| 19 | + assert.ok(result.includes('No more content available')); |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + describe('extract', () => { |
| 24 | + it('should extract content from HTML', () => { |
| 25 | + const html = '<div><h1>Title</h1><p>Content</p><nav>Menu</nav></div>'; |
| 26 | + const result = extract(html); |
| 27 | + assert.ok(result.includes('Title')); |
| 28 | + assert.ok(result.includes('Content')); |
| 29 | + assert.ok(!result.includes('Menu')); // nav should be removed |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + describe('processURL', () => { |
| 34 | + it('should process HTML content', async () => { |
| 35 | + const [content, prefix] = await processURL( |
| 36 | + 'https://example.com', |
| 37 | + 'test-user-agent', |
| 38 | + false, |
| 39 | + ); |
| 40 | + assert.ok(content.length > 0); |
| 41 | + assert.equal(prefix, ''); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should handle raw content request', async () => { |
| 45 | + const [content, prefix] = await processURL( |
| 46 | + 'https://example.com', |
| 47 | + 'test-user-agent', |
| 48 | + true, |
| 49 | + ); |
| 50 | + assert.ok(content.includes('<html')); |
| 51 | + assert.ok(prefix.includes('raw')); |
| 52 | + }); |
| 53 | + }); |
| 54 | +}); |
0 commit comments