util.dart 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import 'package:app_flowy/startup/startup.dart';
  2. import 'package:app_flowy/user/application/auth_service.dart';
  3. import 'package:easy_localization/easy_localization.dart';
  4. import 'package:flowy_infra/uuid.dart';
  5. import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter/services.dart';
  8. import 'package:flutter_test/flutter_test.dart';
  9. import 'package:integration_test/integration_test.dart';
  10. import 'package:app_flowy/main.dart';
  11. import 'package:shared_preferences/shared_preferences.dart';
  12. class AppFlowyIntegrateTest {
  13. static Future<AppFlowyIntegrateTest> ensureInitialized() async {
  14. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  15. SharedPreferences.setMockInitialValues({});
  16. main();
  17. return AppFlowyIntegrateTest();
  18. }
  19. }
  20. class AppFlowyBlocTest {
  21. static Future<AppFlowyBlocTest> ensureInitialized() async {
  22. TestWidgetsFlutterBinding.ensureInitialized();
  23. SharedPreferences.setMockInitialValues({});
  24. pathProviderInitialized();
  25. await EasyLocalization.ensureInitialized();
  26. await FlowyRunner.run(FlowyTestApp());
  27. return AppFlowyBlocTest();
  28. }
  29. }
  30. void pathProviderInitialized() {
  31. const MethodChannel channel =
  32. MethodChannel('plugins.flutter.io/path_provider');
  33. channel.setMockMethodCallHandler((MethodCall methodCall) async {
  34. return ".";
  35. });
  36. }
  37. Future<UserProfilePB> signIn() async {
  38. final authService = getIt<AuthService>();
  39. const password = "AppFlowy123@";
  40. final uid = uuid();
  41. final userEmail = "[email protected]";
  42. final result = await authService.signUp(
  43. name: "FlowyTestUser",
  44. password: password,
  45. email: userEmail,
  46. );
  47. return result.fold(
  48. (user) => user,
  49. (error) {
  50. throw StateError("$error");
  51. },
  52. );
  53. }
  54. class FlowyTestApp implements EntryPoint {
  55. @override
  56. Widget create() {
  57. return Container();
  58. }
  59. }