Skip to content

Commit

Permalink
#705 Fix routing in team management and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaeser2 committed Jan 10, 2024
1 parent ca6e0f7 commit 20f622b
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 9 deletions.
33 changes: 33 additions & 0 deletions frontend/src/app/shared/routeUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {getRouteToTeam, getRouteToUserDetails} from "./routeUtils";

describe('routeUtils', () => {
describe('getRouteToUserDetails', () => {

it("should not include team fragment when teamId is missing", () => {
expect(getRouteToUserDetails(1)).toBe(`/team-management/details/member/1`);
});

it("should include team fragment when teamId is missing", () => {
expect(getRouteToUserDetails(1, 11)).toBe(`/team-management/11/details/member/1`);
});


it("should work with id=0", () => {
expect(getRouteToUserDetails(0, 0)).toBe(`/team-management/0/details/member/0`);
});

})

describe('getRouteToTeam', () => {

it("should work with normal id", () => {
expect(getRouteToTeam(1)).toBe(`/team-management/1`);
});


it("should work with id=0", () => {
expect(getRouteToTeam(0)).toBe(`/team-management/0`);
});

});
});
7 changes: 5 additions & 2 deletions frontend/src/app/shared/routeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export const getRouteToUserDetails = (userId: number) => 'details/member/' + userId;
export const getRouteToTeam = (teamId: number) => '/team-management/' + teamId;
export const getRouteToUserDetails = (userId: number, teamId?: number) => {
const teamFragment = teamId !== undefined ? `/${teamId}` : '';
return `/team-management${teamFragment}/details/member/${userId}`;
};
export const getRouteToTeam = (teamId: number) => `/team-management/${teamId}`;
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ <h3 *ngIf="!selectedTeam">Alle Teams</h3>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef>Name</th>
<td mat-cell *matCellDef="let element">
<a [routerLink]="getMemberDetailsLink(element)"> {{ element.firstname }} {{ element.lastname }} </a>
<a [routerLink]="getMemberDetailsLink(element, selectedTeam)">
{{ element.firstname }} {{ element.lastname }}
</a>
</td>
</ng-container>

Expand Down Expand Up @@ -95,7 +97,7 @@ <h3 *ngIf="!selectedTeam">Alle Teams</h3>
<tr
mat-row
class="cursor-pointer"
[routerLink]="getMemberDetailsLink(row)"
[routerLink]="getMemberDetailsLink(row, selectedTeam)"
*matRowDef="let row; columns: displayedColumns"
></tr>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ export class MemberListComponent implements OnInit, OnDestroy {
dialogRef.afterClosed().subscribe(() => this.cd.markForCheck());
}

getMemberDetailsLink(user: User) {
return getRouteToUserDetails(user.id);
getMemberDetailsLink(user: User, team?: Team) {
return getRouteToUserDetails(user.id, team?.id);
}

removeMemberFromTeam(entry: UserTableEntry, event: MouseEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@
[attr.data-testId]="'teamManagementSearchResult'"
>
<mat-optgroup [label]="'TEAM_MANAGEMENT.USERS' | translate" *ngIf="(filteredUsers$ | async)?.length">
<mat-option *ngFor="let user of filteredUsers$ | async" (click)="selectUser(user)" [value]="user.displayValue">
<mat-option
*ngFor="let user of filteredUsers$ | async"
(onSelectionChange)="selectUser(user)"
[value]="user.displayValue"
>
<span [innerHtml]="user.htmlValue"></span>
</mat-option>
</mat-optgroup>
<mat-optgroup [label]="'TEAM_MANAGEMENT.TEAMS' | translate" *ngIf="(filteredTeams$ | async)?.length">
<mat-option *ngFor="let team of filteredTeams$ | async" (click)="selectTeam(team)" [value]="team.displayValue">
<mat-option
*ngFor="let team of filteredTeams$ | async"
(onSelectionChange)="selectTeam(team)"
[value]="team.displayValue"
>
<span [innerHtml]="team.htmlValue"></span>
</mat-option>
</mat-optgroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('SearchTeamManagementComponent', () => {
it('should switch to user page when selected', () => {
component.selectUser(users[0]);

expect(navigateSpy).toHaveBeenCalledWith('details/member/1');
expect(navigateSpy).toHaveBeenCalledWith('/team-management/details/member/1');
});

it('should switch to teams page when selected', () => {
Expand Down

0 comments on commit 20f622b

Please sign in to comment.