diff --git a/__tests__/src/lib/componentPlugins.test.js b/__tests__/src/lib/componentPlugins.test.js new file mode 100644 index 0000000000000000000000000000000000000000..dde13deb433508e2c4e13615107e9d1b1b1f026e --- /dev/null +++ b/__tests__/src/lib/componentPlugins.test.js @@ -0,0 +1,30 @@ +import componentPlugins from '../../../src/lib/componentPlugins'; + +describe('componentPlugins', () => { + const originalMirador = window.Mirador; + beforeAll(() => { + window.Mirador = { + plugins: { + fooPlugin: { + name: 'fooPlugin', + parent: 'FooComponent', + }, + barPlugin: { + name: 'barPlugin', + parent: 'FooComponent', + }, + }, + }; + }); + afterAll(() => { + window.Mirador = originalMirador; + }); + it('only selects plugins that are defined in config', () => { + expect(componentPlugins('FooComponent', ['barPlugin'])[0].name).toEqual('barPlugin'); + expect(componentPlugins('FooComponent', ['barPlugin']).length).toEqual(1); + }); + it('only selects plugins that define component as parent', () => { + expect(componentPlugins('BarComponent', ['barPlugin'])).toEqual([]); + expect(componentPlugins('FooComponent', ['fooPlugin']).length).toEqual(1); + }); +});