* feat: 🎸 Expose extension config to modules Currently, only the preRegistration hook receives the extension's configuration as a parameter. Providing getModuleFn's with the extension's configuration, and all lifecycle/modules with the application's configuration as rootConfig should open the doors to more configurable extensions. Closes: #1268 * CR Update: Pass extension and service config through extension manager preinit/getmodule * CR Update: Remove appConfig from servicesManager * CR Update: Remove appconfig variable
99 lines
3.0 KiB
JavaScript
99 lines
3.0 KiB
JavaScript
import ServicesManager from './ServicesManager.js';
|
|
import log from '../log.js';
|
|
|
|
jest.mock('./../log.js');
|
|
|
|
describe('ServicesManager.js', () => {
|
|
let servicesManager;
|
|
|
|
beforeEach(() => {
|
|
servicesManager = new ServicesManager();
|
|
log.warn.mockClear();
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
describe('registerServices()', () => {
|
|
it('calls registerService() for each service', () => {
|
|
servicesManager.registerService = jest.fn();
|
|
|
|
servicesManager.registerServices([
|
|
{ name: 'UINotificationTestService', create: jest.fn() },
|
|
{ name: 'UIModalTestService', create: jest.fn() },
|
|
]);
|
|
|
|
expect(servicesManager.registerService.mock.calls.length).toBe(2);
|
|
});
|
|
|
|
it('calls registerService() for each service passing its configuration if tuple', () => {
|
|
servicesManager.registerService = jest.fn();
|
|
const fakeConfiguration = { testing: true };
|
|
|
|
servicesManager.registerServices([
|
|
{ name: 'UINotificationTestService', create: jest.fn() },
|
|
[{ name: 'UIModalTestService', create: jest.fn() }, fakeConfiguration],
|
|
]);
|
|
|
|
expect(servicesManager.registerService.mock.calls[1][1]).toEqual(
|
|
fakeConfiguration
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('registerService()', () => {
|
|
const fakeService = { name: 'UINotificationService', create: jest.fn() };
|
|
|
|
it('logs a warning if the service is null or undefined', () => {
|
|
const undefinedService = undefined;
|
|
const nullService = null;
|
|
|
|
servicesManager.registerService(undefinedService);
|
|
servicesManager.registerService(nullService);
|
|
|
|
expect(log.warn.mock.calls.length).toBe(2);
|
|
});
|
|
|
|
it('logs a warning if the service does not have a name', () => {
|
|
const serviceWithEmptyName = { name: '', create: jest.fn() };
|
|
const serviceWithoutName = { create: jest.fn() };
|
|
|
|
servicesManager.registerService(serviceWithEmptyName);
|
|
servicesManager.registerService(serviceWithoutName);
|
|
|
|
expect(log.warn.mock.calls.length).toBe(2);
|
|
});
|
|
|
|
it('logs a warning if the service does not have a create factory function', () => {
|
|
const serviceWithoutCreate = { name: 'UINotificationService' };
|
|
|
|
servicesManager.registerService(serviceWithoutCreate);
|
|
|
|
expect(log.warn.mock.calls.length).toBe(1);
|
|
});
|
|
|
|
it('tracks which services have been registered', () => {
|
|
servicesManager.registerService(fakeService);
|
|
|
|
expect(servicesManager.registeredServiceNames).toContain(
|
|
fakeService.name
|
|
);
|
|
});
|
|
|
|
it('logs a warning if the service has an name that has already been registered', () => {
|
|
servicesManager.registerService(fakeService);
|
|
servicesManager.registerService(fakeService);
|
|
|
|
expect(log.warn.mock.calls.length).toBe(1);
|
|
});
|
|
|
|
it('pass dependencies and configuration to service create factory function', () => {
|
|
const configuration = { config: 'Some configuration' };
|
|
|
|
servicesManager.registerService(fakeService, configuration);
|
|
|
|
expect(fakeService.create.mock.calls[0][0]).toEqual({
|
|
configuration,
|
|
});
|
|
});
|
|
});
|
|
});
|