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 af5ace3e13868afb9179eee7219f0217da9ae8a7..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,7 +22,6 @@ * unter der Lizenz sind dem Lizenztext zu entnehmen. */ import { - convertForDataTest, ConvertForDataTestPipe, createStateResource, EnumToLabelPipe, @@ -185,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'); }); }); @@ -359,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 c6c0d6a5cf87cf30a60eae27fafed9974a8fb754..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 @@ -79,10 +79,7 @@ export class VorgangListItemComponent implements OnInit { const status: string = this.getStatus(); const approvalStatus: string = this.getApprovalText(); const createdAt: string = formatFullDateWithTimeWithoutSeconds(this.vorgang.createdAt); - const userText: string = - userProfileResource ? - `Aktuell zugewiesener Nutzer: ${getUserName(userProfileResource)}` - : 'Kein Bearbeiter zugewiesen'; + const userText: string = this.getUserText(userProfileResource); this.ariaLabel = `Vorgang: ${name}, Aktenzeichen: ${aktenzeichen}, Nummer: ${nummer} Status: ${status} ${approvalStatus}, Eingang: ${createdAt}, ${userText}`; @@ -121,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'; + } }