import 'package:flutter_test/flutter_test.dart'; import 'package:marianum_mobile/api/webuntis/queries/get_rooms/get_rooms_response.dart'; import 'package:marianum_mobile/api/webuntis/queries/get_subjects/get_subjects_response.dart'; import 'package:marianum_mobile/api/webuntis/services/lesson_resolver.dart'; import 'package:marianum_mobile/state/app/modules/timetable/bloc/timetable_state.dart'; TimetableState _state({ Set subjects = const {}, Set rooms = const {}, }) => TimetableState( subjects: subjects.isEmpty ? null : GetSubjectsResponse(subjects), rooms: rooms.isEmpty ? null : GetRoomsResponse(rooms), startDate: DateTime(2026, 1, 1), endDate: DateTime(2026, 12, 31), ); void main() { group('LessonResolver.resolveSubject', () { test('returns the matching subject when the id is found', () { final math = GetSubjectsResponseObject(7, 'M', 'Mathe', 'Ma', true); final state = _state(subjects: {math}); final result = LessonResolver.resolveSubject(state, 7); expect(result.id, 7); expect(result.name, 'M'); expect(result.longName, 'Mathe'); }); test('returns the placeholder fallback when id is null', () { final state = _state(subjects: const {}); final result = LessonResolver.resolveSubject(state, null); expect(result.id, 0); expect(result.name, '?'); expect(result.longName, 'Unbekannt'); }); test('returns the placeholder fallback when id is unknown', () { final math = GetSubjectsResponseObject(7, 'M', 'Mathe', 'Ma', true); final state = _state(subjects: {math}); final result = LessonResolver.resolveSubject(state, 999); expect(result.id, 0); expect(result.longName, 'Unbekannt'); }); }); group('LessonResolver.resolveRoom', () { test('returns the matching room when the id is found', () { final room = GetRoomsResponseObject( 3, 'A1', 'Aula 1', true, 'Hauptgebäude', ); final state = _state(rooms: {room}); final result = LessonResolver.resolveRoom(state, 3); expect(result.id, 3); expect(result.name, 'A1'); expect(result.building, 'Hauptgebäude'); }); test('returns the placeholder fallback when id is unknown', () { final state = _state(rooms: const {}); final result = LessonResolver.resolveRoom(state, 42); expect(result.id, 0); expect(result.name, '?'); }); }); group('LessonFormatter', () { test('iconForCode picks the right icon per status', () { expect( LessonFormatter.iconForCode('cancelled').codePoint, isNot(LessonFormatter.iconForCode('irregular').codePoint), ); expect( LessonFormatter.iconForCode(null).codePoint, isNot(LessonFormatter.iconForCode('cancelled').codePoint), ); }); test('statusLabel maps known codes to German labels', () { expect(LessonFormatter.statusLabel(null), 'Regulär'); expect(LessonFormatter.statusLabel(''), 'Regulär'); expect(LessonFormatter.statusLabel('cancelled'), 'Entfällt'); expect(LessonFormatter.statusLabel('irregular'), 'Geändert'); expect(LessonFormatter.statusLabel('something-else'), 'something-else'); }); test('codePrefix prepends a label for known codes', () { expect(LessonFormatter.codePrefix('cancelled'), 'Entfällt: '); expect(LessonFormatter.codePrefix('irregular'), 'Änderung: '); expect(LessonFormatter.codePrefix(null), ''); }); test('formatLine renders name + (longname) + · extra in that order', () { expect( LessonFormatter.formatLine( 'Mathe', longname: 'Mathematik', extra: 'Hauptgebäude', ), 'Mathe (Mathematik) · Hauptgebäude', ); }); test('formatLine omits longname when it equals name', () { expect(LessonFormatter.formatLine('Mathe', longname: 'Mathe'), 'Mathe'); }); test('formatLine substitutes ? when name is empty', () { expect(LessonFormatter.formatLine(''), '?'); }); }); }