UNPKG

@pdfme/common

Version:

TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!

81 lines 3.34 kB
import { pluginRegistry } from '../src/pluginRegistry.js'; describe('pluginRegistry', () => { it('returns all entries as [label, plugin] pairs', () => { const plugins = { pluginA: { propPanel: { defaultSchema: { type: 'typeA' } } }, pluginB: { propPanel: { defaultSchema: { type: 'typeB' } } }, }; // @ts-ignore const registry = pluginRegistry(plugins); expect(registry.entries()).toEqual([ ['pluginA', plugins.pluginA], ['pluginB', plugins.pluginB], ]); }); it('returns all plugin values', () => { const plugins = { pluginA: { propPanel: { defaultSchema: { type: 'typeA' } } }, pluginB: { propPanel: { defaultSchema: { type: 'typeB' } } }, }; // @ts-ignore const registry = pluginRegistry(plugins); expect(registry.values()).toEqual([plugins.pluginA, plugins.pluginB]); }); it('checks if plugins exist', () => { const plugins = { pluginA: { propPanel: { defaultSchema: { type: 'typeA' } } }, }; // @ts-ignore const registry = pluginRegistry(plugins); expect(registry.exists()).toBe(true); }); it('returns false if no plugins exist', () => { const plugins = {}; const registry = pluginRegistry(plugins); expect(registry.exists()).toBe(false); }); it('finds a plugin with label by type', () => { const plugins = { pluginA: { propPanel: { defaultSchema: { type: 'typeA' } } }, pluginB: { propPanel: { defaultSchema: { type: 'typeB' } } }, }; // @ts-ignore const registry = pluginRegistry(plugins); expect(registry.findWithLabelByType('typeA')).toEqual(['pluginA', plugins.pluginA]); }); it('returns undefined if no plugin matches the type in findWithLabelByType', () => { const plugins = { pluginA: { propPanel: { defaultSchema: { type: 'typeA' } } }, }; // @ts-ignore const registry = pluginRegistry(plugins); expect(registry.findWithLabelByType('typeB')).toEqual(['', undefined]); }); it('finds a plugin by type', () => { const plugins = { pluginA: { propPanel: { defaultSchema: { type: 'typeA' } } }, pluginB: { propPanel: { defaultSchema: { type: 'typeB' } } }, }; // @ts-ignore const registry = pluginRegistry(plugins); expect(registry.findByType('typeA')).toEqual(plugins.pluginA); }); it('returns undefined if no plugin matches the type in findByType', () => { const plugins = { pluginA: { propPanel: { defaultSchema: { type: 'typeA' } } }, }; // @ts-ignore const registry = pluginRegistry(plugins); expect(registry.findByType('typeB')).toBeUndefined(); }); it('ignores plugins without a valid propPanel in findWithLabelByType', () => { const plugins = { pluginA: { propPanel: { defaultSchema: { type: 'typeA' } } }, pluginB: { propPanel: null }, }; // @ts-ignore const registry = pluginRegistry(plugins); expect(registry.findWithLabelByType('typeB')).toEqual(['', undefined]); }); }); //# sourceMappingURL=pluginRegistry.test.js.map