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.

test: fix calendar integration test #2919 (#2920)

Richard Shiue3acd36e580a0
diff --git a/frontend/appflowy_flutter/integration_test/database_calendar_test.dart b/frontend/appflowy_flutter/integration_test/database_calendar_test.dart
index bd9eae15d7..7268e2134d 100644
--- a/frontend/appflowy_flutter/integration_test/database_calendar_test.dart
+++ b/frontend/appflowy_flutter/integration_test/database_calendar_test.dart
@@ -206,12 +206,13 @@ void main() {
await tester.tapCreateCalendarButton();
// Create a new event in today's calendar cell
+ final today = DateTime.now();
await tester.scrollToToday();
- await tester.doubleClickCalendarCell(DateTime.now());
+ await tester.doubleClickCalendarCell(today);
await tester.dismissRowDetailPage();
// Make sure that the event is today
- tester.assertNumberofEventsOnSpecificDay(1, DateTime.now());
+ tester.assertNumberofEventsOnSpecificDay(1, today);
// Click on the event
await tester.openCalendarEvent(index: 0);
@@ -220,9 +221,11 @@ void main() {
await tester.tapDateCellInRowDetailPage();
await tester.findDateEditor(findsOneWidget);
- // Edit the event's date
- final tomorrow = DateTime.now().add(const Duration(days: 1));
- await tester.selectDay(content: tomorrow.day);
+ // Edit the event's date. To avoid selecting a day outside of the current month, the new date will be one day closer to the middle of the month.
+ final newDate = today.day < 15
+ ? today.add(const Duration(days: 1))
+ : today.subtract(const Duration(days: 1));
+ await tester.selectDay(content: newDate.day);
await tester.dismissCellEditor();
// Dismiss the row details page
@@ -230,7 +233,7 @@ void main() {
// Make sure that the event is edited
tester.assertNumberOfEventsInCalendar(1);
- tester.assertNumberofEventsOnSpecificDay(1, tomorrow);
+ tester.assertNumberofEventsOnSpecificDay(1, newDate);
});
testWidgets('reschedule an event by drag-and-drop', (tester) async {
diff --git a/frontend/appflowy_flutter/integration_test/database_cell_test.dart b/frontend/appflowy_flutter/integration_test/database_cell_test.dart
index b5855f73b7..ec7dbe477f 100644
--- a/frontend/appflowy_flutter/integration_test/database_cell_test.dart
+++ b/frontend/appflowy_flutter/integration_test/database_cell_test.dart
@@ -237,7 +237,7 @@ void main() {
await tester.assertDateCellInGrid(
rowIndex: 0,
fieldType: fieldType,
- content: DateFormat('MMM d, y').format(today),
+ content: DateFormat('MMM dd, y').format(today),
);
await tester.tapCellInGrid(rowIndex: 0, fieldType: fieldType);
@@ -252,7 +252,7 @@ void main() {
await tester.assertDateCellInGrid(
rowIndex: 0,
fieldType: fieldType,
- content: DateFormat('MMM d, y HH:mm').format(now),
+ content: DateFormat('MMM dd, y HH:mm').format(now),
);
await tester.tapCellInGrid(rowIndex: 0, fieldType: fieldType);
diff --git a/frontend/appflowy_flutter/integration_test/util/database_test_op.dart b/frontend/appflowy_flutter/integration_test/util/database_test_op.dart
index a9035a8f90..43b50cd0c5 100644
--- a/frontend/appflowy_flutter/integration_test/util/database_test_op.dart
+++ b/frontend/appflowy_flutter/integration_test/util/database_test_op.dart
@@ -2,6 +2,7 @@ import 'dart:io';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database_view/board/presentation/board_page.dart';
+import 'package:appflowy/plugins/database_view/calendar/application/calendar_bloc.dart';
import 'package:appflowy/plugins/database_view/calendar/presentation/calendar_day.dart';
import 'package:appflowy/plugins/database_view/calendar/presentation/calendar_page.dart';
import 'package:appflowy/plugins/database_view/calendar/presentation/toolbar/calendar_layout_setting.dart';
@@ -40,6 +41,7 @@ import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart';
import 'package:appflowy/workspace/presentation/widgets/toggle/toggle.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/setting_entities.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
+import 'package:calendar_view/calendar_view.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/text_input.dart';
@@ -977,9 +979,20 @@ extension AppFlowyDatabaseTest on WidgetTester {
Future<void> scrollToToday() async {
final todayCell = find.byWidgetPredicate(
(widget) => widget is CalendarDayCard && widget.isToday,
- skipOffstage: false,
);
- await ensureVisible(todayCell);
+ final scrollable = find
+ .descendant(
+ of: find.byType(MonthView<CalendarDayEvent>),
+ matching: find.byWidgetPredicate(
+ (widget) => widget is Scrollable && widget.axis == Axis.vertical,
+ ),
+ )
+ .first;
+ await scrollUntilVisible(
+ todayCell,
+ 300,
+ scrollable: scrollable,
+ );
await pumpAndSettle(const Duration(milliseconds: 300));
}