From 103b81e18e2624be39b84944fe5f744df620b3c8 Mon Sep 17 00:00:00 2001 From: lianbenjamin <79077248+lianbenjamin@users.noreply.github.com> Date: Wed, 10 Jul 2024 12:59:47 +0300 Subject: [PATCH] add getComponentItem API to the manager --- .../bottom-bar/bottom-bar-registry-manager.ts | 22 ++++++++-------- tests/e2e/bottom-bar-registry-manager.spec.js | 25 ++++++++++++------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/components/bottom-bar/bottom-bar-registry-manager.ts b/src/components/bottom-bar/bottom-bar-registry-manager.ts index fe0212bfa..41d31436d 100644 --- a/src/components/bottom-bar/bottom-bar-registry-manager.ts +++ b/src/components/bottom-bar/bottom-bar-registry-manager.ts @@ -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 { - return this._registry; + public getComponentItem(componentName: string): any { + return this._registry.get(componentName); } public clear(): void { @@ -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()); } }; diff --git a/tests/e2e/bottom-bar-registry-manager.spec.js b/tests/e2e/bottom-bar-registry-manager.spec.js index e9f479b45..8e2399dce 100644 --- a/tests/e2e/bottom-bar-registry-manager.spec.js +++ b/tests/e2e/bottom-bar-registry-manager.spec.js @@ -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, @@ -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); }); }); });