diff --git a/src/main/webapp/app/exercises/text/participate/text-editor.component.html b/src/main/webapp/app/exercises/text/participate/text-editor.component.html index c070d57e29ea..c240142e10c2 100644 --- a/src/main/webapp/app/exercises/text/participate/text-editor.component.html +++ b/src/main/webapp/app/exercises/text/participate/text-editor.component.html @@ -1,5 +1,5 @@
- @if (displayHeader) { + @if (displayHeader()) { {{ 'artemisApp.textSubmission.textEditor' | artemisTranslate }}: @@ -54,7 +54,7 @@ @if (isReadOnlyWithShowResult) { @if (showHistory) {
- +
} } @@ -64,7 +64,7 @@ @if (textExercise) { @@ -79,7 +79,7 @@ @@ -87,7 +87,7 @@ @@ -104,7 +104,7 @@ [disabled]="!isActive || !submission || !isOwnerOfParticipation" (keydown.tab)="onTextEditorTab(textEditor, $event)" (input)="onTextEditorInput($event)" - [hidden]="submission && !submission.submitted && isExamSummary" + [hidden]="submission && !submission.submitted && isExamSummary()" > @if (textExercise?.teamMode) { (); + displayHeader = input(true); + expandProblemStatement = input(true); + inputExercise = input(); + inputSubmission = input(); + inputParticipation = input(); + isExamSummary = input(false); textExercise: TextExercise; participation: StudentParticipation; @@ -109,7 +108,7 @@ export class TextEditorComponent implements OnInit, OnDestroy, ComponentCanDeact if (this.inputValuesArePresent()) { this.setupComponentWithInputValues(); } else { - const participationId = this.participationId !== undefined ? this.participationId : Number(this.route.snapshot.paramMap.get('participationId')); + const participationId = this.participationId() !== undefined ? this.participationId() : Number(this.route.snapshot.paramMap.get('participationId')); this.submissionId = Number(this.route.snapshot.paramMap.get('submissionId')) || undefined; if (Number.isNaN(participationId)) { @@ -121,7 +120,7 @@ export class TextEditorComponent implements OnInit, OnDestroy, ComponentCanDeact this.updateParticipation(this.participation, this.submissionId); }); - this.textService.get(participationId).subscribe({ + this.textService.get(participationId!).subscribe({ next: (data: StudentParticipation) => this.updateParticipation(data, this.submissionId), error: (error: HttpErrorResponse) => onError(this.alertService, error), }); @@ -163,7 +162,7 @@ export class TextEditorComponent implements OnInit, OnDestroy, ComponentCanDeact } private inputValuesArePresent(): boolean { - return !!(this.inputExercise || this.inputSubmission || this.inputParticipation); + return !!(this.inputExercise() || this.inputSubmission() || this.inputParticipation()); } /** @@ -174,14 +173,14 @@ export class TextEditorComponent implements OnInit, OnDestroy, ComponentCanDeact * @private */ private setupComponentWithInputValues() { - if (this.inputExercise) { - this.textExercise = this.inputExercise; + if (this.inputExercise() !== undefined) { + this.textExercise = this.inputExercise()!; } - if (this.inputSubmission) { - this.submission = this.inputSubmission; + if (this.inputSubmission() !== undefined) { + this.submission = this.inputSubmission()!; } - if (this.inputParticipation) { - this.participation = this.inputParticipation; + if (this.inputParticipation() !== undefined) { + this.participation = this.inputParticipation()!; } if (this.submission?.text) { diff --git a/src/main/webapp/app/overview/result-history/result-history.component.html b/src/main/webapp/app/overview/result-history/result-history.component.html index cfa6cdbb897e..3748b2755790 100644 --- a/src/main/webapp/app/overview/result-history/result-history.component.html +++ b/src/main/webapp/app/overview/result-history/result-history.component.html @@ -5,12 +5,19 @@ @for (result of displayedResults; track result; let i = $index) {
-
- +
+
(); + exercise = input(); + selectedResultId = input(); showPreviousDivider = false; displayedResults: Result[]; movedLastRatedResult: boolean; ngOnChanges(): void { - this.showPreviousDivider = this.results.length > MAX_RESULT_HISTORY_LENGTH; - if (this.exercise?.type === ExerciseType.TEXT || this.exercise?.type === ExerciseType.MODELING) { - this.displayedResults = this.results.filter((result) => result.successful !== undefined); + this.showPreviousDivider = this.results().length > MAX_RESULT_HISTORY_LENGTH; + if (this.exercise()?.type === ExerciseType.TEXT || this.exercise()?.type === ExerciseType.MODELING) { + this.displayedResults = this.results().filter((result) => result.successful !== undefined); } else { - this.displayedResults = this.results; + this.displayedResults = this.results(); } const successfulResultsLength = this.displayedResults.length; if (successfulResultsLength > MAX_RESULT_HISTORY_LENGTH) { this.displayedResults = this.displayedResults.slice(successfulResultsLength - MAX_RESULT_HISTORY_LENGTH); - const lastRatedResult = this.results.filter((result) => result.rated).last(); + const lastRatedResult = this.results() + .filter((result) => result.rated) + .last(); if (!this.displayedResults.first()?.rated && lastRatedResult) { this.displayedResults[0] = lastRatedResult; this.movedLastRatedResult = true; diff --git a/src/test/javascript/spec/component/overview/result-history/result-history.component.spec.ts b/src/test/javascript/spec/component/overview/result-history/result-history.component.spec.ts index 8c5333322db6..b5746f24e492 100644 --- a/src/test/javascript/spec/component/overview/result-history/result-history.component.spec.ts +++ b/src/test/javascript/spec/component/overview/result-history/result-history.component.spec.ts @@ -1,8 +1,10 @@ +import { input, runInInjectionContext } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ResultHistoryComponent } from 'app/overview/result-history/result-history.component'; import { MockPipe } from 'ng-mocks'; import { ArtemisDatePipe } from 'app/shared/pipes/artemis-date.pipe'; import { ArtemisTestModule } from '../../../test.module'; +import { Result } from 'app/entities/result.model'; describe('ResultHistoryComponent', () => { let component: ResultHistoryComponent; @@ -25,11 +27,13 @@ describe('ResultHistoryComponent', () => { }); it('should initialize with same rated results', () => { - component.results = [ - { rated: true, id: 1 }, - { rated: true, id: 2 }, - { rated: true, id: 3 }, - ]; + runInInjectionContext(TestBed, () => { + component.results = input([ + { rated: true, id: 1 }, + { rated: true, id: 2 }, + { rated: true, id: 3 }, + ]); + }); component.ngOnChanges(); expect(component.displayedResults).toEqual([ { rated: true, id: 1 }, @@ -39,14 +43,16 @@ describe('ResultHistoryComponent', () => { expect(component.showPreviousDivider).toBeFalse(); expect(component.movedLastRatedResult).toBeFalsy(); - component.results = [ - { rated: false, id: 1 }, - { rated: false, id: 2 }, - { rated: false, id: 3 }, - { rated: false, id: 4 }, - { rated: false, id: 5 }, - { rated: false, id: 6 }, - ]; + runInInjectionContext(TestBed, () => { + component.results = input([ + { rated: false, id: 1 }, + { rated: false, id: 2 }, + { rated: false, id: 3 }, + { rated: false, id: 4 }, + { rated: false, id: 5 }, + { rated: false, id: 6 }, + ]); + }); component.ngOnChanges(); expect(component.displayedResults).toEqual([ { rated: false, id: 2 }, @@ -60,11 +66,13 @@ describe('ResultHistoryComponent', () => { }); it('should initialize with mixed rated results', () => { - component.results = [ - { rated: true, id: 1 }, - { rated: false, id: 2 }, - { rated: false, id: 3 }, - ]; + runInInjectionContext(TestBed, () => { + component.results = input([ + { rated: true, id: 1 }, + { rated: false, id: 2 }, + { rated: false, id: 3 }, + ]); + }); component.ngOnChanges(); expect(component.displayedResults).toEqual([ { rated: true, id: 1 }, @@ -74,14 +82,16 @@ describe('ResultHistoryComponent', () => { expect(component.showPreviousDivider).toBeFalse(); expect(component.movedLastRatedResult).toBeFalsy(); - component.results = [ - { rated: true, id: 1 }, - { rated: false, id: 2 }, - { rated: false, id: 3 }, - { rated: false, id: 4 }, - { rated: false, id: 5 }, - { rated: false, id: 6 }, - ]; + runInInjectionContext(TestBed, () => { + component.results = input([ + { rated: true, id: 1 }, + { rated: false, id: 2 }, + { rated: false, id: 3 }, + { rated: false, id: 4 }, + { rated: false, id: 5 }, + { rated: false, id: 6 }, + ]); + }); component.ngOnChanges(); expect(component.displayedResults).toEqual([ { rated: true, id: 1 }, diff --git a/src/test/javascript/spec/component/text-editor/text-editor.component.spec.ts b/src/test/javascript/spec/component/text-editor/text-editor.component.spec.ts index 0f65d8bc2ef3..47902e658500 100644 --- a/src/test/javascript/spec/component/text-editor/text-editor.component.spec.ts +++ b/src/test/javascript/spec/component/text-editor/text-editor.component.spec.ts @@ -1,4 +1,4 @@ -import { DebugElement } from '@angular/core'; +import { DebugElement, input, runInInjectionContext } from '@angular/core'; import dayjs from 'dayjs/esm'; import { ActivatedRoute, RouterModule, convertToParamMap } from '@angular/router'; import { ComponentFixture, TestBed, fakeAsync, flush, tick } from '@angular/core/testing'; @@ -110,9 +110,11 @@ describe('TextEditorComponent', () => { }); it('should use inputValues if present instead of loading new details', fakeAsync(() => { - comp.inputExercise = textExercise; - comp.inputParticipation = participation; - comp.inputSubmission = { id: 1, text: 'test' }; + runInInjectionContext(TestBed, () => { + comp.inputExercise = input(textExercise); + comp.inputParticipation = input(participation); + comp.inputSubmission = input({ id: 1, text: 'test' }); + }); // @ts-ignore updateParticipation is private const updateParticipationSpy = jest.spyOn(comp, 'updateParticipation'); // @ts-ignore setupComponentWithInputValuesSpy is private