switch_folder_test.dart 3.2 KB

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