diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.linkrel.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.linkrel.ts index b852cd1da23446a4983fbb67c472162746cf2cac..8617b6bab78053fe6e186c151b298ba25dafed97 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.linkrel.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.linkrel.ts @@ -25,6 +25,7 @@ export enum PostfachMailListLinkRel { POSTFACH_MAIL_LIST = 'postfachMailList', SEND_POSTFACH_MAIL = 'sendPostfachMail', UPLOAD_ATTACHMENT = 'uploadAttachment', + RESET_HAS_NEW_POSTFACH_NACHRICHT = 'resetHasNewPostfachNachricht', SET_HAS_NEW_POSTFACH_NACHRICHT = 'setHasNewPostfachNachricht', } diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.repository.spec.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.repository.spec.ts index 4c48ebdbd07d0dec8170610df1db6bb64b12bd22..c67a73ad7045df1fa47596e1e45a0d8b4a35fba1 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.repository.spec.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.repository.spec.ts @@ -70,24 +70,42 @@ describe('PostfachRepository', () => { }); }); + describe('resetHasNewPostfachNachrichten', () => { + const postfachMailListResource: PostfachMailListResource = createPostfachMailListResource([ + PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT, + ]); + + it('should call resourceFactory with resource', () => { + repository.resetHasNewPostfachNachrichten(postfachMailListResource); + + expect(resourceFactory.from).toHaveBeenCalledWith(postfachMailListResource); + }); + + it('should call resourceWrapper with link', () => { + repository.resetHasNewPostfachNachrichten(postfachMailListResource); + + expect(resourceWrapper.put).toHaveBeenCalledWith(PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT, { + hasNewPostfachNachricht: false, + }); + }); + }); + describe('setHasNewPostfachNachrichten', () => { const postfachMailListResource: PostfachMailListResource = createPostfachMailListResource([ PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT, ]); it('should call resourceFactory with resource', () => { - repository.setHasNewPostfachNachrichten(postfachMailListResource, true); + repository.setHasNewPostfachNachrichten(postfachMailListResource); expect(resourceFactory.from).toHaveBeenCalledWith(postfachMailListResource); }); it('should call resourceWrapper with link', () => { - const hasNewPostfachNachricht = true; - - repository.setHasNewPostfachNachrichten(postfachMailListResource, hasNewPostfachNachricht); + repository.setHasNewPostfachNachrichten(postfachMailListResource); expect(resourceWrapper.put).toHaveBeenCalledWith(PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT, { - hasNewPostfachNachricht: hasNewPostfachNachricht, + hasNewPostfachNachricht: true, }); }); }); diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.repository.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.repository.ts index 6b9bcb74023cd27b44ce9eaa34a80c19d19b6b00..76696a94d78a5c640114e98f045018f022e831ca 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.repository.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.repository.ts @@ -36,9 +36,15 @@ export class PostfachRepository { return this.resourceFactory.from(vorgang).get(VorgangHeaderLinkRel.POSTFACH_MAILS); } - public setHasNewPostfachNachrichten(postfachNachrichtenList: PostfachMailListResource, value: boolean): Observable<unknown> { + public resetHasNewPostfachNachrichten(postfachNachrichtenList: PostfachMailListResource): Observable<unknown> { + return this.resourceFactory.from(postfachNachrichtenList).put(PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT, { + hasNewPostfachNachricht: false, + }); + } + + public setHasNewPostfachNachrichten(postfachNachrichtenList: PostfachMailListResource): Observable<unknown> { return this.resourceFactory.from(postfachNachrichtenList).put(PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT, { - hasNewPostfachNachricht: value, + hasNewPostfachNachricht: true, }); } } 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 7480badf04632f9ede8e8c03122118717a6c8f03..9149471c8d22327948bb18ae382aeeeb45cafe32 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 @@ -400,48 +400,30 @@ describe('PostfachService', () => { }); describe('doResetHasNewPostfachNachrichten', () => { - beforeEach(() => { - service.setHasNewPostfachNachrichten = jest.fn(); - }); - - it('should call setHasNewPostfachNachrichten if link exists', () => { - service.postfachMailList$.next( - createStateResource(createPostfachMailListResource([PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT])), - ); - - service._doResetHasNewPostfachNachrichten(); - - expect(service.setHasNewPostfachNachrichten).toHaveBeenCalledWith(false); - }); + describe('on existing link', () => { + const postfachNachrichtenListResource: PostfachMailListResource = createPostfachMailListResource([ + PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT, + ]); - it('should NOT call service if link not exists', () => { - service.postfachMailList$.next(createStateResource(createPostfachMailListResource())); + beforeEach(() => { + service.postfachMailList$.next(createStateResource(postfachNachrichtenListResource)); + repository.resetHasNewPostfachNachrichten.mockReturnValue(of(postfachNachrichtenListResource)); + }); - service._doResetHasNewPostfachNachrichten(); + it('should call repository if link exists', () => { + service._doResetHasNewPostfachNachrichten(); - expect(service.setHasNewPostfachNachrichten).not.toHaveBeenCalled(); + expect(repository.resetHasNewPostfachNachrichten).toHaveBeenCalledWith(postfachNachrichtenListResource); + }); }); - }); - - describe('setHasNewPostfachNachrichten', () => { - const postfachNachrichtenListResource: PostfachMailListResource = createPostfachMailListResource([ - PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT, - ]); - beforeEach(() => { + it('should NOT call repository if link not exists', () => { + const postfachNachrichtenListResource: PostfachMailListResource = createPostfachMailListResource(); service.postfachMailList$.next(createStateResource(postfachNachrichtenListResource)); - repository.setHasNewPostfachNachrichten.mockReturnValue(of(postfachNachrichtenListResource)); - }); - - it('should call repository setHasNewPostfachNachrichten', () => { - const hasNewPostfachNachrichten = true; - service.setHasNewPostfachNachrichten(hasNewPostfachNachrichten); + service._doResetHasNewPostfachNachrichten(); - expect(repository.setHasNewPostfachNachrichten).toHaveBeenCalledWith( - postfachNachrichtenListResource, - hasNewPostfachNachrichten, - ); + expect(repository.resetHasNewPostfachNachrichten).not.toHaveBeenCalled(); }); }); 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 4d58138d9e351632122702937fdf077489c6a962..d0ab2285274ce4ed753d2cf9a9cd601eb04306fa 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts @@ -217,13 +217,13 @@ export class PostfachService { } _doResetHasNewPostfachNachrichten(): void { - if (hasLink(this.postfachMailList$.value.resource, PostfachMailListLinkRel.SET_HAS_NEW_POSTFACH_NACHRICHT)) { - this.setHasNewPostfachNachrichten(false); + if (hasLink(this.postfachMailList$.value.resource, PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT)) { + this.repository.resetHasNewPostfachNachrichten(this.postfachMailList$.value.resource).pipe(take(1)).subscribe(); } } - public setHasNewPostfachNachrichten(value: boolean) { - this.repository.setHasNewPostfachNachrichten(this.postfachMailList$.value.resource, value).pipe(take(1)).subscribe(); + public setHasNewPostfachNachrichten() { + this.repository.setHasNewPostfachNachrichten(this.postfachMailList$.value.resource).pipe(take(1)).subscribe(); } _pollSendPostfachMailCommand(command: StateResource<CommandResource>): StateResource<CommandResource> { diff --git a/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component.spec.ts b/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component.spec.ts index 75e04b6d66f9199f61b7e16f58b4636f3a81eecd..37d5c2efd99a21a8c73ec7e87ea336d367b12268 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component.spec.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component.spec.ts @@ -58,7 +58,7 @@ describe('MailUnreadButtonLinkContainerComponent', () => { it('should call set hasNewPostfachNachrichten to true', () => { component.markMailAsUnread(); - expect(postfachService.setHasNewPostfachNachrichten).toHaveBeenCalledWith(true); + expect(postfachService.setHasNewPostfachNachrichten).toHaveBeenCalled(); }); }); }); diff --git a/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component.ts b/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component.ts index 82ffa0165d2a6ea5c32e59920901318e943a8a60..678e0beb0db2f43ff86c5a57d8f30b8cae0dd370 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component.ts @@ -23,6 +23,6 @@ export class MailUnreadButtonLinkContainerComponent { protected readonly PostfachMailListLinkRel = PostfachMailListLinkRel; markMailAsUnread() { - this.postfachService.setHasNewPostfachNachrichten(true); + this.postfachService.setHasNewPostfachNachrichten(); } } diff --git a/alfa-client/libs/postfach/src/lib/postfach.module.ts b/alfa-client/libs/postfach/src/lib/postfach.module.ts index 05e8f88f55af78f70d4b8fa7d3aad3aa09f6be34..5bf9b5f8494af3ade6caadbbc14710d6b2d14a92 100644 --- a/alfa-client/libs/postfach/src/lib/postfach.module.ts +++ b/alfa-client/libs/postfach/src/lib/postfach.module.ts @@ -61,12 +61,9 @@ import { PostfachMailComponent } from './postfach-mail-list-container/postfach-m import { PostfachMailPdfButtonContainerComponent } from './postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component'; import { PostfachMailPdfButtonComponent } from './postfach-mail-pdf-button-container/postfach-mail-pdf-button/postfach-mail-pdf-button.component'; import { PostfachPageContainerComponent } from './postfach-page-container/postfach-page-container.component'; -import { PostfachPageMailUnreadButtonComponent } from './postfach-page-container/postfach-page/mail-unread-button/mail-unread-button.component'; +import { MailUnreadButtonLinkContainerComponent } from './postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component'; import { PostfachPageMailListComponent } from './postfach-page-container/postfach-page/postfach-page-mail-list/postfach-page-mail-list.component'; import { PostfachPageComponent } from './postfach-page-container/postfach-page/postfach-page.component'; -import { - MailUnreadButtonLinkContainerComponent -} from "./postfach-page-container/postfach-page/mail-unread-button/mail-unread-button-link-container.component"; const routes: Routes = [ { @@ -105,8 +102,6 @@ const routes: Routes = [ TooltipDirective, MultiFileUploadComponent, PostfachMailListMailboxIconComponent, - PostfachPageMailUnreadButtonComponent, - PostfachPageMailUnreadButtonComponent, MailUnreadButtonLinkContainerComponent, ], declarations: [