Skip to content

Commit

Permalink
add client test
Browse files Browse the repository at this point in the history
  • Loading branch information
= Enea_Gore committed Nov 4, 2024
1 parent 370efab commit 1c82313
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/test/javascript/spec/component/rating/rating.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ describe('RatingComponent', () => {
ratingComponent.result.participation = { id: 1 } as Participation;
jest.spyOn(ratingService, 'getRating').mockReturnValue(of(2));
ratingComponentFixture.detectChanges();
ratingComponent.result = { id: 91 } as Result;
ratingComponentFixture.detectChanges();
expect(loadRatingSpy).toHaveBeenCalledTimes(2);
expect(ratingComponent.rating).toBe(2);
});

it('should not call loadRating if result ID remains the same', () => {
// without this condition the loadRating might be spammed making unneccesary api calls
const loadRatingSpy = jest.spyOn(ratingComponent, 'loadRating');
ratingComponent.result = { id: 90 } as Result;
ratingComponent.result.submission = { id: 1 } as Submission;
ratingComponent.result.participation = { id: 1 } as Participation;
jest.spyOn(ratingService, 'getRating').mockReturnValue(of(2));
ratingComponentFixture.detectChanges();
ratingComponent.result = { id: 90 } as Result;
ratingComponentFixture.detectChanges();
expect(loadRatingSpy).toHaveBeenCalledOnce();
expect(ratingComponent.rating).toBe(2);
});
Expand Down

0 comments on commit 1c82313

Please sign in to comment.