From da211897b586c08c4d227ff1690c986d396c9f66 Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Wed, 4 Sep 2024 13:49:46 +0200
Subject: [PATCH] OZG-6620 place signatur in postfach mails

---
 .../postfach-shared/src/lib/postfach.model.ts | 10 ++++--
 .../src/lib/postfach.service.spec.ts          | 19 ++++++++++--
 .../src/lib/postfach.service.ts               | 14 +++++++--
 .../libs/postfach-shared/test/postfach.ts     | 20 +++++++++---
 .../postfach-mail-form.component.html         |  1 +
 .../postfach-mail-form.component.spec.ts      | 31 ++++++++++++++-----
 .../postfach-mail-form.component.ts           |  5 +++
 .../postfach-mail.formservice.spec.ts         | 27 ++++++++++++++--
 .../postfach-mail.formservice.ts              | 14 ++++++---
 ...hricht-reply-editor-container.component.ts |  6 ++--
 .../textarea-editor.component.html            |  1 +
 .../textarea-editor.component.ts              |  1 +
 12 files changed, 122 insertions(+), 27 deletions(-)

diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.model.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.model.ts
index e0da72cebb..2a984d4ddb 100644
--- a/alfa-client/libs/postfach-shared/src/lib/postfach.model.ts
+++ b/alfa-client/libs/postfach-shared/src/lib/postfach.model.ts
@@ -62,7 +62,8 @@ export interface CreatePostfachMailCommand extends CreateCommand {
 export interface PostfachMailResource extends Resource, PostfachMail {}
 
 export interface PostfachMailListResource extends ListResource {
-  features: Features;
+  features: PostfachFeatures;
+  settings: PostfachSettings;
 }
 
 export enum PostfachNachrichtenCount {
@@ -80,7 +81,10 @@ export interface PostfachMailFormDialogData extends FixedDialogData {
   postfachNachricht?: PostfachMailResource;
 }
 
-export interface Features {
-  //TODO Rename to PostfachFeatures
+export interface PostfachFeatures {
   reply: boolean;
 }
+
+export interface PostfachSettings {
+  signatur: string;
+}
diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.service.spec.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.service.spec.ts
index 1d00b7d41a..3d23e1126c 100644
--- a/alfa-client/libs/postfach-shared/src/lib/postfach.service.spec.ts
+++ b/alfa-client/libs/postfach-shared/src/lib/postfach.service.spec.ts
@@ -21,7 +21,6 @@
  * Die sprachspezifischen Genehmigungen und Beschränkungen
  * unter der Lizenz sind dem Lizenztext zu entnehmen.
  */
-import { MatDialog } from '@angular/material/dialog';
 import {
   BinaryFileListResource,
   BinaryFileResource,
@@ -37,6 +36,7 @@ import {
 import { Mock, mock, useFromMock } from '@alfa-client/test-utils';
 import { SnackBarService } from '@alfa-client/ui';
 import { VorgangService, VorgangWithEingangResource } from '@alfa-client/vorgang-shared';
+import { MatDialog } from '@angular/material/dialog';
 import {
   createBinaryFileListResource,
   createBinaryFileResource,
@@ -49,9 +49,11 @@ import {
 import { createVorgangWithEingangResource } from 'libs/vorgang-shared/test/vorgang';
 import { BehaviorSubject, of } from 'rxjs';
 import {
+  createPostfachFeatures,
   createPostfachMail,
   createPostfachMailListResource,
   createPostfachMailResource,
+  createPostfachSettings,
 } from '../../test/postfach';
 import { PostfachFacade } from './+state/postfach.facade';
 import { PostfachMailLinkRel, PostfachMailListLinkRel } from './postfach.linkrel';
@@ -630,7 +632,20 @@ describe('PostfachService', () => {
       );
 
       service.getFeatures().subscribe((features) => {
-        expect(features).toEqual({ reply: true });
+        expect(features).toEqual(createPostfachFeatures());
+        done();
+      });
+    });
+  });
+
+  describe('getSettings', () => {
+    it('should return settings by list stateResource', (done) => {
+      service.postfachMailList$ = new BehaviorSubject(
+        createStateResource(createPostfachMailListResource()),
+      );
+
+      service.getSettings().subscribe((settings) => {
+        expect(settings).toEqual(createPostfachSettings());
         done();
       });
     });
diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts
index f4bc26e468..4fda384295 100644
--- a/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts
+++ b/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts
@@ -58,10 +58,11 @@ import { PostfachMailLinkRel, PostfachMailListLinkRel } from './postfach.linkrel
 import { PostfachMessages } from './postfach.message';
 import {
   CreatePostfachMailCommand,
-  Features,
+  PostfachFeatures,
   PostfachMail,
   PostfachMailListResource,
   PostfachMailResource,
+  PostfachSettings,
 } from './postfach.model';
 import { PostfachRepository } from './postfach.repository';
 import { createResendPostfachMailCommand, createSendPostfachMailCommand } from './postfach.util';
@@ -372,7 +373,7 @@ export class PostfachService {
     this.postfachFacade.clearAttachmentList();
   }
 
-  public getFeatures(): Observable<Features> {
+  public getFeatures(): Observable<PostfachFeatures> {
     return this.getPostfachMailListByVorgang().pipe(
       map(
         (listStateResource: StateResource<PostfachMailListResource>) =>
@@ -380,4 +381,13 @@ export class PostfachService {
       ),
     );
   }
+
+  public getSettings(): Observable<PostfachSettings> {
+    return this.getPostfachMailListByVorgang().pipe(
+      map(
+        (listStateResource: StateResource<PostfachMailListResource>) =>
+          listStateResource.resource.settings,
+      ),
+    );
+  }
 }
diff --git a/alfa-client/libs/postfach-shared/test/postfach.ts b/alfa-client/libs/postfach-shared/test/postfach.ts
index fb0fa71451..4127e34f93 100644
--- a/alfa-client/libs/postfach-shared/test/postfach.ts
+++ b/alfa-client/libs/postfach-shared/test/postfach.ts
@@ -21,8 +21,8 @@
  * Die sprachspezifischen Genehmigungen und Beschränkungen
  * unter der Lizenz sind dem Lizenztext zu entnehmen.
  */
-import { faker } from '@faker-js/faker';
 import { EMPTY_ARRAY, createStateResource } from '@alfa-client/tech-shared';
+import { faker } from '@faker-js/faker';
 import { Resource } from '@ngxp/rest';
 import { toResource } from 'libs/tech-shared/test/resource';
 import { times } from 'lodash-es';
@@ -30,10 +30,12 @@ import { PostfachMailListLinkRel } from '../src/lib/postfach.linkrel';
 import { PostfachNachrichtMessageCode } from '../src/lib/postfach.message-code';
 import {
   Direction,
+  PostfachFeatures,
   PostfachMail,
   PostfachMailFormDialogData,
   PostfachMailListResource,
   PostfachMailResource,
+  PostfachSettings,
   ReplyOption,
 } from '../src/lib/postfach.model';
 
@@ -62,13 +64,23 @@ export function createPostfachMailResources(linkRelations: string[] = []): Postf
 export function createPostfachMailListResource(
   linkRelations: string[] = [],
 ): PostfachMailListResource {
-  return toResource(createPostfachMailListWithAllowedReplyFeature(), [...linkRelations], {
+  return toResource(createPostfachMailList(), [...linkRelations], {
     [PostfachMailListLinkRel.POSTFACH_MAIL_LIST]: createPostfachMailResources(),
   });
 }
 
-function createPostfachMailListWithAllowedReplyFeature(): Resource {
-  return toResource({ features: { reply: true } }, ['sendPostfachMail']);
+function createPostfachMailList(): Resource {
+  return toResource({ features: createPostfachFeatures(), settings: createPostfachSettings() }, [
+    'sendPostfachMail',
+  ]);
+}
+
+export function createPostfachFeatures(): PostfachFeatures {
+  return { reply: true };
+}
+
+export function createPostfachSettings(): PostfachSettings {
+  return { signatur: 'Best regards' };
 }
 
 export class PostfachTestFactory {
diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.html b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.html
index cea292daf1..f9051a515a 100644
--- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.html
+++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.html
@@ -40,6 +40,7 @@
     [formControlName]="formServiceClass.FIELD_MAIL_BODY"
     label="Text"
     class="message-editor mt-3"
+    [value]="signatur"
     [autoFocus]="true"
     [required]="true"
   >
diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.spec.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.spec.ts
index 40d4bc90cd..466c580e54 100644
--- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.spec.ts
+++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.spec.ts
@@ -21,12 +21,6 @@
  * Die sprachspezifischen Genehmigungen und Beschränkungen
  * unter der Lizenz sind dem Lizenztext zu entnehmen.
  */
-import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
-import { MAT_DIALOG_DATA } from '@angular/material/dialog';
-import { MatFormFieldModule } from '@angular/material/form-field';
-import { MatInputModule } from '@angular/material/input';
-import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
 import { PostfachService } from '@alfa-client/postfach-shared';
 import { createStateResource } from '@alfa-client/tech-shared';
 import { Mock, mock, useFromMock } from '@alfa-client/test-utils';
@@ -39,8 +33,14 @@ import {
   TextAreaEditorComponent,
   TextEditorComponent,
 } from '@alfa-client/ui';
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
+import { MAT_DIALOG_DATA } from '@angular/material/dialog';
+import { MatFormFieldModule } from '@angular/material/form-field';
+import { MatInputModule } from '@angular/material/input';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
 import { createCommandResource } from 'libs/command-shared/test/command';
-import { PostfachTestFactory } from 'libs/postfach-shared/test/postfach';
+import { PostfachTestFactory, createPostfachSettings } from 'libs/postfach-shared/test/postfach';
 import { MockComponent } from 'ng-mocks';
 import { of } from 'rxjs';
 import { PostfachMailFormComponent } from './postfach-mail-form.component';
@@ -55,6 +55,9 @@ describe('PostfachMailFormComponent', () => {
   let fixture: ComponentFixture<PostfachMailFormComponent>;
 
   const postfachService: Mock<PostfachService> = mock(PostfachService);
+  const postfachSettings = createPostfachSettings();
+  postfachService.getSettings.mockReturnValue(of(postfachSettings));
+
   const formService: PostfachMailFormservice = new PostfachMailFormservice(
     new FormBuilder(),
     useFromMock(postfachService),
@@ -122,6 +125,20 @@ describe('PostfachMailFormComponent', () => {
         expect(component.patchPostfachNachricht).toHaveBeenCalled();
       });
     });
+
+    describe('on setting signatur', () => {
+      it('should call postfachService', () => {
+        component.ngOnInit();
+
+        expect(postfachService.getSettings).toHaveBeenCalled();
+      });
+
+      it('should set signatur', () => {
+        component.ngOnInit();
+
+        expect(component.signatur).toBe(postfachSettings.signatur);
+      });
+    });
   });
 
   describe('patchPostfachNachricht', () => {
diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.ts
index 6335536d0f..f49b402a43 100644
--- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.ts
+++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.ts
@@ -40,6 +40,7 @@ import * as CommandUtil from '../../../../command-shared/src/lib/command.util';
 })
 export class PostfachMailFormComponent implements OnInit {
   public readonly formServiceClass = PostfachMailFormservice;
+  public signatur = '';
 
   public sendInProgress$: Observable<StateResource<CommandResource>> = of(
     createEmptyStateResource<CommandResource>(),
@@ -55,6 +56,10 @@ export class PostfachMailFormComponent implements OnInit {
     if (isNotNil(this.dialogData.postfachNachricht)) {
       this.patchPostfachNachricht();
     }
+
+    this.formService.getSignatur().subscribe((signatur: string) => {
+      this.signatur = signatur;
+    });
   }
 
   patchPostfachNachricht(): void {
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 0825838a83..ac21899898 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
@@ -21,13 +21,16 @@
  * Die sprachspezifischen Genehmigungen und Beschränkungen
  * unter der Lizenz sind dem Lizenztext zu entnehmen.
  */
-import { UntypedFormBuilder } from '@angular/forms';
 import { CommandResource } from '@alfa-client/command-shared';
 import { PostfachService } from '@alfa-client/postfach-shared';
 import { StateResource, createStateResource } from '@alfa-client/tech-shared';
 import { Mock, mock, useFromMock } from '@alfa-client/test-utils';
+import { UntypedFormBuilder } from '@angular/forms';
 import { createCommandResource } from 'libs/command-shared/test/command';
-import { createPostfachMailResource } from 'libs/postfach-shared/test/postfach';
+import {
+  createPostfachMailResource,
+  createPostfachSettings,
+} from 'libs/postfach-shared/test/postfach';
 import { of } from 'rxjs';
 import { PostfachMailFormservice } from './postfach-mail.formservice';
 
@@ -84,4 +87,24 @@ describe('PostfachMailFormservice', () => {
       });
     });
   });
+
+  describe('get signatur', () => {
+    const postfachSettings = createPostfachSettings();
+
+    beforeEach(() => {
+      service.getSettings.mockReturnValue(of(postfachSettings));
+    });
+
+    it('should call service', () => {
+      formService.getSignatur().subscribe(() => {
+        expect(service.getSettings).toHaveBeenCalled();
+      });
+    });
+
+    it('should return signatur', () => {
+      formService.getSignatur().subscribe((signatur) => {
+        expect(signatur).toBe(postfachSettings.signatur);
+      });
+    });
+  });
 });
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 3e7de900cd..51293968c4 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
@@ -21,6 +21,9 @@
  * Die sprachspezifischen Genehmigungen und Beschränkungen
  * unter der Lizenz sind dem Lizenztext zu entnehmen.
  */
+import { CommandResource } from '@alfa-client/command-shared';
+import { PostfachService, PostfachSettings } from '@alfa-client/postfach-shared';
+import { AbstractFormService, StateResource } from '@alfa-client/tech-shared';
 import { Injectable } from '@angular/core';
 import {
   UntypedFormArray,
@@ -28,11 +31,8 @@ import {
   UntypedFormControl,
   UntypedFormGroup,
 } from '@angular/forms';
-import { CommandResource } from '@alfa-client/command-shared';
-import { PostfachService } from '@alfa-client/postfach-shared';
-import { AbstractFormService, StateResource } from '@alfa-client/tech-shared';
 import { ReplyOption } from 'libs/postfach-shared/src/lib/postfach.model';
-import { Observable } from 'rxjs';
+import { Observable, map } from 'rxjs';
 
 @Injectable()
 export class PostfachMailFormservice extends AbstractFormService {
@@ -70,4 +70,10 @@ export class PostfachMailFormservice extends AbstractFormService {
       return this.postfachService.sendMail(this.getFormValue());
     }
   }
+
+  public getSignatur(): Observable<string> {
+    return this.postfachService
+      .getSettings()
+      .pipe(map((settings: PostfachSettings) => settings.signatur));
+  }
 }
diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.ts
index 1e6ae6bea4..71a0fc57de 100644
--- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.ts
+++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.ts
@@ -1,12 +1,12 @@
-import { Component, OnInit } from '@angular/core';
 import {
-  Features,
   FORBIDDEN_REPLY_OPTION_ITEM,
   POSSIBLE_REPLY_OPTION_ITEM,
+  PostfachFeatures,
   PostfachService,
 } from '@alfa-client/postfach-shared';
 import { FormProvider } from '@alfa-client/tech-shared';
 import { CheckboxEnumEditorItem } from '@alfa-client/ui';
+import { Component, OnInit } from '@angular/core';
 import { Observable } from 'rxjs';
 import { PostfachMailFormservice } from '../postfach-mail.formservice';
 
@@ -19,7 +19,7 @@ import { PostfachMailFormservice } from '../postfach-mail.formservice';
 export class PostfachNachrichtReplyEditorContainerComponent implements OnInit {
   public readonly formServiceClass = PostfachMailFormservice;
 
-  public postfachFeatures$: Observable<Features>;
+  public postfachFeatures$: Observable<PostfachFeatures>;
 
   public checkedItem: CheckboxEnumEditorItem = POSSIBLE_REPLY_OPTION_ITEM;
   public uncheckedItem: CheckboxEnumEditorItem = FORBIDDEN_REPLY_OPTION_ITEM;
diff --git a/alfa-client/libs/ui/src/lib/ui/editor/textarea-editor/textarea-editor.component.html b/alfa-client/libs/ui/src/lib/ui/editor/textarea-editor/textarea-editor.component.html
index 14034ce169..67f8f93bac 100644
--- a/alfa-client/libs/ui/src/lib/ui/editor/textarea-editor/textarea-editor.component.html
+++ b/alfa-client/libs/ui/src/lib/ui/editor/textarea-editor/textarea-editor.component.html
@@ -29,6 +29,7 @@
   <textarea
     #autosize="cdkTextareaAutosize"
     placeholder="{{ placeholder }}"
+    value="{{ value }}"
     matInput
     cdkTextareaAutosize
     [formControl]="fieldControl"
diff --git a/alfa-client/libs/ui/src/lib/ui/editor/textarea-editor/textarea-editor.component.ts b/alfa-client/libs/ui/src/lib/ui/editor/textarea-editor/textarea-editor.component.ts
index 12d1e2d490..b6ae8c8bb3 100644
--- a/alfa-client/libs/ui/src/lib/ui/editor/textarea-editor/textarea-editor.component.ts
+++ b/alfa-client/libs/ui/src/lib/ui/editor/textarea-editor/textarea-editor.component.ts
@@ -37,6 +37,7 @@ export class TextAreaEditorComponent
   @ViewChild('autosize') autosize: CdkTextareaAutosize;
 
   @Input() placeholder: string;
+  @Input() value: string = '';
   @Input() label: string = '';
   @Input() appearance: 'outline' | 'fill' = 'fill';
   @Input() required: boolean = false;
-- 
GitLab