| 
									
										
										
										
											2023-06-20 23:48:34 +08:00
										 |  |  | import 'package:appflowy_backend/protobuf/flowy-database2/setting_entities.pbenum.dart'; | 
					
						
							|  |  |  | import 'package:appflowy_backend/protobuf/flowy-folder2/view.pbenum.dart'; | 
					
						
							|  |  |  | import 'package:flutter_test/flutter_test.dart'; | 
					
						
							|  |  |  | import 'package:integration_test/integration_test.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import 'util/database_test_op.dart'; | 
					
						
							|  |  |  | import 'util/util.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void main() { | 
					
						
							|  |  |  |   IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-05 11:05:05 +08:00
										 |  |  |   group('calendar database view', () { | 
					
						
							| 
									
										
										
										
											2023-06-20 23:48:34 +08:00
										 |  |  |     testWidgets('update calendar layout', (tester) async { | 
					
						
							|  |  |  |       await tester.initializeAppFlowy(); | 
					
						
							|  |  |  |       await tester.tapGoButton(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:06:01 +07:00
										 |  |  |       await tester.createNewPageWithName(layout: ViewLayoutPB.Calendar); | 
					
						
							| 
									
										
										
										
											2023-06-20 23:48:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // open setting
 | 
					
						
							|  |  |  |       await tester.tapDatabaseSettingButton(); | 
					
						
							|  |  |  |       await tester.tapDatabaseLayoutButton(); | 
					
						
							|  |  |  |       await tester.selectDatabaseLayoutType(DatabaseLayoutPB.Board); | 
					
						
							|  |  |  |       await tester.assertCurrentDatabaseLayoutType(DatabaseLayoutPB.Board); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await tester.tapDatabaseSettingButton(); | 
					
						
							|  |  |  |       await tester.tapDatabaseLayoutButton(); | 
					
						
							|  |  |  |       await tester.selectDatabaseLayoutType(DatabaseLayoutPB.Grid); | 
					
						
							|  |  |  |       await tester.assertCurrentDatabaseLayoutType(DatabaseLayoutPB.Grid); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await tester.pumpAndSettle(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     testWidgets('calendar start from day setting', (tester) async { | 
					
						
							|  |  |  |       await tester.initializeAppFlowy(); | 
					
						
							|  |  |  |       await tester.tapGoButton(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Create calendar view
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:06:01 +07:00
										 |  |  |       const name = 'calendar'; | 
					
						
							|  |  |  |       await tester.createNewPageWithName( | 
					
						
							|  |  |  |         name: name, | 
					
						
							|  |  |  |         layout: ViewLayoutPB.Calendar, | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2023-06-20 23:48:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // Open setting
 | 
					
						
							|  |  |  |       await tester.tapDatabaseSettingButton(); | 
					
						
							|  |  |  |       await tester.tapCalendarLayoutSettingButton(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // select the first day of week is Monday
 | 
					
						
							|  |  |  |       await tester.tapFirstDayOfWeek(); | 
					
						
							|  |  |  |       await tester.tapFirstDayOfWeekStartFromMonday(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Open the other page and open the new calendar page again
 | 
					
						
							| 
									
										
										
										
											2023-08-08 07:09:17 +02:00
										 |  |  |       await tester.openPage(gettingStarted); | 
					
						
							| 
									
										
										
										
											2023-06-20 23:48:34 +08:00
										 |  |  |       await tester.pumpAndSettle(const Duration(milliseconds: 300)); | 
					
						
							| 
									
										
										
										
											2023-07-31 19:06:01 +07:00
										 |  |  |       await tester.openPage(name, layout: ViewLayoutPB.Calendar); | 
					
						
							| 
									
										
										
										
											2023-06-20 23:48:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // Open setting again and check the start from Monday is selected
 | 
					
						
							|  |  |  |       await tester.tapDatabaseSettingButton(); | 
					
						
							|  |  |  |       await tester.tapCalendarLayoutSettingButton(); | 
					
						
							|  |  |  |       await tester.tapFirstDayOfWeek(); | 
					
						
							|  |  |  |       tester.assertFirstDayOfWeekStartFromMonday(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await tester.pumpAndSettle(); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-05 11:05:05 +08:00
										 |  |  |     testWidgets('creating and editing calendar events', (tester) async { | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  |       await tester.initializeAppFlowy(); | 
					
						
							|  |  |  |       await tester.tapGoButton(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Create the calendar view
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:06:01 +07:00
										 |  |  |       await tester.createNewPageWithName(layout: ViewLayoutPB.Calendar); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // Scroll until today's date cell is visible
 | 
					
						
							|  |  |  |       await tester.scrollToToday(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Hover over today's calendar cell
 | 
					
						
							|  |  |  |       await tester.hoverOnTodayCalendarCell(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Tap on create new event button
 | 
					
						
							|  |  |  |       await tester.tapAddCalendarEventButton(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Make sure that the row details page is opened
 | 
					
						
							|  |  |  |       tester.assertRowDetailPageOpened(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Dismiss the row details page
 | 
					
						
							|  |  |  |       await tester.dismissRowDetailPage(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       tester.assertNumberOfEventsInCalendar(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Double click on today's calendar cell to create a new event
 | 
					
						
							|  |  |  |       await tester.doubleClickCalendarCell(DateTime.now()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Make sure that the row details page is opened
 | 
					
						
							|  |  |  |       tester.assertRowDetailPageOpened(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Dismiss the row details page
 | 
					
						
							|  |  |  |       await tester.dismissRowDetailPage(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Make sure that the event is inserted in the cell
 | 
					
						
							|  |  |  |       tester.assertNumberOfEventsInCalendar(2); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-05 11:05:05 +08:00
										 |  |  |       // Click on the event
 | 
					
						
							|  |  |  |       await tester.openCalendarEvent(index: 0); | 
					
						
							|  |  |  |       tester.assertRowDetailPageOpened(); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-05 11:05:05 +08:00
										 |  |  |       // Change the title of the event
 | 
					
						
							|  |  |  |       await tester.editTitleInRowDetailPage('hello world'); | 
					
						
							|  |  |  |       await tester.dismissRowDetailPage(); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-05 11:05:05 +08:00
										 |  |  |       // Make sure that the event is edited
 | 
					
						
							|  |  |  |       tester.assertNumberOfEventsInCalendar(1, title: 'hello world'); | 
					
						
							| 
									
										
										
										
											2023-07-09 10:03:22 +07:00
										 |  |  |       tester.assertNumberOfEventsOnSpecificDay(2, DateTime.now()); | 
					
						
							| 
									
										
										
										
											2023-07-05 11:05:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // Click on the event
 | 
					
						
							|  |  |  |       await tester.openCalendarEvent(index: 1); | 
					
						
							|  |  |  |       tester.assertRowDetailPageOpened(); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // Duplicate the event
 | 
					
						
							|  |  |  |       await tester.tapRowDetailPageDuplicateRowButton(); | 
					
						
							|  |  |  |       await tester.dismissRowDetailPage(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Check that there are 2 events
 | 
					
						
							| 
									
										
										
										
											2023-07-05 11:05:05 +08:00
										 |  |  |       tester.assertNumberOfEventsInCalendar(2, title: 'hello world'); | 
					
						
							| 
									
										
										
										
											2023-07-09 10:03:22 +07:00
										 |  |  |       tester.assertNumberOfEventsOnSpecificDay(3, DateTime.now()); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // Delete an event
 | 
					
						
							| 
									
										
										
										
											2023-07-05 11:05:05 +08:00
										 |  |  |       await tester.openCalendarEvent(index: 1); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  |       await tester.tapRowDetailPageDeleteRowButton(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Check that there is 1 event
 | 
					
						
							| 
									
										
										
										
											2023-07-05 11:05:05 +08:00
										 |  |  |       tester.assertNumberOfEventsInCalendar(1, title: 'hello world'); | 
					
						
							| 
									
										
										
										
											2023-07-09 10:03:22 +07:00
										 |  |  |       tester.assertNumberOfEventsOnSpecificDay(2, DateTime.now()); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-05 11:05:05 +08:00
										 |  |  |     testWidgets('rescheduling events', (tester) async { | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  |       await tester.initializeAppFlowy(); | 
					
						
							|  |  |  |       await tester.tapGoButton(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Create the calendar view
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:06:01 +07:00
										 |  |  |       await tester.createNewPageWithName(layout: ViewLayoutPB.Calendar); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-05 11:05:05 +08:00
										 |  |  |       // Create a new event on the first of this month
 | 
					
						
							|  |  |  |       final today = DateTime.now(); | 
					
						
							|  |  |  |       final firstOfThisMonth = DateTime(today.year, today.month, 1); | 
					
						
							|  |  |  |       await tester.doubleClickCalendarCell(firstOfThisMonth); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  |       await tester.dismissRowDetailPage(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-05 11:05:05 +08:00
										 |  |  |       // Drag and drop the event onto the next week, same day
 | 
					
						
							|  |  |  |       await tester.dragDropRescheduleCalendarEvent(firstOfThisMonth); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-05 11:05:05 +08:00
										 |  |  |       // Make sure that the event has been rescheduled to the new date
 | 
					
						
							|  |  |  |       final sameDayNextWeek = firstOfThisMonth.add(const Duration(days: 7)); | 
					
						
							|  |  |  |       tester.assertNumberOfEventsInCalendar(1); | 
					
						
							| 
									
										
										
										
											2023-07-09 10:03:22 +07:00
										 |  |  |       tester.assertNumberOfEventsOnSpecificDay(1, sameDayNextWeek); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-05 11:05:05 +08:00
										 |  |  |       // Delete the event
 | 
					
						
							|  |  |  |       await tester.openCalendarEvent(index: 0, date: sameDayNextWeek); | 
					
						
							|  |  |  |       await tester.tapRowDetailPageDeleteRowButton(); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // Create a new event in today's calendar cell
 | 
					
						
							|  |  |  |       await tester.scrollToToday(); | 
					
						
							| 
									
										
										
										
											2023-07-01 20:29:49 +08:00
										 |  |  |       await tester.doubleClickCalendarCell(today); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  |       await tester.dismissRowDetailPage(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Make sure that the event is today
 | 
					
						
							| 
									
										
										
										
											2023-07-09 10:03:22 +07:00
										 |  |  |       tester.assertNumberOfEventsOnSpecificDay(1, today); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // Click on the event
 | 
					
						
							|  |  |  |       await tester.openCalendarEvent(index: 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Open the date editor of the event
 | 
					
						
							|  |  |  |       await tester.tapDateCellInRowDetailPage(); | 
					
						
							|  |  |  |       await tester.findDateEditor(findsOneWidget); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-01 20:29:49 +08:00
										 |  |  |       // 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); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  |       await tester.dismissCellEditor(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Dismiss the row details page
 | 
					
						
							|  |  |  |       await tester.dismissRowDetailPage(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Make sure that the event is edited
 | 
					
						
							|  |  |  |       tester.assertNumberOfEventsInCalendar(1); | 
					
						
							| 
									
										
										
										
											2023-07-09 10:03:22 +07:00
										 |  |  |       tester.assertNumberOfEventsOnSpecificDay(1, newDate); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:40:49 +08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2023-06-20 23:48:34 +08:00
										 |  |  |   }); | 
					
						
							|  |  |  | } |