Skip to content

Commit

Permalink
increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
edkaya committed Oct 26, 2024
1 parent 7819c04 commit 6722606
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('ExerciseSaveButtonComponent', () => {
expect(icon.componentInstance.icon).toBe(faFloppyDisk);
});

it('should emit call onSave when the button is clicked and submission is not synced', () => {
it('should call onSave when the button is clicked and submission is not synced', () => {
TestBed.runInInjectionContext(() => {
component.submission = input({ isSynced: false, submitted: false } as Submission);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { Course } from 'app/entities/course.model';
import { provideRouter } from '@angular/router';
import { ExerciseSaveButtonComponent } from 'app/exam/participate/exercises/exercise-save-button/exercise-save-button.component';
import { TranslateDirective } from '../../../../../../../main/webapp/app/shared/language/translate.directive';
import { By } from '@angular/platform-browser';

describe('QuizExamSubmissionComponent', () => {
let fixture: ComponentFixture<QuizExamSubmissionComponent>;
Expand Down Expand Up @@ -215,4 +216,21 @@ describe('QuizExamSubmissionComponent', () => {
expect(component.dragAndDropMappings.size).toBe(1);
expect(component.shortAnswerSubmittedTexts.size).toBe(0);
});

it('should call triggerSave if save exercise button is clicked', () => {
const submissionVersion = {
content:
'[ {\r\n "quizQuestion" : {\r\n "type" : "drag-and-drop",\r\n "id" : 2,\r\n "title" : "dnd image",\r\n "text" : "Enter your long question if needed",\r\n "hint" : "Add a hint here (visible during the quiz via ?-Button)",\r\n "points" : 1,\r\n "scoringType" : "PROPORTIONAL_WITH_PENALTY",\r\n "randomizeOrder" : true,\r\n "invalid" : false,\r\n "backgroundFilePath" : "/api/files/drag-and-drop/backgrounds/14/DragAndDropBackground_2023-07-08T19-35-26-953_a3265da6.jpg",\r\n "dropLocations" : [ {\r\n "id" : 12,\r\n "posX" : 45.0,\r\n "posY" : 120.0,\r\n "width" : 62.0,\r\n "height" : 52.0,\r\n "invalid" : false\r\n } ],\r\n "dragItems" : [ {\r\n "id" : 11,\r\n "pictureFilePath" : "/api/files/drag-and-drop/drag-items/11/DragItem_2023-07-08T19-35-26-956_2ffe94ba.jpg",\r\n "invalid" : false\r\n } ]\r\n },\r\n "mappings" : [ {\r\n "invalid" : false,\r\n "dragItem" : {\r\n "id" : 11,\r\n "pictureFilePath" : "/api/files/drag-and-drop/drag-items/11/DragItem_2023-07-08T19-35-26-956_2ffe94ba.jpg",\r\n "invalid" : false\r\n },\r\n "dropLocation" : {\r\n "id" : 12,\r\n "posX" : 45.0,\r\n "posY" : 120.0,\r\n "width" : 62.0,\r\n "height" : 52.0,\r\n "invalid" : false\r\n }\r\n } ]\r\n} ]',
} as unknown as SubmissionVersion;
component.studentSubmission = new ModelingSubmission();
component.exercise = new QuizExercise(new Course(), undefined);
component.exercise.quizQuestions = [dragAndDropQuestion];
component.quizConfiguration = { quizQuestions: [dragAndDropQuestion] };
component.setSubmissionVersion(submissionVersion);
fixture.detectChanges();
const saveExerciseSpy = jest.spyOn(component, 'notifyTriggerSave');
const saveButton = fixture.debugElement.query(By.directive(ExerciseSaveButtonComponent));
saveButton.triggerEventHandler('save', null);
expect(saveExerciseSpy).toHaveBeenCalledOnce();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,15 @@ describe('TextExamSubmissionComponent', () => {
expect(component.answer).toBe('submission version');
expect(component.submissionVersion).toBe(submissionVersion);
});

it('should call triggerSave if save exercise button is clicked', () => {
component.exercise = exercise;
textSubmission.text = 'Hello World';
component.studentSubmission = textSubmission;
fixture.detectChanges();
const saveExerciseSpy = jest.spyOn(component, 'notifyTriggerSave');
const saveButton = fixture.debugElement.query(By.directive(ExerciseSaveButtonComponent));
saveButton.triggerEventHandler('save', null);
expect(saveExerciseSpy).toHaveBeenCalledOnce();
});
});

0 comments on commit 6722606

Please sign in to comment.