Skip to content

Commit

Permalink
fix modeling-exam-submission.component.spec.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
coolchock committed Jan 4, 2025
1 parent 069178c commit ea55e4d
Showing 1 changed file with 33 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,20 @@ describe('ModelingExamSubmissionComponent', () => {

fixture = TestBed.createComponent(ModelingExamSubmissionComponent);
comp = fixture.componentInstance;
resetComponent();
fixture.detectChanges();
});

afterEach(() => {
jest.restoreAllMocks();
});

describe('With exercise', () => {
beforeEach(() => {
resetComponent();
});
it('should initialize', () => {
fixture.detectChanges();
expect(ModelingExamSubmissionComponent).not.toBeNull();
});

it('should show static text in header', () => {
fixture.detectChanges();
const el = fixture.debugElement.query(By.css('.exercise-title'));
expect(el).not.toBeNull();
});
Expand Down Expand Up @@ -121,12 +122,6 @@ describe('ModelingExamSubmissionComponent', () => {
});

describe('ngOnInit', () => {
beforeEach(() => {
resetComponent();
});
afterEach(() => {
jest.restoreAllMocks();
});
it('should call updateViewFromSubmission', () => {
const updateViewStub = jest.spyOn(comp, 'updateViewFromSubmission');
comp.ngOnInit();
Expand All @@ -135,27 +130,18 @@ describe('ModelingExamSubmissionComponent', () => {
});

describe('getSubmission', () => {
beforeEach(() => {
resetComponent();
});
it('should return student submission', () => {
expect(comp.getSubmission()).toEqual(mockSubmission);
});
});

describe('getExercise', () => {
beforeEach(() => {
resetComponent();
});
it('should return exercise', () => {
expect(comp.getExerciseId()).toEqual(mockExercise.id);
});
});

describe('updateProblemStatement', () => {
beforeEach(() => {
resetComponent();
});
it('should update problem statement', () => {
const newProblemStatement = 'new problem statement';
comp.updateProblemStatement(newProblemStatement);
Expand All @@ -164,13 +150,6 @@ describe('ModelingExamSubmissionComponent', () => {
});

describe('updateSubmissionFromView', () => {
beforeEach(() => {
resetComponent();
fixture.detectChanges();
});
afterEach(() => {
jest.restoreAllMocks();
});
it('should set submission model to new model from modeling editor', () => {
const modelingEditor = fixture.debugElement.query(By.directive(ModelingEditorComponent)).componentInstance;
const newModel = { newModel: true };
Expand All @@ -185,9 +164,6 @@ describe('ModelingExamSubmissionComponent', () => {
});

describe('hasUnsavedChanges', () => {
beforeEach(() => {
resetComponent();
});
it('should return true if isSynced false', () => {
comp.studentSubmission().isSynced = false;
expect(comp.hasUnsavedChanges()).toBeTrue();
Expand All @@ -199,9 +175,6 @@ describe('ModelingExamSubmissionComponent', () => {
});

describe('modelChanged', () => {
beforeEach(() => {
resetComponent();
});
it('should set isSynced to false', () => {
comp.studentSubmission().isSynced = true;
comp.modelChanged({} as UMLModel);
Expand All @@ -210,9 +183,6 @@ describe('ModelingExamSubmissionComponent', () => {
});

describe('explanationChanged', () => {
beforeEach(() => {
resetComponent();
});
it('should set explanation text to given value and isSynced to false', () => {
const explanationText = 'New Explanation Text';
comp.studentSubmission().isSynced = true;
Expand All @@ -222,31 +192,33 @@ describe('ModelingExamSubmissionComponent', () => {
});
});

it('should update the model on submission version change', async () => {
resetComponent();
const parsedModel = {
version: '3.0.0',
type: 'ClassDiagram',
size: { width: 220, height: 420 },
interactive: { elements: {}, relationships: {} },
elements: {},
relationships: {},
assessments: {},
} as UMLModel;

jest.spyOn(comp, 'modelingEditor').mockReturnValue({
apollonEditor: { nextRender: Promise.resolve(), model: parsedModel } as unknown as ApollonEditor,
} as unknown as ModelingEditorComponent);
const submissionVersion = {
content:
'Model: {"version":"3.0.0","type":"ClassDiagram","size":{"width":220,"height":420},"interactive":{"elements":{},"relationships":{}},"elements":{},"relationships":{},"assessments":{}}; Explanation: explanation',
} as unknown as SubmissionVersion;
await comp.setSubmissionVersion(submissionVersion);
fixture.detectChanges();
await fixture.whenStable();
describe('version changed', () => {
it('should update the model on submission version change', async () => {
const parsedModel = {
version: '3.0.0',
type: 'ClassDiagram',
size: { width: 220, height: 420 },
interactive: { elements: {}, relationships: {} },
elements: {},
relationships: {},
assessments: {},
} as UMLModel;

jest.spyOn(comp, 'modelingEditor').mockReturnValue({
apollonEditor: { nextRender: Promise.resolve(), model: parsedModel } as unknown as ApollonEditor,
} as unknown as ModelingEditorComponent);
const submissionVersion = {
content:
'Model: {"version":"3.0.0","type":"ClassDiagram","size":{"width":220,"height":420},"interactive":{"elements":{},"relationships":{}},"elements":{},"relationships":{},"assessments":{}}; Explanation: explanation',
} as unknown as SubmissionVersion;
await comp.setSubmissionVersion(submissionVersion);

expect(comp.submissionVersion).toEqual(submissionVersion);
expect(comp.umlModel).toEqual(parsedModel);
expect(comp.explanationText).toBe('explanation');
fixture.detectChanges();
await fixture.whenStable();

expect(comp.submissionVersion).toEqual(submissionVersion);
expect(comp.umlModel).toEqual(parsedModel);
expect(comp.explanationText).toBe('explanation');
});
});
});

0 comments on commit ea55e4d

Please sign in to comment.