import { describe, expect, it } from 'vitest';
import { convertHtmlToBlockNote } from '../contentConversion';
function textFromBlock(block: any): string {
const content = Array.isArray(block.content) ? block.content : [];
return content.map((item: any) => item.text ?? '').join('');
}
describe('convertHtmlToBlockNote email table handling', () => {
it('preserves table blocks by default', async () => {
const result = await convertHtmlToBlockNote(`
| Name | Ada Lovelace |
| Business Email Address | ada@example.com |
`);
expect(result.some((block) => block.type === 'table')).toBe(true);
});
it('preserves normal data tables as BlockNote table blocks even when email table cleanup is enabled', async () => {
const result = await convertHtmlToBlockNote(`
| Name | Email |
| Ada Lovelace | ada@example.com |
| Grace Hopper | grace@example.com |
`, { flattenTables: true });
const tableBlock = result.find((block) => block.type === 'table');
expect(tableBlock).toBeDefined();
expect((tableBlock?.content as any)?.rows).toHaveLength(3);
expect((tableBlock?.content as any)?.rows[0].cells).toHaveLength(2);
});
it('splits collapsed nested layout-table content into label/value paragraphs', async () => {
const result = await convertHtmlToBlockNote(`
Entry Details
Tools & Resources
Name | Ada Lovelace |
Business Email Address | ada@example.com |
Description of Issue | Requesting a call back. |
|
|
`, { flattenTables: true });
expect(result.every((block) => block.type === 'paragraph')).toBe(true);
expect(result.map(textFromBlock)).toContain('Name Ada Lovelace');
expect(result.map(textFromBlock)).toContain('Business Email Address ada@example.com');
expect(result.map(textFromBlock)).toContain('Description of Issue Requesting a call back.');
});
});