Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coolchock committed Jan 4, 2025
1 parent 069178c commit d1ff991
Showing 1 changed file with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('ModelingExamSubmissionComponent', () => {

const resetComponent = () => {
if (comp) {
mockSubmission = { explanationText: 'Test Explanation', model: JSON.stringify({ model: true }) } as ModelingSubmission;
mockSubmission = { explanationText: 'Test Explanation', model: JSON.stringify({ version: '2.0.0', model: true }) } as ModelingSubmission;
const course = new Course();
course.isAtLeastInstructor = true;
mockExercise = new ModelingExercise(UMLDiagramType.ClassDiagram, course, undefined);
Expand All @@ -36,7 +36,7 @@ describe('ModelingExamSubmissionComponent', () => {
}
};

beforeEach(() => {
beforeEach(async () => {
TestBed.configureTestingModule({
imports: [ArtemisTestModule, NgbTooltipMocksModule],
declarations: [
Expand All @@ -52,14 +52,18 @@ describe('ModelingExamSubmissionComponent', () => {

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

afterEach(() => {
fixture.destroy();
jest.restoreAllMocks();
TestBed.resetTestingModule();
});

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

Expand Down Expand Up @@ -107,7 +111,7 @@ describe('ModelingExamSubmissionComponent', () => {
fixture.detectChanges();
const modelingEditor = fixture.debugElement.query(By.directive(ModelingEditorComponent));
expect(modelingEditor).not.toBeNull();
expect(modelingEditor.componentInstance.umlModel).toEqual({ model: true, assessments: {} });
expect(modelingEditor.componentInstance.umlModel).toEqual({ version: '2.0.0', model: true, assessments: {} });
expect(modelingEditor.componentInstance.withExplanation).toBeTrue();
expect(modelingEditor.componentInstance.explanation).toEqual(mockSubmission.explanationText);
expect(modelingEditor.componentInstance.diagramType).toEqual(UMLDiagramType.ClassDiagram);
Expand Down Expand Up @@ -164,14 +168,8 @@ describe('ModelingExamSubmissionComponent', () => {
});

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

describe('hasUnsavedChanges', () => {
beforeEach(() => {
resetComponent();
});
it('should return true if isSynced false', () => {
comp.studentSubmission().isSynced = false;
expect(comp.hasUnsavedChanges()).toBeTrue();
Expand Down Expand Up @@ -242,8 +237,6 @@ describe('ModelingExamSubmissionComponent', () => {
'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();

expect(comp.submissionVersion).toEqual(submissionVersion);
expect(comp.umlModel).toEqual(parsedModel);
Expand Down

0 comments on commit d1ff991

Please sign in to comment.