From cf1188681588f987f0bd14a667e54a709c6f90e9 Mon Sep 17 00:00:00 2001 From: Martin <git@mail.de> Date: Fri, 21 Feb 2025 14:13:22 +0100 Subject: [PATCH] OZG-7593 add condition for routerLink --- .../incomming-mail.component.html | 2 +- .../incomming-mail.component.spec.ts | 31 ++++++++++++- .../outgoing-mail.component.html | 7 ++- .../outgoing-mail.component.spec.ts | 44 ++++++++++++++----- 4 files changed, 67 insertions(+), 17 deletions(-) diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/incomming-mail/incomming-mail.component.html b/alfa-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/incomming-mail/incomming-mail.component.html index 0c9088cebc..948be283b5 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/incomming-mail/incomming-mail.component.html +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/incomming-mail/incomming-mail.component.html @@ -23,7 +23,7 @@ unter der Lizenz sind dem Lizenztext zu entnehmen. --> -<a routerLink="postfach"> +<a [routerLink]="onPage ? null : 'postfach'" data-test-class="incoming-mail-routing"> <div class="mail-head"> <div class="subject" data-test-id="mail-subject"> <mat-icon data-test-id="reply-icon">reply</mat-icon> diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/incomming-mail/incomming-mail.component.spec.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/incomming-mail/incomming-mail.component.spec.ts index e2a9572af4..7ef16d31fb 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/incomming-mail/incomming-mail.component.spec.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/incomming-mail/incomming-mail.component.spec.ts @@ -23,11 +23,13 @@ */ import { ON_PAGE, PostfachMailLinkRel } from '@alfa-client/postfach-shared'; import { FormatDateWithTimePipe, HasLinkPipe } from '@alfa-client/tech-shared'; -import { getElementFromFixture } from '@alfa-client/test-utils'; +import { getDebugElementFromFixtureByCss, getElementFromFixture } from '@alfa-client/test-utils'; import { registerLocaleData } from '@angular/common'; import localeDe from '@angular/common/locales/de'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { MatIcon } from '@angular/material/icon'; +import { provideRouter, RouterLinkWithHref, RouterModule } from '@angular/router'; +import { getDataTestClassOf, getDataTestIdOf } from 'libs/tech-shared/test/data-test'; import { MockComponent } from 'ng-mocks'; import { createPostfachMailResource } from '../../../../../../../postfach-shared/test/postfach'; import { PostfachMailDateComponent } from '../postfach-mail-date/postfach-mail-date.component'; @@ -39,7 +41,8 @@ describe('IncommingMailComponent', () => { let component: IncommingMailComponent; let fixture: ComponentFixture<IncommingMailComponent>; - const attachmentIcon: string = '[data-test-id="postfach-nachricht-attachment-icon"]'; + const attachmentIcon: string = getDataTestIdOf('postfach-nachricht-attachment-icon'); + const routing: string = getDataTestClassOf('incoming-mail-routing'); beforeEach(async () => { await TestBed.configureTestingModule({ @@ -51,7 +54,9 @@ describe('IncommingMailComponent', () => { HasLinkPipe, MatIcon, ], + imports: [RouterModule], providers: [ + provideRouter([]), { provide: ON_PAGE, useValue: undefined, @@ -82,4 +87,26 @@ describe('IncommingMailComponent', () => { expect(element).toBeInstanceOf(HTMLElement); }); }); + + describe('routing should be', () => { + it('null on page site', () => { + component.onPage = false; + + fixture.detectChanges(); + + const routerElement = getDebugElementFromFixtureByCss(fixture, routing); + const routerLinkInstance: RouterLinkWithHref = (<any>routerElement).injector.get(RouterLinkWithHref); + expect((<any>routerLinkInstance).routerLinkInput[0]).toEqual('postfach'); + }); + + it('"postfach" on detail site', () => { + component.onPage = true; + + fixture.detectChanges(); + + const routerElement = getDebugElementFromFixtureByCss(fixture, routing); + const routerLinkInstance: RouterLinkWithHref = (<any>routerElement).injector.get(RouterLinkWithHref); + expect((<any>routerLinkInstance).routerLinkInput).toBeNull(); + }); + }); }); diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/outgoing-mail/outgoing-mail.component.html b/alfa-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/outgoing-mail/outgoing-mail.component.html index c1fcab4f48..a3d8233fcc 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/outgoing-mail/outgoing-mail.component.html +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/outgoing-mail/outgoing-mail.component.html @@ -25,7 +25,8 @@ --> <a [ngClass]="{ error: postfachMail | hasLink: postfachNachrichtLinkRel.RESEND_POSTFACH_MAIL }" - routerLink="postfach" + [routerLink]="onPage ? null : 'postfach'" + data-test-class="outgoing-mail-routing" > <div class="mail-head"> <alfa-user-profile-in-postfach-mail-container @@ -53,9 +54,7 @@ > </a> -<alfa-outgoing-mail-error-container - [postfachMailResource]="postfachMail" -></alfa-outgoing-mail-error-container> +<alfa-outgoing-mail-error-container [postfachMailResource]="postfachMail"></alfa-outgoing-mail-error-container> <alfa-postfach-nachricht-edit-button-container *ngIf="(postfachMail | hasLink: postfachNachrichtLinkRel.EDIT) && !onPage" data-test-id="postfach-nachricht-edit-button-container" diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/outgoing-mail/outgoing-mail.component.spec.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/outgoing-mail/outgoing-mail.component.spec.ts index bda7d7fa45..1c5549014c 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/outgoing-mail/outgoing-mail.component.spec.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-list-container/postfach-mail-list/postfach-mail/outgoing-mail/outgoing-mail.component.spec.ts @@ -21,19 +21,21 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { MatIcon } from '@angular/material/icon'; import { ON_PAGE, PostfachMailLinkRel, PostfachMailResource } from '@alfa-client/postfach-shared'; -import { HasLinkPipe, StateResource, createStateResource } from '@alfa-client/tech-shared'; +import { createStateResource, HasLinkPipe, StateResource } from '@alfa-client/tech-shared'; import { existsAsHtmlElement, + getDebugElementFromFixtureByCss, getElementFromFixture, getMockComponent, notExistsAsHtmlElement, } from '@alfa-client/test-utils'; import { UserProfileInPostfachMailContainerComponent } from '@alfa-client/user-profile'; import { VorgangWithEingangResource } from '@alfa-client/vorgang-shared'; -import { getDataTestIdOf } from 'libs/tech-shared/test/data-test'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { MatIcon } from '@angular/material/icon'; +import { provideRouter, RouterLinkWithHref, RouterModule } from '@angular/router'; +import { getDataTestClassOf, getDataTestIdOf } from 'libs/tech-shared/test/data-test'; import { createVorgangWithEingangResource } from 'libs/vorgang-shared/test/vorgang'; import { MockComponent } from 'ng-mocks'; import { createPostfachMailResource } from '../../../../../../../postfach-shared/test/postfach'; @@ -50,6 +52,8 @@ describe('OutgoingMailComponent', () => { const postfachEditButton: string = getDataTestIdOf('postfach-nachricht-edit-button-container'); const postfachOutgoingNachrichtDate: string = getDataTestIdOf('postfach-outgoing-nachricht-date'); + const routing: string = getDataTestClassOf('outgoing-mail-routing'); + beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [ @@ -62,7 +66,9 @@ describe('OutgoingMailComponent', () => { MockComponent(PostfachMailDateComponent), MockComponent(PostfachNachrichtEditButtonContainerComponent), ], + imports: [RouterModule], providers: [ + provideRouter([]), { provide: ON_PAGE, useValue: undefined, @@ -95,9 +101,7 @@ describe('OutgoingMailComponent', () => { }); describe('edit button container component', () => { - const postfachNachricht: PostfachMailResource = createPostfachMailResource([ - PostfachMailLinkRel.EDIT, - ]); + const postfachNachricht: PostfachMailResource = createPostfachMailResource([PostfachMailLinkRel.EDIT]); describe('on existing edit link', () => { beforeEach(() => { @@ -151,9 +155,7 @@ describe('OutgoingMailComponent', () => { }); describe('in detail context', () => { - const postfachNachricht: PostfachMailResource = createPostfachMailResource([ - PostfachMailLinkRel.EDIT, - ]); + const postfachNachricht: PostfachMailResource = createPostfachMailResource([PostfachMailLinkRel.EDIT]); beforeEach(() => { component.onPage = true; @@ -185,4 +187,26 @@ describe('OutgoingMailComponent', () => { notExistsAsHtmlElement(fixture, postfachOutgoingNachrichtDate); }); }); + + describe('routing should be', () => { + it('null on page site', () => { + component.onPage = false; + + fixture.detectChanges(); + + const routerElement = getDebugElementFromFixtureByCss(fixture, routing); + const routerLinkInstance: RouterLinkWithHref = routerElement.injector.get(RouterLinkWithHref); + expect((<any>routerLinkInstance).routerLinkInput[0]).toEqual('postfach'); + }); + + it('"postfach" on detail site', () => { + component.onPage = true; + + fixture.detectChanges(); + + const routerElement = getDebugElementFromFixtureByCss(fixture, routing); + const routerLinkInstance: RouterLinkWithHref = routerElement.injector.get(RouterLinkWithHref); + expect((<any>routerLinkInstance).routerLinkInput).toBeNull(); + }); + }); }); -- GitLab