Files
Newsletter-Link-Catalog/tests/parsing.test.ts
T

39 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { genericParser } from '../src/parsing/generic.js';
import { selectParser } from '../src/parsing/plugins.js';
describe('parser plugin selection', () => {
it('selects Substack for Substack headers and generic otherwise', () => {
expect(selectParser({ headers: { listId: 'thing.substack.com' }, html: '' }).name).toBe(
'substack'
);
expect(
selectParser({ headers: {}, html: '<a href="https://example.com">Example</a>' }).name
).toBe('generic');
});
});
describe('generic parser', () => {
it('keeps descriptions local to each link when many links share a container', () => {
const links = genericParser.parse({
html: `
<div>
<h2>CSS & HTML Tools</h2>
<a href="https://cascade.example">Cascade</a> - CSS property icons.
<a href="https://frames.example">Fancy Frames</a> - Decorative border generator.
SPONSORED
<a href="https://flexboxle.example">flexboxle</a> - A daily puzzle game to master CSS Flexbox.
<a href="https://types.example">Typescale AI</a> - A typescale generator.
</div>
`
});
expect(links.map((link) => link.description)).toEqual([
'Cascade - CSS property icons.',
'Fancy Frames - Decorative border generator.',
'SPONSORED flexboxle - A daily puzzle game to master CSS Flexbox.',
'Typescale AI - A typescale generator.'
]);
});
});