-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b54a24c
commit 4db333e
Showing
10 changed files
with
227 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import { AddMemberToTeamDialogComponent } from './add-member-to-team-dialog.comp | |
import { SharedModule } from '../../shared/shared.module'; | ||
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog'; | ||
import { team1, users } from '../../shared/testData'; | ||
import { of, takeLast } from 'rxjs'; | ||
import { BehaviorSubject, of, skip } from 'rxjs'; | ||
import { MatFormFieldModule } from '@angular/material/form-field'; | ||
import { MatAutocompleteModule } from '@angular/material/autocomplete'; | ||
import { User } from '../../shared/types/model/User'; | ||
|
@@ -14,8 +14,6 @@ import { MatTable } from '@angular/material/table'; | |
describe('AddMemberToTeamDialogComponent', () => { | ||
let component: AddMemberToTeamDialogComponent; | ||
let fixture: ComponentFixture<AddMemberToTeamDialogComponent>; | ||
let userService: UserService; | ||
let teamService: TeamService; | ||
|
||
const userServiceMock = { | ||
getUsers: jest.fn(), | ||
|
@@ -50,12 +48,12 @@ describe('AddMemberToTeamDialogComponent', () => { | |
|
||
fixture = TestBed.createComponent(AddMemberToTeamDialogComponent); | ||
component = fixture.componentInstance; | ||
userService = TestBed.inject(UserService); | ||
teamService = TestBed.inject(TeamService); | ||
|
||
component.table = { | ||
renderRows: () => undefined, | ||
} as MatTable<User[]>; | ||
|
||
component.selectedUsers$ = new BehaviorSubject<User[]>([]); | ||
}); | ||
|
||
it('should create', () => { | ||
|
@@ -64,17 +62,20 @@ describe('AddMemberToTeamDialogComponent', () => { | |
|
||
it('should set allPossibleUsers correctly', () => { | ||
component.ngOnInit(); | ||
expect(component.allPossibleUsers.length).toBe(users.length - 1); | ||
expect(component.allPossibleUsers).not.toContain(users[0]); | ||
component.usersForSelection$!.subscribe((filteredUsers) => { | ||
expect(filteredUsers.length).toBe(users.length - 1); | ||
expect(filteredUsers).not.toContain(users[0]); | ||
}); | ||
}); | ||
|
||
it('should set filteredUsers correctly: search by PaCo', (done) => { | ||
component.search = { | ||
valueChanges: of('PaCo'), | ||
} as any; | ||
|
||
component.ngOnInit(); | ||
|
||
component.usersForSelection$!.pipe(takeLast(1)).subscribe((filteredUsers) => { | ||
component.usersForSelection$!.subscribe((filteredUsers) => { | ||
expect(filteredUsers.length).toBe(1); | ||
expect(filteredUsers[0].email).toBe('[email protected]'); | ||
done(); | ||
|
@@ -85,18 +86,20 @@ describe('AddMemberToTeamDialogComponent', () => { | |
component.search = { | ||
valueChanges: of('puzzle.ch'), | ||
} as any; | ||
component.selectedUsers = [users[1]]; | ||
|
||
component.selectedUsers$.next([users[1]]); | ||
|
||
component.ngOnInit(); | ||
|
||
component.usersForSelection$!.pipe(takeLast(1)).subscribe((filteredUsers) => { | ||
expect(filteredUsers.length).toBe(component.allPossibleUsers.length - 1); | ||
component.usersForSelection$!.pipe(skip(1)).subscribe((filteredUsers) => { | ||
expect(filteredUsers.length).toBe(users.length - 2); | ||
expect(filteredUsers.map((u) => u.id)).not.toContain(users[1].id); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should set teamname correctly', () => { | ||
expect(component.getDialogTitle()).toBe(`Members für Team ${team1.name} einladen`); | ||
expect(component.getDialogTitle()).toBe(`Members zu Team ${team1.name} hinzufügen`); | ||
}); | ||
|
||
it('should return correct display value', () => { | ||
|
@@ -105,17 +108,17 @@ describe('AddMemberToTeamDialogComponent', () => { | |
|
||
it('should add user to selected users and restore search value', () => { | ||
component.search.setValue('test'); | ||
component.selectedUsers = [users[1], users[2]]; | ||
component.selectedUsers$.next([users[1], users[2]]); | ||
component.selectUser(users[3]); | ||
expect(component.search.value).toBe(''); | ||
expect(component.selectedUsers.length).toBe(3); | ||
expect(component.selectedUsers.map((u) => u.id)).toStrictEqual([users[1].id, users[2].id, users[3].id]); | ||
expect(component.selectedUsers$.getValue().length).toBe(3); | ||
expect(component.selectedUsers$.getValue().map((u) => u.id)).toStrictEqual([users[1].id, users[2].id, users[3].id]); | ||
}); | ||
|
||
it('should remove user from selected users', () => { | ||
component.selectedUsers = [...users]; | ||
component.selectedUsers$.next([...users]); | ||
component.remove(users[0]); | ||
expect(component.selectedUsers.length).toBe(users.length - 1); | ||
expect(component.selectedUsers.map((u) => u.id)).not.toContain(users[0].id); | ||
expect(component.selectedUsers$.getValue().length).toBe(users.length - 1); | ||
expect(component.selectedUsers$.getValue().map((u) => u.id)).not.toContain(users[0].id); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
frontend/src/app/team-management/add-user-team/add-user-team.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import {ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {AddUserTeamComponent} from './add-user-team.component'; | ||
import {TeamService} from '../../services/team.service'; | ||
import {team1, team2, team3, testUser} from '../../shared/testData'; | ||
import {of} from 'rxjs'; | ||
|
||
describe('AddUserTeamComponent', () => { | ||
let component: AddUserTeamComponent; | ||
let fixture: ComponentFixture<AddUserTeamComponent>; | ||
let teamService: TeamService; | ||
|
||
const teamServiceMock = { | ||
getAllTeams: jest.fn(), | ||
}; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [AddUserTeamComponent], | ||
providers: [{ provide: TeamService, useValue: teamServiceMock }], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(AddUserTeamComponent); | ||
component = fixture.componentInstance; | ||
teamService = TestBed.inject(TeamService); | ||
|
||
teamServiceMock.getAllTeams.mockReturnValue(of([team1, team2, team3])); | ||
component.currentTeams$ = of(testUser.userTeamList); | ||
|
||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create the component', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should filter adminTeams correctly', done => { | ||
team1.isWriteable = true; | ||
team2.isWriteable = true; | ||
team3.isWriteable = false; | ||
component.ngOnInit(); | ||
component.adminTeams$!.subscribe(teams => { | ||
expect(teams.length).toBe(1); | ||
expect(teams[0].id).toBe(team2.id); | ||
done(); | ||
}) | ||
}) | ||
|
||
it('createUserTeam should create the userTeam', () => { | ||
component.createUserTeam(team1); | ||
expect(component.userTeam).toStrictEqual({ | ||
team: team1, | ||
isTeamAdmin: false, | ||
}); | ||
}); | ||
|
||
it('save should throw exception if userTeam is undefined', () => { | ||
expect(() => component.save()).toThrowError('UserTeam should be defined here'); | ||
}) | ||
|
||
it('save should emit addUserTeam event and set userTeam to undefined', done => { | ||
component.userTeam = testUser.userTeamList[0]; | ||
component.addUserTeam.subscribe(() => { | ||
done(); | ||
}) | ||
component.save(); | ||
expect(component.userTeam).toBe(undefined); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.