Skip to content

Commit

Permalink
fix naming of team management
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Dec 23, 2024
1 parent 67cc87a commit 434d93f
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
@import "../style/variables";

.input-fields {
margin-bottom: 0.5rem;
}

mat-select {
outline: 1px solid #a4a4af;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,18 @@ describe('TeamManagementComponent', () => {
});

it('should call service method to update team if data input is not null', async () => {
jest.spyOn(teamServiceMock, 'updateTeam').mockReturnValue(of(teamFormObject));

component.data = { team: marketingTeamWriteable };
component.teamForm.setValue(teamFormObject);
jest.spyOn(teamServiceMock, 'updateTeam').mockReturnValue(of(teamFormObject));
fixture.detectChanges();
component.saveTeam();

expect(teamServiceMock.updateTeam).toHaveBeenCalled();
expect(teamServiceMock.updateTeam).toHaveBeenCalledWith({
...teamFormObject,
expect(teamServiceMock.updateTeam).toHaveBeenCalledWith(expect.objectContaining({
id: marketingTeamWriteable.id,
version: marketingTeamWriteable.version,
} as Team);
}));
});

it('should set team values in from on init if data is not null', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ describe('AddMemberToTeamDialogComponent', () => {
});
});

it('should set teamname correctly', () => {
it('should set team name correctly im title', () => {
expect(component.getDialogTitle()).toBe(`Members zu Team ${team1.name} hinzufügen`);
});

it('should return correct display value', () => {
it('should return correct display value for given user', () => {
expect(component.getDisplayValue(users[0])).toBe(`${users[0].firstName} ${users[0].lastName} (${users[0].email})`);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
<div
class="tooltip-wrapper"
[matTooltip]="'Der User ist bereits in allen Teams in welchen Sie Admin sind'"
[matTooltipDisabled]="!addButtonDisabled(selectableAdminTeams)"
[matTooltipDisabled]="!isAddButtonDisabled(selectableAdminTeams)"
>
<button
*ngIf="showAddButton(allAdminTeams$ | async)"
*ngIf="isAddButtonVisible(allAdminTeams$ | async)"
(click)="createUserTeam(selectableAdminTeams[0])"
[attr.data-testId]="'add-user'"
class="mdc-button px-0 pe-2"
[disabled]="addButtonDisabled(selectableAdminTeams)"
[disabled]="isAddButtonDisabled(selectableAdminTeams)"
color="primary"
mat-button
>
<span class="d-flex align-items-center fw-bold add-text">
<img
[src]="
addButtonDisabled(selectableAdminTeams)
isAddButtonDisabled(selectableAdminTeams)
? '/assets/icons/new-icon-disabled.svg'
: '/assets/icons/new-icon.svg'
"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ describe('AddUserTeamComponent', () => {
expect(teams.length).toBe(2);
expect(teams[0].id).toBe(team1Copy.id);
expect(teams[1].id).toBe(team2Copy.id);
expect(component.showAddButton(teams)).toBeTruthy();
expect(component.isAddButtonVisible(teams)).toBeTruthy();
done();
});
});

it('createUserTeam should create the userTeam', () => {
it('should create the userTeam when createUserTeam is called', () => {
component.createUserTeam(team1Copy);
expect(component.userTeam).toStrictEqual({
team: team1Copy,
Expand All @@ -74,10 +74,10 @@ describe('AddUserTeamComponent', () => {
});

it('save should throw exception if userTeam is undefined', () => {
expect(() => component.save()).toThrowError('UserTeam should be defined here');
expect(() => component.save()).toThrow('UserTeam should be defined here');
});

it('save should emit addUserTeam event and set userTeam to undefined', (done) => {
it('should emit addUserTeam event and set userTeam to undefined after save', (done) => {
component.userTeam = testUser.userTeamList[0];
component.addUserTeam.subscribe(() => {
done();
Expand All @@ -88,16 +88,16 @@ describe('AddUserTeamComponent', () => {

it('should test showAddButton', () => {
component.userTeam = testUser.userTeamList[0];
expect(component.showAddButton(null)).toBeFalsy();
expect(component.showAddButton([team1Copy, team2Copy])).toBeFalsy();
expect(component.isAddButtonVisible(null)).toBeFalsy();
expect(component.isAddButtonVisible([team1Copy, team2Copy])).toBeFalsy();
component.userTeam = undefined;
expect(component.showAddButton([])).toBeFalsy();
expect(component.showAddButton([team1Copy, team2Copy])).toBeTruthy();
expect(component.isAddButtonVisible([])).toBeFalsy();
expect(component.isAddButtonVisible([team1Copy, team2Copy])).toBeTruthy();
});

it('should test addButtonDisabled', () => {
expect(component.addButtonDisabled([team1Copy])).toBeFalsy();
expect(component.addButtonDisabled([])).toBeTruthy();
expect(component.addButtonDisabled(null)).toBeTruthy();
expect(component.isAddButtonDisabled([team1Copy])).toBeFalsy();
expect(component.isAddButtonDisabled([])).toBeTruthy();
expect(component.isAddButtonDisabled(null)).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class AddUserTeamComponent implements OnInit, OnDestroy {
selectableAdminTeams$: Observable<Team[]> | undefined;
allAdminTeams$: Observable<Team[]> | undefined;

private unsubscribe$ = new Subject<void>();
private readonly unsubscribe$ = new Subject<void>();

constructor(private readonly teamService: TeamService) {}

Expand Down Expand Up @@ -63,11 +63,11 @@ export class AddUserTeamComponent implements OnInit, OnDestroy {
this.userTeam = undefined;
}

showAddButton(adminTeams: Team[] | null) {
isAddButtonVisible(adminTeams: Team[] | null) {
return !this.userTeam && adminTeams?.length;
}

addButtonDisabled(selectableAdminTeams: Team[] | null) {
isAddButtonDisabled(selectableAdminTeams: Team[] | null) {
return !selectableAdminTeams?.length;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('DeleteUserComponent', () => {
expect(component).toBeTruthy();
});

it('deleteUser() should delete user and reload users', () => {
it('should delete and reload users after deleteUser is called', () => {
// arrange
userServiceMock.deleteUser.mockReturnValue(of(userServiceMock.deleteUser));
dialogRefMock.afterClosed.mockReturnValue(of('some data'));
Expand All @@ -78,7 +78,7 @@ describe('DeleteUserComponent', () => {
expect(mockLocation.back).toHaveBeenCalledTimes(1);
});

it('deleteUser() should not reload users when UserService throws an error', () => {
it('should not reload users when UserService throws an error after deleteUser() is called', () => {
// arrange
function createErrorSubject() {
const myError = new Subject<any>();
Expand All @@ -99,7 +99,7 @@ describe('DeleteUserComponent', () => {
expect(mockLocation.back).toHaveBeenCalledTimes(0);
});

it('deleteUserWithChecks() should not delete user which is member of a Team', () => {
it('should check deleteUserWithChecks() should not delete user which is member of a Team', () => {
// arrange (user is member of team Lorem)
component.userIsMemberOfTeams = true;
component.user.userTeamList = [
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('DeleteUserComponent', () => {
});
});

it('deleteUserWithChecks() should not delete user which has KeyResults', () => {
it('should not delete user which has KeyResults when deleteUserWithChecks() is called ', () => {
// arrange (user has KeyResult one)
component.userIsMemberOfTeams = false;
component.userOkrData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class DeleteUserComponent implements OnInit {
deleteUserWithChecks() {
if (this.isUserMemberOfTeams()) {
const dialogTitle = `User kann nicht gelöscht werden`;
const dialogText = `${getFullNameOfUser(this.user)} ist in folgenden Teams und kann daher nicht gelöscht werden: ${this.dialogDetailsUserTeams()}`;
const dialogText = `${getFullNameOfUser(this.user)} ist in folgenden Teams und kann daher nicht gelöscht werden: ${this.getDialogDetailsUserTeams()}`;
this.showUnableToDeleteUserDialog(dialogTitle, dialogText);
return;
} else if (this.isUserOwnerOfKeyResults()) {
Expand All @@ -104,7 +104,7 @@ export class DeleteUserComponent implements OnInit {
return this.userOkrData !== undefined ? this.userOkrData.keyResults.length > 0 : true;
}

dialogDetailsUserTeams() {
getDialogDetailsUserTeams() {
if (this.userOkrData) {
return this.user.userTeamList //
.map((userTeam) => userTeam.team.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ describe('InviteUserDialogComponent', () => {
component.registerUsers();
tick();

expect(userServiceMock.createUsers).toBeCalledTimes(1);
expect(userServiceMock.createUsers).toBeCalledWith(component.form.value);
expect(dialogRefMock.close).toBeCalledTimes(1);
expect(userServiceMock.createUsers).toHaveBeenCalledTimes(1);
expect(userServiceMock.createUsers).toHaveBeenCalledWith(component.form.value);
expect(dialogRefMock.close).toHaveBeenCalledTimes(1);
}));

it('registerUsers should not call createUsers form is not valid', fakeAsync(() => {
component.registerUsers();
tick();

expect(userServiceMock.createUsers).toBeCalledTimes(0);
expect(dialogRefMock.close).toBeCalledTimes(0);
expect(userServiceMock.createUsers).toHaveBeenCalledTimes(0);
expect(dialogRefMock.close).toHaveBeenCalledTimes(0);
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h2>
<div class="w-100">
<app-edit-okr-champion
[user]="userRef"
(okrChampionChange)="isOkrChampionChange($event, userRef)"
(okrChampionChange)="setIsOkrChampion($event, userRef)"
></app-edit-okr-champion>
</div>
<div class="w-100">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ export class MemberDetailComponent implements OnInit, OnDestroy {
private loadUser(userId: number) {
this.userService
.getUserById(userId)
.pipe(tap((user) => this.setSelectedUserIsLoggedinUser(user)))
.pipe(tap((user) => this.setSelectedUserIsLoggedInUser(user)))
.subscribe((user) => {
this.user = user;
this.currentUserTeams$.next(user.userTeamList);
this.cd.markForCheck();
});
}

private setSelectedUserIsLoggedinUser(selectedUser: User) {
private setSelectedUserIsLoggedInUser(selectedUser: User) {
this.selectedUserIsLoggedInUser = selectedUser.id === this.userService.getCurrentUser().id;
}

Expand Down Expand Up @@ -125,7 +125,7 @@ export class MemberDetailComponent implements OnInit, OnDestroy {
this.router.navigate(['../'], { relativeTo: this.route.parent });
}

isOkrChampionChange(okrChampion: boolean, user: User) {
setIsOkrChampion(okrChampion: boolean, user: User) {
this.userService.setIsOkrChampion(user, okrChampion).subscribe(() => {
this.loadUser(user.id);
this.teamService.reloadTeams();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ describe('MemberListTableComponent', () => {
component.removeMemberFromTeam(entry as UserTableEntry, new MouseEvent('click'));
tick();

expect(teamServiceMock.removeUserFromTeam).toBeCalledTimes(1);
expect(teamServiceMock.removeUserFromTeam).toBeCalledWith(entry.id, component.selectedTeam$.value);
expect(userServiceMock.reloadUsers).toBeCalledTimes(1);
expect(userServiceMock.reloadCurrentUser).toBeCalledTimes(1);
expect(teamServiceMock.removeUserFromTeam).toHaveBeenCalledWith(1);
expect(teamServiceMock.removeUserFromTeam).toHaveBeenCalledWith(entry.id, component.selectedTeam$.value);
expect(userServiceMock.reloadUsers).toHaveBeenCalledWith(1);
expect(userServiceMock.reloadCurrentUser).toHaveBeenCalledWith(1);
}));

it('removeMemberFromTeam should not call removeUserFromTeam and reloadUsers if not confirmed', fakeAsync(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MatInputModule } from '@angular/material/input';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FilteredTeam, FilteredUser, SearchTeamManagementComponent } from './search-team-management.component';
import { TranslateTestingModule } from 'ngx-translate-testing';
// @ts-ignore
import * as de from '../../../assets/i18n/de.json';
import { MatIconModule } from '@angular/material/icon';
import { ReactiveFormsModule } from '@angular/forms';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
flex-direction: row;
align-items: center;
}

app-puzzle-icon-button {
margin-left: 0.5rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testin
import { ShowEditRoleComponent } from './show-edit-role.component';
import { testUser } from '../../shared/testData';
import { TranslateTestingModule } from 'ngx-translate-testing';
// @ts-ignore
import * as de from '../../../assets/i18n/de.json';

describe('ShowEditRoleComponent', () => {
Expand Down

0 comments on commit 434d93f

Please sign in to comment.