105 lines
3.8 KiB
TypeScript
105 lines
3.8 KiB
TypeScript
![]() |
import { tap, expect, webhelpers } from '@git.zone/tstest/tapbundle';
|
||
|
|
||
|
import { BlockRegistry } from '../ts_web/elements/wysiwyg/blocks/block.registry.js';
|
||
|
import { DividerBlockHandler } from '../ts_web/elements/wysiwyg/blocks/content/divider.block.js';
|
||
|
import { ParagraphBlockHandler } from '../ts_web/elements/wysiwyg/blocks/text/paragraph.block.js';
|
||
|
import { HeadingBlockHandler } from '../ts_web/elements/wysiwyg/blocks/text/heading.block.js';
|
||
|
|
||
|
// Import block registration to ensure handlers are registered
|
||
|
import '../ts_web/elements/wysiwyg/wysiwyg.blockregistration.js';
|
||
|
|
||
|
tap.test('BlockRegistry should register and retrieve handlers', async () => {
|
||
|
// Test divider handler
|
||
|
const dividerHandler = BlockRegistry.getHandler('divider');
|
||
|
expect(dividerHandler).toBeDefined();
|
||
|
expect(dividerHandler).toBeInstanceOf(DividerBlockHandler);
|
||
|
expect(dividerHandler?.type).toEqual('divider');
|
||
|
|
||
|
// Test paragraph handler
|
||
|
const paragraphHandler = BlockRegistry.getHandler('paragraph');
|
||
|
expect(paragraphHandler).toBeDefined();
|
||
|
expect(paragraphHandler).toBeInstanceOf(ParagraphBlockHandler);
|
||
|
expect(paragraphHandler?.type).toEqual('paragraph');
|
||
|
|
||
|
// Test heading handlers
|
||
|
const heading1Handler = BlockRegistry.getHandler('heading-1');
|
||
|
expect(heading1Handler).toBeDefined();
|
||
|
expect(heading1Handler).toBeInstanceOf(HeadingBlockHandler);
|
||
|
expect(heading1Handler?.type).toEqual('heading-1');
|
||
|
|
||
|
const heading2Handler = BlockRegistry.getHandler('heading-2');
|
||
|
expect(heading2Handler).toBeDefined();
|
||
|
expect(heading2Handler).toBeInstanceOf(HeadingBlockHandler);
|
||
|
expect(heading2Handler?.type).toEqual('heading-2');
|
||
|
|
||
|
const heading3Handler = BlockRegistry.getHandler('heading-3');
|
||
|
expect(heading3Handler).toBeDefined();
|
||
|
expect(heading3Handler).toBeInstanceOf(HeadingBlockHandler);
|
||
|
expect(heading3Handler?.type).toEqual('heading-3');
|
||
|
});
|
||
|
|
||
|
tap.test('Block handlers should render content correctly', async () => {
|
||
|
const testBlock = {
|
||
|
id: 'test-1',
|
||
|
type: 'paragraph' as const,
|
||
|
content: 'Test paragraph content'
|
||
|
};
|
||
|
|
||
|
const handler = BlockRegistry.getHandler('paragraph');
|
||
|
expect(handler).toBeDefined();
|
||
|
|
||
|
if (handler) {
|
||
|
const rendered = handler.render(testBlock, false);
|
||
|
expect(rendered).toContain('contenteditable="true"');
|
||
|
expect(rendered).toContain('data-block-type="paragraph"');
|
||
|
expect(rendered).toContain('Test paragraph content');
|
||
|
}
|
||
|
});
|
||
|
|
||
|
tap.test('Divider handler should render correctly', async () => {
|
||
|
const dividerBlock = {
|
||
|
id: 'test-divider',
|
||
|
type: 'divider' as const,
|
||
|
content: ' '
|
||
|
};
|
||
|
|
||
|
const handler = BlockRegistry.getHandler('divider');
|
||
|
expect(handler).toBeDefined();
|
||
|
|
||
|
if (handler) {
|
||
|
const rendered = handler.render(dividerBlock, false);
|
||
|
expect(rendered).toContain('class="block divider"');
|
||
|
expect(rendered).toContain('tabindex="0"');
|
||
|
expect(rendered).toContain('divider-icon');
|
||
|
}
|
||
|
});
|
||
|
|
||
|
tap.test('Heading handlers should render with correct levels', async () => {
|
||
|
const headingBlock = {
|
||
|
id: 'test-h1',
|
||
|
type: 'heading-1' as const,
|
||
|
content: 'Test Heading'
|
||
|
};
|
||
|
|
||
|
const handler = BlockRegistry.getHandler('heading-1');
|
||
|
expect(handler).toBeDefined();
|
||
|
|
||
|
if (handler) {
|
||
|
const rendered = handler.render(headingBlock, false);
|
||
|
expect(rendered).toContain('class="block heading-1"');
|
||
|
expect(rendered).toContain('contenteditable="true"');
|
||
|
expect(rendered).toContain('Test Heading');
|
||
|
}
|
||
|
});
|
||
|
|
||
|
tap.test('getAllTypes should return all registered types', async () => {
|
||
|
const allTypes = BlockRegistry.getAllTypes();
|
||
|
expect(allTypes).toContain('divider');
|
||
|
expect(allTypes).toContain('paragraph');
|
||
|
expect(allTypes).toContain('heading-1');
|
||
|
expect(allTypes).toContain('heading-2');
|
||
|
expect(allTypes).toContain('heading-3');
|
||
|
expect(allTypes.length).toBeGreaterThanOrEqual(5);
|
||
|
});
|
||
|
|
||
|
export default tap.start();
|