From 2ceaa462269aa1c1c21c875230b16f6a131d73df Mon Sep 17 00:00:00 2001 From: Henry Taeschner Date: Sat, 9 Nov 2024 15:53:09 +0100 Subject: [PATCH] fix: tests --- src/app/shared/utils.spec.ts | 18 ++++++++++++++++++ src/app/shared/utils.ts | 4 ++-- .../theme-designer/theme-designer.component.ts | 15 ++++----------- .../theme-detail/theme-detail.component.ts | 2 +- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/app/shared/utils.spec.ts b/src/app/shared/utils.spec.ts index f06c58a..44468e3 100644 --- a/src/app/shared/utils.spec.ts +++ b/src/app/shared/utils.spec.ts @@ -125,6 +125,24 @@ describe('util functions', () => { }) describe('bffImageUrl', () => { + it('should return a correct image path', () => { + const basePath = 'base' + const name = 'name' + + const preparedUrl = bffImageUrl(basePath, name, RefType.Logo) + + expect(preparedUrl).toBe('base/images/name/logo') + }) + + it('should return a path without base', () => { + const basePath = undefined + const name = 'name' + + const preparedUrl = bffImageUrl(basePath, name) + + expect(preparedUrl).toBe('/images/name/logo') + }) + it('should return empty string if no name is provided', () => { const basePath = 'base' const name = undefined diff --git a/src/app/shared/utils.ts b/src/app/shared/utils.ts index 33c7e02..c2cd237 100644 --- a/src/app/shared/utils.ts +++ b/src/app/shared/utils.ts @@ -44,8 +44,8 @@ export function prepareUrlPath(url?: string, path?: string): string { else if (url) return url else return '' } -export function bffImageUrl(basePath: string | undefined, name: string | undefined, refType: RefType): string { - return !name ? '' : basePath + '/images/' + name + '/' + refType +export function bffImageUrl(basePath: string | undefined, name: string | undefined, refType?: RefType): string { + return !name ? '' : (basePath ?? '') + '/images/' + name + '/' + (refType ?? RefType.Logo) } /** diff --git a/src/app/theme/theme-designer/theme-designer.component.ts b/src/app/theme/theme-designer/theme-designer.component.ts index 9a0121d..ef23968 100644 --- a/src/app/theme/theme-designer/theme-designer.component.ts +++ b/src/app/theme/theme-designer/theme-designer.component.ts @@ -39,7 +39,7 @@ export class ThemeDesignerComponent implements OnInit { public copyOfPrefix: string | undefined public themeVars = themeVariables public themeTemplates!: SelectItem[] - public bffImagePath = '' + public bffImagePath: string | undefined public fetchingLogoUrl?: string public fetchingFaviconUrl?: string public imageLogoUrlExists = false @@ -76,7 +76,7 @@ export class ThemeDesignerComponent implements OnInit { ) { this.changeMode = route.snapshot.paramMap.has('name') ? 'EDIT' : 'CREATE' this.themeName = route.snapshot.paramMap.get('name') - this.bffImagePath = this.imageApi.configuration.basePath! + this.bffImagePath = this.imageApi.configuration.basePath this.prepareActionButtons() this.fontForm = new FormGroup({}) @@ -320,19 +320,12 @@ export class ThemeDesignerComponent implements OnInit { public onShowSaveAsDialog(): void { const basicFormName = this.basicForm.controls['name'].value const basicFormDisplayName = this.basicForm.controls['displayName'].value - this.updateSaveAsElement(this.saveAsThemeName, this.copyOfPrefix + basicFormName) - this.updateSaveAsElement(this.saveAsThemeDisplayName, this.copyOfPrefix + basicFormDisplayName) - } - - private updateSaveAsElement(saveAsElement: ElementRef | undefined, newValue: string): void { - if (saveAsElement) { - saveAsElement.nativeElement.value = newValue - } + this.saveAsThemeName!.nativeElement.value = this.copyOfPrefix + basicFormName + this.saveAsThemeDisplayName!.nativeElement.value = this.copyOfPrefix + basicFormDisplayName } // EDIT private updateTheme(): void { - console.log('updateTheme') this.themeApi .getThemeByName({ name: this.themeName! }) .pipe( diff --git a/src/app/theme/theme-detail/theme-detail.component.ts b/src/app/theme/theme-detail/theme-detail.component.ts index b439dcc..0ab63cb 100644 --- a/src/app/theme/theme-detail/theme-detail.component.ts +++ b/src/app/theme/theme-detail/theme-detail.component.ts @@ -176,7 +176,7 @@ export class ThemeDetailComponent implements OnInit, AfterViewInit { ) }, error: (err) => { - console.log(err) + console.error(err) this.msgService.error({ summaryKey: 'ACTIONS.EXPORT.EXPORT_THEME_FAIL' }) } })