From 6c50f3380a6c2ed6679440136d7f95d25c0b9ec8 Mon Sep 17 00:00:00 2001 From: Marc Date: Wed, 11 May 2022 11:38:56 +0200 Subject: [PATCH 01/12] enable sorting for finalGrades, refs 337 --- .../test-edit-grades.component.html | 4 ++++ src/app/shared/models/student-grades.ts | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/app/events/components/test-edit-grades/test-edit-grades.component.html b/src/app/events/components/test-edit-grades/test-edit-grades.component.html index 0e0830ac4..857fede47 100644 --- a/src/app/events/components/test-edit-grades/test-edit-grades.component.html +++ b/src/app/events/components/test-edit-grades/test-edit-grades.component.html @@ -80,12 +80,16 @@
{{ 'tests.grade' | translate }}
+
+ {{ state.getSortingChar$('FinalGrade') | async }} +
) => ( sg2: StudentGrade ): number => { const modificator = ascending ? 1 : -1; + console.log('SORTING: compareFn: ', sg1, sg2); switch (key) { case 'FullName': return ( modificator * sg1.student.FullName.localeCompare(sg2.student.FullName) ); + case 'FinalGrade': + if (!sg1.finalGrade.finalGradeId || !sg2.finalGrade.finalGradeId) + return 0; + return ( + modificator * + compareNumbers(sg1.finalGrade.finalGradeId, sg2.finalGrade.finalGradeId) + ); } return modificator * compareGrades(key, sg1, sg2); @@ -130,6 +138,12 @@ const compareGrades = ( ); }; +function compareNumbers(nr1: number, nr2: number) { + if (nr1 === nr2) return 0; + if (nr1 < nr2) return -1; + return 1; +} + function isGrade(g: GradeOrNoResult): g is Grade { return g.kind === 'grade'; } From 4a1dd8d1e8a5fb090859086021b0bf2fe8ce08ac Mon Sep 17 00:00:00 2001 From: Marc Date: Wed, 11 May 2022 13:55:51 +0200 Subject: [PATCH 02/12] enable sorting for tests mean, refs 337 --- .../test-edit-grades/test-edit-grades.component.html | 4 ++++ src/app/shared/models/student-grades.ts | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/app/events/components/test-edit-grades/test-edit-grades.component.html b/src/app/events/components/test-edit-grades/test-edit-grades.component.html index 857fede47..d429494ec 100644 --- a/src/app/events/components/test-edit-grades/test-edit-grades.component.html +++ b/src/app/events/components/test-edit-grades/test-edit-grades.component.html @@ -94,12 +94,16 @@
{{ 'tests.mean' | translate }}
+
+ {{ state.getSortingChar$('TestsMean') | async }} +
) => ( sg2: StudentGrade ): number => { const modificator = ascending ? 1 : -1; - console.log('SORTING: compareFn: ', sg1, sg2); switch (key) { case 'FullName': @@ -105,11 +104,17 @@ export const compareFn = ({ key, ascending }: Sorting) => ( ); case 'FinalGrade': if (!sg1.finalGrade.finalGradeId || !sg2.finalGrade.finalGradeId) - return 0; + return -1; return ( modificator * compareNumbers(sg1.finalGrade.finalGradeId, sg2.finalGrade.finalGradeId) ); + case 'TestsMean': + if (!sg1.finalGrade.average || !sg2.finalGrade.average) return -1; + return ( + modificator * + compareNumbers(sg1.finalGrade.average, sg2.finalGrade.average) + ); } return modificator * compareGrades(key, sg1, sg2); From abe8ca6d90546f79a80d383089d71dc64cc1899e Mon Sep 17 00:00:00 2001 From: Marc Date: Wed, 11 May 2022 15:58:00 +0200 Subject: [PATCH 03/12] fix sorting for tests with and without points, refs 337 --- src/app/shared/models/student-grades.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/app/shared/models/student-grades.ts b/src/app/shared/models/student-grades.ts index 7b55b8319..01330c95a 100644 --- a/src/app/shared/models/student-grades.ts +++ b/src/app/shared/models/student-grades.ts @@ -133,14 +133,15 @@ const compareGrades = ( .filter(isGrade) .find((g: Grade) => g.test.Id === test.Id); - // oh boy - typescript is really nice /s - if (test.IsPointGrading) { + const sorting = + (grades1?.result?.GradeId?.valueOf() ?? 0) - + (grades2?.result?.GradeId?.valueOf() ?? 0); + + if (sorting === 0 && test.IsPointGrading) { return (grades2?.result?.Points ?? 0) - (grades1?.result?.Points ?? 0); } - return ( - (grades2?.result?.GradeValue?.valueOf() ?? 0) - - (grades1?.result?.GradeValue?.valueOf() ?? 0) - ); + + return sorting; }; function compareNumbers(nr1: number, nr2: number) { From 4d87c2db544e4d134c7cf72d08f1c55139e819e2 Mon Sep 17 00:00:00 2001 From: Marc Date: Wed, 11 May 2022 16:25:28 +0200 Subject: [PATCH 04/12] reset points when sorting, refs 333 --- src/app/events/components/grade/grade.component.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/events/components/grade/grade.component.ts b/src/app/events/components/grade/grade.component.ts index 58919a270..336dcdb3c 100644 --- a/src/app/events/components/grade/grade.component.ts +++ b/src/app/events/components/grade/grade.component.ts @@ -2,6 +2,7 @@ import { Component, EventEmitter, Input, + OnChanges, OnDestroy, OnInit, Output, @@ -33,7 +34,7 @@ const DEBOUNCE_TIME = 500; templateUrl: './grade.component.html', styleUrls: ['./grade.component.scss'], }) -export class GradeComponent implements OnInit, OnDestroy { +export class GradeComponent implements OnInit, OnDestroy, OnChanges { @Input() grade: GradeOrNoResult; @Input() student: Student; @Input() tabIndex: number; @@ -94,6 +95,11 @@ export class GradeComponent implements OnInit, OnDestroy { .subscribe((body) => this.gradeChanged.emit(body)); } + ngOnChanges() { + if (this.grade.kind === 'grade') + this.pointsInput.setValue(this.grade.result.Points); + } + ngOnDestroy() { this.destroy$.next(); } From da5704214d92356426c94f1643c17f9065b4747d Mon Sep 17 00:00:00 2001 From: Marc Date: Wed, 11 May 2022 16:33:30 +0200 Subject: [PATCH 05/12] fix mean sorting when there are no results, refs 333 --- src/app/shared/models/student-grades.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/shared/models/student-grades.ts b/src/app/shared/models/student-grades.ts index 01330c95a..54fac8334 100644 --- a/src/app/shared/models/student-grades.ts +++ b/src/app/shared/models/student-grades.ts @@ -104,13 +104,14 @@ export const compareFn = ({ key, ascending }: Sorting) => ( ); case 'FinalGrade': if (!sg1.finalGrade.finalGradeId || !sg2.finalGrade.finalGradeId) - return -1; + return modificator * -1; return ( modificator * compareNumbers(sg1.finalGrade.finalGradeId, sg2.finalGrade.finalGradeId) ); case 'TestsMean': - if (!sg1.finalGrade.average || !sg2.finalGrade.average) return -1; + if (!sg1.finalGrade.average || !sg2.finalGrade.average) + return modificator * -1; return ( modificator * compareNumbers(sg1.finalGrade.average, sg2.finalGrade.average) From 7e2532eb46e53b1c36fd6ad1e22ff11c4cadde66 Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 12 May 2022 10:53:52 +0200 Subject: [PATCH 06/12] fix sorting for tests with point grading, refs 333 --- src/app/events/components/grade/grade.component.ts | 1 + src/app/shared/models/student-grades.ts | 11 +++-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/app/events/components/grade/grade.component.ts b/src/app/events/components/grade/grade.component.ts index 336dcdb3c..c21a27128 100644 --- a/src/app/events/components/grade/grade.component.ts +++ b/src/app/events/components/grade/grade.component.ts @@ -98,6 +98,7 @@ export class GradeComponent implements OnInit, OnDestroy, OnChanges { ngOnChanges() { if (this.grade.kind === 'grade') this.pointsInput.setValue(this.grade.result.Points); + if (this.grade.kind === 'no-result') this.pointsInput.setValue(null); } ngOnDestroy() { diff --git a/src/app/shared/models/student-grades.ts b/src/app/shared/models/student-grades.ts index 54fac8334..f20cfa48f 100644 --- a/src/app/shared/models/student-grades.ts +++ b/src/app/shared/models/student-grades.ts @@ -134,15 +134,10 @@ const compareGrades = ( .filter(isGrade) .find((g: Grade) => g.test.Id === test.Id); - const sorting = - (grades1?.result?.GradeId?.valueOf() ?? 0) - - (grades2?.result?.GradeId?.valueOf() ?? 0); + if (test.IsPointGrading) + return (grades1?.result.Points ?? 0) - (grades2?.result.Points ?? 0); - if (sorting === 0 && test.IsPointGrading) { - return (grades2?.result?.Points ?? 0) - (grades1?.result?.Points ?? 0); - } - - return sorting; + return (grades1?.result.GradeId ?? 0) - (grades2?.result.GradeId ?? 0); }; function compareNumbers(nr1: number, nr2: number) { From 06527c432d7d023ebd7ad793394ace317b674b98 Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 12 May 2022 11:37:47 +0200 Subject: [PATCH 07/12] fix sorting for tests with point grading, refs 333 --- src/app/shared/models/student-grades.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/shared/models/student-grades.ts b/src/app/shared/models/student-grades.ts index f20cfa48f..a2ff5aefb 100644 --- a/src/app/shared/models/student-grades.ts +++ b/src/app/shared/models/student-grades.ts @@ -137,7 +137,11 @@ const compareGrades = ( if (test.IsPointGrading) return (grades1?.result.Points ?? 0) - (grades2?.result.Points ?? 0); - return (grades1?.result.GradeId ?? 0) - (grades2?.result.GradeId ?? 0); + return ( + ((grades1?.result.GradeId ?? Number.POSITIVE_INFINITY) - + (grades2?.result.GradeId ?? Number.POSITIVE_INFINITY)) * + -1 + ); }; function compareNumbers(nr1: number, nr2: number) { From ae368b5b4d2d21113b99ad1df9dcbd04130cef16 Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 12 May 2022 13:05:42 +0200 Subject: [PATCH 08/12] WIP: Add unit test for sorting point grading tests, refs 333 --- src/app/shared/models/student-grades.spec.ts | 72 ++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/app/shared/models/student-grades.spec.ts b/src/app/shared/models/student-grades.spec.ts index 02d61553b..ca4b7efd4 100644 --- a/src/app/shared/models/student-grades.spec.ts +++ b/src/app/shared/models/student-grades.spec.ts @@ -14,7 +14,12 @@ import { StudentGrade, toMaxPoints, transform, + compareFn, + SortKeys, } from './student-grades'; +import { Sorting } from '../services/sort.service'; +import { Student } from './student.model'; +import { Grade } from './student-grades'; describe('student-grade utils', () => { describe('student grades with results and final grades', () => { @@ -248,5 +253,72 @@ describe('student-grade utils', () => { 4.333333333333333 ); }); + + it('should sort tests by points', () => { + let student: Student = buildStudent(1234); + + let thisFinalGrade: FinalGrade = { + id: 12, + average: 4, + finalGradeId: 20, + canGrade: true, + }; + + let thatFinalGrade: FinalGrade = { + id: 13, + average: 5, + finalGradeId: 21, + canGrade: true, + }; + + let resultA = buildResult(123, 456); + resultA.Points = 100; + + let test = buildTest(1234, 123, [resultA]); + + let gradeA: Grade = { + kind: 'grade', + result: resultA, + test: test, + }; + + let resultB = buildResult(123, 456); + resultB.Points = 50; + + let testB = buildTest(1234, 123, [resultA]); + + let gradeB: Grade = { + kind: 'grade', + result: resultA, + test: testB, + }; + + let thisStudentGrade: StudentGrade = { + student: student, + finalGrade: thisFinalGrade, + grades: [gradeA], + }; + let thatStudentGrade: StudentGrade = { + student: student, + finalGrade: thatFinalGrade, + grades: [gradeB], + }; + + let thisResult = buildResult(123, 12); + thisResult.Points = 100; + let thisTest = buildTest(1234, 123, [thisResult]); + thisTest.IsPointGrading = true; + + let sorting: Sorting = { key: thisTest, ascending: true }; + + const studentGrades = [thisStudentGrade, thatStudentGrade]; + + // when + + // then + expect(studentGrades.sort(compareFn(sorting))).toContain( + thisStudentGrade + ); + }); }); }); From 163e447d8984a5e5c810e1c5d5f4be6e27321b4f Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 12 May 2022 15:04:54 +0200 Subject: [PATCH 09/12] wrap table sorting test in describe, refs 333 --- src/app/shared/models/student-grades.spec.ts | 132 ++++++++++--------- 1 file changed, 67 insertions(+), 65 deletions(-) diff --git a/src/app/shared/models/student-grades.spec.ts b/src/app/shared/models/student-grades.spec.ts index ca4b7efd4..098ff2973 100644 --- a/src/app/shared/models/student-grades.spec.ts +++ b/src/app/shared/models/student-grades.spec.ts @@ -254,71 +254,73 @@ describe('student-grade utils', () => { ); }); - it('should sort tests by points', () => { - let student: Student = buildStudent(1234); - - let thisFinalGrade: FinalGrade = { - id: 12, - average: 4, - finalGradeId: 20, - canGrade: true, - }; - - let thatFinalGrade: FinalGrade = { - id: 13, - average: 5, - finalGradeId: 21, - canGrade: true, - }; - - let resultA = buildResult(123, 456); - resultA.Points = 100; - - let test = buildTest(1234, 123, [resultA]); - - let gradeA: Grade = { - kind: 'grade', - result: resultA, - test: test, - }; - - let resultB = buildResult(123, 456); - resultB.Points = 50; - - let testB = buildTest(1234, 123, [resultA]); - - let gradeB: Grade = { - kind: 'grade', - result: resultA, - test: testB, - }; - - let thisStudentGrade: StudentGrade = { - student: student, - finalGrade: thisFinalGrade, - grades: [gradeA], - }; - let thatStudentGrade: StudentGrade = { - student: student, - finalGrade: thatFinalGrade, - grades: [gradeB], - }; - - let thisResult = buildResult(123, 12); - thisResult.Points = 100; - let thisTest = buildTest(1234, 123, [thisResult]); - thisTest.IsPointGrading = true; - - let sorting: Sorting = { key: thisTest, ascending: true }; - - const studentGrades = [thisStudentGrade, thatStudentGrade]; - - // when - - // then - expect(studentGrades.sort(compareFn(sorting))).toContain( - thisStudentGrade - ); + describe('test table sorting', () => { + it('should sort tests by points', () => { + let student: Student = buildStudent(1234); + + let thisFinalGrade: FinalGrade = { + id: 12, + average: 4, + finalGradeId: 20, + canGrade: true, + }; + + let thatFinalGrade: FinalGrade = { + id: 13, + average: 5, + finalGradeId: 21, + canGrade: true, + }; + + let resultA = buildResult(123, 456); + resultA.Points = 100; + + let test = buildTest(1234, 123, [resultA]); + + let gradeA: Grade = { + kind: 'grade', + result: resultA, + test: test, + }; + + let resultB = buildResult(123, 456); + resultB.Points = 50; + + let testB = buildTest(1234, 123, [resultA]); + + let gradeB: Grade = { + kind: 'grade', + result: resultA, + test: testB, + }; + + let thisStudentGrade: StudentGrade = { + student: student, + finalGrade: thisFinalGrade, + grades: [gradeA], + }; + let thatStudentGrade: StudentGrade = { + student: student, + finalGrade: thatFinalGrade, + grades: [gradeB], + }; + + let thisResult = buildResult(123, 12); + thisResult.Points = 100; + let thisTest = buildTest(1234, 123, [thisResult]); + thisTest.IsPointGrading = true; + + let sorting: Sorting = { key: thisTest, ascending: true }; + + const studentGrades = [thisStudentGrade, thatStudentGrade]; + + // when + + // then + expect(studentGrades.sort(compareFn(sorting))).toContain( + thisStudentGrade + ); + }); }); }); }); From 74b8704a81a4acd1f069e0c9255fe3d263864849 Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 12 May 2022 16:02:09 +0200 Subject: [PATCH 10/12] rename grade in studentGrades, refs 333 --- .../components/grade/grade.component.spec.ts | 10 +++++----- src/app/shared/models/student-grades.spec.ts | 6 +++--- src/app/shared/models/student-grades.ts | 14 +++++++------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/app/events/components/grade/grade.component.spec.ts b/src/app/events/components/grade/grade.component.spec.ts index 1a600798e..25eebd820 100644 --- a/src/app/events/components/grade/grade.component.spec.ts +++ b/src/app/events/components/grade/grade.component.spec.ts @@ -1,7 +1,7 @@ import { DebugElement } from '@angular/core'; import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { DropDownItem } from 'src/app/shared/models/drop-down-item.model'; -import { Grade, NoResult } from 'src/app/shared/models/student-grades'; +import { GradeKind, NoResult } from 'src/app/shared/models/student-grades'; import { byTestId } from 'src/specs/utils'; import { buildResult, @@ -51,7 +51,7 @@ describe('GradeComponent', () => { describe('tests without point grading', () => { let gradingScaleOptions: DropDownItem[]; - let grade: Grade; + let grade: GradeKind; beforeEach(() => { gradingScaleOptions = [ @@ -150,7 +150,7 @@ describe('GradeComponent', () => { it('should show points in input field', () => { // given - const grade: Grade = { + const grade: GradeKind = { kind: 'grade', result, test, @@ -168,7 +168,7 @@ describe('GradeComponent', () => { }); }); describe('points input validation', () => { - let grade: Grade; + let grade: GradeKind; beforeEach(() => { grade = { @@ -209,7 +209,7 @@ describe('GradeComponent', () => { }); describe('enable and disable grading scale options', () => { - let grade: Grade; + let grade: GradeKind; beforeEach(() => { grade = { diff --git a/src/app/shared/models/student-grades.spec.ts b/src/app/shared/models/student-grades.spec.ts index 098ff2973..91f380e63 100644 --- a/src/app/shared/models/student-grades.spec.ts +++ b/src/app/shared/models/student-grades.spec.ts @@ -19,7 +19,7 @@ import { } from './student-grades'; import { Sorting } from '../services/sort.service'; import { Student } from './student.model'; -import { Grade } from './student-grades'; +import { GradeKind } from './student-grades'; describe('student-grade utils', () => { describe('student grades with results and final grades', () => { @@ -277,7 +277,7 @@ describe('student-grade utils', () => { let test = buildTest(1234, 123, [resultA]); - let gradeA: Grade = { + let gradeA: GradeKind = { kind: 'grade', result: resultA, test: test, @@ -288,7 +288,7 @@ describe('student-grade utils', () => { let testB = buildTest(1234, 123, [resultA]); - let gradeB: Grade = { + let gradeB: GradeKind = { kind: 'grade', result: resultA, test: testB, diff --git a/src/app/shared/models/student-grades.ts b/src/app/shared/models/student-grades.ts index a2ff5aefb..0ac3cf94b 100644 --- a/src/app/shared/models/student-grades.ts +++ b/src/app/shared/models/student-grades.ts @@ -17,7 +17,7 @@ export type FinalGrade = { canGrade: boolean; }; -export type Grade = { +export type GradeKind = { kind: 'grade'; result: Result; test: Test; @@ -28,7 +28,7 @@ export type NoResult = { test: Test; }; -export type GradeOrNoResult = Grade | NoResult; +export type GradeOrNoResult = GradeKind | NoResult; export type SortKeys = 'FullName' | Test | 'FinalGrade' | 'TestsMean'; @@ -126,13 +126,13 @@ const compareGrades = ( sg1: StudentGrade, sg2: StudentGrade ): number => { - const grades1: Grade | undefined = sg1.grades + const grades1: GradeKind | undefined = sg1.grades .filter(isGrade) - .find((g: Grade) => g.test.Id === test.Id); + .find((g: GradeKind) => g.test.Id === test.Id); - const grades2: Grade | undefined = sg2.grades + const grades2: GradeKind | undefined = sg2.grades .filter(isGrade) - .find((g: Grade) => g.test.Id === test.Id); + .find((g: GradeKind) => g.test.Id === test.Id); if (test.IsPointGrading) return (grades1?.result.Points ?? 0) - (grades2?.result.Points ?? 0); @@ -150,7 +150,7 @@ function compareNumbers(nr1: number, nr2: number) { return 1; } -function isGrade(g: GradeOrNoResult): g is Grade { +function isGrade(g: GradeOrNoResult): g is GradeKind { return g.kind === 'grade'; } From 3eb79203e2e5872f23b819c5adb2a5ce00448cbb Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 12 May 2022 16:08:27 +0200 Subject: [PATCH 11/12] create spec builders for studentGrade, refs 333 --- src/app/shared/models/student-grades.spec.ts | 78 ++++++-------------- src/spec-builders.ts | 38 ++++++++++ 2 files changed, 60 insertions(+), 56 deletions(-) diff --git a/src/app/shared/models/student-grades.spec.ts b/src/app/shared/models/student-grades.spec.ts index 91f380e63..4e25412c3 100644 --- a/src/app/shared/models/student-grades.spec.ts +++ b/src/app/shared/models/student-grades.spec.ts @@ -1,9 +1,11 @@ import { Course } from 'src/app/shared/models/course.model'; import { buildCourse, + buildGradeKind, buildGrading, buildResult, buildStudent, + buildStudentGrade, buildTest, } from 'src/spec-builders'; import { @@ -258,67 +260,31 @@ describe('student-grade utils', () => { it('should sort tests by points', () => { let student: Student = buildStudent(1234); - let thisFinalGrade: FinalGrade = { - id: 12, - average: 4, - finalGradeId: 20, - canGrade: true, - }; - - let thatFinalGrade: FinalGrade = { - id: 13, - average: 5, - finalGradeId: 21, - canGrade: true, - }; - - let resultA = buildResult(123, 456); - resultA.Points = 100; - - let test = buildTest(1234, 123, [resultA]); - - let gradeA: GradeKind = { - kind: 'grade', - result: resultA, - test: test, - }; - - let resultB = buildResult(123, 456); - resultB.Points = 50; - - let testB = buildTest(1234, 123, [resultA]); - - let gradeB: GradeKind = { - kind: 'grade', - result: resultA, - test: testB, - }; - - let thisStudentGrade: StudentGrade = { - student: student, - finalGrade: thisFinalGrade, - grades: [gradeA], - }; - let thatStudentGrade: StudentGrade = { - student: student, - finalGrade: thatFinalGrade, - grades: [gradeB], - }; - - let thisResult = buildResult(123, 12); - thisResult.Points = 100; - let thisTest = buildTest(1234, 123, [thisResult]); - thisTest.IsPointGrading = true; - - let sorting: Sorting = { key: thisTest, ascending: true }; + let result = buildResult(123, 456); + result.Points = 100; + let otherResult = buildResult(123, 456); + result.Points = 50; + + let test = buildTest(1234, 123, [result, otherResult]); + let gradeKind: GradeKind = buildGradeKind('grade', result, test); + let otherGradeKind: GradeKind = buildGradeKind( + 'grade', + otherResult, + test + ); + let studentGrade = buildStudentGrade(student, [ + gradeKind, + otherGradeKind, + ]); + let otherStudentGrade = buildStudentGrade(student, [otherGradeKind]); - const studentGrades = [thisStudentGrade, thatStudentGrade]; + let sorting: Sorting = { key: test, ascending: true }; - // when + const studentGrades = [studentGrade, otherStudentGrade]; // then expect(studentGrades.sort(compareFn(sorting))).toContain( - thisStudentGrade + otherStudentGrade ); }); }); diff --git a/src/spec-builders.ts b/src/spec-builders.ts index 6dc4c9227..0260bda86 100644 --- a/src/spec-builders.ts +++ b/src/spec-builders.ts @@ -26,6 +26,12 @@ import { import { Result, Test } from './app/shared/models/test.model'; import { StudyClass } from './app/shared/models/study-class.model'; import { Grade } from './app/shared/models/grading-scale.model'; +import { + FinalGrade, + GradeKind, + GradeOrNoResult, + StudentGrade, +} from './app/shared/models/student-grades'; /*import { TokenPayload } from './app/shared/models/token-payload.model';*/ export function buildReference(id = 123, href?: string): Reference { @@ -603,3 +609,35 @@ export function buildFinalGrading(id: number): FinalGrading { Id: id, }; } + +export function buildStudentGrade( + student: Student, + gradesOrNoResults: GradeOrNoResult[] +): StudentGrade { + return { + student: student, + finalGrade: buildFinalGrade(), + grades: gradesOrNoResults, + }; +} + +export function buildGradeKind( + kind: any, + result: Result, + test: Test +): GradeKind { + return { + kind: kind, + result: result, + test: test, + }; +} + +function buildFinalGrade(): FinalGrade { + return { + id: 12, + average: 4, + finalGradeId: 20, + canGrade: true, + }; +} From 9348dd5b92366c151d5d1d20501f688c7aef3600 Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 12 May 2022 16:29:46 +0200 Subject: [PATCH 12/12] remove test, refs 333 --- src/app/shared/models/student-grades.spec.ts | 40 -------------------- 1 file changed, 40 deletions(-) diff --git a/src/app/shared/models/student-grades.spec.ts b/src/app/shared/models/student-grades.spec.ts index 4e25412c3..02d61553b 100644 --- a/src/app/shared/models/student-grades.spec.ts +++ b/src/app/shared/models/student-grades.spec.ts @@ -1,11 +1,9 @@ import { Course } from 'src/app/shared/models/course.model'; import { buildCourse, - buildGradeKind, buildGrading, buildResult, buildStudent, - buildStudentGrade, buildTest, } from 'src/spec-builders'; import { @@ -16,12 +14,7 @@ import { StudentGrade, toMaxPoints, transform, - compareFn, - SortKeys, } from './student-grades'; -import { Sorting } from '../services/sort.service'; -import { Student } from './student.model'; -import { GradeKind } from './student-grades'; describe('student-grade utils', () => { describe('student grades with results and final grades', () => { @@ -255,38 +248,5 @@ describe('student-grade utils', () => { 4.333333333333333 ); }); - - describe('test table sorting', () => { - it('should sort tests by points', () => { - let student: Student = buildStudent(1234); - - let result = buildResult(123, 456); - result.Points = 100; - let otherResult = buildResult(123, 456); - result.Points = 50; - - let test = buildTest(1234, 123, [result, otherResult]); - let gradeKind: GradeKind = buildGradeKind('grade', result, test); - let otherGradeKind: GradeKind = buildGradeKind( - 'grade', - otherResult, - test - ); - let studentGrade = buildStudentGrade(student, [ - gradeKind, - otherGradeKind, - ]); - let otherStudentGrade = buildStudentGrade(student, [otherGradeKind]); - - let sorting: Sorting = { key: test, ascending: true }; - - const studentGrades = [studentGrade, otherStudentGrade]; - - // then - expect(studentGrades.sort(compareFn(sorting))).toContain( - otherStudentGrade - ); - }); - }); }); });