Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ class TermSettingsPageController extends ChangeNotifier {
}

Future<void> setSubjectWeight(SubjectId subjectId, Weight weight) async {
final subRef = termRef.subject(subjectId);
TermSubjectRef subRef = termRef.subject(subjectId);
Comment thread
nilsreichardt marked this conversation as resolved.
final isNewSubject = gradesService.getSubject(subjectId) == null;
if (isNewSubject) {
subjectId = _createSubject(subRef);
final newSubjectId = _createSubject(subRef);
subRef = termRef.subject(newSubjectId);

// Firestore had a soft limit of 1 write per second per document. However,
// this limit isn't mentioned in the documentation anymore. We still keep
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2026 Sharezone UG (haftungsbeschränkt)
// Licensed under the EUPL-1.2-or-later.
//
// You may obtain a copy of the Licence at:
// https://joinup.ec.europa.eu/software/page/eupl
//
// SPDX-License-Identifier: EUPL-1.2

import 'package:flutter_test/flutter_test.dart';
import 'package:group_domain_models/group_domain_models.dart';
import 'package:sharezone/grades/grades_service/grades_service.dart';
import 'package:sharezone/grades/pages/term_settings_page/term_settings_page_controller.dart';

import '../../grades_test_common.dart';

void main() {
group('$TermSettingsPageController', () {
test(
'setSubjectWeight creates a missing subject and updates the weight',
() async {
const termId = TermId('term-id');
const courseId = 'course-id';
final service = GradesService();
final testController = GradesTestController(gradesService: service);
testController.createTerm(termWith(id: termId));

final controller = TermSettingsPageController(
gradesService: service,
termRef: service.term(termId),
coursesStream: Stream.value([
Course.create().copyWith(
id: courseId,
name: 'English LK',
subject: 'English',
abbreviation: 'EN',
),
]),
);

await Future<void>.delayed(Duration.zero);
await controller.setSubjectWeight(
const SubjectId(courseId),
const Weight.factor(2),
);

final termSubject = testController
.term(termId)
.subjects
.singleWhere((subject) => subject.name == 'English');
expect(termSubject.weightingForTermGrade, const Weight.factor(2));

controller.dispose();
},
);
});
}
Loading