mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
|
|
import { Binder } from './binder';
|
||
|
|
|
||
|
|
describe('binder tests', () => {
|
||
|
|
let binder;
|
||
|
|
|
||
|
|
beforeEach(() => {
|
||
|
|
binder = new Binder();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should return an empty array for non existing extension points', () => {
|
||
|
|
const extensions = binder.getExtensions('hitchhiker');
|
||
|
|
expect(extensions).toEqual([]);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should return the binded extensions', () => {
|
||
|
|
binder.bind('hitchhicker.trillian', 'heartOfGold');
|
||
|
|
binder.bind('hitchhicker.trillian', 'earth');
|
||
|
|
|
||
|
|
const extensions = binder.getExtensions('hitchhicker.trillian');
|
||
|
|
expect(extensions).toEqual(['heartOfGold', 'earth']);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should return the first bound extension', () => {
|
||
|
|
binder.bind('hitchhicker.trillian', 'heartOfGold');
|
||
|
|
binder.bind('hitchhicker.trillian', 'earth');
|
||
|
|
|
||
|
|
expect(binder.getExtension('hitchhicker.trillian')).toBe('heartOfGold');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should return null if no extension was bound', () => {
|
||
|
|
expect(binder.getExtension('hitchhicker.trillian')).toBe(null);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should return true, if an extension is bound', () => {
|
||
|
|
binder.bind('hitchhicker.trillian', 'heartOfGold');
|
||
|
|
expect(binder.hasExtension('hitchhicker.trillian')).toBe(true);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should return false, if no extension is bound', () => {
|
||
|
|
expect(binder.hasExtension('hitchhicker.trillian')).toBe(false);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should return only extensions which predicates matches', () => {
|
||
|
|
binder.bind(
|
||
|
|
'hitchhicker.trillian',
|
||
|
|
'heartOfGold',
|
||
|
|
(props: object) => props.category === 'a',
|
||
|
|
);
|
||
|
|
binder.bind(
|
||
|
|
'hitchhicker.trillian',
|
||
|
|
'earth',
|
||
|
|
(props: object) => props.category === 'b',
|
||
|
|
);
|
||
|
|
binder.bind(
|
||
|
|
'hitchhicker.trillian',
|
||
|
|
'earth2',
|
||
|
|
(props: object) => props.category === 'a',
|
||
|
|
);
|
||
|
|
|
||
|
|
const extensions = binder.getExtensions('hitchhicker.trillian', {
|
||
|
|
category: 'b',
|
||
|
|
});
|
||
|
|
expect(extensions).toEqual(['earth']);
|
||
|
|
});
|
||
|
|
});
|