diff --git a/alfa-client/libs/vorgang/src/lib/vorgang-list-container/vorgang-list/vorgang-list-item/vorgang-list-item.component.spec.ts b/alfa-client/libs/vorgang/src/lib/vorgang-list-container/vorgang-list/vorgang-list-item/vorgang-list-item.component.spec.ts index 892fe541f8856a26fec7f3d77dad427eebb690b4..6015354498a4860c7c4bfabd7feb57ce2f9c7a93 100644 --- a/alfa-client/libs/vorgang/src/lib/vorgang-list-container/vorgang-list/vorgang-list-item/vorgang-list-item.component.spec.ts +++ b/alfa-client/libs/vorgang/src/lib/vorgang-list-container/vorgang-list/vorgang-list-item/vorgang-list-item.component.spec.ts @@ -22,9 +22,8 @@ * unter der Lizenz sind dem Lizenztext zu entnehmen. */ import { - convertForDataTest, ConvertForDataTestPipe, - createEmptyStateResource, + createStateResource, EnumToLabelPipe, HasLinkPipe, ToResourceUriPipe, @@ -32,7 +31,7 @@ import { import { getElementFromFixture, mock } from '@alfa-client/test-utils'; import { PostfachIconComponent } from '@alfa-client/ui'; import { UserProfileInVorgangListItemContainerComponent } from '@alfa-client/user-profile'; -import { UserProfileService } from '@alfa-client/user-profile-shared'; +import { UserProfileResource, UserProfileService } from '@alfa-client/user-profile-shared'; import { VorgangHeaderLinkRel, VorgangStatus } from '@alfa-client/vorgang-shared'; import { AktenzeichenComponent, @@ -52,6 +51,7 @@ import { MatIconTestingModule } from '@angular/material/icon/testing'; import { MatTooltipModule } from '@angular/material/tooltip'; import { RouterTestingModule } from '@angular/router/testing'; import { getDataTestClassOf, getDataTestIdOf } from 'libs/tech-shared/test/data-test'; +import { createUserProfileResource } from 'libs/user-profile-shared/test/user-profile'; import { createVorgangResource } from 'libs/vorgang-shared/test/vorgang'; import { MockComponent, MockModule } from 'ng-mocks'; import { of } from 'rxjs'; @@ -72,6 +72,8 @@ describe('VorgangListItemComponent', () => { const postfachStatus: string = getDataTestClassOf('postfach-icon'); const bescheidStatus: string = getDataTestIdOf('vorgang-list-item-bescheid-status'); + const userProfile: UserProfileResource = createUserProfileResource(); + beforeEach(async () => { await TestBed.configureTestingModule({ imports: [RouterTestingModule, MatIconTestingModule], @@ -114,35 +116,47 @@ describe('VorgangListItemComponent', () => { }); describe('ngOnInit', () => { - it('should build aria label', () => { - component.buildAriaLabel = jest.fn(); - - component.ngOnInit(); - - expect(component.buildAriaLabel).toHaveBeenCalled(); - }); - describe('user profile', () => { beforeEach(() => { + component.buildAriaLabel = jest.fn(); component.userProfileService.getAssignedUserProfile = jest .fn() - .mockReturnValue(of(createEmptyStateResource())); + .mockReturnValue(of(createStateResource(userProfile))); }); - it('should not get profile if vorgang has no "assigned to" link', () => { - component.vorgang = createVorgangResource(); + describe('vorgang has no "assigned to" link', () => { + beforeEach(() => { + component.vorgang = createVorgangResource(); + }); + it('should not get profile', () => { + component.ngOnInit(); + + expect(component.userProfileService.getAssignedUserProfile).not.toHaveBeenCalled(); + }); - component.ngOnInit(); + it('should build aria label without user profile resource', () => { + component.ngOnInit(); - expect(component.userProfileService.getAssignedUserProfile).not.toHaveBeenCalled(); + expect(component.buildAriaLabel).toHaveBeenCalledWith(); + }); }); - it('should get profile', () => { - component.vorgang = createVorgangResource([VorgangHeaderLinkRel.ASSIGNED_TO]); + describe('vorgang has "assigned to" link', () => { + beforeEach(() => { + component.vorgang = createVorgangResource([VorgangHeaderLinkRel.ASSIGNED_TO]); + }); + + it('should get profile', () => { + component.ngOnInit(); + + expect(component.userProfileService.getAssignedUserProfile).toHaveBeenCalled(); + }); - component.ngOnInit(); + it('should build aria label with user profile resource', () => { + component.ngOnInit(); - expect(component.userProfileService.getAssignedUserProfile).toHaveBeenCalled(); + expect(component.buildAriaLabel).toHaveBeenCalledWith(userProfile); + }); }); }); }); @@ -170,142 +184,166 @@ describe('VorgangListItemComponent', () => { }); }); - describe('Aria label', () => { - it('should contain Wiedervorlage', () => { + describe('mail icon', () => { + beforeEach(() => { component.vorgang = createVorgangResource([ VorgangHeaderLinkRel.VORGANG_WITH_EINGANG, - VorgangHeaderLinkRel.WIEDERVORLAGEN, + VorgangHeaderLinkRel.POSTFACH_MAILS, ]); - const listItem: string = getDataTestIdOf( - `vorgang-list-item-${convertForDataTest(component.vorgang.name)}`, - ); - component.ngOnInit(); + }); + + it('should show mail icon if Vorgang has new Postfachnachricht', () => { + component.vorgang.hasPostfachNachricht = true; fixture.detectChanges(); - const element: HTMLDivElement = fixture.nativeElement.querySelector(listItem); - const ariaLabel: string = element.getAttribute('aria-label'); + const statusElement = getElementFromFixture(fixture, postfachStatus); - expect(ariaLabel).toContain('Wiedervorlage'); + expect(statusElement).toBeInstanceOf(HTMLElement); }); - it('should not contain Wiedervorlage if no nextFrist but LinkRel.WIEDERVORLAGEN', () => { - component.vorgang = { - ...createVorgangResource([ - VorgangHeaderLinkRel.VORGANG_WITH_EINGANG, - VorgangHeaderLinkRel.WIEDERVORLAGEN, - ]), - nextFrist: null, - }; - const listItem: string = getDataTestIdOf( - `vorgang-list-item-${convertForDataTest(component.vorgang.name)}`, - ); - component.ngOnInit(); + it('should not show mail icon if Vorgang has no new Postfachnachricht', () => { + component.vorgang.hasPostfachNachricht = false; fixture.detectChanges(); - const element: HTMLDivElement = fixture.nativeElement.querySelector(listItem); - const ariaLabel: string = element.getAttribute('aria-label'); + const statusElement = getElementFromFixture(fixture, postfachStatus); - expect(ariaLabel).not.toContain('Wiedervorlage'); + expect(statusElement).not.toBeInstanceOf(HTMLElement); }); + }); - it('should not contain Wiedervorlage if no LinkRel.WIEDERVORLAGEN', () => { - component.vorgang = createVorgangResource([VorgangHeaderLinkRel.VORGANG_WITH_EINGANG]); - const listItem: string = getDataTestIdOf( - `vorgang-list-item-${convertForDataTest(component.vorgang.name)}`, - ); - component.ngOnInit(); + describe('Bescheid-Status', () => { + it('should show bescheid status if Vorgang has antragBewilligt true', () => { + component.vorgang.antragBewilligt = true; fixture.detectChanges(); - const element: HTMLDivElement = fixture.nativeElement.querySelector(listItem); - const ariaLabel: string = element.getAttribute('aria-label'); + const element = getElementFromFixture(fixture, bescheidStatus); - expect(ariaLabel).not.toContain('Wiedervorlage'); + expect(element).toBeInstanceOf(HTMLElement); }); - it('should contain hasPostfachnachricht text if vorgang has Postfachnachricht', () => { - component.vorgang.hasPostfachNachricht = true; - component.vorgang.hasNewPostfachNachricht = false; - const listItem: string = getDataTestIdOf( - `vorgang-list-item-${convertForDataTest(component.vorgang.name)}`, - ); - component.ngOnInit(); + it('should show bescheid status if Vorgang has antragBewilligt false', () => { + component.vorgang.antragBewilligt = false; fixture.detectChanges(); - const element: HTMLDivElement = fixture.nativeElement.querySelector(listItem); - const ariaLabel: string = element.getAttribute('aria-label'); + const element = getElementFromFixture(fixture, bescheidStatus); - expect(ariaLabel).toContain('enthält Postfachnachrichten'); + expect(element).toBeInstanceOf(HTMLElement); }); - it('should contain hasNewPostfachnachricht text if vorgang has new Postfachnachricht', () => { - component.vorgang.hasPostfachNachricht = true; - component.vorgang.hasNewPostfachNachricht = true; - const listItem: string = getDataTestIdOf( - `vorgang-list-item-${convertForDataTest(component.vorgang.name)}`, - ); - component.ngOnInit(); + it('should not show bescheid status if Vorgang has no antragBewilligt', () => { + component.vorgang.antragBewilligt = null; fixture.detectChanges(); - const element: HTMLDivElement = fixture.nativeElement.querySelector(listItem); - const ariaLabel: string = element.getAttribute('aria-label'); + const element = getElementFromFixture(fixture, bescheidStatus); - expect(ariaLabel).toContain('enthält neue Postfachnachrichten'); + expect(element).not.toBeInstanceOf(HTMLElement); }); }); - describe('mail icon', () => { + describe('buildAriaLabel', () => { beforeEach(() => { + component.getWiedervorlageText = jest.fn(); + component.getPostfachNachricht = jest.fn(); + }); + it('should get status', () => { + component.getStatus = jest.fn(); + + component.buildAriaLabel(); + + expect(component.getStatus).toHaveBeenCalled(); + }); + + it('should get approval text', () => { + component.getApprovalText = jest.fn(); + + component.buildAriaLabel(); + + expect(component.getApprovalText).toHaveBeenCalled(); + }); + + it('should get user text', () => { + component.getUserText = jest.fn(); + + component.buildAriaLabel(userProfile); + + expect(component.getUserText).toHaveBeenCalledWith(userProfile); + }); + + it('should get Wiedervorlage', () => { component.vorgang = createVorgangResource([ VorgangHeaderLinkRel.VORGANG_WITH_EINGANG, - VorgangHeaderLinkRel.POSTFACH_MAILS, + VorgangHeaderLinkRel.WIEDERVORLAGEN, ]); + + component.buildAriaLabel(); + + expect(component.getWiedervorlageText).toHaveBeenCalled(); }); - it('should show mail icon if Vorgang has new Postfachnachricht', () => { + it('should not get Wiedervorlage if no nextFrist but LinkRel.WIEDERVORLAGEN', () => { + component.vorgang = { + ...createVorgangResource([ + VorgangHeaderLinkRel.VORGANG_WITH_EINGANG, + VorgangHeaderLinkRel.WIEDERVORLAGEN, + ]), + nextFrist: null, + }; + + component.buildAriaLabel(); + + expect(component.getWiedervorlageText).not.toHaveBeenCalled(); + }); + + it('should not get Wiedervorlage if no LinkRel.WIEDERVORLAGEN', () => { + component.vorgang = createVorgangResource([VorgangHeaderLinkRel.VORGANG_WITH_EINGANG]); + + component.buildAriaLabel(); + + expect(component.getWiedervorlageText).not.toHaveBeenCalled(); + }); + + it('should get message text if vorgang has message', () => { component.vorgang.hasPostfachNachricht = true; - fixture.detectChanges(); - const statusElement = getElementFromFixture(fixture, postfachStatus); + component.buildAriaLabel(); - expect(statusElement).toBeInstanceOf(HTMLElement); + expect(component.getPostfachNachricht).toHaveBeenCalled(); }); - it('should not show mail icon if Vorgang has no new Postfachnachricht', () => { + it('should not get message text if vorgang has no messages', () => { component.vorgang.hasPostfachNachricht = false; - fixture.detectChanges(); - const statusElement = getElementFromFixture(fixture, postfachStatus); + component.buildAriaLabel(); - expect(statusElement).not.toBeInstanceOf(HTMLElement); + expect(component.getPostfachNachricht).not.toHaveBeenCalled(); }); }); - describe('Bescheid-Status', () => { - it('should show bescheid status if Vorgang has antragBewilligt true', () => { - component.vorgang.antragBewilligt = true; - fixture.detectChanges(); + describe('getWiedervorlageText', () => { + it('should return text for next resubmission', () => { + component.vorgang.nextFrist = new Date('07.02.1977'); - const element = getElementFromFixture(fixture, bescheidStatus); + const result: string = component.getWiedervorlageText(); - expect(element).toBeInstanceOf(HTMLElement); + expect(result).toBe(', Nächste Wiedervorlage am 02.07.1977'); }); + }); - it('should show bescheid status if Vorgang has antragBewilligt false', () => { - component.vorgang.antragBewilligt = false; - fixture.detectChanges(); + describe('getPostfachNachricht', () => { + it('should return "contains new messages"', () => { + component.vorgang.hasNewPostfachNachricht = true; - const element = getElementFromFixture(fixture, bescheidStatus); + const result: string = component.getPostfachNachricht(); - expect(element).toBeInstanceOf(HTMLElement); + expect(result).toBe(', enthält neue Postfachnachrichten'); }); - it('should not show bescheid status if Vorgang has no antragBewilligt', () => { - component.vorgang.antragBewilligt = null; - fixture.detectChanges(); + it('should return "contains messages"', () => { + component.vorgang.hasNewPostfachNachricht = false; - const element = getElementFromFixture(fixture, bescheidStatus); + const result: string = component.getPostfachNachricht(); - expect(element).not.toBeInstanceOf(HTMLElement); + expect(result).toBe(', enthält Postfachnachrichten'); }); }); @@ -344,4 +382,20 @@ describe('VorgangListItemComponent', () => { expect(result).toBe('abgelehnt'); }); }); + + describe('getUserText', () => { + it('should return no assigned user text', () => { + const result: string = component.getUserText(undefined); + + expect(result).toBe('Kein Bearbeiter zugewiesen'); + }); + + it('should return assigned user text', () => { + const result: string = component.getUserText(userProfile); + + expect(result).toBe( + `Aktuell zugewiesener Nutzer: ${userProfile.firstName} ${userProfile.lastName}`, + ); + }); + }); }); diff --git a/alfa-client/libs/vorgang/src/lib/vorgang-list-container/vorgang-list/vorgang-list-item/vorgang-list-item.component.ts b/alfa-client/libs/vorgang/src/lib/vorgang-list-container/vorgang-list/vorgang-list-item/vorgang-list-item.component.ts index a86e83410e370fdf599f5bc80c69b008e8ac9fbf..b8cbab9cabd6479cc85550faf03fd35dc9550a9c 100644 --- a/alfa-client/libs/vorgang/src/lib/vorgang-list-container/vorgang-list/vorgang-list-item/vorgang-list-item.component.ts +++ b/alfa-client/libs/vorgang/src/lib/vorgang-list-container/vorgang-list/vorgang-list-item/vorgang-list-item.component.ts @@ -22,7 +22,6 @@ * unter der Lizenz sind dem Lizenztext zu entnehmen. */ import { - createEmptyStateResource, EnumToLabelPipe, formatFullDateWithTimeWithoutSeconds, formatToPrettyDate, @@ -53,7 +52,6 @@ export class VorgangListItemComponent implements OnInit { @Input() vorgang: VorgangResource; readonly vorgangLinkRel = VorgangHeaderLinkRel; - userProfile: StateResource<UserProfileResource> = createEmptyStateResource<UserProfileResource>(); public ariaLabel: string = ''; @@ -63,22 +61,27 @@ export class VorgangListItemComponent implements OnInit { if (hasLink(this.vorgang, VorgangHeaderLinkRel.ASSIGNED_TO)) { this.userProfileService .getAssignedUserProfile(this.vorgang, VorgangHeaderLinkRel.ASSIGNED_TO) - .pipe(first(isNotNull)) + .pipe( + first((userProfile: StateResource<UserProfileResource>) => + isNotNull(userProfile.resource), + ), + ) .subscribe((userProfileStateResource: StateResource<UserProfileResource>) => { - this.userProfile = userProfileStateResource; + this.buildAriaLabel(userProfileStateResource.resource); }); - } - this.buildAriaLabel(); + } else this.buildAriaLabel(); } - buildAriaLabel() { + buildAriaLabel(userProfileResource: UserProfileResource = undefined) { const name: string = this.vorgang.name; const aktenzeichen: string = getAktenzeichenText(this.vorgang); const nummer: string = this.vorgang.nummer; + const status: string = this.getStatus(); const approvalStatus: string = this.getApprovalText(); const createdAt: string = formatFullDateWithTimeWithoutSeconds(this.vorgang.createdAt); + const userText: string = this.getUserText(userProfileResource); - this.ariaLabel = `Vorgang: ${name}, Aktenzeichen: ${aktenzeichen}, Nummer: ${nummer} Status: ${this.getStatus()} ${approvalStatus}, Eingang: ${createdAt}, Aktuell zugewiesener Nutzer: ${getUserName(this.userProfile.resource)}`; + this.ariaLabel = `Vorgang: ${name}, Aktenzeichen: ${aktenzeichen}, Nummer: ${nummer} Status: ${status} ${approvalStatus}, Eingang: ${createdAt}, ${userText}`; if ( hasLink(this.vorgang, VorgangHeaderLinkRel.WIEDERVORLAGEN) && @@ -115,4 +118,10 @@ export class VorgangListItemComponent implements OnInit { return this.vorgang.antragBewilligt ? 'bewilligt' : 'abgelehnt'; } + + getUserText(userProfileResource: UserProfileResource): string { + return userProfileResource ? + `Aktuell zugewiesener Nutzer: ${getUserName(userProfileResource)}` + : 'Kein Bearbeiter zugewiesen'; + } }