From 9f70a2b43809619fe55df638177bea0aa08ebd77 Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Wed, 9 Nov 2022 10:42:37 +0100
Subject: [PATCH] OZG-2966 OZG-3098 create export as pdf button; include button
 in vorgangdetail page

---
 .../postfach-mail-list.component.html         |  3 +
 .../postfach-mail-list.component.spec.ts      | 33 ++++++++++-
 .../postfach-mail-list.component.ts           |  3 +-
 ...h-mail-pdf-button-container.component.html |  7 +++
 ...h-mail-pdf-button-container.component.scss |  0
 ...ail-pdf-button-container.component.spec.ts | 56 +++++++++++++++++++
 ...ach-mail-pdf-button-container.component.ts | 23 ++++++++
 .../postfach-page-mail-list.component.html    |  8 +--
 8 files changed, 124 insertions(+), 9 deletions(-)
 create mode 100644 goofy-client/libs/postfach/src/lib/postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component.html
 create mode 100644 goofy-client/libs/postfach/src/lib/postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component.scss
 create mode 100644 goofy-client/libs/postfach/src/lib/postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component.spec.ts
 create mode 100644 goofy-client/libs/postfach/src/lib/postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component.ts

diff --git a/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail-list.component.html b/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail-list.component.html
index 6f9e266a9f..54b4e18157 100644
--- a/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail-list.component.html
+++ b/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail-list.component.html
@@ -1,4 +1,7 @@
 <h3 class="nachrichten">Nachrichten</h3>
+
+<goofy-client-postfach-mail-pdf-button-container *ngIf="vorgang | hasLink: vorgangHeaderLinkRel.POSTFACH_MAILS" data-test-id="postfach-pdf-button"></goofy-client-postfach-mail-pdf-button-container>
+
 <goofy-client-spinner [stateResource]="postfachMailListStateResource">
 	<goofy-client-postfach-mail *ngFor="let postfachMail of postfachMailListStateResource.resource | toEmbeddedResources: postfachMailListLinkRel.POSTFACH_MAIL_LIST"
 			class="postfach"
diff --git a/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail-list.component.spec.ts b/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail-list.component.spec.ts
index 26da81f55e..75b6d17989 100644
--- a/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail-list.component.spec.ts
+++ b/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail-list.component.spec.ts
@@ -3,9 +3,13 @@ import { PostfachMailListLinkRel } from '@goofy-client/postfach-shared';
 import { ConvertForDataTestPipe, createStateResource, HasLinkPipe, ToEmbeddedResourcesPipe } from '@goofy-client/tech-shared';
 import { getElementFromFixture } from '@goofy-client/test-utils';
 import { ExpansionPanelComponent, SpinnerComponent } from '@goofy-client/ui';
+import { VorgangHeaderLinkRel } from '@goofy-client/vorgang-shared';
 import { createPostfachMailListResource } from 'libs/postfach-shared/test/postfach';
+import { getDataTestIdOf } from 'libs/tech-shared/test/data-test';
+import { createVorgangWithEingangResource } from 'libs/vorgang-shared/test/vorgang';
 import { MockComponent } from 'ng-mocks';
 import { PostfachMailButtonContainerComponent } from '../../postfach-mail-button-container/postfach-mail-button-container.component';
+import { PostfachMailPdfButtonContainerComponent } from '../../postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component';
 import { PostfachMailListComponent } from './postfach-mail-list.component';
 import { PostfachMailComponent } from './postfach-mail/postfach-mail.component';
 
@@ -13,8 +17,9 @@ describe('PostfachMailListComponent', () => {
 	let component: PostfachMailListComponent;
 	let fixture: ComponentFixture<PostfachMailListComponent>;
 
-	const postfachMailButton: string = '[data-test-id="postfach-mail-button-container"]';
-	const noPostfachText: string = '[data-test-id="no-postfach-text"]';
+	const postfachMailButton: string = getDataTestIdOf('postfach-mail-button-container');
+	const noPostfachText: string = getDataTestIdOf('no-postfach-text');
+	const postfachPdfButton: string = getDataTestIdOf('postfach-pdf-button');
 
 	beforeEach(async () => {
 		await TestBed.configureTestingModule({
@@ -26,7 +31,8 @@ describe('PostfachMailListComponent', () => {
 				MockComponent(ExpansionPanelComponent),
 				MockComponent(PostfachMailComponent),
 				MockComponent(SpinnerComponent),
-				MockComponent(PostfachMailButtonContainerComponent)
+				MockComponent(PostfachMailButtonContainerComponent),
+				MockComponent(PostfachMailPdfButtonContainerComponent)
 			]
 		})
 			.compileComponents();
@@ -82,4 +88,25 @@ describe('PostfachMailListComponent', () => {
 			expect(button).toBeInstanceOf(HTMLElement);
 		})
 	})
+
+	describe('postfach pdf button', () => {
+
+		it('should show if link exist', () => {
+			component.vorgang = createVorgangWithEingangResource([VorgangHeaderLinkRel.POSTFACH_MAILS]);
+			fixture.detectChanges();
+
+			var pdfButtonElement = getElementFromFixture(fixture, postfachPdfButton);
+
+			expect(pdfButtonElement).toBeInTheDocument();
+		})
+
+		it('should hide if link is missing', () => {
+			component.vorgang = createVorgangWithEingangResource();
+			fixture.detectChanges();
+
+			var pdfButtonElement = getElementFromFixture(fixture, postfachPdfButton);
+
+			expect(pdfButtonElement).not.toBeInTheDocument();
+		})
+	})
 });
\ No newline at end of file
diff --git a/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail-list.component.ts b/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail-list.component.ts
index 971d850e37..b72ff2135e 100644
--- a/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail-list.component.ts
+++ b/goofy-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail-list.component.ts
@@ -1,7 +1,7 @@
 import { Component, Input } from '@angular/core';
 import { PostfachMailListLinkRel, PostfachMailListResource } from '@goofy-client/postfach-shared';
 import { StateResource } from '@goofy-client/tech-shared';
-import { VorgangWithEingangResource } from '@goofy-client/vorgang-shared';
+import { VorgangHeaderLinkRel, VorgangWithEingangResource } from '@goofy-client/vorgang-shared';
 
 @Component({
 	selector: 'goofy-client-postfach-mail-list',
@@ -14,4 +14,5 @@ export class PostfachMailListComponent {
 	@Input() vorgang: VorgangWithEingangResource;
 
 	readonly postfachMailListLinkRel = PostfachMailListLinkRel;
+	readonly vorgangHeaderLinkRel = VorgangHeaderLinkRel;
 }
diff --git a/goofy-client/libs/postfach/src/lib/postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component.html b/goofy-client/libs/postfach/src/lib/postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component.html
new file mode 100644
index 0000000000..17d1182452
--- /dev/null
+++ b/goofy-client/libs/postfach/src/lib/postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component.html
@@ -0,0 +1,7 @@
+<goofy-client-button-with-spinner data-test-id="send-mail-button"
+	[showSpinner]="isDownloadPdfInProgress | async"
+	text="download Pdf"
+	icon="add"
+	toolTip="Nachrichten als Pdf downloaden"
+	(clickEmitter)="downloadPdf()">
+</goofy-client-button-with-spinner>
\ No newline at end of file
diff --git a/goofy-client/libs/postfach/src/lib/postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component.scss b/goofy-client/libs/postfach/src/lib/postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component.scss
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/goofy-client/libs/postfach/src/lib/postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component.spec.ts b/goofy-client/libs/postfach/src/lib/postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component.spec.ts
new file mode 100644
index 0000000000..61af1dd5b6
--- /dev/null
+++ b/goofy-client/libs/postfach/src/lib/postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component.spec.ts
@@ -0,0 +1,56 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { PostfachService } from '@goofy-client/postfach-shared';
+import { Mock, mock } from '@goofy-client/test-utils';
+import { ButtonWithSpinnerComponent } from '@goofy-client/ui';
+import { MockComponent } from 'ng-mocks';
+import { PostfachMailPdfButtonContainerComponent } from './postfach-mail-pdf-button-container.component';
+
+describe('PostfachMailPdfButtonContainerComponent', () => {
+	let component: PostfachMailPdfButtonContainerComponent;
+	let fixture: ComponentFixture<PostfachMailPdfButtonContainerComponent>;
+
+	const postfachService: Mock<PostfachService> = mock(PostfachService);
+
+	beforeEach(async () => {
+		await TestBed.configureTestingModule({
+			declarations: [
+				PostfachMailPdfButtonContainerComponent,
+				MockComponent(ButtonWithSpinnerComponent)
+			],
+			providers: [
+				{
+					provide: PostfachService,
+					useValue: postfachService
+				}
+			]
+		}).compileComponents();
+
+		fixture = TestBed.createComponent(
+			PostfachMailPdfButtonContainerComponent
+		);
+		component = fixture.componentInstance;
+		fixture.detectChanges();
+	});
+
+	it('should create', () => {
+		expect(component).toBeTruthy();
+	});
+
+	describe('ngOnInit', () => {
+
+		it('should call postfachService', () => {
+			component.ngOnInit();
+
+			expect(postfachService.isDownloadPdfInProgress).toHaveBeenCalled();
+		})
+	})
+
+	describe('downloadPdf', () => {
+
+		it('should call service', () => {
+			component.downloadPdf();
+
+			expect(postfachService.downloadPdf).toHaveBeenCalled();
+		})
+	})
+});
diff --git a/goofy-client/libs/postfach/src/lib/postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component.ts b/goofy-client/libs/postfach/src/lib/postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component.ts
new file mode 100644
index 0000000000..96b91a8b5e
--- /dev/null
+++ b/goofy-client/libs/postfach/src/lib/postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component.ts
@@ -0,0 +1,23 @@
+import { Component, OnInit } from '@angular/core';
+import { PostfachService } from '@goofy-client/postfach-shared';
+import { Observable } from 'rxjs';
+
+@Component({
+	selector: 'goofy-client-postfach-mail-pdf-button-container',
+	templateUrl: './postfach-mail-pdf-button-container.component.html',
+	styleUrls: ['./postfach-mail-pdf-button-container.component.scss'],
+})
+export class PostfachMailPdfButtonContainerComponent implements OnInit {
+
+	isDownloadPdfInProgress: Observable<boolean>;
+
+	constructor(private postfachService: PostfachService) { }
+
+	ngOnInit(): void {
+		this.isDownloadPdfInProgress = this.postfachService.isDownloadPdfInProgress();
+	}
+
+	downloadPdf(): void {
+		this.postfachService.downloadPdf();
+	}
+}
\ No newline at end of file
diff --git a/goofy-client/libs/postfach/src/lib/postfach-page-container/postfach-page/postfach-page-mail-list/postfach-page-mail-list.component.html b/goofy-client/libs/postfach/src/lib/postfach-page-container/postfach-page/postfach-page-mail-list/postfach-page-mail-list.component.html
index c93b9a30e9..1a365c2f03 100644
--- a/goofy-client/libs/postfach/src/lib/postfach-page-container/postfach-page/postfach-page-mail-list/postfach-page-mail-list.component.html
+++ b/goofy-client/libs/postfach/src/lib/postfach-page-container/postfach-page/postfach-page-mail-list/postfach-page-mail-list.component.html
@@ -1,10 +1,8 @@
 <goofy-client-spinner *ngIf="postfachMailListStateResource">
 
-	<goofy-client-postfach-mail
-			*ngFor="let postfachMail of postfachMailListStateResource.resource | toEmbeddedResources: postfachMailListLinkRel.POSTFACH_MAIL_LIST"
-			[postfachMail]="postfachMail"
-			class="postfach postfach-links-disabled"
-			[attr.data-test-id]="(postfachMail.subject | convertForDataTest) + '-item'">
+	<goofy-client-postfach-mail *ngFor="let postfachMail of postfachMailListStateResource.resource | toEmbeddedResources: postfachMailListLinkRel.POSTFACH_MAIL_LIST" [attr.data-test-id]="(postfachMail.subject | convertForDataTest) + '-item'"
+		class="postfach postfach-links-disabled"
+		[postfachMail]="postfachMail">
 	</goofy-client-postfach-mail>
 
 </goofy-client-spinner>
-- 
GitLab