switch_folder_test.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import 'package:appflowy/workspace/application/settings/prelude.dart';
  2. import 'package:flutter_test/flutter_test.dart';
  3. import 'package:integration_test/integration_test.dart';
  4. import 'util/mock/mock_file_picker.dart';
  5. import 'util/util.dart';
  6. void main() {
  7. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  8. group('customize the folder path', () {
  9. const location = 'appflowy';
  10. setUp(() async {
  11. await TestFolder.cleanTestLocation(location);
  12. await TestFolder.setTestLocation(location);
  13. });
  14. tearDown(() async {
  15. await TestFolder.cleanTestLocation(location);
  16. });
  17. tearDownAll(() async {
  18. await TestFolder.cleanTestLocation(null);
  19. });
  20. testWidgets('switch to B from A, then switch to A again', (tester) async {
  21. const String userA = 'userA';
  22. const String userB = 'userB';
  23. await TestFolder.cleanTestLocation(userA);
  24. await TestFolder.cleanTestLocation(userB);
  25. await TestFolder.setTestLocation(userA);
  26. await tester.initializeAppFlowy();
  27. await tester.tapGoButton();
  28. tester.expectToSeeWelcomePage();
  29. // switch to user B
  30. {
  31. // set user name to userA
  32. await tester.openSettings();
  33. await tester.openSettingsPage(SettingsPage.user);
  34. await tester.enterUserName(userA);
  35. await tester.openSettingsPage(SettingsPage.files);
  36. await tester.pumpAndSettle();
  37. // mock the file_picker result
  38. await mockGetDirectoryPath(userB);
  39. await tester.tapCustomLocationButton();
  40. await tester.pumpAndSettle();
  41. tester.expectToSeeWelcomePage();
  42. // set user name to userB
  43. await tester.openSettings();
  44. await tester.openSettingsPage(SettingsPage.user);
  45. await tester.enterUserName(userB);
  46. }
  47. // switch to the userA
  48. {
  49. await tester.openSettingsPage(SettingsPage.files);
  50. await tester.pumpAndSettle();
  51. // mock the file_picker result
  52. await mockGetDirectoryPath(userA);
  53. await tester.tapCustomLocationButton();
  54. await tester.pumpAndSettle();
  55. tester.expectToSeeWelcomePage();
  56. tester.expectToSeeUserName(userA);
  57. }
  58. // switch to the userB again
  59. {
  60. await tester.openSettings();
  61. await tester.openSettingsPage(SettingsPage.files);
  62. await tester.pumpAndSettle();
  63. // mock the file_picker result
  64. await mockGetDirectoryPath(userB);
  65. await tester.tapCustomLocationButton();
  66. await tester.pumpAndSettle();
  67. tester.expectToSeeWelcomePage();
  68. tester.expectToSeeUserName(userB);
  69. }
  70. await TestFolder.cleanTestLocation(userA);
  71. await TestFolder.cleanTestLocation(userB);
  72. });
  73. testWidgets('reset to default location', (tester) async {
  74. await tester.initializeAppFlowy();
  75. await tester.tapGoButton();
  76. // home and readme document
  77. tester.expectToSeeWelcomePage();
  78. // open settings and restore the location
  79. await tester.openSettings();
  80. await tester.openSettingsPage(SettingsPage.files);
  81. await tester.restoreLocation();
  82. expect(
  83. await TestFolder.defaultDevelopmentLocation(),
  84. await TestFolder.currentLocation(),
  85. );
  86. });
  87. });
  88. }