switch_folder_test.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import 'package:appflowy/startup/startup.dart';
  2. import 'package:appflowy/startup/tasks/prelude.dart';
  3. import 'package:appflowy/workspace/application/settings/prelude.dart';
  4. import 'package:flutter_test/flutter_test.dart';
  5. import 'package:integration_test/integration_test.dart';
  6. import 'package:path/path.dart' as p;
  7. import 'util/mock/mock_file_picker.dart';
  8. import 'util/util.dart';
  9. void main() {
  10. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  11. group('customize the folder path', () {
  12. testWidgets('switch to B from A, then switch to A again', (tester) async {
  13. const userA = 'UserA';
  14. const userB = 'UserB';
  15. final initialPath = p.join(userA, appFlowyDataFolder);
  16. final context = await tester.initializeAppFlowy(
  17. pathExtension: initialPath,
  18. );
  19. // remove the last extension
  20. final rootPath = context.applicationDataDirectory.replaceFirst(
  21. initialPath,
  22. '',
  23. );
  24. await tester.tapGoButton();
  25. tester.expectToSeeHomePage();
  26. // switch to user B
  27. {
  28. // set user name for userA
  29. await tester.openSettings();
  30. await tester.openSettingsPage(SettingsPage.user);
  31. await tester.enterUserName(userA);
  32. await tester.openSettingsPage(SettingsPage.files);
  33. await tester.pumpAndSettle();
  34. // mock the file_picker result
  35. await mockGetDirectoryPath(
  36. p.join(rootPath, userB),
  37. );
  38. await tester.tapCustomLocationButton();
  39. await tester.pumpAndSettle();
  40. tester.expectToSeeHomePage();
  41. // set user name for userB
  42. await tester.openSettings();
  43. await tester.openSettingsPage(SettingsPage.user);
  44. await tester.enterUserName(userB);
  45. }
  46. // switch to the userA
  47. {
  48. await tester.openSettingsPage(SettingsPage.files);
  49. await tester.pumpAndSettle();
  50. // mock the file_picker result
  51. await mockGetDirectoryPath(
  52. p.join(rootPath, userA),
  53. );
  54. await tester.tapCustomLocationButton();
  55. await tester.pumpAndSettle();
  56. tester.expectToSeeHomePage();
  57. tester.expectToSeeUserName(userA);
  58. }
  59. // switch to the userB again
  60. {
  61. await tester.openSettings();
  62. await tester.openSettingsPage(SettingsPage.files);
  63. await tester.pumpAndSettle();
  64. // mock the file_picker result
  65. await mockGetDirectoryPath(
  66. p.join(rootPath, userB),
  67. );
  68. await tester.tapCustomLocationButton();
  69. await tester.pumpAndSettle();
  70. tester.expectToSeeHomePage();
  71. tester.expectToSeeUserName(userB);
  72. }
  73. });
  74. testWidgets('reset to default location', (tester) async {
  75. await tester.initializeAppFlowy();
  76. await tester.tapGoButton();
  77. // home and readme document
  78. tester.expectToSeeHomePage();
  79. // open settings and restore the location
  80. await tester.openSettings();
  81. await tester.openSettingsPage(SettingsPage.files);
  82. await tester.restoreLocation();
  83. expect(
  84. await appFlowyApplicationDataDirectory().then((value) => value.path),
  85. await getIt<ApplicationDataStorage>().getPath(),
  86. );
  87. });
  88. });
  89. }