Skip to content

Commit

Permalink
add getComponentItem API to the manager
Browse files Browse the repository at this point in the history
  • Loading branch information
lianbenjamin committed Jul 10, 2024
1 parent 50ffe81 commit 103b81e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
22 changes: 11 additions & 11 deletions src/components/bottom-bar/bottom-bar-registry-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ export class BottomBarRegistryManager {
this._registry = new Map();
}

public register(component: string, componentIcon: any): void {
if (!this._registry.get(component)) {
this._registry.set(component, componentIcon);
public register(componentName: string, componentIcon: any): void {
if (!this.getComponentItem(componentName)) {
this._registry.set(componentName, componentIcon);
}
}

public unregister(component: string): void {
if (this._registry.get(component)) {
this._registry.delete(component);
public unregister(componentName: string): void {
if (this.getComponentItem(componentName)) {
this._registry.delete(componentName);
}
}

public get registry(): Map<string, any> {
return this._registry;
public getComponentItem(componentName: string): any {
return this._registry.get(componentName);
}

public clear(): void {
Expand All @@ -34,9 +34,9 @@ export class BottomBarRegistryManager {

export const bottomBarRegistryManager: string = 'bottomBarRegistryManager';

export const registerToBottomBar = (compName: string, player: any, getIconDtoCallback: () => any): void => {
export const registerToBottomBar = (componentName: string, player: any, getIconDtoCallback: () => any): void => {
const bottomBarRegistry = (player?.getService(bottomBarRegistryManager) as BottomBarRegistryManager) || undefined;
if (bottomBarRegistry && !bottomBarRegistry.registry.get(compName)) {
bottomBarRegistry.register(compName, getIconDtoCallback());
if (bottomBarRegistry && !bottomBarRegistry.getComponentItem(componentName)) {
bottomBarRegistry.register(componentName, getIconDtoCallback());
}
};
25 changes: 16 additions & 9 deletions tests/e2e/bottom-bar-registry-manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {BottomBarRegistryManager} from '../../src/components/bottom-bar';

describe('BottomBarRegistryManager', () => {
const myComponentName = 'MyComponent';
const iconDto = {
const iconDtoObj = {
ariaLabel: 'aria label',
displayName: myComponentName,
order: 5,
Expand All @@ -25,26 +25,33 @@ describe('BottomBarRegistryManager', () => {

describe('register API', () => {
it('Should register a component to the manager', () => {
bottomBarRegistryManager.register(myComponentName, iconDto);
bottomBarRegistryManager.registry.size.should.equal(1);
bottomBarRegistryManager.register(myComponentName, iconDtoObj);
bottomBarRegistryManager._registry.size.should.equal(1);
});
});

describe('unregister API', () => {
it('Should unregister a component from the manager', () => {
bottomBarRegistryManager.register(myComponentName, iconDto);
bottomBarRegistryManager.registry.size.should.equal(1);
bottomBarRegistryManager.register(myComponentName, iconDtoObj);
bottomBarRegistryManager._registry.size.should.equal(1);
bottomBarRegistryManager.unregister(myComponentName);
bottomBarRegistryManager.registry.size.should.equal(0);
bottomBarRegistryManager._registry.size.should.equal(0);
});
});

describe('clear API', () => {
it('Should clear the registry of the manager', () => {
bottomBarRegistryManager.register(myComponentName, iconDto);
bottomBarRegistryManager.registry.size.should.equal(1);
bottomBarRegistryManager.register(myComponentName, iconDtoObj);
bottomBarRegistryManager._registry.size.should.equal(1);
bottomBarRegistryManager.clear();
bottomBarRegistryManager.registry.size.should.equal(0);
bottomBarRegistryManager._registry.size.should.equal(0);
});
});

describe('getComponentItem API', () => {
it('Should get the added component item from the manager', () => {
bottomBarRegistryManager.register(myComponentName, iconDtoObj);
bottomBarRegistryManager.getComponentItem(myComponentName).should.equal(iconDtoObj);
});
});
});

0 comments on commit 103b81e

Please sign in to comment.