diff --git a/frontend/appflowy_flutter/integration_test/runner.dart b/frontend/appflowy_flutter/integration_test/runner.dart index fb1d3248cd..700e500938 100644 --- a/frontend/appflowy_flutter/integration_test/runner.dart +++ b/frontend/appflowy_flutter/integration_test/runner.dart @@ -19,8 +19,7 @@ import 'document/document_test_runner.dart' as document_test_runner; import 'empty_test.dart' as first_test; import 'hotkeys_test.dart' as hotkeys_test; import 'import_files_test.dart' as import_files_test; -import 'settings/user_icon_test.dart' as user_icon_test; -import 'settings/user_language_test.dart' as user_language_test; +import 'settings/settings_runner.dart' as settings_test_runner; import 'share_markdown_test.dart' as share_markdown_test; import 'sidebar/sidebar_test_runner.dart' as sidebar_test_runner; import 'switch_folder_test.dart' as switch_folder_test; @@ -75,8 +74,7 @@ void main() { appearance_test_runner.main(); // User settings - user_icon_test.main(); - user_language_test.main(); + settings_test_runner.main(); if (isCloudEnabled) { auth_test_runner.main(); diff --git a/frontend/appflowy_flutter/integration_test/settings/notifications_settings_test.dart b/frontend/appflowy_flutter/integration_test/settings/notifications_settings_test.dart new file mode 100644 index 0000000000..ab7458b250 --- /dev/null +++ b/frontend/appflowy_flutter/integration_test/settings/notifications_settings_test.dart @@ -0,0 +1,41 @@ +import 'package:appflowy/workspace/application/settings/settings_dialog_bloc.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; + +import '../util/util.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + group('board add row test', () { + testWidgets('Add card from header', (tester) async { + await tester.initializeAppFlowy(); + await tester.tapGoButton(); + + await tester.openSettings(); + await tester.openSettingsPage(SettingsPage.notifications); + await tester.pumpAndSettle(); + + final switchFinder = find.byType(Switch); + + // Defaults to enabled + Switch switchWidget = tester.widget(switchFinder); + expect(switchWidget.value, true); + + // Disable + await tester.tap(switchFinder); + await tester.pumpAndSettle(); + + switchWidget = tester.widget(switchFinder); + expect(switchWidget.value, false); + + // Enable again + await tester.tap(switchFinder); + await tester.pumpAndSettle(); + + switchWidget = tester.widget(switchFinder); + expect(switchWidget.value, true); + }); + }); +} diff --git a/frontend/appflowy_flutter/integration_test/settings/settings_runner.dart b/frontend/appflowy_flutter/integration_test/settings/settings_runner.dart new file mode 100644 index 0000000000..2b56915690 --- /dev/null +++ b/frontend/appflowy_flutter/integration_test/settings/settings_runner.dart @@ -0,0 +1,13 @@ +import 'package:integration_test/integration_test.dart'; + +import 'notifications_settings_test.dart' as notifications_settings_test; +import 'user_icon_test.dart' as user_icon_test; +import 'user_language_test.dart' as user_language_test; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + notifications_settings_test.main(); + user_icon_test.main(); + user_language_test.main(); +} diff --git a/frontend/appflowy_flutter/lib/startup/deps_resolver.dart b/frontend/appflowy_flutter/lib/startup/deps_resolver.dart index bc66aaf878..a8d8bd8faa 100644 --- a/frontend/appflowy_flutter/lib/startup/deps_resolver.dart +++ b/frontend/appflowy_flutter/lib/startup/deps_resolver.dart @@ -19,7 +19,6 @@ import 'package:appflowy/user/presentation/router.dart'; import 'package:appflowy/workspace/application/edit_panel/edit_panel_bloc.dart'; import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart'; import 'package:appflowy/workspace/application/notifications/notification_action_bloc.dart'; -import 'package:appflowy/workspace/application/settings/notifications/notification_settings_cubit.dart'; import 'package:appflowy/workspace/application/settings/prelude.dart'; import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart'; import 'package:appflowy/workspace/application/user/prelude.dart'; @@ -164,13 +163,7 @@ void _resolveHomeDeps(GetIt getIt) { getIt.registerLazySingleton(() => TabsBloc()); - getIt.registerSingleton( - NotificationSettingsCubit(), - ); - - getIt.registerSingleton( - ReminderBloc(notificationSettings: getIt()), - ); + getIt.registerSingleton(ReminderBloc()); } void _resolveFolderDeps(GetIt getIt) { diff --git a/frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart b/frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart index 265f36c3ec..01733a7e83 100644 --- a/frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart +++ b/frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart @@ -131,7 +131,7 @@ class _ApplicationWidgetState extends State { )..readLocaleWhenAppLaunch(context), ), BlocProvider( - create: (_) => getIt(), + create: (_) => NotificationSettingsCubit(), ), BlocProvider( create: (_) => DocumentAppearanceCubit()..fetch(), diff --git a/frontend/appflowy_flutter/lib/user/application/reminder/reminder_bloc.dart b/frontend/appflowy_flutter/lib/user/application/reminder/reminder_bloc.dart index 4a34a6d004..4110131814 100644 --- a/frontend/appflowy_flutter/lib/user/application/reminder/reminder_bloc.dart +++ b/frontend/appflowy_flutter/lib/user/application/reminder/reminder_bloc.dart @@ -4,10 +4,10 @@ import 'package:appflowy/generated/locale_keys.g.dart'; import 'package:appflowy/startup/startup.dart'; import 'package:appflowy/user/application/reminder/reminder_extension.dart'; import 'package:appflowy/user/application/reminder/reminder_service.dart'; +import 'package:appflowy/user/application/user_settings_service.dart'; import 'package:appflowy/workspace/application/notifications/notification_action.dart'; import 'package:appflowy/workspace/application/notifications/notification_action_bloc.dart'; import 'package:appflowy/workspace/application/notifications/notification_service.dart'; -import 'package:appflowy/workspace/application/settings/notifications/notification_settings_cubit.dart'; import 'package:appflowy_backend/log.dart'; import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'; import 'package:bloc/bloc.dart'; @@ -20,16 +20,11 @@ import 'package:freezed_annotation/freezed_annotation.dart'; part 'reminder_bloc.freezed.dart'; class ReminderBloc extends Bloc { - final NotificationSettingsCubit _notificationSettings; - late final NotificationActionBloc actionBloc; late final ReminderService reminderService; late final Timer timer; - ReminderBloc({ - required NotificationSettingsCubit notificationSettings, - }) : _notificationSettings = notificationSettings, - super(ReminderState()) { + ReminderBloc() : super(ReminderState()) { actionBloc = getIt(); reminderService = const ReminderService(); timer = _periodicCheck(); @@ -146,7 +141,7 @@ class ReminderBloc extends Bloc { Timer _periodicCheck() { return Timer.periodic( const Duration(minutes: 1), - (_) { + (_) async { final now = DateTime.now(); for (final reminder in state.upcomingReminders) { @@ -159,7 +154,9 @@ class ReminderBloc extends Bloc { ); if (scheduledAt.isBefore(now)) { - if (_notificationSettings.state.isNotificationsEnabled) { + final notificationSettings = + await UserSettingsBackendService().getNotificationSettings(); + if (notificationSettings.notificationsEnabled) { NotificationMessage( identifier: reminder.id, title: LocaleKeys.reminderNotification_title.tr(),