Skip to content

Commit

Permalink
refactor(core): rename first argument of FeatureServiceRegistry const…
Browse files Browse the repository at this point in the history
…ructor (#249)
  • Loading branch information
clebert committed Jan 11, 2019
1 parent 92579d9 commit 2d1933c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
56 changes: 31 additions & 25 deletions packages/core/src/__tests__/feature-app-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface MockFeatureServiceRegistry extends FeatureServiceRegistryLike {

describe('FeatureAppManager', () => {
let featureAppManager: FeatureAppManagerLike;
let mockRegistry: MockFeatureServiceRegistry;
let mockFeatureServiceRegistry: MockFeatureServiceRegistry;
let mockFeatureServicesBinding: FeatureServicesBinding;
let mockFeatureServicesBindingUnbind: () => void;
let mockModuleLoader: ModuleLoader;
Expand All @@ -33,7 +33,7 @@ describe('FeatureAppManager', () => {
unbind: mockFeatureServicesBindingUnbind
};

mockRegistry = {
mockFeatureServiceRegistry = {
registerFeatureServices: jest.fn(),
bindFeatureServices: jest.fn(() => mockFeatureServicesBinding)
};
Expand All @@ -43,7 +43,7 @@ describe('FeatureAppManager', () => {
mockFeatureAppDefinition = {create: mockFeatureAppCreate, id: 'testId'};
mockFeatureAppModule = {default: mockFeatureAppDefinition};
mockModuleLoader = jest.fn(async () => mockFeatureAppModule);
featureAppManager = new FeatureAppManager(mockRegistry);
featureAppManager = new FeatureAppManager(mockFeatureServiceRegistry);

spyConsoleInfo = jest.spyOn(console, 'info');
spyConsoleInfo.mockImplementation(jest.fn());
Expand All @@ -55,7 +55,7 @@ describe('FeatureAppManager', () => {

describe('#getAsyncFeatureAppDefinition', () => {
beforeEach(() => {
featureAppManager = new FeatureAppManager(mockRegistry, {
featureAppManager = new FeatureAppManager(mockFeatureServiceRegistry, {
moduleLoader: mockModuleLoader
});
});
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('FeatureAppManager', () => {
});

it('throws an error if no module loader was provided', () => {
featureAppManager = new FeatureAppManager(mockRegistry);
featureAppManager = new FeatureAppManager(mockFeatureServiceRegistry);

expect(() =>
featureAppManager.getAsyncFeatureAppDefinition('/example.js')
Expand All @@ -149,7 +149,7 @@ describe('FeatureAppManager', () => {
const mockConfig = {kind: 'test'};
const idSpecifier = 'testIdSpecifier';

featureAppManager = new FeatureAppManager(mockRegistry, {
featureAppManager = new FeatureAppManager(mockFeatureServiceRegistry, {
configs: {[mockFeatureAppDefinition.id]: mockConfig}
});

Expand All @@ -158,9 +158,9 @@ describe('FeatureAppManager', () => {
idSpecifier
);

expect(mockRegistry.bindFeatureServices.mock.calls).toEqual([
[mockFeatureAppDefinition, idSpecifier]
]);
expect(mockFeatureServiceRegistry.bindFeatureServices.mock.calls).toEqual(
[[mockFeatureAppDefinition, idSpecifier]]
);

const {featureServices} = mockFeatureServicesBinding;

Expand All @@ -170,20 +170,24 @@ describe('FeatureAppManager', () => {
});

describe('with a Feature App definition with own Feature Service definitions', () => {
let registryMethodCalls: string[];
let featureServiceRegistryMethodCalls: string[];

beforeEach(() => {
registryMethodCalls = [];
featureServiceRegistryMethodCalls = [];

mockRegistry.registerFeatureServices.mockImplementation(() => {
registryMethodCalls.push('registerFeatureServices');
});
mockFeatureServiceRegistry.registerFeatureServices.mockImplementation(
() => {
featureServiceRegistryMethodCalls.push('registerFeatureServices');
}
);

mockRegistry.bindFeatureServices.mockImplementation(() => {
registryMethodCalls.push('bindFeatureServices');
mockFeatureServiceRegistry.bindFeatureServices.mockImplementation(
() => {
featureServiceRegistryMethodCalls.push('bindFeatureServices');

return mockFeatureServicesBinding;
});
return mockFeatureServicesBinding;
}
);

mockFeatureAppDefinition = {
...mockFeatureAppDefinition,
Expand All @@ -197,15 +201,17 @@ describe('FeatureAppManager', () => {
'testIdSpecifier'
);

expect(mockRegistry.registerFeatureServices.mock.calls).toEqual([
expect(
mockFeatureServiceRegistry.registerFeatureServices.mock.calls
).toEqual([
[mockFeatureAppDefinition.ownFeatureServiceDefinitions, 'testId']
]);

expect(mockRegistry.bindFeatureServices.mock.calls).toEqual([
[mockFeatureAppDefinition, 'testIdSpecifier']
]);
expect(
mockFeatureServiceRegistry.bindFeatureServices.mock.calls
).toEqual([[mockFeatureAppDefinition, 'testIdSpecifier']]);

expect(registryMethodCalls).toEqual([
expect(featureServiceRegistryMethodCalls).toEqual([
'registerFeatureServices',
'bindFeatureServices'
]);
Expand Down Expand Up @@ -379,7 +385,7 @@ describe('FeatureAppManager', () => {

describe('#preloadFeatureApp', () => {
beforeEach(() => {
featureAppManager = new FeatureAppManager(mockRegistry, {
featureAppManager = new FeatureAppManager(mockFeatureServiceRegistry, {
moduleLoader: mockModuleLoader
});
});
Expand All @@ -395,7 +401,7 @@ describe('FeatureAppManager', () => {
});

it('throws an error if no module loader was provided', () => {
featureAppManager = new FeatureAppManager(mockRegistry);
featureAppManager = new FeatureAppManager(mockFeatureServiceRegistry);

expect(() =>
featureAppManager.getAsyncFeatureAppDefinition('/example.js')
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/feature-app-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class FeatureAppManager implements FeatureAppManagerLike {
>();

public constructor(
private readonly registry: FeatureServiceRegistryLike,
private readonly featureServiceRegistry: FeatureServiceRegistryLike,
private readonly options: FeatureAppManagerOptions = {}
) {}

Expand Down Expand Up @@ -187,7 +187,7 @@ export class FeatureAppManager implements FeatureAppManagerLike {
}

if (featureAppDefinition.ownFeatureServiceDefinitions) {
this.registry.registerFeatureServices(
this.featureServiceRegistry.registerFeatureServices(
featureAppDefinition.ownFeatureServiceDefinitions,
featureAppDefinition.id
);
Expand All @@ -207,7 +207,7 @@ export class FeatureAppManager implements FeatureAppManagerLike {
const config = configs && configs[featureAppDefinition.id];
const featureAppUid = createUid(featureAppDefinition.id, idSpecifier);

const binding = this.registry.bindFeatureServices(
const binding = this.featureServiceRegistry.bindFeatureServices(
featureAppDefinition,
idSpecifier
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('FeatureAppContainer', () => {
spyConsoleError.mockRestore();
});

it('calls the feature app manager with the given Feature App definition and id specifier', () => {
it('calls the Feature App manager with the given Feature App definition and id specifier', () => {
shallow(
<FeatureAppContainer
featureAppManager={mockManager}
Expand Down

0 comments on commit 2d1933c

Please sign in to comment.