Skip to content

Commit

Permalink
fix testfiles of services and shared
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Dec 23, 2024
1 parent 7f65fe9 commit 710fbc5
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 338 deletions.
4 changes: 2 additions & 2 deletions frontend/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { OverviewComponent } from './components/overview/overview.component';
import { ObjectiveDetailComponent } from './components/objective-detail/objective-detail.component';
import { CommonModule } from '@angular/common';

const oauthServiceMock = {
const oAuthServiceMock = {
configure(environment: AuthConfig): void {},
initCodeFlow(): void {},
setupAutomaticSilentRefresh(): void {},
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('AppComponent', () => {
NoopAnimationsModule,
CommonModule,
],
providers: [{ provide: OAuthService, useValue: oauthServiceMock }],
providers: [{ provide: OAuthService, useValue: oAuthServiceMock }],
declarations: [AppComponent, OverviewComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
Expand Down
37 changes: 19 additions & 18 deletions frontend/src/app/services/objective-menu-actions.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ describe('ObjectiveMenuActionsService', () => {
specificMenuEntriesSpy = jest.spyOn(service as any, 'getSpecificMenuEntries');
});

afterEach(() => {
expect(specificMenuEntriesSpy).toHaveBeenCalledTimes(1);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
Expand All @@ -31,53 +35,50 @@ describe('ObjectiveMenuActionsService', () => {
it('should return default and specific menu entries for an ongoing objective', () => {
let spyOn = jest.spyOn(service as any, 'getOngoingMenuActions');

let objectiveMinLocal: ObjectiveMin = objectiveMin;
objectiveMinLocal.state = State.ONGOING;
service.getMenu(objectiveMinLocal);
let ongoingObjectiveMin: ObjectiveMin = objectiveMin;
ongoingObjectiveMin.state = State.ONGOING;
service.getMenu(ongoingObjectiveMin);
expect(spyOn).toHaveBeenCalledTimes(1);
});

it('should return draft menu entries for a draft objective', () => {
let spyOn = jest.spyOn(service as any, 'getDraftMenuActions');

let objectiveMinLocal: ObjectiveMin = objectiveMin;
objectiveMinLocal.state = State.DRAFT;
service.getMenu(objectiveMinLocal);
let draftObjectiveMin: ObjectiveMin = objectiveMin;
draftObjectiveMin.state = State.DRAFT;
service.getMenu(draftObjectiveMin);
expect(spyOn).toHaveBeenCalledTimes(1);
});

it('should return completed menu entries for a successful objective', () => {
let spyOn = jest.spyOn(service as any, 'getCompletedMenuActions');

let objectiveMinLocal: ObjectiveMin = objectiveMin;
objectiveMinLocal.state = State.SUCCESSFUL;
service.getMenu(objectiveMinLocal);
let successfulObjectiveMin: ObjectiveMin = objectiveMin;
successfulObjectiveMin.state = State.SUCCESSFUL;
service.getMenu(successfulObjectiveMin);
expect(spyOn).toHaveBeenCalledTimes(1);
});

it('should return completed menu entries for a non-successful objective', () => {
let spyOn = jest.spyOn(service as any, 'getCompletedMenuActions');

let objectiveMinLocal: ObjectiveMin = objectiveMin;
objectiveMinLocal.state = State.NOTSUCCESSFUL;
service.getMenu(objectiveMinLocal);
let notSuccessfulObjectiveMinLocal: ObjectiveMin = objectiveMin;
notSuccessfulObjectiveMinLocal.state = State.NOTSUCCESSFUL;
service.getMenu(notSuccessfulObjectiveMinLocal);
expect(spyOn).toHaveBeenCalledTimes(1);
});
afterEach(() => {
expect(specificMenuEntriesSpy).toHaveBeenCalledTimes(1);
});
});

describe('getReleaseAction', () => {
it('should return release from backlog action for an objective in backlog quarter', () => {
describe('get correct release action', () => {
it('should return release from backlog action for an objective in the backlog quarter', () => {
jest.spyOn(service as any, 'isInBacklogQuarter').mockReturnValue(true);
let spyOn = jest.spyOn(service as any, 'isInBacklogQuarter').mockReturnValue(true);
// @ts-expect-error
service.getReleaseAction(objectiveMin);
expect(spyOn).toHaveBeenCalledTimes(1);
});

it('should return release from quarter action for an objective in non-backlog quarter', () => {
it('should return release from quarter action for an objective in a non-backlog quarter', () => {
let spyOn = jest.spyOn(service as any, 'isInBacklogQuarter').mockReturnValue(false);
// @ts-expect-error
service.getReleaseAction(objectiveMin);
Expand Down
26 changes: 13 additions & 13 deletions frontend/src/app/services/toaster.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,49 @@ import { ToasterType } from '../shared/types/enums/ToasterType';

describe('ToasterService', () => {
let service: ToasterService;
let toastr: ToastrService;
let toaster: ToastrService;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [ToastrModule.forRoot()],
providers: [ToasterService],
});
service = TestBed.inject(ToasterService);
toastr = TestBed.inject(ToastrService);
toaster = TestBed.inject(ToastrService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});

it('showSuccess should call right method', () => {
jest.spyOn(toastr, 'success');
it('should call right method for showSuccess', () => {
jest.spyOn(toaster, 'success');
service.showSuccess('test');
expect(toastr.success).toBeCalledWith('test', 'Erfolgreich!');
expect(toaster.success).toHaveBeenCalledWith('test', 'Erfolgreich!');
});

it('showError should call right method', () => {
jest.spyOn(toastr, 'error');
it('should call right method for showError', () => {
jest.spyOn(toaster, 'error');
service.showError('test');
expect(toastr.error).toBeCalledWith('test', 'Fehler!');
expect(toaster.error).toHaveBeenCalledWith('test', 'Fehler!');
});

it('showWarn should call right method', () => {
jest.spyOn(toastr, 'warning');
it('should call right method for showWarn', () => {
jest.spyOn(toaster, 'warning');
service.showWarn('test');
expect(toastr.warning).toBeCalledWith('test', 'Warnung!');
expect(toaster.warning).toHaveBeenCalledWith('test', 'Warnung!');
});

it.each([
[ToasterType.SUCCESS, 'message', 'showSuccess'],
[ToasterType.WARN, 'message', 'showWarn'],
[ToasterType.ERROR, 'message', 'showError'],
[999, 'message', 'showSuccess'],
])('showWarn should call right method', (toasterType: number, message: string, func: any) => {
])('should call right method for dynamic toaster', (toasterType: number, message: string, func: any) => {
const spy = jest.spyOn(service, func);

service.showCustomToaster(message, toasterType);

expect(spy).toBeCalledWith(message);
expect(spy).toHaveBeenCalledWith(message);
});
});
20 changes: 10 additions & 10 deletions frontend/src/app/services/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ describe('UserService', () => {
expect(service).toBeTruthy();
});

it('getUsers should only reload users when they are not loaded yet', (done) => {
it('should only reload getUsers when they are not loaded yet', (done) => {
const spy = jest.spyOn(service, 'reloadUsers');
service.getUsers().subscribe(() => {
expect(spy).toBeCalledTimes(1);
expect(spy).toHaveBeenCalledTimes(1);
httpMock.expectOne(URL);
service.getUsers().subscribe((users) => {
expect(spy).toBeCalledTimes(1);
expect(spy).toHaveBeenCalledTimes(1);
expect(users).toStrictEqual([]);
done();
});
});
});

it('get current user should throw error, when not loaded', () => {
expect(() => service.getCurrentUser()).toThrowError('user should not be undefined here');
it('should throw error if current User is not loaded', () => {
expect(() => service.getCurrentUser()).toThrow('user should not be undefined here');
});

it('init current user should load user', (done) => {
expect(() => service.getCurrentUser()).toThrowError('user should not be undefined here');
it('should load current user after user init', (done) => {
expect(() => service.getCurrentUser()).toThrow('user should not be undefined here');
service.getOrInitCurrentUser().subscribe(() => {
expect(service.getCurrentUser()).toBe(users[0]);
done();
Expand All @@ -52,7 +52,7 @@ describe('UserService', () => {
req.flush(users[0]);
});

it('setIsOkrChampion should call put operation, reloadUsers and reloadCurrentUser', fakeAsync(() => {
it('should call put operation, reloadUsers and reloadCurrentUser when setIsOkrChampion is called', fakeAsync(() => {
service.setIsOkrChampion(testUser, true).subscribe();
const req = httpMock.expectOne(`api/v1/users/${testUser.id}/isokrchampion/true`);
req.flush(users[0]);
Expand All @@ -65,7 +65,7 @@ describe('UserService', () => {
req3.flush({});
}));

it('createUsers should call createAll and reloadUsers', fakeAsync(() => {
it('should call createAll and reloadUsers when createUsers is called', fakeAsync(() => {
service.createUsers(users).subscribe();
const req = httpMock.expectOne(`api/v1/users/createall`);
req.flush(users);
Expand All @@ -76,7 +76,7 @@ describe('UserService', () => {
req2.flush({});
}));

it('deleteUser should call /userId and reloadUsers', fakeAsync(() => {
it('should call /userId and reloadUsers when deleteUser is called', fakeAsync(() => {
service.deleteUser(testUser).subscribe();
const req = httpMock.expectOne(`api/v1/users/${testUser.id}`);
req.flush(users);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('ScoringComponent', () => {
[{ fail: 100, commit: 100, target: 99, className: 'score-green', borderClass: 'target' }],
[{ fail: 100, commit: 100, target: 100, className: 'score-green', borderClass: 'target' }],
[{ fail: 100, commit: 100, target: 101, className: 'score-stretch', borderClass: 'none' }],
])('should set styles correctly', async (object: any) => {
])('should set styles correctly for given values', async (object: any) => {
component.targetPercent = object.target;
component.commitPercent = object.commit;
component.failPercent = object.fail;
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('ScoringComponent', () => {
[{ zoneValue: Zone.FAIL, fail: 100, commit: 0, target: 0 }],
[{ zoneValue: Zone.COMMIT, fail: 100, commit: 100, target: 0 }],
[{ zoneValue: Zone.TARGET, fail: 100, commit: 100, target: 100 }],
])('should set percentages correctly', (object: any) => {
])('should set percentages correctly for ordinal zone', (object: any) => {
//Reset component
component.targetPercent = 0;
component.commitPercent = 0;
Expand Down

This file was deleted.

Loading

0 comments on commit 710fbc5

Please sign in to comment.