From 25fbd956beb41cb3cf9a1e1441334f3f83a69c5f Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Thu, 12 Sep 2024 14:59:35 +0200 Subject: [PATCH] OZG-6376 OZG-6696 Add editor info to button label --- ...er-profile-button-container.component.html | 2 +- ...profile-button-container.component.spec.ts | 32 +++++++++++++++++-- ...user-profile-button-container.component.ts | 24 ++++++++++++-- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/alfa-client/libs/user-profile/src/lib/user-profile-in-vorgang-container/user-profile-in-vorgang/user-profile-button-container/user-profile-button-container.component.html b/alfa-client/libs/user-profile/src/lib/user-profile-in-vorgang-container/user-profile-in-vorgang/user-profile-button-container/user-profile-button-container.component.html index 5fa5cdf3ab..f455cb9944 100644 --- a/alfa-client/libs/user-profile/src/lib/user-profile-in-vorgang-container/user-profile-in-vorgang/user-profile-button-container/user-profile-button-container.component.html +++ b/alfa-client/libs/user-profile/src/lib/user-profile-in-vorgang-container/user-profile-in-vorgang/user-profile-button-container/user-profile-button-container.component.html @@ -28,7 +28,7 @@ [matMenuTriggerFor]="menu.matMenu" (menuOpened)="showUserProfileSearch()" (menuClosed)="hideUserProfileSearch()" - aria-label="Bearbeiter ändern" + [attr.aria-label]="userButtonLabel" class="user-profile-button" > <alfa-user-icon diff --git a/alfa-client/libs/user-profile/src/lib/user-profile-in-vorgang-container/user-profile-in-vorgang/user-profile-button-container/user-profile-button-container.component.spec.ts b/alfa-client/libs/user-profile/src/lib/user-profile-in-vorgang-container/user-profile-in-vorgang/user-profile-button-container/user-profile-button-container.component.spec.ts index 4464f2f109..6c12e1395e 100644 --- a/alfa-client/libs/user-profile/src/lib/user-profile-in-vorgang-container/user-profile-in-vorgang/user-profile-button-container/user-profile-button-container.component.spec.ts +++ b/alfa-client/libs/user-profile/src/lib/user-profile-in-vorgang-container/user-profile-in-vorgang/user-profile-button-container/user-profile-button-container.component.spec.ts @@ -21,10 +21,11 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { createEmptyStateResource, StateResource } from '@alfa-client/tech-shared'; import { mock } from '@alfa-client/test-utils'; import { OzgcloudMenuComponent, UiModule } from '@alfa-client/ui'; -import { UserProfileService } from '@alfa-client/user-profile-shared'; +import { UserProfileResource, UserProfileService } from '@alfa-client/user-profile-shared'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { MockComponent } from 'ng-mocks'; import { BehaviorSubject } from 'rxjs'; import { UserIconComponent } from '../../../user-icon/user-icon.component'; @@ -114,4 +115,31 @@ describe('UserProfileButtonContainerComponent', () => { expect(userProfileService.hideUserProfileSearch).toHaveBeenCalled(); }); }); + + describe('getUserButtonLabel', () => { + it('should return label', () => { + component.userProfile = createEmptyStateResource(); + + const result = component.getUserButtonLabel(); + + expect(result).toBe('Bearbeiter ändern. Aktueller Bearbeiter: Unbekannter Benutzer'); + }); + }); + + describe('set userProfile', () => { + const userProfileStateResource: StateResource<UserProfileResource> = createEmptyStateResource(); + it('should set userProfile', () => { + component.userProfile = userProfileStateResource; + + expect(component.userProfile).toBe(userProfileStateResource); + }); + + it('should get label for user button', () => { + component.getUserButtonLabel = jest.fn(); + + component.userProfile = userProfileStateResource; + + expect(component.getUserButtonLabel).toHaveBeenCalled(); + }); + }); }); diff --git a/alfa-client/libs/user-profile/src/lib/user-profile-in-vorgang-container/user-profile-in-vorgang/user-profile-button-container/user-profile-button-container.component.ts b/alfa-client/libs/user-profile/src/lib/user-profile-in-vorgang-container/user-profile-in-vorgang/user-profile-button-container/user-profile-button-container.component.ts index 1c74518823..e559f74639 100644 --- a/alfa-client/libs/user-profile/src/lib/user-profile-in-vorgang-container/user-profile-in-vorgang/user-profile-button-container/user-profile-button-container.component.ts +++ b/alfa-client/libs/user-profile/src/lib/user-profile-in-vorgang-container/user-profile-in-vorgang/user-profile-button-container/user-profile-button-container.component.ts @@ -21,10 +21,14 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ +import { StateResource } from '@alfa-client/tech-shared'; +import { + getUserName, + UserProfileResource, + UserProfileService, +} from '@alfa-client/user-profile-shared'; import { Component, Input, OnInit, ViewChild } from '@angular/core'; import { MatMenuTrigger } from '@angular/material/menu'; -import { StateResource } from '@alfa-client/tech-shared'; -import { UserProfileResource, UserProfileService } from '@alfa-client/user-profile-shared'; import { Observable, tap } from 'rxjs'; @Component({ @@ -33,11 +37,21 @@ import { Observable, tap } from 'rxjs'; styleUrls: ['./user-profile-button-container.component.scss'], }) export class UserProfileButtonContainerComponent implements OnInit { - @Input() userProfile: StateResource<UserProfileResource>; + @Input() + set userProfile(value: StateResource<UserProfileResource>) { + this._userProfile = value; + this.userButtonLabel = this.getUserButtonLabel(); + } + + get userProfile() { + return this._userProfile; + } @ViewChild(MatMenuTrigger) menuTrigger: MatMenuTrigger; showUserProfileSearch$: Observable<boolean>; + private _userProfile: StateResource<UserProfileResource>; + userButtonLabel: string; constructor(public userProfileService: UserProfileService) {} @@ -64,4 +78,8 @@ export class UserProfileButtonContainerComponent implements OnInit { public hideUserProfileSearch(): void { this.userProfileService.hideUserProfileSearch(); } + + public getUserButtonLabel(): string { + return `Bearbeiter ändern. Aktueller Bearbeiter: ${getUserName(this.userProfile.resource)}`; + } } -- GitLab