From c01a20216b4f96d8bc95993b599093f2c50879b7 Mon Sep 17 00:00:00 2001 From: "AAVN\\pvquan" Date: Wed, 25 Dec 2024 18:40:38 +0700 Subject: [PATCH] enhance FE unit test --- .../release-preview.component.html | 2 +- .../release-preview.component.ts | 40 +++++-------------- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/marketplace-ui/src/app/modules/release-preview/release-preview.component.html b/marketplace-ui/src/app/modules/release-preview/release-preview.component.html index 8865d982..8bdc8b58 100644 --- a/marketplace-ui/src/app/modules/release-preview/release-preview.component.html +++ b/marketplace-ui/src/app/modules/release-preview/release-preview.component.html @@ -72,7 +72,7 @@

[selectedItem]="getSelectedTabLabel() | translate" buttonClass="form-select flex-grow-1 text-start content-tab-dropdown" (itemSelected)=" - onTabChange($event.value) + setActiveTab($event.value) "> diff --git a/marketplace-ui/src/app/modules/release-preview/release-preview.component.ts b/marketplace-ui/src/app/modules/release-preview/release-preview.component.ts index 85598017..52af3ab7 100644 --- a/marketplace-ui/src/app/modules/release-preview/release-preview.component.ts +++ b/marketplace-ui/src/app/modules/release-preview/release-preview.component.ts @@ -74,12 +74,8 @@ export class ReleasePreviewComponent { this.handlePreviewPage(); } - setActiveTab(tab: string): void { - this.activeTab = tab; - } - - onTabChange(event: string) { - this.setActiveTab(event); + setActiveTab(event: string): void { + this.activeTab = event; } handlePreviewPage(): void { @@ -108,32 +104,18 @@ export class ReleasePreviewComponent { getContent(value: string): boolean { const content = this.readmeContent(); - if (!content || Object.keys(content).length === 0) { - return false; - } - - const conditions: { [key: string]: boolean } = { - description: - content.description !== null && - CommonUtils.isContentDisplayedBasedOnLanguage( - content.description, - this.languageService.selectedLanguage() - ), - demo: - content.demo !== null && - CommonUtils.isContentDisplayedBasedOnLanguage( - content.demo, - this.languageService.selectedLanguage() - ), - setup: - content.setup !== null && + if (content && content[value as keyof ReleasePreviewData]) { + const tabContent = content[value as keyof ReleasePreviewData]; + return ( + tabContent != null && + Object.keys(tabContent).length > 0 && CommonUtils.isContentDisplayedBasedOnLanguage( - content.setup, + tabContent, this.languageService.selectedLanguage() ) - }; - - return conditions[value] ?? false; + ); + } + return false; } getSelectedTabLabel() {