2023-02-26 08:27:17 +00:00
|
|
|
import 'package:appflowy/startup/launch_configuration.dart';
|
|
|
|
import 'package:appflowy/startup/startup.dart';
|
2023-05-21 10:53:59 +00:00
|
|
|
import 'package:appflowy/user/application/auth/auth_service.dart';
|
2023-02-26 08:27:17 +00:00
|
|
|
import 'package:appflowy/user/application/user_service.dart';
|
|
|
|
import 'package:appflowy/workspace/application/workspace/workspace_service.dart';
|
2023-04-04 00:41:16 +00:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
|
2022-10-15 15:34:56 +00:00
|
|
|
import 'package:flowy_infra/uuid.dart';
|
2023-04-04 00:41:16 +00:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-folder2/workspace.pb.dart';
|
2023-01-08 04:10:53 +00:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
|
2022-10-15 15:34:56 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:integration_test/integration_test.dart';
|
2023-02-26 08:27:17 +00:00
|
|
|
import 'package:appflowy/main.dart';
|
2022-10-15 15:34:56 +00:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
class AppFlowyIntegrateTest {
|
|
|
|
static Future<AppFlowyIntegrateTest> ensureInitialized() async {
|
|
|
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
SharedPreferences.setMockInitialValues({});
|
|
|
|
main();
|
|
|
|
return AppFlowyIntegrateTest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-16 08:51:21 +00:00
|
|
|
class AppFlowyUnitTest {
|
|
|
|
late UserProfilePB userProfile;
|
2023-02-26 08:27:17 +00:00
|
|
|
late UserBackendService userService;
|
2022-10-16 08:51:21 +00:00
|
|
|
late WorkspaceService workspaceService;
|
|
|
|
late List<WorkspacePB> workspaces;
|
|
|
|
|
|
|
|
static Future<AppFlowyUnitTest> ensureInitialized() async {
|
2022-10-15 15:34:56 +00:00
|
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
SharedPreferences.setMockInitialValues({});
|
2022-10-16 08:51:21 +00:00
|
|
|
_pathProviderInitialized();
|
2022-10-15 15:34:56 +00:00
|
|
|
|
|
|
|
await FlowyRunner.run(FlowyTestApp());
|
2022-10-16 08:51:21 +00:00
|
|
|
|
|
|
|
final test = AppFlowyUnitTest();
|
|
|
|
await test._signIn();
|
|
|
|
await test._loadWorkspace();
|
|
|
|
|
|
|
|
await test._initialServices();
|
|
|
|
return test;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _signIn() async {
|
|
|
|
final authService = getIt<AuthService>();
|
|
|
|
const password = "AppFlowy123@";
|
|
|
|
final uid = uuid();
|
|
|
|
final userEmail = "$uid@appflowy.io";
|
|
|
|
final result = await authService.signUp(
|
|
|
|
name: "TestUser",
|
|
|
|
password: password,
|
|
|
|
email: userEmail,
|
|
|
|
);
|
|
|
|
return result.fold(
|
2023-05-21 10:53:59 +00:00
|
|
|
(error) {},
|
2022-10-16 08:51:21 +00:00
|
|
|
(user) {
|
|
|
|
userProfile = user;
|
2023-02-26 08:27:17 +00:00
|
|
|
userService = UserBackendService(userId: userProfile.id);
|
2022-10-16 08:51:21 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkspacePB get currentWorkspace => workspaces[0];
|
|
|
|
|
|
|
|
Future<void> _loadWorkspace() async {
|
|
|
|
final result = await userService.getWorkspaces();
|
|
|
|
result.fold(
|
|
|
|
(value) => workspaces = value,
|
|
|
|
(error) {
|
|
|
|
throw Exception(error);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _initialServices() async {
|
|
|
|
workspaceService = WorkspaceService(workspaceId: currentWorkspace.id);
|
|
|
|
}
|
|
|
|
|
2023-04-04 00:41:16 +00:00
|
|
|
Future<ViewPB> createTestApp() async {
|
2022-10-16 08:51:21 +00:00
|
|
|
final result = await workspaceService.createApp(name: "Test App");
|
|
|
|
return result.fold(
|
|
|
|
(app) => app,
|
|
|
|
(error) => throw Exception(error),
|
|
|
|
);
|
2022-10-15 15:34:56 +00:00
|
|
|
}
|
2022-10-25 01:01:26 +00:00
|
|
|
|
2023-04-04 00:41:16 +00:00
|
|
|
Future<List<ViewPB>> loadApps() async {
|
2022-10-25 01:01:26 +00:00
|
|
|
final result = await workspaceService.getApps();
|
|
|
|
|
|
|
|
return result.fold(
|
|
|
|
(apps) => apps,
|
|
|
|
(error) => throw Exception(error),
|
|
|
|
);
|
|
|
|
}
|
2022-10-15 15:34:56 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 08:51:21 +00:00
|
|
|
void _pathProviderInitialized() {
|
2022-10-15 15:34:56 +00:00
|
|
|
const MethodChannel channel =
|
|
|
|
MethodChannel('plugins.flutter.io/path_provider');
|
|
|
|
channel.setMockMethodCallHandler((MethodCall methodCall) async {
|
|
|
|
return ".";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class FlowyTestApp implements EntryPoint {
|
|
|
|
@override
|
2022-12-20 03:14:42 +00:00
|
|
|
Widget create(LaunchConfiguration config) {
|
2022-10-15 15:34:56 +00:00
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
}
|
2022-10-16 08:51:21 +00:00
|
|
|
|
2022-10-26 14:36:34 +00:00
|
|
|
Future<void> blocResponseFuture({int millisecond = 200}) {
|
2022-10-25 08:51:51 +00:00
|
|
|
return Future.delayed(Duration(milliseconds: millisecond));
|
2022-10-23 09:52:17 +00:00
|
|
|
}
|
|
|
|
|
2022-10-26 14:36:34 +00:00
|
|
|
Duration blocResponseDuration({int milliseconds = 200}) {
|
2022-10-25 08:51:51 +00:00
|
|
|
return Duration(milliseconds: milliseconds);
|
2022-10-16 08:51:21 +00:00
|
|
|
}
|