database_calendar_test.dart 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import 'package:appflowy_backend/protobuf/flowy-database2/setting_entities.pbenum.dart';
  2. import 'package:appflowy_backend/protobuf/flowy-folder2/view.pbenum.dart';
  3. import 'package:flutter_test/flutter_test.dart';
  4. import 'package:integration_test/integration_test.dart';
  5. import 'util/database_test_op.dart';
  6. import 'util/util.dart';
  7. void main() {
  8. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  9. group('calendar database view', () {
  10. testWidgets('update calendar layout', (tester) async {
  11. await tester.initializeAppFlowy();
  12. await tester.tapGoButton();
  13. await tester.tapAddButton();
  14. await tester.tapCreateCalendarButton();
  15. // open setting
  16. await tester.tapDatabaseSettingButton();
  17. await tester.tapDatabaseLayoutButton();
  18. await tester.selectDatabaseLayoutType(DatabaseLayoutPB.Board);
  19. await tester.assertCurrentDatabaseLayoutType(DatabaseLayoutPB.Board);
  20. await tester.tapDatabaseSettingButton();
  21. await tester.tapDatabaseLayoutButton();
  22. await tester.selectDatabaseLayoutType(DatabaseLayoutPB.Grid);
  23. await tester.assertCurrentDatabaseLayoutType(DatabaseLayoutPB.Grid);
  24. await tester.pumpAndSettle();
  25. });
  26. testWidgets('calendar start from day setting', (tester) async {
  27. await tester.initializeAppFlowy();
  28. await tester.tapGoButton();
  29. // Create calendar view
  30. await tester.createNewPageWithName(ViewLayoutPB.Calendar, 'calendar');
  31. // Open setting
  32. await tester.tapDatabaseSettingButton();
  33. await tester.tapCalendarLayoutSettingButton();
  34. // select the first day of week is Monday
  35. await tester.tapFirstDayOfWeek();
  36. await tester.tapFirstDayOfWeekStartFromMonday();
  37. // Open the other page and open the new calendar page again
  38. await tester.openPage(readme);
  39. await tester.pumpAndSettle(const Duration(milliseconds: 300));
  40. await tester.openPage('calendar');
  41. // Open setting again and check the start from Monday is selected
  42. await tester.tapDatabaseSettingButton();
  43. await tester.tapCalendarLayoutSettingButton();
  44. await tester.tapFirstDayOfWeek();
  45. tester.assertFirstDayOfWeekStartFromMonday();
  46. await tester.pumpAndSettle();
  47. });
  48. testWidgets('creating and editing calendar events', (tester) async {
  49. await tester.initializeAppFlowy();
  50. await tester.tapGoButton();
  51. // Create the calendar view
  52. await tester.tapAddButton();
  53. await tester.tapCreateCalendarButton();
  54. // Scroll until today's date cell is visible
  55. await tester.scrollToToday();
  56. // Hover over today's calendar cell
  57. await tester.hoverOnTodayCalendarCell();
  58. // Tap on create new event button
  59. await tester.tapAddCalendarEventButton();
  60. // Make sure that the row details page is opened
  61. tester.assertRowDetailPageOpened();
  62. // Dismiss the row details page
  63. await tester.dismissRowDetailPage();
  64. tester.assertNumberOfEventsInCalendar(1);
  65. // Double click on today's calendar cell to create a new event
  66. await tester.doubleClickCalendarCell(DateTime.now());
  67. // Make sure that the row details page is opened
  68. tester.assertRowDetailPageOpened();
  69. // Dismiss the row details page
  70. await tester.dismissRowDetailPage();
  71. // Make sure that the event is inserted in the cell
  72. tester.assertNumberOfEventsInCalendar(2);
  73. // Click on the event
  74. await tester.openCalendarEvent(index: 0);
  75. tester.assertRowDetailPageOpened();
  76. // Change the title of the event
  77. await tester.editTitleInRowDetailPage('hello world');
  78. await tester.dismissRowDetailPage();
  79. // Make sure that the event is edited
  80. tester.assertNumberOfEventsInCalendar(1, title: 'hello world');
  81. tester.assertNumberOfEventsOnSpecificDay(2, DateTime.now());
  82. // Click on the event
  83. await tester.openCalendarEvent(index: 1);
  84. tester.assertRowDetailPageOpened();
  85. // Duplicate the event
  86. await tester.tapRowDetailPageDuplicateRowButton();
  87. await tester.dismissRowDetailPage();
  88. // Check that there are 2 events
  89. tester.assertNumberOfEventsInCalendar(2, title: 'hello world');
  90. tester.assertNumberOfEventsOnSpecificDay(3, DateTime.now());
  91. // Delete an event
  92. await tester.openCalendarEvent(index: 1);
  93. await tester.tapRowDetailPageDeleteRowButton();
  94. // Check that there is 1 event
  95. tester.assertNumberOfEventsInCalendar(1, title: 'hello world');
  96. tester.assertNumberOfEventsOnSpecificDay(2, DateTime.now());
  97. });
  98. testWidgets('rescheduling events', (tester) async {
  99. await tester.initializeAppFlowy();
  100. await tester.tapGoButton();
  101. // Create the calendar view
  102. await tester.tapAddButton();
  103. await tester.tapCreateCalendarButton();
  104. // Create a new event on the first of this month
  105. final today = DateTime.now();
  106. final firstOfThisMonth = DateTime(today.year, today.month, 1);
  107. await tester.doubleClickCalendarCell(firstOfThisMonth);
  108. await tester.dismissRowDetailPage();
  109. // Drag and drop the event onto the next week, same day
  110. await tester.dragDropRescheduleCalendarEvent(firstOfThisMonth);
  111. // Make sure that the event has been rescheduled to the new date
  112. final sameDayNextWeek = firstOfThisMonth.add(const Duration(days: 7));
  113. tester.assertNumberOfEventsInCalendar(1);
  114. tester.assertNumberOfEventsOnSpecificDay(1, sameDayNextWeek);
  115. // Delete the event
  116. await tester.openCalendarEvent(index: 0, date: sameDayNextWeek);
  117. await tester.tapRowDetailPageDeleteRowButton();
  118. // Create a new event in today's calendar cell
  119. await tester.scrollToToday();
  120. await tester.doubleClickCalendarCell(today);
  121. await tester.dismissRowDetailPage();
  122. // Make sure that the event is today
  123. tester.assertNumberOfEventsOnSpecificDay(1, today);
  124. // Click on the event
  125. await tester.openCalendarEvent(index: 0);
  126. // Open the date editor of the event
  127. await tester.tapDateCellInRowDetailPage();
  128. await tester.findDateEditor(findsOneWidget);
  129. // 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.
  130. final newDate = today.day < 15
  131. ? today.add(const Duration(days: 1))
  132. : today.subtract(const Duration(days: 1));
  133. await tester.selectDay(content: newDate.day);
  134. await tester.dismissCellEditor();
  135. // Dismiss the row details page
  136. await tester.dismissRowDetailPage();
  137. // Make sure that the event is edited
  138. tester.assertNumberOfEventsInCalendar(1);
  139. tester.assertNumberOfEventsOnSpecificDay(1, newDate);
  140. });
  141. });
  142. }