diff --git a/lib/firebase_hausaufgabenheft_logik/lib/src/homework_transformation.dart b/lib/firebase_hausaufgabenheft_logik/lib/src/homework_transformation.dart index 4f3e70860..cfefa36f8 100644 --- a/lib/firebase_hausaufgabenheft_logik/lib/src/homework_transformation.dart +++ b/lib/firebase_hausaufgabenheft_logik/lib/src/homework_transformation.dart @@ -59,9 +59,16 @@ Future tryToConvertToHomework( } Subject subject; if (courseColorHex != null) { - subject = Subject(homework.subject, color: Color(courseColorHex)); + subject = Subject( + homework.subject, + color: Color(courseColorHex), + abbreviation: homework.subjectAbbreviation, + ); } else { - subject = Subject(homework.subject); + subject = Subject( + homework.subject, + abbreviation: homework.subjectAbbreviation, + ); } converted = HomeworkReadModel( diff --git a/lib/firebase_hausaufgabenheft_logik/test/lazy_loading_controller_test.dart b/lib/firebase_hausaufgabenheft_logik/test/lazy_loading_controller_test.dart index ec99b12b0..bec652661 100644 --- a/lib/firebase_hausaufgabenheft_logik/test/lazy_loading_controller_test.dart +++ b/lib/firebase_hausaufgabenheft_logik/test/lazy_loading_controller_test.dart @@ -33,7 +33,7 @@ List listOfHomeworksWithLength(int length) => List.generate( id: HomeworkId("$index"), todoDate: DateTime.now(), status: CompletionStatus.completed, - subject: Subject("Mathe"), + subject: Subject("Mathe", abbreviation: 'Ma'), title: const Title("ABC"), withSubmissions: false), ); diff --git a/lib/hausaufgabenheft_logik/lib/src/models/subject.dart b/lib/hausaufgabenheft_logik/lib/src/models/subject.dart index f2640e0fd..c4e367a79 100644 --- a/lib/hausaufgabenheft_logik/lib/src/models/subject.dart +++ b/lib/hausaufgabenheft_logik/lib/src/models/subject.dart @@ -11,16 +11,15 @@ import 'package:hausaufgabenheft_logik/src/views/color.dart'; class Subject { final String name; final Color? color; + final String abbreviation; - Subject(this.name, {this.color}) { + Subject(this.name, {this.color, required this.abbreviation}) { if (name.isEmpty) { throw ArgumentError.value( name, 'name', "The subject name can't be empty"); } } - String get abbreviation => name.length >= 2 ? name.substring(0, 2) : name; - @override int get hashCode => name.hashCode; diff --git a/lib/hausaufgabenheft_logik/test/create_homework_util.dart b/lib/hausaufgabenheft_logik/test/create_homework_util.dart index e1e250914..bb5b9e571 100644 --- a/lib/hausaufgabenheft_logik/test/create_homework_util.dart +++ b/lib/hausaufgabenheft_logik/test/create_homework_util.dart @@ -20,12 +20,13 @@ HomeworkReadModel createHomework( String id = 'willBeRandom', bool done = false, bool withSubmissions = false, - Color? subjectColor}) { + Color? subjectColor, + String abbreviation = 'Abb'}) { id = id == 'willBeRandom' ? randomString(5) : id; return HomeworkReadModel( id: HomeworkId(id), todoDate: todoDate.asDateTime(), - subject: Subject(subject, color: subjectColor), + subject: Subject(subject, color: subjectColor, abbreviation: abbreviation), title: Title(title), withSubmissions: withSubmissions, status: done ? CompletionStatus.completed : CompletionStatus.open, diff --git a/lib/hausaufgabenheft_logik/test/create_student_homework_view_test.dart b/lib/hausaufgabenheft_logik/test/create_student_homework_view_test.dart index fbbba86d5..35572d91b 100644 --- a/lib/hausaufgabenheft_logik/test/create_student_homework_view_test.dart +++ b/lib/hausaufgabenheft_logik/test/create_student_homework_view_test.dart @@ -35,7 +35,11 @@ void main() { id: HomeworkId('Id'), status: CompletionStatus.open, todoDate: const Date(year: 2019, month: 1, day: 28).asDateTime(), - subject: Subject('Mathematik', color: white), + subject: Subject( + 'Mathematik', + color: white, + abbreviation: 'Ma', + ), withSubmissions: false, title: const Title('S. 35 6a) und 8c)'), ); diff --git a/lib/hausaufgabenheft_logik/test/homework_list_test.dart b/lib/hausaufgabenheft_logik/test/homework_list_test.dart index 32dc60e8a..aaa5c09d7 100644 --- a/lib/hausaufgabenheft_logik/test/homework_list_test.dart +++ b/lib/hausaufgabenheft_logik/test/homework_list_test.dart @@ -74,9 +74,9 @@ void main() { }); }); test('getDistinctSubjects', () { - var mathe = Subject('Mathe'); - var englisch = Subject('Englisch'); - var deutsch = Subject('Deutsch'); + var mathe = Subject('Mathe', abbreviation: 'Ma'); + var englisch = Subject('Englisch', abbreviation: 'En'); + var deutsch = Subject('Deutsch', abbreviation: 'De'); final subjects = [mathe, englisch, mathe, mathe, deutsch]; final homeworks = [ for (final subject in subjects) createHomework(subject: subject.name) diff --git a/lib/hausaufgabenheft_logik/test/subject_test.dart b/lib/hausaufgabenheft_logik/test/subject_test.dart index c990789f4..7069db6a1 100644 --- a/lib/hausaufgabenheft_logik/test/subject_test.dart +++ b/lib/hausaufgabenheft_logik/test/subject_test.dart @@ -13,26 +13,18 @@ import 'package:test/test.dart'; void main() { group('Subject', () { Subject createValidSubjectWith({Color? color}) { - return Subject('SomeSubjectName', color: color); + return Subject('SomeSubjectName', color: color, abbreviation: 'SSN'); } test('A Subject cant be constructed with an empty subject name', () { - expect(() => Subject(''), throwsArgumentError); - }); - test( - 'generates an own subject abreviation from the given subject if no abbreviation is specified', - () { - expect(Subject('Mathematik').abbreviation, 'Ma'); - }); - test( - 'If the subject name is shorter than two characters it uses the subject name as an abbreviation', - () { - expect(Subject('M').abbreviation, 'M'); + expect(() => Subject('', abbreviation: ''), throwsArgumentError); }); + test('has no color of not given', () { final subject = createValidSubjectWith(color: null); expect(subject.color, isNull); }); + test('sets the optional color to the given color', () { final subject = createValidSubjectWith(color: const Color(1337)); expect(subject.color, const Color(1337));