Skip to content
Snippets Groups Projects
Commit 257ab0e6 authored by Albert Bruns's avatar Albert Bruns
Browse files

OZG-7773 postfach e2e test fix

parent 678ac3eb
No related branches found
No related tags found
1 merge request!120OZG-7773-Nachrichten-auf-ungelesen-setzen
...@@ -26,6 +26,7 @@ import { CommandResource, CommandService } from '@alfa-client/command-shared'; ...@@ -26,6 +26,7 @@ import { CommandResource, CommandService } from '@alfa-client/command-shared';
import { NavigationFacade, NavigationService, RouteData } from '@alfa-client/navigation-shared'; import { NavigationFacade, NavigationService, RouteData } from '@alfa-client/navigation-shared';
import { import {
createEmptyStateResource, createEmptyStateResource,
createErrorStateResource,
createLoadingStateResource, createLoadingStateResource,
createStateResource, createStateResource,
StateResource, StateResource,
...@@ -43,6 +44,7 @@ import { CommandLinkRel } from 'libs/command-shared/src/lib/command.linkrel'; ...@@ -43,6 +44,7 @@ import { CommandLinkRel } from 'libs/command-shared/src/lib/command.linkrel';
import { createCommandErrorResource, createCommandResource } from 'libs/command-shared/test/command'; import { createCommandErrorResource, createCommandResource } from 'libs/command-shared/test/command';
import { createVorgangWithEingangResource } from 'libs/vorgang-shared/test/vorgang'; import { createVorgangWithEingangResource } from 'libs/vorgang-shared/test/vorgang';
import { BehaviorSubject, Observable, of } from 'rxjs'; import { BehaviorSubject, Observable, of } from 'rxjs';
import { createProblemDetail } from '../../../tech-shared/test/error';
import { multipleCold, singleColdCompleted, singleHot } from '../../../tech-shared/test/marbles'; import { multipleCold, singleColdCompleted, singleHot } from '../../../tech-shared/test/marbles';
import { import {
createPostfachFeatures, createPostfachFeatures,
...@@ -513,14 +515,12 @@ describe('PostfachService', () => { ...@@ -513,14 +515,12 @@ describe('PostfachService', () => {
}); });
describe('loadPostfachMailList', () => { describe('loadPostfachMailList', () => {
const postfachMailList: PostfachMailListResource = createPostfachMailListResource();
beforeEach(() => { beforeEach(() => {
repository.loadPostfachMailList.mockReturnValue(of(postfachMailList));
service._setPostfachMailListLoading = jest.fn(); service._setPostfachMailListLoading = jest.fn();
service._setPostfachMailList = jest.fn(); service._handleVorgangError = jest.fn();
vorgangService.getVorgangWithEingang.mockReturnValue(of(createStateResource(createVorgangWithEingangResource()))); service.loadPostfachMailsByVorgang = jest.fn();
}); });
it('should set loading to true', () => { it('should set loading to true', () => {
service._loadPostfachMailList(); service._loadPostfachMailList();
...@@ -533,16 +533,38 @@ describe('PostfachService', () => { ...@@ -533,16 +533,38 @@ describe('PostfachService', () => {
expect(vorgangService.getVorgangWithEingang).toHaveBeenCalled(); expect(vorgangService.getVorgangWithEingang).toHaveBeenCalled();
}); });
it('should call repository', () => { it('should handle vorgang error', () => {
service._loadPostfachMailList(); service._loadPostfachMailList();
expect(repository.loadPostfachMailList).toHaveBeenCalled(); expect(service._handleVorgangError).toHaveBeenCalledWith(vorgangWithEingangStateResource);
}); });
it('should set loading to false', () => { it('should call loadPostfachMailsByVorgang', () => {
service._loadPostfachMailList(); 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', () => { ...@@ -576,8 +598,6 @@ describe('PostfachService', () => {
}); });
describe('isDownloadPdfInProgress', () => { describe('isDownloadPdfInProgress', () => {
const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource();
it('should call facade to download pdf', (done) => { it('should call facade to download pdf', (done) => {
vorgangService.getVorgangWithEingang.mockReturnValue(of(createStateResource(vorgang))); vorgangService.getVorgangWithEingang.mockReturnValue(of(createStateResource(vorgang)));
postfachFacade.isDownloadPdfInProgress.mockReturnValue(of(true)); postfachFacade.isDownloadPdfInProgress.mockReturnValue(of(true));
......
...@@ -35,6 +35,7 @@ import { ...@@ -35,6 +35,7 @@ import {
import { NavigationFacade, NavigationService, RouteData } from '@alfa-client/navigation-shared'; import { NavigationFacade, NavigationService, RouteData } from '@alfa-client/navigation-shared';
import { import {
createEmptyStateResource, createEmptyStateResource,
createErrorStateResource,
createLoadingStateResource, createLoadingStateResource,
createStateResource, createStateResource,
doIfLoadingRequired, doIfLoadingRequired,
...@@ -326,12 +327,20 @@ export class PostfachService { ...@@ -326,12 +327,20 @@ export class PostfachService {
this._setPostfachMailListLoading(); this._setPostfachMailListLoading();
this.vorgangService this.vorgangService
.getVorgangWithEingang() .getVorgangWithEingang()
.pipe(filter(isLoaded), take(1)) .pipe(
tap((state: StateResource<VorgangWithEingangResource>) => this._handleVorgangError(state)),
filter(isLoaded),
take(1),
)
.subscribe((vorgangWithEingangStateResource) => { .subscribe((vorgangWithEingangStateResource) => {
this.loadPostfachMailsByVorgang(vorgangWithEingangStateResource.resource); this.loadPostfachMailsByVorgang(vorgangWithEingangStateResource.resource);
}); });
} }
_handleVorgangError(state: StateResource<VorgangWithEingangResource>): void {
if (state.error) this.postfachMailList$.next(createErrorStateResource(state.error));
}
_refreshVorgangSubscription(): void { _refreshVorgangSubscription(): void {
this.vorgangChangeSubscription.unsubscribe(); this.vorgangChangeSubscription.unsubscribe();
this._listenToVorgangChange(); this._listenToVorgangChange();
...@@ -367,7 +376,10 @@ export class PostfachService { ...@@ -367,7 +376,10 @@ export class PostfachService {
} }
public loadPostfachMailsByVorgang(vorgang: VorgangResource): void { public loadPostfachMailsByVorgang(vorgang: VorgangResource): void {
this.loadPostfachMailSubscription = this.repository.loadPostfachMailList(vorgang).subscribe((postfachMaiList) => { this.loadPostfachMailSubscription = this.repository
.loadPostfachMailList(vorgang)
.pipe()
.subscribe((postfachMaiList) => {
if (!isNull(postfachMaiList)) { if (!isNull(postfachMaiList)) {
this._setPostfachMailList(postfachMaiList); this._setPostfachMailList(postfachMaiList);
setTimeout(() => this.loadPostfachMailSubscription.unsubscribe(), 0); setTimeout(() => this.loadPostfachMailSubscription.unsubscribe(), 0);
......
...@@ -24,9 +24,13 @@ ...@@ -24,9 +24,13 @@
--> -->
<ozgcloud-spinner [stateResource]="postfachMailListStateResource"> <ozgcloud-spinner [stateResource]="postfachMailListStateResource">
@for(postfachMail of postfachMailListStateResource.resource | toEmbeddedResources: postfachMailListLinkRel.POSTFACH_MAIL_LIST; track $index){ @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 <alfa-postfach-mail
[attr.data-test-id]="(postfachMail.subject | convertForDataTest) + '-item'" [attr.data-test-id]="(postfachMail.subject | convertForDataTest) + '-item'"
class="postfach w-full lg:w-1/2" class="postfach w-full lg:w-1/2"
[postfachMail]="postfachMail" [postfachMail]="postfachMail"
...@@ -41,4 +45,6 @@ ...@@ -41,4 +45,6 @@
<alfa-mail-unread-button-link-container [postfachMailListResource]="postfachMailListStateResource.resource" /> <alfa-mail-unread-button-link-container [postfachMailListResource]="postfachMailListStateResource.resource" />
</div> </div>
</div>
}
</ozgcloud-spinner> </ozgcloud-spinner>
...@@ -22,11 +22,19 @@ ...@@ -22,11 +22,19 @@
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
import { PostfachMailListResource } from '@alfa-client/postfach-shared'; 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 { SpinnerComponent } from '@alfa-client/ui';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MockComponent } from 'ng-mocks'; import { MockComponent } from 'ng-mocks';
import { createPostfachMailListResource } from '../../../../../../postfach-shared/test/postfach'; 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 { 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 { 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'; import { MailUnreadButtonLinkContainerComponent } from '../mail-unread-button/mail-unread-button-link-container.component';
...@@ -36,6 +44,8 @@ describe('PostfachPageMailListComponent', () => { ...@@ -36,6 +44,8 @@ describe('PostfachPageMailListComponent', () => {
let component: PostfachPageMailListComponent; let component: PostfachPageMailListComponent;
let fixture: ComponentFixture<PostfachPageMailListComponent>; let fixture: ComponentFixture<PostfachPageMailListComponent>;
const mailList: string = getDataTestIdOf('postfach-page-mail-list');
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
declarations: [ declarations: [
...@@ -61,4 +71,22 @@ describe('PostfachPageMailListComponent', () => { ...@@ -61,4 +71,22 @@ describe('PostfachPageMailListComponent', () => {
it('should create', () => { it('should create', () => {
expect(component).toBeTruthy(); 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);
});
});
}); });
...@@ -35,6 +35,5 @@ ...@@ -35,6 +35,5 @@
<h1 data-test-id="postfach-mail-heading" class="pl-7 pt-4 text-lg font-medium">Nachrichten zum Vorgang</h1> <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 <alfa-postfach-page-mail-list
[postfachMailListStateResource]="postfachMailListStateResource" [postfachMailListStateResource]="postfachMailListStateResource"
data-test-id="postfach-page-mail-list"
/> />
</div> </div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment