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 ba5855b3d3b59607a10a65179a6af92cad3a39aa..08fe1caa948dd2a6c4f4c200d45d2b331bdd87af 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 @@ -26,6 +26,7 @@ import { CommandResource, CommandService } from '@alfa-client/command-shared'; import { NavigationFacade, NavigationService, RouteData } from '@alfa-client/navigation-shared'; import { createEmptyStateResource, + createErrorStateResource, createLoadingStateResource, createStateResource, StateResource, @@ -43,6 +44,7 @@ import { CommandLinkRel } from 'libs/command-shared/src/lib/command.linkrel'; import { createCommandErrorResource, createCommandResource } from 'libs/command-shared/test/command'; import { createVorgangWithEingangResource } from 'libs/vorgang-shared/test/vorgang'; import { BehaviorSubject, Observable, of } from 'rxjs'; +import { createProblemDetail } from '../../../tech-shared/test/error'; import { multipleCold, singleColdCompleted, singleHot } from '../../../tech-shared/test/marbles'; import { createPostfachFeatures, @@ -513,14 +515,12 @@ describe('PostfachService', () => { }); describe('loadPostfachMailList', () => { - const postfachMailList: PostfachMailListResource = createPostfachMailListResource(); - beforeEach(() => { - repository.loadPostfachMailList.mockReturnValue(of(postfachMailList)); service._setPostfachMailListLoading = jest.fn(); - service._setPostfachMailList = jest.fn(); - vorgangService.getVorgangWithEingang.mockReturnValue(of(createStateResource(createVorgangWithEingangResource()))); + service._handleVorgangError = jest.fn(); + service.loadPostfachMailsByVorgang = jest.fn(); }); + it('should set loading to true', () => { service._loadPostfachMailList(); @@ -533,16 +533,38 @@ describe('PostfachService', () => { expect(vorgangService.getVorgangWithEingang).toHaveBeenCalled(); }); - it('should call repository', () => { + it('should handle vorgang error', () => { service._loadPostfachMailList(); - expect(repository.loadPostfachMailList).toHaveBeenCalled(); + expect(service._handleVorgangError).toHaveBeenCalledWith(vorgangWithEingangStateResource); }); - it('should set loading to false', () => { + it('should call loadPostfachMailsByVorgang', () => { service._loadPostfachMailList(); - expect(service._setPostfachMailList).toHaveBeenCalled(); + expect(service.loadPostfachMailsByVorgang).toHaveBeenCalledWith(vorgang); + }); + }); + + describe('handleVorgangError', () => { + beforeEach(() => { + service.postfachMailList$.next = jest.fn(); + }); + + it('should set error', () => { + const errorState: StateResource<VorgangWithEingangResource> = createErrorStateResource(createProblemDetail()); + + service._handleVorgangError(errorState); + + expect(service.postfachMailList$.next).toHaveBeenCalledWith(errorState); + }); + + it('should not set if there is no error', () => { + const errorState: StateResource<VorgangWithEingangResource> = createStateResource(vorgang); + + service._handleVorgangError(errorState); + + expect(service.postfachMailList$.next).not.toHaveBeenCalled(); }); }); @@ -576,8 +598,6 @@ describe('PostfachService', () => { }); describe('isDownloadPdfInProgress', () => { - const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource(); - it('should call facade to download pdf', (done) => { vorgangService.getVorgangWithEingang.mockReturnValue(of(createStateResource(vorgang))); postfachFacade.isDownloadPdfInProgress.mockReturnValue(of(true)); 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 957de44c04dc22d0223151999119fb0a2c7fa350..64c238ddfa7e4609433ef21659d44ef364f3f166 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts @@ -35,6 +35,7 @@ import { import { NavigationFacade, NavigationService, RouteData } from '@alfa-client/navigation-shared'; import { createEmptyStateResource, + createErrorStateResource, createLoadingStateResource, createStateResource, doIfLoadingRequired, @@ -326,12 +327,20 @@ export class PostfachService { this._setPostfachMailListLoading(); this.vorgangService .getVorgangWithEingang() - .pipe(filter(isLoaded), take(1)) + .pipe( + tap((state: StateResource<VorgangWithEingangResource>) => this._handleVorgangError(state)), + filter(isLoaded), + take(1), + ) .subscribe((vorgangWithEingangStateResource) => { this.loadPostfachMailsByVorgang(vorgangWithEingangStateResource.resource); }); } + _handleVorgangError(state: StateResource<VorgangWithEingangResource>): void { + if (state.error) this.postfachMailList$.next(createErrorStateResource(state.error)); + } + _refreshVorgangSubscription(): void { this.vorgangChangeSubscription.unsubscribe(); this._listenToVorgangChange(); @@ -367,12 +376,15 @@ export class PostfachService { } public loadPostfachMailsByVorgang(vorgang: VorgangResource): void { - this.loadPostfachMailSubscription = this.repository.loadPostfachMailList(vorgang).subscribe((postfachMaiList) => { - if (!isNull(postfachMaiList)) { - this._setPostfachMailList(postfachMaiList); - setTimeout(() => this.loadPostfachMailSubscription.unsubscribe(), 0); - } - }); + this.loadPostfachMailSubscription = this.repository + .loadPostfachMailList(vorgang) + .pipe() + .subscribe((postfachMaiList) => { + if (!isNull(postfachMaiList)) { + this._setPostfachMailList(postfachMaiList); + setTimeout(() => this.loadPostfachMailSubscription.unsubscribe(), 0); + } + }); } _setPostfachMailList(postfachMailList: PostfachMailListResource): void { diff --git a/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/postfach-page-mail-list/postfach-page-mail-list.component.html b/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/postfach-page-mail-list/postfach-page-mail-list.component.html index 1729d7519c1a41b14e730394d1fb9b55b962c413..e6ab2f9717f81043221c63057b214b3f6d175f46 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/postfach-page-mail-list/postfach-page-mail-list.component.html +++ b/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/postfach-page-mail-list/postfach-page-mail-list.component.html @@ -24,21 +24,27 @@ --> <ozgcloud-spinner [stateResource]="postfachMailListStateResource"> - @for(postfachMail of postfachMailListStateResource.resource | toEmbeddedResources: postfachMailListLinkRel.POSTFACH_MAIL_LIST; track $index){ - <alfa-postfach-mail - - [attr.data-test-id]="(postfachMail.subject | convertForDataTest) + '-item'" - class="postfach w-full lg:w-1/2" - [postfachMail]="postfachMail" - /> + @if (postfachMailListStateResource.resource) { + <div data-test-id="postfach-page-mail-list"> + @for ( + postfachMail of postfachMailListStateResource.resource | toEmbeddedResources: postfachMailListLinkRel.POSTFACH_MAIL_LIST; + track $index + ) { + <alfa-postfach-mail + [attr.data-test-id]="(postfachMail.subject | convertForDataTest) + '-item'" + class="postfach w-full lg:w-1/2" + [postfachMail]="postfachMail" + /> + } + + <div class="mb-4 ml-6 mt-4 flex gap-4"> + <alfa-postfach-mail-pdf-button-container + [postfachMailListResource]="postfachMailListStateResource.resource" + [showButtonWithLabel]="true" + /> + + <alfa-mail-unread-button-link-container [postfachMailListResource]="postfachMailListStateResource.resource" /> + </div> + </div> } - - <div class="mb-4 ml-6 mt-4 flex gap-4"> - <alfa-postfach-mail-pdf-button-container - [postfachMailListResource]="postfachMailListStateResource.resource" - [showButtonWithLabel]="true" - /> - - <alfa-mail-unread-button-link-container [postfachMailListResource]="postfachMailListStateResource.resource" /> - </div> </ozgcloud-spinner> diff --git a/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/postfach-page-mail-list/postfach-page-mail-list.component.spec.ts b/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/postfach-page-mail-list/postfach-page-mail-list.component.spec.ts index b6b9acf468b81b2049a7b2e70438926ff66230c6..fc2527033ffe69e2059f4d5c0ef29c6bd483788c 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/postfach-page-mail-list/postfach-page-mail-list.component.spec.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/postfach-page-mail-list/postfach-page-mail-list.component.spec.ts @@ -22,11 +22,19 @@ * unter der Lizenz sind dem Lizenztext zu entnehmen. */ import { PostfachMailListResource } from '@alfa-client/postfach-shared'; -import { ConvertForDataTestPipe, createStateResource, HasLinkPipe, ToEmbeddedResourcesPipe } from '@alfa-client/tech-shared'; +import { + ConvertForDataTestPipe, + createEmptyStateResource, + createStateResource, + HasLinkPipe, + ToEmbeddedResourcesPipe, +} from '@alfa-client/tech-shared'; +import { existsAsHtmlElement, notExistsAsHtmlElement } from '@alfa-client/test-utils'; import { SpinnerComponent } from '@alfa-client/ui'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { MockComponent } from 'ng-mocks'; import { createPostfachMailListResource } from '../../../../../../postfach-shared/test/postfach'; +import { getDataTestIdOf } from '../../../../../../tech-shared/test/data-test'; import { PostfachMailComponent } from '../../../postfach-mail-list-container/postfach-mail-list/postfach-mail/postfach-mail.component'; import { PostfachMailPdfButtonContainerComponent } from '../../../postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component'; import { MailUnreadButtonLinkContainerComponent } from '../mail-unread-button/mail-unread-button-link-container.component'; @@ -36,6 +44,8 @@ describe('PostfachPageMailListComponent', () => { let component: PostfachPageMailListComponent; let fixture: ComponentFixture<PostfachPageMailListComponent>; + const mailList: string = getDataTestIdOf('postfach-page-mail-list'); + beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [ @@ -61,4 +71,22 @@ describe('PostfachPageMailListComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + describe('mail list', () => { + it('should exist if resource', () => { + component.postfachMailListStateResource = createStateResource<PostfachMailListResource>(createPostfachMailListResource()); + + fixture.detectChanges(); + + existsAsHtmlElement(fixture, mailList); + }); + + it('should not exist if no resource', () => { + component.postfachMailListStateResource = createEmptyStateResource<PostfachMailListResource>(); + + fixture.detectChanges(); + + notExistsAsHtmlElement(fixture, mailList); + }); + }); }); diff --git a/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/postfach-page.component.html b/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/postfach-page.component.html index 0317a0d0c5b0552dd3484ecc997d3fe0a8e431bd..5b3a6128d731837cef2d40158f1e6534f670604d 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/postfach-page.component.html +++ b/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/postfach-page.component.html @@ -35,6 +35,5 @@ <h1 data-test-id="postfach-mail-heading" class="pl-7 pt-4 text-lg font-medium">Nachrichten zum Vorgang</h1> <alfa-postfach-page-mail-list [postfachMailListStateResource]="postfachMailListStateResource" - data-test-id="postfach-page-mail-list" /> </div>