switch_folder_test.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import 'package:appflowy/user/presentation/folder/folder_widget.dart';
  2. import 'package:flowy_infra_ui/style_widget/text_field.dart';
  3. import 'package:flutter_test/flutter_test.dart';
  4. import 'package:integration_test/integration_test.dart';
  5. import 'util/mock/mock_file_picker.dart';
  6. import 'util/util.dart';
  7. void main() {
  8. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  9. group('customize the folder path', () {
  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(
  22. 'customize folder name and path when launching app in first time',
  23. (tester) async {
  24. const folderName = 'appflowy';
  25. await TestFolder.cleanTestLocation(folderName);
  26. await tester.initializeAppFlowy();
  27. // Click create button
  28. await tester.tapCreateButton();
  29. // Set directory
  30. final cfw = find.byType(CreateFolderWidget);
  31. expect(cfw, findsOneWidget);
  32. final state = tester.state(cfw) as CreateFolderWidgetState;
  33. final dir = await TestFolder.testLocation(null);
  34. state.directory = dir.path;
  35. // input folder name
  36. final ftf = find.byType(FlowyTextField);
  37. expect(ftf, findsOneWidget);
  38. await tester.enterText(ftf, 'appflowy');
  39. // Click create button again
  40. await tester.tapCreateButton();
  41. await tester.expectToSeeWelcomePage();
  42. await TestFolder.cleanTestLocation(folderName);
  43. });
  44. testWidgets('open a new folder when launching app in first time',
  45. (tester) async {
  46. const folderName = 'appflowy';
  47. await TestFolder.cleanTestLocation(folderName);
  48. await TestFolder.setTestLocation(folderName);
  49. await tester.initializeAppFlowy();
  50. // tap open button
  51. await mockGetDirectoryPath(folderName);
  52. await tester.tapOpenFolderButton();
  53. await tester.wait(1000);
  54. await tester.expectToSeeWelcomePage();
  55. await TestFolder.cleanTestLocation(folderName);
  56. });
  57. testWidgets('switch to B from A, then switch to A again', (tester) async {
  58. const String userA = 'userA';
  59. const String userB = 'userB';
  60. await TestFolder.cleanTestLocation(userA);
  61. await TestFolder.setTestLocation(userA);
  62. await tester.initializeAppFlowy();
  63. await tester.tapGoButton();
  64. await tester.expectToSeeWelcomePage();
  65. // switch to user B
  66. {
  67. await tester.openSettings();
  68. await tester.openSettingsPage(SettingsPage.user);
  69. await tester.enterUserName(userA);
  70. await tester.openSettingsPage(SettingsPage.files);
  71. await tester.pumpAndSettle();
  72. // mock the file_picker result
  73. await mockGetDirectoryPath(userB);
  74. await tester.tapCustomLocationButton();
  75. await tester.pumpAndSettle();
  76. await tester.expectToSeeWelcomePage();
  77. }
  78. // switch to the userA
  79. {
  80. await tester.openSettings();
  81. await tester.openSettingsPage(SettingsPage.user);
  82. await tester.enterUserName(userB);
  83. await tester.openSettingsPage(SettingsPage.files);
  84. await tester.pumpAndSettle();
  85. // mock the file_picker result
  86. await mockGetDirectoryPath(userA);
  87. await tester.tapCustomLocationButton();
  88. await tester.pumpAndSettle();
  89. await tester.expectToSeeWelcomePage();
  90. expect(find.textContaining(userA), findsOneWidget);
  91. }
  92. // switch to the userB again
  93. {
  94. await tester.openSettings();
  95. await tester.openSettingsPage(SettingsPage.files);
  96. await tester.pumpAndSettle();
  97. // mock the file_picker result
  98. await mockGetDirectoryPath(userB);
  99. await tester.tapCustomLocationButton();
  100. await tester.pumpAndSettle();
  101. await tester.expectToSeeWelcomePage();
  102. expect(find.textContaining(userB), findsOneWidget);
  103. }
  104. await TestFolder.cleanTestLocation(userA);
  105. await TestFolder.cleanTestLocation(userB);
  106. });
  107. testWidgets('reset to default location', (tester) async {
  108. await tester.initializeAppFlowy();
  109. await tester.tapGoButton();
  110. // home and readme document
  111. await tester.expectToSeeWelcomePage();
  112. // open settings and restore the location
  113. await tester.openSettings();
  114. await tester.openSettingsPage(SettingsPage.files);
  115. await tester.restoreLocation();
  116. expect(
  117. await TestFolder.defaultDevelopmentLocation(),
  118. await TestFolder.currentLocation(),
  119. );
  120. });
  121. });
  122. }