Skip to content

Commit

Permalink
Make GradeId const. (#1527)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonas <--help>
  • Loading branch information
Jonas-Sander authored Apr 24, 2024
1 parent 86814a4 commit a999223
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion app/lib/grades/models/grade_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
import 'package:common_domain_models/common_domain_models.dart';

class GradeId extends Id {
GradeId(super.id);
const GradeId(super.id);
}
20 changes: 10 additions & 10 deletions app/test/grades/grades_repository_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void main() {
id: const SubjectId('Philosophie'),
grades: [
gradeWith(
id: GradeId('grade1'),
id: const GradeId('grade1'),
value: 4.0,
),
],
Expand Down Expand Up @@ -187,7 +187,7 @@ void main() {
subjectId: const SubjectId('mathe'),
termId: const TermId('02-10-term'),
value: Grade(
id: GradeId('grade-1'),
id: const GradeId('grade-1'),
value: '13',
gradingSystem: GradingSystem.zeroToFifteenPoints,
type: const GradeTypeId('my-custom-grade-type'),
Expand All @@ -200,7 +200,7 @@ void main() {
subjectId: const SubjectId('mathe'),
termId: const TermId('02-10-term'),
value: Grade(
id: GradeId('grade-2'),
id: const GradeId('grade-2'),
value: '3',
gradingSystem: GradingSystem.zeroToFifteenPoints,
type: GradeType.vocabularyTest.id,
Expand All @@ -214,7 +214,7 @@ void main() {
subjectId: const SubjectId('englisch'),
termId: const TermId('01-10-term'),
value: Grade(
id: GradeId('grade-3'),
id: const GradeId('grade-3'),
value: '2-',
gradingSystem: GradingSystem.oneToSixWithPlusAndMinus,
type: const GradeTypeId('my-custom-grade-type'),
Expand All @@ -227,7 +227,7 @@ void main() {
subjectId: const SubjectId('englisch'),
termId: const TermId('01-10-term'),
value: Grade(
id: GradeId('grade-4'),
id: const GradeId('grade-4'),
value: 'Sehr zufriedenstellend',
gradingSystem: GradingSystem.austrianBehaviouralGrades,
type: GradeType.oralParticipation.id,
Expand All @@ -251,7 +251,7 @@ void main() {
gradeType: const GradeTypeId('my-custom-grade-type'),
weight: const Weight.percent(200));
service.changeGradeWeight(
id: GradeId('grade-1'),
id: const GradeId('grade-1'),
termId: const TermId('02-10-term'),
weight: const Weight.factor(0.5));
service.changeSubjectWeightTypeSettings(
Expand Down Expand Up @@ -499,7 +499,7 @@ void main() {
gradingSystem: GradingSystemModel.zeroToFifteenPoints,
grades: IListConst([
GradeModel(
id: GradeId('grade-1'),
id: const GradeId('grade-1'),
subjectId: const SubjectId('mathe'),
termId: const TermId('02-10-term'),
originalInput: '13',
Expand All @@ -517,7 +517,7 @@ void main() {
details: 'hello',
),
GradeModel(
id: GradeId('grade-2'),
id: const GradeId('grade-2'),
subjectId: const SubjectId('mathe'),
termId: const TermId('02-10-term'),
originalInput: 3,
Expand Down Expand Up @@ -582,7 +582,7 @@ void main() {
grades: IListConst(
[
GradeModel(
id: GradeId('grade-3'),
id: const GradeId('grade-3'),
subjectId: const SubjectId('englisch'),
termId: const TermId('01-10-term'),
originalInput: '2-',
Expand All @@ -601,7 +601,7 @@ void main() {
details: 'ollah',
),
GradeModel(
id: GradeId('grade-4'),
id: const GradeId('grade-4'),
subjectId: const SubjectId('englisch'),
termId: const TermId('01-10-term'),
originalInput: 'Sehr zufriedenstellend',
Expand Down
62 changes: 31 additions & 31 deletions app/test/grades/grades_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void main() {
weight: const Weight.factor(0.5),
grades: [
gradeWith(
id: GradeId('grade1'),
id: const GradeId('grade1'),
value: 3.0,
includeInGradeCalculations: false),
gradeWith(value: 1.5),
Expand All @@ -146,7 +146,7 @@ void main() {
controller
.term(term.id)
.subject(const SubjectId('Sport'))
.grade(GradeId('grade1'))
.grade(const GradeId('grade1'))
.isTakenIntoAccount,
false);

Expand All @@ -163,7 +163,7 @@ void main() {
weightType: WeightType.perGrade,
grades: [
gradeWith(
id: GradeId('grade1'),
id: const GradeId('grade1'),
value: 3.0,
includeInGradeCalculations: false,
),
Expand All @@ -181,15 +181,15 @@ void main() {
termId: term.id,
subjectId: const SubjectId('Sport'),
weights: {
GradeId('grade1'): const Weight.percent(100),
const GradeId('grade1'): const Weight.percent(100),
},
);

expect(
controller
.term(term.id)
.subject(const SubjectId('Sport'))
.grade(GradeId('grade1'))
.grade(const GradeId('grade1'))
.isTakenIntoAccount,
true);
expect(
Expand Down Expand Up @@ -344,8 +344,8 @@ void main() {
final controller = GradesTestController();

const subjectId = SubjectId('Deutsch');
final grade1Id = GradeId('grade1');
final grade2Id = GradeId('grade2');
const grade1Id = GradeId('grade1');
const grade2Id = GradeId('grade2');

const presentation = GradeType.presentation;
const exam = GradeType.writtenExam;
Expand Down Expand Up @@ -691,11 +691,11 @@ void main() {
name: 'Deutsch',
grades: [
gradeWith(
id: GradeId('grade1'),
id: const GradeId('grade1'),
value: "2+",
gradingSystem: GradingSystem.oneToSixWithPlusAndMinus),
gradeWith(
id: GradeId('grade2'),
id: const GradeId('grade2'),
value: 1.75,
gradingSystem: GradingSystem.oneToSixWithPlusAndMinus),
],
Expand All @@ -708,14 +708,14 @@ void main() {
controller
.term(term.id)
.subject(const SubjectId('Deutsch'))
.grade(GradeId('grade1'))
.grade(const GradeId('grade1'))
.originalInput,
'2+');
expect(
controller
.term(term.id)
.subject(const SubjectId('Deutsch'))
.grade(GradeId('grade2'))
.grade(const GradeId('grade2'))
.originalInput,
1.75);
});
Expand Down Expand Up @@ -1052,7 +1052,7 @@ void main() {
id: const SubjectId('Philosophie'),
grades: [
gradeWith(
id: GradeId('grade1'),
id: const GradeId('grade1'),
value: 4.0,
date: Date.fromDateTime(DateTime(2024, 03, 26)),
),
Expand All @@ -1066,7 +1066,7 @@ void main() {
controller
.term(term.id)
.subject(const SubjectId('Philosophie'))
.grade(GradeId('grade1'))
.grade(const GradeId('grade1'))
.date,
Date('2024-03-26'));
});
Expand All @@ -1079,12 +1079,12 @@ void main() {
id: const SubjectId('Philosophie'),
grades: [
gradeWith(
id: GradeId('grade1'),
id: const GradeId('grade1'),
gradingSystem: GradingSystem.oneToFiveWithDecimals,
value: 2.5,
),
gradeWith(
id: GradeId('grade2'),
id: const GradeId('grade2'),
gradingSystem: GradingSystem.sixToOneWithDecimals,
value: 4.2,
),
Expand All @@ -1097,15 +1097,15 @@ void main() {
final grade1 = controller
.term(term.id)
.subject(const SubjectId('Philosophie'))
.grade(GradeId('grade1'));
.grade(const GradeId('grade1'));
// On both since the calculated averageGrade is only a [GradeValue], not a [GradeResult].
expect(grade1.gradingSystem, GradingSystem.oneToFiveWithDecimals);
expect(grade1.value.gradingSystem, GradingSystem.oneToFiveWithDecimals);

final grade2 = controller
.term(term.id)
.subject(const SubjectId('Philosophie'))
.grade(GradeId('grade2'));
.grade(const GradeId('grade2'));
expect(grade2.gradingSystem, GradingSystem.sixToOneWithDecimals);
expect(grade2.value.gradingSystem, GradingSystem.sixToOneWithDecimals);
});
Expand All @@ -1118,11 +1118,11 @@ void main() {
id: const SubjectId('Philosophie'),
grades: [
gradeWith(
id: GradeId('grade1'),
id: const GradeId('grade1'),
value: 4.0,
),
gradeWith(
id: GradeId('grade2'),
id: const GradeId('grade2'),
value: 4.5,
),
],
Expand All @@ -1131,7 +1131,7 @@ void main() {
);
controller.createTerm(term);

controller.deleteGrade(gradeId: GradeId('grade1'));
controller.deleteGrade(gradeId: const GradeId('grade1'));

expect(
controller
Expand All @@ -1147,7 +1147,7 @@ void main() {
.grades
.single
.id,
GradeId('grade2'));
const GradeId('grade2'));
});
test(
'When trying to add a grade with the same id as an existing grade then a $DuplicateGradeIdException is thrown',
Expand All @@ -1160,7 +1160,7 @@ void main() {
id: const SubjectId('Philosophie'),
grades: [
gradeWith(
id: GradeId('grade1'),
id: const GradeId('grade1'),
value: 4.0,
),
],
Expand All @@ -1174,11 +1174,11 @@ void main() {
termId: term.id,
subjectId: const SubjectId('Philosophie'),
value: gradeWith(
id: GradeId('grade1'),
id: const GradeId('grade1'),
value: 4.0,
),
),
throwsA(DuplicateGradeIdException(GradeId('grade1'))),
throwsA(const DuplicateGradeIdException(GradeId('grade1'))),
);
});
test(
Expand All @@ -1192,7 +1192,7 @@ void main() {
id: const SubjectId('Philosophie'),
grades: [
gradeWith(
id: GradeId('grade1'),
id: const GradeId('grade1'),
value: 4.0,
),
],
Expand All @@ -1203,9 +1203,9 @@ void main() {

expect(
() => controller.deleteGrade(
gradeId: GradeId('unknown'),
gradeId: const GradeId('unknown'),
),
throwsA(GradeNotFoundException(GradeId('unknown'))),
throwsA(const GradeNotFoundException(GradeId('unknown'))),
);
});
test('A grade has a title', () {
Expand All @@ -1217,7 +1217,7 @@ void main() {
id: const SubjectId('Philosophie'),
grades: [
gradeWith(
id: GradeId('grade1'),
id: const GradeId('grade1'),
value: 4.0,
title: 'Klausur',
),
Expand All @@ -1231,7 +1231,7 @@ void main() {
controller
.term(term.id)
.subject(const SubjectId('Philosophie'))
.grade(GradeId('grade1'))
.grade(const GradeId('grade1'))
.title,
'Klausur');
});
Expand All @@ -1244,7 +1244,7 @@ void main() {
id: const SubjectId('Philosophie'),
grades: [
gradeWith(
id: GradeId('grade1'),
id: const GradeId('grade1'),
value: 4.0,
details: 'my details',
),
Expand All @@ -1258,7 +1258,7 @@ void main() {
controller
.term(term.id)
.subject(const SubjectId('Philosophie'))
.grade(GradeId('grade1'))
.grade(const GradeId('grade1'))
.details,
'my details');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import 'grade_details_page_test.mocks.dart';
MockSpec<GradeDetailsPageControllerFactory>(),
])
void main() {
final id = GradeId('1');
const id = GradeId('1');

late MockGradeDetailsPageControllerFactory controllerFactory;
late MockGradeDetailsPageController controller;
Expand Down Expand Up @@ -73,7 +73,7 @@ void main() {
create: (context) => controller,
),
],
child: GradeDetailsPage(id: id),
child: const GradeDetailsPage(id: id),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import 'grade_details_page_test.mocks.dart';
])
void main() {
group(GradeDetailsPage, () {
final id = GradeId('1');
const id = GradeId('1');
late MockGradeDetailsPageControllerFactory controllerFactory;
late MockGradeDetailsPageController controller;

Expand Down Expand Up @@ -74,7 +74,7 @@ void main() {
value: controllerFactory,
child: ChangeNotifierProvider<GradeDetailsPageController>.value(
value: controller,
child: GradeDetailsPage(id: id),
child: const GradeDetailsPage(id: id),
),
),
wrapper: materialAppWrapper(theme: theme),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ void main() {
(
grades: [
(
id: GradeId('1'),
id: const GradeId('1'),
gradeTypeIcon: const Icon(Icons.note_add),
date: Date.fromDateTime(DateTime(2021, 2, 2)).toDateString,
grade: '1,0',
title: 'Klausur',
),
(
id: GradeId('2'),
id: const GradeId('2'),
gradeTypeIcon: const Icon(Icons.text_format),
date: Date.fromDateTime(DateTime(2021, 2, 1)).toDateString,
grade: '2+',
Expand Down

0 comments on commit a999223

Please sign in to comment.