database_calendar_test.dart 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. const location = 'appflowy';
  11. setUp(() async {
  12. await TestFolder.cleanTestLocation(location);
  13. await TestFolder.setTestLocation(location);
  14. });
  15. tearDown(() async {
  16. await TestFolder.cleanTestLocation(location);
  17. });
  18. tearDownAll(() async {
  19. await TestFolder.cleanTestLocation(null);
  20. });
  21. testWidgets('update calendar layout', (tester) async {
  22. await tester.initializeAppFlowy();
  23. await tester.tapGoButton();
  24. await tester.tapAddButton();
  25. await tester.tapCreateCalendarButton();
  26. // open setting
  27. await tester.tapDatabaseSettingButton();
  28. await tester.tapDatabaseLayoutButton();
  29. await tester.selectDatabaseLayoutType(DatabaseLayoutPB.Board);
  30. await tester.assertCurrentDatabaseLayoutType(DatabaseLayoutPB.Board);
  31. await tester.tapDatabaseSettingButton();
  32. await tester.tapDatabaseLayoutButton();
  33. await tester.selectDatabaseLayoutType(DatabaseLayoutPB.Grid);
  34. await tester.assertCurrentDatabaseLayoutType(DatabaseLayoutPB.Grid);
  35. await tester.pumpAndSettle();
  36. });
  37. testWidgets('calendar start from day setting', (tester) async {
  38. await tester.initializeAppFlowy();
  39. await tester.tapGoButton();
  40. // Create calendar view
  41. await tester.createNewPageWithName(ViewLayoutPB.Calendar, 'calendar');
  42. // Open setting
  43. await tester.tapDatabaseSettingButton();
  44. await tester.tapCalendarLayoutSettingButton();
  45. // select the first day of week is Monday
  46. await tester.tapFirstDayOfWeek();
  47. await tester.tapFirstDayOfWeekStartFromMonday();
  48. // Open the other page and open the new calendar page again
  49. await tester.openPage(readme);
  50. await tester.pumpAndSettle(const Duration(milliseconds: 300));
  51. await tester.openPage('calendar');
  52. // Open setting again and check the start from Monday is selected
  53. await tester.tapDatabaseSettingButton();
  54. await tester.tapCalendarLayoutSettingButton();
  55. await tester.tapFirstDayOfWeek();
  56. tester.assertFirstDayOfWeekStartFromMonday();
  57. await tester.pumpAndSettle();
  58. });
  59. testWidgets('create new calendar event using new button', (tester) async {
  60. await tester.initializeAppFlowy();
  61. await tester.tapGoButton();
  62. // Create the calendar view
  63. await tester.tapAddButton();
  64. await tester.tapCreateCalendarButton();
  65. // Scroll until today's date cell is visible
  66. await tester.scrollToToday();
  67. // Hover over today's calendar cell
  68. await tester.hoverOnTodayCalendarCell();
  69. // Tap on create new event button
  70. await tester.tapAddCalendarEventButton();
  71. // Make sure that the row details page is opened
  72. tester.assertRowDetailPageOpened();
  73. // Dismiss the row details page
  74. await tester.dismissRowDetailPage();
  75. // Make sure that the event is inserted in the cell
  76. tester.assertNumberOfEventsInCalendar(1);
  77. // Create another event on the same day
  78. await tester.hoverOnTodayCalendarCell();
  79. await tester.tapAddCalendarEventButton();
  80. await tester.dismissRowDetailPage();
  81. tester.assertNumberOfEventsInCalendar(2);
  82. tester.assertNumberofEventsOnSpecificDay(2, DateTime.now());
  83. });
  84. testWidgets('create new calendar event by double-clicking', (tester) async {
  85. await tester.initializeAppFlowy();
  86. await tester.tapGoButton();
  87. // Create the calendar view
  88. await tester.tapAddButton();
  89. await tester.tapCreateCalendarButton();
  90. // Scroll until today's date cell is visible
  91. await tester.scrollToToday();
  92. // Double click on today's calendar cell to create a new event
  93. await tester.doubleClickCalendarCell(DateTime.now());
  94. // Make sure that the row details page is opened
  95. tester.assertRowDetailPageOpened();
  96. // Dismiss the row details page
  97. await tester.dismissRowDetailPage();
  98. // Make sure that the event is inserted in the cell
  99. tester.assertNumberOfEventsInCalendar(1);
  100. // Create another event on the same day
  101. await tester.doubleClickCalendarCell(DateTime.now());
  102. await tester.dismissRowDetailPage();
  103. tester.assertNumberOfEventsInCalendar(2);
  104. tester.assertNumberofEventsOnSpecificDay(2, DateTime.now());
  105. });
  106. testWidgets('duplicate/delete a calendar event', (tester) async {
  107. await tester.initializeAppFlowy();
  108. await tester.tapGoButton();
  109. // Create the calendar view
  110. await tester.tapAddButton();
  111. await tester.tapCreateCalendarButton();
  112. // Create a new event in today's calendar cell
  113. await tester.scrollToToday();
  114. await tester.doubleClickCalendarCell(DateTime.now());
  115. // Duplicate the event
  116. await tester.tapRowDetailPageDuplicateRowButton();
  117. await tester.dismissRowDetailPage();
  118. // Check that there are 2 events
  119. tester.assertNumberOfEventsInCalendar(2);
  120. // Delete an event
  121. await tester.openCalendarEvent(index: 0);
  122. await tester.tapRowDetailPageDeleteRowButton();
  123. // Check that there is 1 event
  124. tester.assertNumberOfEventsInCalendar(1);
  125. });
  126. testWidgets('edit the title of a calendar date event', (tester) async {
  127. await tester.initializeAppFlowy();
  128. await tester.tapGoButton();
  129. // Create the calendar view
  130. await tester.tapAddButton();
  131. await tester.tapCreateCalendarButton();
  132. // Create a new event in today's calendar cell
  133. await tester.scrollToToday();
  134. await tester.doubleClickCalendarCell(DateTime.now());
  135. await tester.dismissRowDetailPage();
  136. // Click on the event
  137. await tester.openCalendarEvent(index: 0);
  138. // Make sure that the row details page is opened
  139. tester.assertRowDetailPageOpened();
  140. // Change the title of the event
  141. await tester.editTitleInRowDetailPage('hello world');
  142. // Dismiss the row details page
  143. await tester.dismissRowDetailPage();
  144. // Make sure that the event is edited
  145. tester.assertNumberOfEventsInCalendar(1, title: 'hello world');
  146. });
  147. testWidgets(
  148. 'edit the date of the date field being used to layout the calendar',
  149. (tester) async {
  150. await tester.initializeAppFlowy();
  151. await tester.tapGoButton();
  152. // Create the calendar view
  153. await tester.tapAddButton();
  154. await tester.tapCreateCalendarButton();
  155. // Create a new event in today's calendar cell
  156. await tester.scrollToToday();
  157. await tester.doubleClickCalendarCell(DateTime.now());
  158. await tester.dismissRowDetailPage();
  159. // Make sure that the event is today
  160. tester.assertNumberofEventsOnSpecificDay(1, DateTime.now());
  161. // Click on the event
  162. await tester.openCalendarEvent(index: 0);
  163. // Open the date editor of the event
  164. await tester.tapDateCellInRowDetailPage();
  165. await tester.findDateEditor(findsOneWidget);
  166. // Edit the event's date
  167. final tomorrow = DateTime.now().add(const Duration(days: 1));
  168. await tester.selectDay(content: tomorrow.day);
  169. await tester.dismissCellEditor();
  170. // Dismiss the row details page
  171. await tester.dismissRowDetailPage();
  172. // Make sure that the event is edited
  173. tester.assertNumberOfEventsInCalendar(1);
  174. tester.assertNumberofEventsOnSpecificDay(1, tomorrow);
  175. });
  176. testWidgets('reschedule an event by drag-and-drop', (tester) async {
  177. await tester.initializeAppFlowy();
  178. await tester.tapGoButton();
  179. // Create the calendar view
  180. await tester.tapAddButton();
  181. await tester.tapCreateCalendarButton();
  182. // Create a new event on the first of this month
  183. final today = DateTime.now();
  184. final firstOfThisMonth = DateTime(today.year, today.month, 1);
  185. await tester.doubleClickCalendarCell(firstOfThisMonth);
  186. await tester.dismissRowDetailPage();
  187. // Drag and drop the event onto the next week, same day
  188. await tester.dragDropRescheduleCalendarEvent(firstOfThisMonth);
  189. // Make sure that the event has been rescheduled to the new date
  190. tester.assertNumberOfEventsInCalendar(1);
  191. tester.assertNumberofEventsOnSpecificDay(
  192. 1,
  193. firstOfThisMonth.add(const Duration(days: 7)),
  194. );
  195. });
  196. });
  197. }