Skip to content

Commit

Permalink
test: Fix settings loading issue
Browse files Browse the repository at this point in the history
refs: #68
  • Loading branch information
apomalyn authored and XavierPaquet-Rapold committed Mar 9, 2024
1 parent 94eb2da commit 9ca3608
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
13 changes: 9 additions & 4 deletions lib/core/viewmodels/schedule_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,16 @@ class ScheduleViewModel extends FutureViewModel<List<CourseActivity>> {

bool isLoadingEvents = false;

bool get calendarViewSetting =>
settings[PreferencesFlag.scheduleListView] as bool;
bool get calendarViewSetting {
if (busy(settings)) {
return false;
}
return settings[PreferencesFlag.scheduleListView] as bool;
}

@override
Future<List<CourseActivity>> futureToRun() async {
loadSettings();
List<CourseActivity>? activities = await _courseRepository.getCoursesActivities(fromCacheOnly: true);
try {
setBusyForObject(isLoadingEvents, true);
Expand Down Expand Up @@ -238,15 +243,15 @@ class ScheduleViewModel extends FutureViewModel<List<CourseActivity>> {
}

Future loadSettings() async {
setBusy(true);
setBusyForObject(settings, true);
settings.clear();
settings.addAll(await _settingsManager.getScheduleSettings());
calendarFormat =
settings[PreferencesFlag.scheduleCalendarFormat] as CalendarFormat;

await loadSettingsScheduleActivities();

setBusy(false);
setBusyForObject(settings, false);
}

Future loadSettingsScheduleActivities() async {
Expand Down
22 changes: 10 additions & 12 deletions lib/ui/views/schedule_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,24 @@ class _ScheduleViewState extends State<ScheduleView>
ViewModelBuilder<ScheduleViewModel>.reactive(
viewModelBuilder: () => ScheduleViewModel(
intl: AppIntl.of(context)!, initialSelectedDate: widget.initialDay),
onModelReady: (model) {
if (model.settings.isEmpty) {
model.loadSettings();
}
},
builder: (context, model, child) => BaseScaffold(
isLoading: model.busy(model.isLoadingEvents),
isInteractionLimitedWhileLoading: false,
appBar: AppBar(
title: Text(AppIntl.of(context)!.title_schedule),
centerTitle: false,
automaticallyImplyLeading: false,
actions: _buildActionButtons(model),
actions:
model.busy(model.settings) ? [] : _buildActionButtons(model),
),
body: RefreshIndicator(
child: !model.calendarViewSetting
? _buildCalendarView(model, context)
: _buildListView(model, context),
onRefresh: () => model.refresh(),
)),
body: model.busy(model.settings)
? const SizedBox()
: RefreshIndicator(
child: !model.calendarViewSetting
? _buildCalendarView(model, context)
: _buildListView(model, context),
onRefresh: () => model.refresh(),
)),
);

Widget _buildListView(ScheduleViewModel model, BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion test/ui/views/schedule_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ void main() {

await tester.pumpWidget(localizedWidget(
child: FeatureDiscovery(child: const ScheduleView())));
await tester.pumpAndSettle(const Duration(seconds: 1));
await tester.pumpAndSettle();

// DateFormat has to be after the pumpWidget to correctly load the locale
final dateFormat = DateFormat.MMMMEEEEd();
Expand Down

0 comments on commit 9ca3608

Please sign in to comment.