2023-06-11 14:19:44 +08:00
|
|
|
import 'package:appflowy/workspace/application/settings/prelude.dart';
|
2023-06-21 19:10:16 +08:00
|
|
|
import 'package:appflowy/workspace/application/settings/settings_location_cubit.dart';
|
|
|
|
import 'package:flowy_infra/uuid.dart';
|
2022-12-20 11:14:42 +08:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:integration_test/integration_test.dart';
|
|
|
|
|
|
|
|
import 'util/mock/mock_file_picker.dart';
|
|
|
|
import 'util/util.dart';
|
2023-06-21 19:10:16 +08:00
|
|
|
import 'package:path/path.dart' as p;
|
2022-12-20 11:14:42 +08:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
|
|
|
group('customize the folder path', () {
|
|
|
|
const location = 'appflowy';
|
|
|
|
|
|
|
|
setUp(() async {
|
|
|
|
await TestFolder.cleanTestLocation(location);
|
|
|
|
await TestFolder.setTestLocation(location);
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() async {
|
|
|
|
await TestFolder.cleanTestLocation(location);
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDownAll(() async {
|
|
|
|
await TestFolder.cleanTestLocation(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('switch to B from A, then switch to A again', (tester) async {
|
2023-06-21 19:10:16 +08:00
|
|
|
final userA = uuid();
|
|
|
|
final userB = uuid();
|
2022-12-20 11:14:42 +08:00
|
|
|
|
|
|
|
await TestFolder.cleanTestLocation(userA);
|
2023-06-11 14:19:44 +08:00
|
|
|
await TestFolder.cleanTestLocation(userB);
|
2023-06-21 19:10:16 +08:00
|
|
|
await TestFolder.setTestLocation(p.join(userA, appFlowyDataFolder));
|
2022-12-20 11:14:42 +08:00
|
|
|
|
|
|
|
await tester.initializeAppFlowy();
|
|
|
|
|
|
|
|
await tester.tapGoButton();
|
2023-06-12 20:32:55 +08:00
|
|
|
tester.expectToSeeHomePage();
|
2022-12-20 11:14:42 +08:00
|
|
|
|
2023-03-20 13:29:17 +00:00
|
|
|
// switch to user B
|
2022-12-20 11:14:42 +08:00
|
|
|
{
|
2023-06-11 14:19:44 +08:00
|
|
|
// set user name to userA
|
2022-12-20 11:14:42 +08:00
|
|
|
await tester.openSettings();
|
|
|
|
await tester.openSettingsPage(SettingsPage.user);
|
|
|
|
await tester.enterUserName(userA);
|
|
|
|
|
|
|
|
await tester.openSettingsPage(SettingsPage.files);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
|
|
|
// mock the file_picker result
|
|
|
|
await mockGetDirectoryPath(userB);
|
|
|
|
await tester.tapCustomLocationButton();
|
|
|
|
await tester.pumpAndSettle();
|
2023-06-12 20:32:55 +08:00
|
|
|
tester.expectToSeeHomePage();
|
2022-12-20 11:14:42 +08:00
|
|
|
|
2023-06-11 14:19:44 +08:00
|
|
|
// set user name to userB
|
2022-12-20 11:14:42 +08:00
|
|
|
await tester.openSettings();
|
|
|
|
await tester.openSettingsPage(SettingsPage.user);
|
|
|
|
await tester.enterUserName(userB);
|
2023-06-11 14:19:44 +08:00
|
|
|
}
|
2022-12-20 11:14:42 +08:00
|
|
|
|
2023-06-11 14:19:44 +08:00
|
|
|
// switch to the userA
|
|
|
|
{
|
2022-12-20 11:14:42 +08:00
|
|
|
await tester.openSettingsPage(SettingsPage.files);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
|
|
|
// mock the file_picker result
|
|
|
|
await mockGetDirectoryPath(userA);
|
|
|
|
await tester.tapCustomLocationButton();
|
|
|
|
|
|
|
|
await tester.pumpAndSettle();
|
2023-06-12 20:32:55 +08:00
|
|
|
tester.expectToSeeHomePage();
|
2023-06-11 14:19:44 +08:00
|
|
|
tester.expectToSeeUserName(userA);
|
2022-12-20 11:14:42 +08:00
|
|
|
}
|
|
|
|
|
2023-03-20 13:29:17 +00:00
|
|
|
// switch to the userB again
|
2022-12-20 11:14:42 +08:00
|
|
|
{
|
|
|
|
await tester.openSettings();
|
|
|
|
await tester.openSettingsPage(SettingsPage.files);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
|
|
|
// mock the file_picker result
|
|
|
|
await mockGetDirectoryPath(userB);
|
|
|
|
await tester.tapCustomLocationButton();
|
|
|
|
|
|
|
|
await tester.pumpAndSettle();
|
2023-06-12 20:32:55 +08:00
|
|
|
tester.expectToSeeHomePage();
|
2023-06-11 14:19:44 +08:00
|
|
|
tester.expectToSeeUserName(userB);
|
2022-12-20 11:14:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
await TestFolder.cleanTestLocation(userA);
|
|
|
|
await TestFolder.cleanTestLocation(userB);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('reset to default location', (tester) async {
|
|
|
|
await tester.initializeAppFlowy();
|
|
|
|
|
|
|
|
await tester.tapGoButton();
|
|
|
|
|
|
|
|
// home and readme document
|
2023-06-12 20:32:55 +08:00
|
|
|
tester.expectToSeeHomePage();
|
2022-12-20 11:14:42 +08:00
|
|
|
|
|
|
|
// open settings and restore the location
|
|
|
|
await tester.openSettings();
|
|
|
|
await tester.openSettingsPage(SettingsPage.files);
|
|
|
|
await tester.restoreLocation();
|
|
|
|
|
|
|
|
expect(
|
|
|
|
await TestFolder.defaultDevelopmentLocation(),
|
|
|
|
await TestFolder.currentLocation(),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|