-
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
4f98384
commit a084700
Showing
2 changed files
with
115 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,17 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; | ||
import { UserService } from '../../services/user.service'; | ||
import { team1 } from '../../shared/testData'; | ||
import { DeleteUserComponent } from './delete-user.component'; | ||
import { User } from '../../shared/types/model/User'; | ||
import { of } from 'rxjs'; | ||
|
||
export const testUserWithTeam: User = { | ||
id: 1, | ||
firstname: 'Bob', | ||
lastname: 'Baumeister', | ||
isOkrChampion: false, | ||
userTeamList: [ | ||
{ | ||
id: 1, | ||
team: team1, | ||
isTeamAdmin: false, | ||
}, | ||
], | ||
email: '[email protected]', | ||
}; | ||
|
||
export const testUserWithoutTeam: User = { | ||
id: 2, | ||
firstname: 'Hans', | ||
lastname: 'Muster', | ||
isOkrChampion: false, | ||
userTeamList: [], | ||
email: '[email protected]', | ||
}; | ||
import { UserOkrData } from '../../shared/types/model/UserOkrData'; | ||
|
||
describe('DeleteUserComponent', () => { | ||
let component: DeleteUserComponent; | ||
let fixture: ComponentFixture<DeleteUserComponent>; | ||
|
||
const userServiceMock = { | ||
deleteUser: jest.fn(), | ||
isUserMemberOfTeams: jest.fn(), | ||
getUserOkrData: jest.fn(), | ||
}; | ||
|
||
const matDialogMock = { | ||
|
@@ -47,6 +24,7 @@ describe('DeleteUserComponent', () => { | |
}; | ||
|
||
beforeEach(async () => { | ||
jest.resetAllMocks(); | ||
await TestBed.configureTestingModule({ | ||
declarations: [], | ||
imports: [], | ||
|
@@ -61,24 +39,66 @@ describe('DeleteUserComponent', () => { | |
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should return true if user is in a team', () => { | ||
component.user = testUserWithTeam; | ||
it('should load UserOkrData and MemberTeamStatus (case is member of teams + with KeyResults)', fakeAsync(() => { | ||
const userOkrData: UserOkrData = { | ||
keyResults: [ | ||
{ | ||
keyResultId: 100, | ||
keyResultName: 'keyResult1', | ||
objectiveId: 200, | ||
objectiveName: 'objective1', | ||
}, | ||
], | ||
}; | ||
|
||
component.currentTeams$ = of([]); | ||
userServiceMock.getUserOkrData.mockReturnValue(of(userOkrData)); | ||
userServiceMock.isUserMemberOfTeams.mockReturnValue(of(true)); | ||
|
||
component.ngOnInit(); | ||
tick(); | ||
|
||
expect(component.userOkrData).toBe(userOkrData); | ||
expect(component.userIsMemberOfTeams).toBe(true); | ||
})); | ||
|
||
it('should load UserOkrData and MemberTeamStatus (case not member of teams + no KeyResults)', fakeAsync(() => { | ||
const userOkrDataWithoutKeyResults: UserOkrData = { | ||
keyResults: [], | ||
}; | ||
|
||
component.currentTeams$ = of([]); | ||
userServiceMock.getUserOkrData.mockReturnValue(of(userOkrDataWithoutKeyResults)); | ||
userServiceMock.isUserMemberOfTeams.mockReturnValue(of(false)); | ||
|
||
component.ngOnInit(); | ||
tick(); | ||
|
||
expect(component.userOkrData).toBe(userOkrDataWithoutKeyResults); | ||
expect(component.userIsMemberOfTeams).toBe(false); | ||
})); | ||
|
||
it('should return true if userIsMemberOfTeams is undefined', () => { | ||
component.userIsMemberOfTeams = undefined; | ||
expect(component.isUserMemberOfTeams()).toBe(true); | ||
}); | ||
|
||
it('should return true if userIsMemberOfTeams is true', () => { | ||
component.userIsMemberOfTeams = true; | ||
expect(component.isUserMemberOfTeams()).toBe(true); | ||
}); | ||
|
||
it.skip('should return false if user it not in a team', () => { | ||
component.user = testUserWithoutTeam; | ||
it('should return false if userIsMemberOfTeams is false', () => { | ||
component.userIsMemberOfTeams = false; | ||
expect(component.isUserMemberOfTeams()).toBe(false); | ||
}); | ||
|
||
it('should return true userOkrData is undefined', () => { | ||
component.user = testUserWithoutTeam; | ||
it('should return true if userOkrData is undefined', () => { | ||
component.userOkrData = undefined; | ||
expect(component.isUserOwnerOfKeyResults()).toBe(true); | ||
}); | ||
|
||
it('should return false if userOkrData has no keyResults', () => { | ||
component.user = testUserWithoutTeam; | ||
component.userOkrData = { | ||
keyResults: [], | ||
}; | ||
|
@@ -87,7 +107,6 @@ describe('DeleteUserComponent', () => { | |
}); | ||
|
||
it('should return true if user is owner of keyResults', () => { | ||
component.user = testUserWithoutTeam; | ||
component.userOkrData = { | ||
keyResults: [ | ||
{ | ||
|
@@ -102,17 +121,67 @@ describe('DeleteUserComponent', () => { | |
expect(component.isUserOwnerOfKeyResults()).toBe(true); | ||
}); | ||
|
||
it('should not delete user when user is member of teams', () => { | ||
component.user = { | ||
id: 2, | ||
firstname: 'Hans', | ||
lastname: 'Muster', | ||
isOkrChampion: false, | ||
userTeamList: [], | ||
email: '[email protected]', | ||
}; | ||
component.userIsMemberOfTeams = true; | ||
|
||
component.deleteUser(); | ||
|
||
expect(userServiceMock.deleteUser).not.toHaveBeenCalledWith(component.user); | ||
}); | ||
|
||
it('should not delete user when user is owner of keyResults', () => { | ||
component.user = { | ||
id: 2, | ||
firstname: 'Hans', | ||
lastname: 'Muster', | ||
isOkrChampion: false, | ||
userTeamList: [], | ||
email: '[email protected]', | ||
}; | ||
component.userIsMemberOfTeams = false; | ||
component.userOkrData = { | ||
keyResults: [ | ||
{ | ||
keyResultId: 100, | ||
keyResultName: 'keyResult1', | ||
objectiveId: 200, | ||
objectiveName: 'objective1', | ||
}, | ||
], | ||
}; | ||
|
||
component.deleteUser(); | ||
|
||
expect(userServiceMock.deleteUser).not.toHaveBeenCalledWith(component.user); | ||
}); | ||
|
||
it('should delete user if user is not in a team and user has no keyResults', () => { | ||
component.user = testUserWithoutTeam; | ||
component.user = { | ||
id: 2, | ||
firstname: 'Hans', | ||
lastname: 'Muster', | ||
isOkrChampion: false, | ||
userTeamList: [], | ||
email: '[email protected]', | ||
}; | ||
component.userOkrData = { | ||
keyResults: [], | ||
}; | ||
component.userIsMemberOfTeams = false; | ||
matDialogMock.open.mockReturnValue(matDialogRefMock); | ||
matDialogRefMock.afterClosed.mockReturnValue(of()); | ||
userServiceMock.deleteUser.mockReturnValue(of()); | ||
|
||
component.deleteUser(); | ||
|
||
setTimeout(() => expect(userServiceMock.deleteUser).toHaveBeenCalled(), 100); | ||
setTimeout(() => expect(userServiceMock.deleteUser).toHaveBeenCalledWith(component.user), 100); | ||
}); | ||
}); |
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