From 247a8ccfb0d9830b3e875009c795cb769d9a091c Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Mon, 9 Sep 2024 12:42:56 +0200 Subject: [PATCH] OZG-6499 OZG-6620 add newline to mail body --- .../libs/postfach-shared/test/postfach.ts | 4 ++++ .../postfach-mail.formservice.spec.ts | 18 +++++++++++++----- .../postfach-mail.formservice.ts | 14 +++++++++++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/alfa-client/libs/postfach-shared/test/postfach.ts b/alfa-client/libs/postfach-shared/test/postfach.ts index 4127e34f93..0ca6f2c9f3 100644 --- a/alfa-client/libs/postfach-shared/test/postfach.ts +++ b/alfa-client/libs/postfach-shared/test/postfach.ts @@ -83,6 +83,10 @@ export function createPostfachSettings(): PostfachSettings { return { signatur: 'Best regards' }; } +export function createEmptyPostfachSettings(): PostfachSettings { + return { signatur: '' }; +} + export class PostfachTestFactory { public static POSTFACH_NACHRICHT: PostfachMail = { subject: faker.random.words(3), diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.spec.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.spec.ts index c2773a73eb..fbf54ddd0d 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.spec.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.spec.ts @@ -28,6 +28,7 @@ import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; import { UntypedFormBuilder } from '@angular/forms'; import { createCommandResource } from 'libs/command-shared/test/command'; import { + createEmptyPostfachSettings, createPostfachMailResource, createPostfachSettings, } from 'libs/postfach-shared/test/postfach'; @@ -36,15 +37,13 @@ import { PostfachMailFormservice } from './postfach-mail.formservice'; describe('PostfachMailFormservice', () => { let formService: PostfachMailFormservice; - let service: Mock<any>; + let service: Mock<any> = mock(PostfachService); const formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); const postfachSettings: PostfachSettings = createPostfachSettings(); beforeEach(() => { - service = mock(PostfachService); service.getSettings.mockReturnValue(of(postfachSettings)); - formService = new PostfachMailFormservice(formBuilder, useFromMock(service)); }); @@ -97,12 +96,21 @@ describe('PostfachMailFormservice', () => { expect(service.getSettings).toHaveBeenCalled(); }); - it('should init mail body with signatur', () => { + it('should set field mail body with signatur and newline if signatur is not empty', () => { formService.initMailBody(); const mailBodyValue = formService.form.get(PostfachMailFormservice.FIELD_MAIL_BODY).value; + expect(mailBodyValue).toBe(`\n${postfachSettings.signatur}`); + }); + + it('should not set field mail body if signatur is empty', () => { + service.getSettings.mockReturnValue(of(createEmptyPostfachSettings())); + formService = new PostfachMailFormservice(formBuilder, useFromMock(service)); - expect(mailBodyValue).toBe(postfachSettings.signatur); + formService.initMailBody(); + + const mailBodyValue = formService.form.get(PostfachMailFormservice.FIELD_MAIL_BODY).value; + expect(mailBodyValue).toBe(null); }); }); }); diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.ts index ad2e99d1f8..0b5beafc1a 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.ts @@ -66,11 +66,23 @@ export class PostfachMailFormservice extends AbstractFormService { this.loadPostfachSettingsSubscription = this.postfachService .getSettings() .subscribe((settings: PostfachSettings) => { - this.form.get(PostfachMailFormservice.FIELD_MAIL_BODY)?.setValue(settings.signatur); + if (settings.signatur) { + this.patchMailBodyWithSignaturAndNewline(settings.signatur); + } this.loadPostfachSettingsSubscription.unsubscribe(); }); } + private patchMailBodyWithSignaturAndNewline(signatur: string) { + this.form + .get(PostfachMailFormservice.FIELD_MAIL_BODY) + .setValue(this.addNewlineAtBeginning(signatur)); + } + + private addNewlineAtBeginning(value: string): string { + return `\n${value}`; + } + protected getPathPrefix(): string { return PostfachMailFormservice.FIELD_PATH_PREFIX; } -- GitLab