database_calendar_test.dart 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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('database', () {
  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('create new calendar event using new button', (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. // Make sure that the event is inserted in the cell
  65. tester.assertNumberOfEventsInCalendar(1);
  66. // Create another event on the same day
  67. await tester.hoverOnTodayCalendarCell();
  68. await tester.tapAddCalendarEventButton();
  69. await tester.dismissRowDetailPage();
  70. tester.assertNumberOfEventsInCalendar(2);
  71. tester.assertNumberofEventsOnSpecificDay(2, DateTime.now());
  72. });
  73. testWidgets('create new calendar event by double-clicking', (tester) async {
  74. await tester.initializeAppFlowy();
  75. await tester.tapGoButton();
  76. // Create the calendar view
  77. await tester.tapAddButton();
  78. await tester.tapCreateCalendarButton();
  79. // Scroll until today's date cell is visible
  80. await tester.scrollToToday();
  81. // Double click on today's calendar cell to create a new event
  82. await tester.doubleClickCalendarCell(DateTime.now());
  83. // Make sure that the row details page is opened
  84. tester.assertRowDetailPageOpened();
  85. // Dismiss the row details page
  86. await tester.dismissRowDetailPage();
  87. // Make sure that the event is inserted in the cell
  88. tester.assertNumberOfEventsInCalendar(1);
  89. // Create another event on the same day
  90. await tester.doubleClickCalendarCell(DateTime.now());
  91. await tester.dismissRowDetailPage();
  92. tester.assertNumberOfEventsInCalendar(2);
  93. tester.assertNumberofEventsOnSpecificDay(2, DateTime.now());
  94. });
  95. testWidgets('duplicate/delete a calendar event', (tester) async {
  96. await tester.initializeAppFlowy();
  97. await tester.tapGoButton();
  98. // Create the calendar view
  99. await tester.tapAddButton();
  100. await tester.tapCreateCalendarButton();
  101. // Create a new event in today's calendar cell
  102. await tester.scrollToToday();
  103. await tester.doubleClickCalendarCell(DateTime.now());
  104. // Duplicate the event
  105. await tester.tapRowDetailPageDuplicateRowButton();
  106. await tester.dismissRowDetailPage();
  107. // Check that there are 2 events
  108. tester.assertNumberOfEventsInCalendar(2);
  109. // Delete an event
  110. await tester.openCalendarEvent(index: 0);
  111. await tester.tapRowDetailPageDeleteRowButton();
  112. // Check that there is 1 event
  113. tester.assertNumberOfEventsInCalendar(1);
  114. });
  115. testWidgets('edit the title of a calendar date event', (tester) async {
  116. await tester.initializeAppFlowy();
  117. await tester.tapGoButton();
  118. // Create the calendar view
  119. await tester.tapAddButton();
  120. await tester.tapCreateCalendarButton();
  121. // Create a new event in today's calendar cell
  122. await tester.scrollToToday();
  123. await tester.doubleClickCalendarCell(DateTime.now());
  124. await tester.dismissRowDetailPage();
  125. // Click on the event
  126. await tester.openCalendarEvent(index: 0);
  127. // Make sure that the row details page is opened
  128. tester.assertRowDetailPageOpened();
  129. // Change the title of the event
  130. await tester.editTitleInRowDetailPage('hello world');
  131. // Dismiss the row details page
  132. await tester.dismissRowDetailPage();
  133. // Make sure that the event is edited
  134. tester.assertNumberOfEventsInCalendar(1, title: 'hello world');
  135. });
  136. testWidgets(
  137. 'edit the date of the date field being used to layout the calendar',
  138. (tester) async {
  139. await tester.initializeAppFlowy();
  140. await tester.tapGoButton();
  141. // Create the calendar view
  142. await tester.tapAddButton();
  143. await tester.tapCreateCalendarButton();
  144. // Create a new event in today's calendar cell
  145. final today = DateTime.now();
  146. await tester.scrollToToday();
  147. await tester.doubleClickCalendarCell(today);
  148. await tester.dismissRowDetailPage();
  149. // Make sure that the event is today
  150. tester.assertNumberofEventsOnSpecificDay(1, today);
  151. // Click on the event
  152. await tester.openCalendarEvent(index: 0);
  153. // Open the date editor of the event
  154. await tester.tapDateCellInRowDetailPage();
  155. await tester.findDateEditor(findsOneWidget);
  156. // 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.
  157. final newDate = today.day < 15
  158. ? today.add(const Duration(days: 1))
  159. : today.subtract(const Duration(days: 1));
  160. await tester.selectDay(content: newDate.day);
  161. await tester.dismissCellEditor();
  162. // Dismiss the row details page
  163. await tester.dismissRowDetailPage();
  164. // Make sure that the event is edited
  165. tester.assertNumberOfEventsInCalendar(1);
  166. tester.assertNumberofEventsOnSpecificDay(1, newDate);
  167. });
  168. testWidgets('reschedule an event by drag-and-drop', (tester) async {
  169. await tester.initializeAppFlowy();
  170. await tester.tapGoButton();
  171. // Create the calendar view
  172. await tester.tapAddButton();
  173. await tester.tapCreateCalendarButton();
  174. // Create a new event on the first of this month
  175. final today = DateTime.now();
  176. final firstOfThisMonth = DateTime(today.year, today.month, 1);
  177. await tester.doubleClickCalendarCell(firstOfThisMonth);
  178. await tester.dismissRowDetailPage();
  179. // Drag and drop the event onto the next week, same day
  180. await tester.dragDropRescheduleCalendarEvent(firstOfThisMonth);
  181. // Make sure that the event has been rescheduled to the new date
  182. tester.assertNumberOfEventsInCalendar(1);
  183. tester.assertNumberofEventsOnSpecificDay(
  184. 1,
  185. firstOfThisMonth.add(const Duration(days: 7)),
  186. );
  187. });
  188. });
  189. }