Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: date issue when enbling time feild (#6447)

Ahad Patela04c1577707a
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_test_runner_1.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_test_runner_1.dart
index 36b9891554..7cc7d9dc38 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_test_runner_1.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_test_runner_1.dart
@@ -47,6 +47,5 @@ void main() {
document_more_actions_test.main();
document_with_file_test.main();
document_shortcuts_test.main();
-
// Don't add new tests here. Add them to document_test_runner_2.dart
}
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_test_runner_2.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_test_runner_2.dart
index 3a0a3d5adf..fc295709dd 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_test_runner_2.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_test_runner_2.dart
@@ -4,6 +4,8 @@ import 'document_app_lifecycle_test.dart' as document_app_lifecycle_test;
import 'document_deletion_test.dart' as document_deletion_test;
import 'document_option_action_test.dart' as document_option_action_test;
import 'document_title_test.dart' as document_title_test;
+import 'document_with_date_reminder_test.dart'
+ as document_with_date_reminder_test;
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
@@ -13,6 +15,7 @@ void main() {
// Disable subPage test temporarily, enable it in version 0.7.2
// document_sub_page_test.main();
document_app_lifecycle_test.main();
+ document_with_date_reminder_test.main();
document_deletion_test.main();
document_option_action_test.main();
}
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_with_date_reminder_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_with_date_reminder_test.dart
new file mode 100644
index 0000000000..0eda885abb
--- /dev/null
+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_with_date_reminder_test.dart
@@ -0,0 +1,125 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_date_block.dart';
+import 'package:appflowy/workspace/application/settings/date_time/date_format_ext.dart';
+import 'package:appflowy/workspace/presentation/widgets/toggle/toggle.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
+import 'package:easy_localization/easy_localization.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:integration_test/integration_test.dart';
+
+import '../../shared/util.dart';
+import '../board/board_hide_groups_test.dart';
+
+void main() {
+ setUp(() {
+ IntegrationTestWidgetsFlutterBinding.ensureInitialized();
+ TestWidgetsFlutterBinding.ensureInitialized();
+ });
+
+ group('date or reminder block in document', () {
+ testWidgets("insert date with time block", (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapAnonymousSignInButton();
+
+ // create a new document
+ await tester.createNewPageWithNameUnderParent(
+ name: 'Date with time test',
+ );
+
+ // tap the first line of the document
+ await tester.editor.tapLineOfEditorAt(0);
+ await tester.editor.showSlashMenu();
+ await tester.editor.tapSlashMenuItemWithName(
+ LocaleKeys.document_slashMenu_name_dateOrReminder.tr(),
+ offset: 100,
+ );
+
+ final dateTimeSettings = DateTimeSettingsPB(
+ dateFormat: UserDateFormatPB.Friendly,
+ timeFormat: UserTimeFormatPB.TwentyFourHour,
+ );
+ final DateTime currentDateTime = DateTime.now();
+ final String formattedDate =
+ dateTimeSettings.dateFormat.formatDate(currentDateTime, false);
+
+ // get current date in editor
+ expect(find.byType(MentionDateBlock), findsOneWidget);
+ expect(find.text('@$formattedDate'), findsOneWidget);
+
+ // tap on date field
+ await tester.tap(find.byType(MentionDateBlock));
+ await tester.pumpAndSettle();
+
+ // tap the toggle of include time
+ await tester.tap(find.byType(Toggle));
+ await tester.pumpAndSettle();
+
+ // add time 11:12
+ final currentTime = DateFormat('HH:mm').format(DateTime.now());
+ final textField = find.byWidgetPredicate(
+ (widget) =>
+ widget is TextField && widget.controller!.text == currentTime,
+ );
+ await tester.enterText(textField, "11:12");
+ await tester.editor.tapLineOfEditorAt(0);
+ await tester.pumpAndSettle();
+
+ // we will get field with current date and 11:12 as time
+ expect(find.byType(MentionDateBlock), findsOneWidget);
+ expect(find.text('@$formattedDate 11:12'), findsOneWidget);
+ });
+
+ testWidgets("insert date with reminder block", (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapAnonymousSignInButton();
+
+ // create a new document
+ await tester.createNewPageWithNameUnderParent(
+ name: 'Date with reminder test',
+ );
+
+ // tap the first line of the document
+ await tester.editor.tapLineOfEditorAt(0);
+ await tester.editor.showSlashMenu();
+ await tester.editor.tapSlashMenuItemWithName(
+ LocaleKeys.document_slashMenu_name_dateOrReminder.tr(),
+ offset: 100,
+ );
+
+ final dateTimeSettings = DateTimeSettingsPB(
+ dateFormat: UserDateFormatPB.Friendly,
+ timeFormat: UserTimeFormatPB.TwentyFourHour,
+ );
+ final DateTime currentDateTime = DateTime.now();
+ final String formattedDate =
+ dateTimeSettings.dateFormat.formatDate(currentDateTime, false);
+
+ // get current date in editor
+ expect(find.byType(MentionDateBlock), findsOneWidget);
+ expect(find.text('@$formattedDate'), findsOneWidget);
+
+ // tap on date field
+ await tester.tap(find.byType(MentionDateBlock));
+ await tester.pumpAndSettle();
+
+ // tap reminder and set reminder to 1 day before
+ await tester.tap(find.text(LocaleKeys.datePicker_reminderLabel.tr()));
+ await tester.pumpAndSettle();
+ await tester.tap(
+ find.textContaining(
+ LocaleKeys.datePicker_reminderOptions_oneDayBefore.tr(),
+ ),
+ );
+
+ await tester.editor.tapLineOfEditorAt(0);
+ await tester.pumpAndSettle();
+
+ // we will get field with current date reminder_clock.svg icon
+ expect(find.byType(MentionDateBlock), findsOneWidget);
+ expect(find.text('@$formattedDate'), findsOneWidget);
+ expect(find.byFlowySvg(FlowySvgs.reminder_clock_s), findsOneWidget);
+ });
+ });
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_date_block.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_date_block.dart
index 56d9ff5207..18cf6303cb 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_date_block.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_date_block.dart
@@ -126,7 +126,7 @@ class _MentionDateBlockState extends State<MentionDateBlock> {
);
} else {
_updateBlock(
- parsedDate!.withoutTime,
+ parsedDate!,
includeTime: includeTime,
);
}