From 3cd6bf52c23f2f6a56ba4c9a73114dad082c36c6 Mon Sep 17 00:00:00 2001 From: Piotrek Zadroga Date: Tue, 29 Oct 2024 13:24:25 +0100 Subject: [PATCH] [#222] don't emit error for empty version --- .../version-status/version-status.component.spec.ts | 13 +++++++++++++ .../app/version-status/version-status.component.ts | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/webui/src/app/version-status/version-status.component.spec.ts b/webui/src/app/version-status/version-status.component.spec.ts index 6ea3500e..61134efe 100644 --- a/webui/src/app/version-status/version-status.component.spec.ts +++ b/webui/src/app/version-status/version-status.component.spec.ts @@ -220,4 +220,17 @@ describe('VersionStatusComponent', () => { let messagesDiv = fixture.nativeElement.querySelector('div.p-messages') expect(messagesDiv).toBeTruthy() }) + + it('should not display feedback when version undefined', () => { + // Arrange + fixture.componentRef.setInput('version', undefined) + fixture.componentRef.setInput('app', 'kea') + fixture.detectChanges() + + // Act & Assert + // No feedback messages are expected. + expect(component.feedbackMessages.length).toEqual(0) + // No error message should be emitted. + expect(messageAddSpy).toHaveBeenCalledTimes(0) + }) }) diff --git a/webui/src/app/version-status/version-status.component.ts b/webui/src/app/version-status/version-status.component.ts index 8f1ef369..bbd761cb 100644 --- a/webui/src/app/version-status/version-status.component.ts +++ b/webui/src/app/version-status/version-status.component.ts @@ -101,6 +101,12 @@ export class VersionStatusComponent implements OnInit, OnDestroy { ngOnInit(): void { this._appName = this.app === 'bind9' ? this.app.toUpperCase() : this.app[0].toUpperCase() + this.app.slice(1) this._appName += this.app === 'stork' ? ' agent' : '' + if (!this.version) { + // Version is a mandatory input. In case it is falsy (undefined, null, empty string), + // simply return. No feedback will be displayed. + return + } + let sanitizedSemver = this.versionService.sanitizeSemver(this.version) if (sanitizedSemver) { this.version = sanitizedSemver