Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryT-CG committed Nov 9, 2024
1 parent 595e72c commit 2ceaa46
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
18 changes: 18 additions & 0 deletions src/app/shared/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand Down
15 changes: 4 additions & 11 deletions src/app/theme/theme-designer/theme-designer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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({})
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/app/theme/theme-detail/theme-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
}
})
Expand Down

0 comments on commit 2ceaa46

Please sign in to comment.