Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove "Lesson start" and "Lesson length" from the timetable settings page, as they can be found in "Lesson times". #1767

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -23,11 +23,9 @@ import 'package:sharezone/settings/src/subpages/timetable/periods/periods_edit_p
import 'package:sharezone/settings/src/subpages/timetable/weekdays/weekdays_edit_page.dart';
import 'package:sharezone/sharezone_plus/page/sharezone_plus_page.dart';
import 'package:sharezone/sharezone_plus/subscription_service/subscription_service.dart';
import 'package:sharezone/timetable/src/edit_time.dart';
import 'package:sharezone/timetable/src/edit_weektype.dart';
import 'package:sharezone/timetable/src/models/lesson_length/lesson_length.dart';
import 'package:sharezone_widgets/sharezone_widgets.dart';
import 'package:time/time.dart';
import 'package:user/user.dart';

class TimetableSettingsPage extends StatelessWidget {
Expand All @@ -48,20 +46,14 @@ class TimetableSettingsPage extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
LessonsLengthField(
streamLessonLength: bloc.lessonLengthStream,
onChanged: (lessonLength) =>
bloc.saveLessonLengthInCache(lessonLength.minutes),
),
_TimetablePeriodsField(),
const Divider(),
_ABWeekField(),
const Divider(),
_TimetablePreferencesField(),
_AbbreviationInTimetable(),
const Divider(),
_TimetableEnabledWeekDaysField(),
const Divider(),
_TimetablePeriodsField(),
const Divider(),
const _ICalLinks(),
// We only show the time picker settings on iOS because on
// other platforms we use the different time picker where we
Expand Down Expand Up @@ -153,11 +145,34 @@ class _ABWeekField extends StatelessWidget {
}
}

class _AbbreviationInTimetable extends StatelessWidget {
@override
Widget build(BuildContext context) {
final bloc = BlocProvider.of<UserSettingsBloc>(context);
return StreamBuilder<UserSettings>(
stream: bloc.streamUserSettings(),
builder: (context, snapshot) {
if (!snapshot.hasData) return Container();
final userSettings = snapshot.data!;
return SwitchListTile.adaptive(
title: const Text("Kürzel im Stundenplan anzeigen"),
value: userSettings.showAbbreviation,
onChanged: (newValue) {
bloc.updateSettings(
userSettings.copyWith(showAbbreviation: newValue));
},
);
},
);
}
}

class _TimetablePeriodsField extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListTile(
title: const Text("Stundenzeiten"),
subtitle: const Text("Stundenplanbeginn, Stundenlänge, etc."),
onTap: () => openPeriodsEditPage(context),
);
}
Expand Down Expand Up @@ -204,45 +219,6 @@ class _TimetableEnabledWeekDaysField extends StatelessWidget {
}
}

class _TimetablePreferencesField extends StatelessWidget {
@override
Widget build(BuildContext context) {
final bloc = BlocProvider.of<UserSettingsBloc>(context);
return StreamBuilder<UserSettings>(
stream: bloc.streamUserSettings(),
builder: (context, snapshot) {
if (!snapshot.hasData) return Container();
final userSettings = snapshot.data;
final tbStart = userSettings!.timetableStartTime;
return Column(
children: <Widget>[
ListTile(
title: const Text("Stundenplanbeginn"),
subtitle: Text(tbStart.time),
onTap: () async {
final newTime = await selectTime(context,
initialTime: Time(hour: 8, minute: 0));
if (newTime != null) {
bloc.updateTimetableStartTime(newTime);
}
},
),
const Divider(),
SwitchListTile.adaptive(
title: const Text("Kürzel im Stundenplan anzeigen"),
value: userSettings.showAbbreviation,
onChanged: (newValue) {
bloc.updateSettings(
userSettings.copyWith(showAbbreviation: newValue));
},
),
],
);
},
);
}
}

class LessonsLengthField extends StatelessWidget {
const LessonsLengthField({
super.key,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions app/test_goldens/timetable/timetable_settings_page_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright (c) 2022 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:bloc_provider/bloc_provider.dart';
import 'package:bloc_provider/multi_bloc_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:golden_toolkit/golden_toolkit.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:provider/provider.dart';
import 'package:sharezone/settings/src/bloc/user_settings_bloc.dart';
import 'package:sharezone/settings/src/subpages/timetable/bloc/timetable_settings_bloc_factory.dart';
import 'package:sharezone/settings/src/subpages/timetable/time_picker_settings_cache.dart';
import 'package:sharezone/settings/src/subpages/timetable/timetable_settings_page.dart';
import 'package:sharezone/sharezone_plus/subscription_service/subscription_service.dart';
import 'package:sharezone/timetable/src/models/lesson_length/lesson_length_cache.dart';
import 'package:sharezone_widgets/sharezone_widgets.dart';
import 'package:user/user.dart';

import 'timetable_settings_page_test.mocks.dart';

@GenerateNiceMocks([
MockSpec<LessonLengthCache>(),
MockSpec<TimePickerSettingsCache>(),
MockSpec<SubscriptionService>(),
MockSpec<UserSettingsBloc>(),
])
void main() {
group(TimetableSettingsPage, () {
late UserSettingsBloc userSettingsBloc;

setUp(() {
userSettingsBloc = MockUserSettingsBloc();

when(userSettingsBloc.streamUserSettings())
.thenAnswer((_) => Stream.value(UserSettings.defaultSettings()));
});

Future<void> pumpTimetableSettingsPage(
WidgetTester tester, {
ThemeData? themeData,
}) async {
await tester.pumpWidgetBuilder(
Provider<SubscriptionService>(
create: (context) => MockSubscriptionService(),
child: MultiBlocProvider(
blocProviders: [
BlocProvider<TimetableSettingsBlocFactory>(
bloc: TimetableSettingsBlocFactory(
MockLessonLengthCache(),
MockTimePickerSettingsCache(),
),
),
BlocProvider<UserSettingsBloc>(bloc: userSettingsBloc)
],
child: (_) => const TimetableSettingsPage(),
),
),
wrapper: materialAppWrapper(theme: themeData),
);
}

testGoldens('should render as expected (light mode)', (tester) async {
await pumpTimetableSettingsPage(
tester,
themeData: getLightTheme(),
);
await multiScreenGolden(tester, 'timetable_settings_page_light');
});

testGoldens('should render as expected (dark mode)', (tester) async {
await pumpTimetableSettingsPage(
tester,
themeData: getDarkTheme(),
);
await multiScreenGolden(tester, 'timetable_settings_page_dark');
});
});
}
Loading
Loading