-
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
fc92272
commit 882b132
Showing
2 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
117 changes: 116 additions & 1 deletion
117
frontend/src/app/team-management/delete-user/delete-user.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 |
---|---|---|
@@ -1,3 +1,118 @@ | ||
import { ComponentFixture, TestBed } 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]', | ||
}; | ||
|
||
describe('DeleteUserComponent', () => { | ||
it('todo write tests', () => {}); | ||
let component: DeleteUserComponent; | ||
let fixture: ComponentFixture<DeleteUserComponent>; | ||
|
||
const userServiceMock = { | ||
deleteUser: jest.fn(), | ||
}; | ||
|
||
const matDialogMock = { | ||
close: jest.fn(), | ||
open: jest.fn(), | ||
}; | ||
|
||
const matDialogRefMock = { | ||
afterClosed: jest.fn(), | ||
}; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [], | ||
imports: [], | ||
providers: [{ provide: UserService, useValue: userServiceMock }], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(DeleteUserComponent); | ||
component = fixture.componentInstance; | ||
}); | ||
|
||
it('should create component', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should return true if user is in a team', () => { | ||
component.user = testUserWithTeam; | ||
expect(component.isUserMemberOfTeams()).toBe(true); | ||
}); | ||
|
||
it('should return false if user it not in a team', () => { | ||
component.user = testUserWithoutTeam; | ||
expect(component.isUserMemberOfTeams()).toBe(false); | ||
}); | ||
|
||
it('should return false userOkrData is undefined', () => { | ||
component.user = testUserWithoutTeam; | ||
component.userOkrData = undefined; | ||
expect(component.isUserOwnerOfKeyResults()).toBe(false); | ||
}); | ||
|
||
it('should return true if userOkrData has no keyResults', () => { | ||
component.user = testUserWithoutTeam; | ||
component.userOkrData = { | ||
keyResults: [], | ||
}; | ||
|
||
expect(component.isUserOwnerOfKeyResults()).toBe(false); | ||
}); | ||
|
||
it('should return true if user is owner of keyResults', () => { | ||
component.user = testUserWithoutTeam; | ||
component.userOkrData = { | ||
keyResults: [ | ||
{ | ||
keyResultId: 100, | ||
keyResultName: 'keyResult1', | ||
objectiveId: 200, | ||
objectiveName: 'objective1', | ||
}, | ||
], | ||
}; | ||
|
||
expect(component.isUserOwnerOfKeyResults()).toBe(true); | ||
}); | ||
|
||
it('should delete user if user is not in a team and user has no keyResults', () => { | ||
component.user = testUserWithoutTeam; | ||
component.userOkrData = { | ||
keyResults: [], | ||
}; | ||
matDialogMock.open.mockReturnValue(matDialogRefMock); | ||
matDialogRefMock.afterClosed.mockReturnValue(of()); | ||
userServiceMock.deleteUser.mockReturnValue(of()); | ||
|
||
component.deleteUser(); | ||
|
||
setTimeout(() => expect(userServiceMock.deleteUser).toHaveBeenCalled(), 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