Skip to content

Commit

Permalink
Allow points input if no grade existed before, refs 336
Browse files Browse the repository at this point in the history
  • Loading branch information
mfehlmann committed Apr 19, 2022
1 parent a6de0ae commit 7efc744
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
9 changes: 3 additions & 6 deletions src/app/events/components/grade/grade.component.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<div class="d-flex flex-column w-100">
<div
*ngIf="grade.kind === 'grade'"
class="d-flex flex-row"
[class.is-invalid]="pointsInput.errors"
>
<div class="d-flex flex-row" [class.is-invalid]="pointsInput.errors">
<div *ngIf="grade.test.IsPointGrading" class="point-input-container mr-3">
<input
#pointInput
Expand All @@ -16,9 +12,10 @@
(input)="onChange(pointInput.value)"
/>
</div>
<div>
<div *ngIf="grade.kind === 'grade'">
{{ grade.result.GradeDesignation }}
</div>
<div *ngIf="grade.kind === 'no-result'">-</div>
</div>
<div *ngIf="pointsInput.errors" class="invalid-feedback">
{{ 'global.validation-errors.invalidPoints' | translate: { maxPoints } }}
Expand Down
15 changes: 15 additions & 0 deletions src/app/events/utils/tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,19 @@ describe('Test utils', () => {
expect(newResults.length).toBe(1);
expect(newResults).toContain(newResult);
});

it('add new result to test that already has results', () => {
// given
const test = buildTest(1, 1, [buildResult(1, 1)]);
const newResult = buildResult(1, 2, 12345);

// when
const newTests = replaceResult(newResult, [test]);

// then1
expect(newTests.length).toBe(1);
const newResults: Result[] = newTests[0].Results!;
expect(newResults.length).toBe(2);
expect(newResults).toContain(newResult);
});
});
7 changes: 3 additions & 4 deletions src/app/events/utils/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ export function replaceResult(result: Result, tests: Test[]): Test[] {
}

function replaceResultInTest(newResult: Result, test: Test) {
const newResults = test.Results?.map((oldResult) =>
newResult.Id === oldResult.Id ? newResult : oldResult
) || [newResult];
return { ...test, Results: newResults };
const filteredResults =
test.Results?.filter((result) => newResult.Id !== result.Id) || [];
return { ...test, Results: [...filteredResults, newResult] };
}

0 comments on commit 7efc744

Please sign in to comment.