Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat: config bloc test
appflowyc559c5cc6b47
diff --git a/frontend/Makefile.toml b/frontend/Makefile.tomlindex f7c47820cd..eacdf7d00f 100644--- a/frontend/Makefile.toml+++ b/frontend/Makefile.toml@@ -14,6 +14,7 @@ RUST_LOG = "info"CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = trueCARGO_MAKE_CRATE_FS_NAME = "dart_ffi"CARGO_MAKE_CRATE_NAME = "dart-ffi"+LIB_NAME = "dart_ffi"VERSION = "0.0.3"FEATURES = "flutter"PRODUCT_NAME = "AppFlowy"@@ -31,6 +32,8 @@ RUST_COMPILE_TARGET = "x86_64-apple-darwin"BUILD_FLAG = "debug"FLUTTER_OUTPUT_DIR = "Debug"PRODUCT_EXT = "app"+CRATE_TYPE = "cdylib"+SDK_EXT = "dylib"[env.production-mac-aarch64]BUILD_FLAG = "release"@@ -39,6 +42,7 @@ RUST_COMPILE_TARGET = "aarch64-apple-darwin"FLUTTER_OUTPUT_DIR = "Release"PRODUCT_EXT = "app"APP_ENVIRONMENT = "production"+CRATE_TYPE = "staticlib"[env.production-mac-x86]BUILD_FLAG = "release"@@ -153,7 +157,6 @@ script = []script_runner = "@duckscript"-[tasks.test-build]condition = { env_set = [ "FLUTTER_FLOWY_SDK_PATH"] }script = [diff --git a/frontend/app_flowy/packages/flowy_sdk/lib/ffi.dart b/frontend/app_flowy/packages/flowy_sdk/lib/ffi.dartindex 71ea1b7286..f7d4b5b2a4 100644--- a/frontend/app_flowy/packages/flowy_sdk/lib/ffi.dart+++ b/frontend/app_flowy/packages/flowy_sdk/lib/ffi.dart@@ -12,12 +12,22 @@ final DynamicLibrary _dl = _open();/// Reference to the Dynamic Library, it should be only used for low-level accessfinal DynamicLibrary dl = _dl;DynamicLibrary _open() {- if (Platform.isAndroid) return DynamicLibrary.open('libdart_ffi.so');- if (Platform.isMacOS) return DynamicLibrary.executable();- if (Platform.isIOS) return DynamicLibrary.executable();- if (Platform.isWindows) return DynamicLibrary.open('dart_ffi.dll');- if (Platform.isLinux) return DynamicLibrary.open('libdart_ffi.so');- throw UnsupportedError('This platform is not supported.');+ if (Platform.environment.containsKey('FLUTTER_TEST')) {+ final prefix = "${Directory.systemTemp.path}/appflowy";+ if (Platform.isLinux) return DynamicLibrary.open('${prefix}/libdart_ffi.so');+ if (Platform.isAndroid) return DynamicLibrary.open('${prefix}/libdart_ffi.so');+ if (Platform.isMacOS) return DynamicLibrary.open('${prefix}/libdart_ffi.dylib');+ if (Platform.isIOS) return DynamicLibrary.open('${prefix}/libdart_ffi.dylib');+ if (Platform.isWindows) return DynamicLibrary.open('${prefix}/dart_ffi.dll');+ throw UnsupportedError('This platform is not supported.');+ } else {+ if (Platform.isLinux) return DynamicLibrary.open('libdart_ffi.so');+ if (Platform.isAndroid) return DynamicLibrary.open('libdart_ffi.so');+ if (Platform.isMacOS) return DynamicLibrary.executable();+ if (Platform.isIOS) return DynamicLibrary.executable();+ if (Platform.isWindows) return DynamicLibrary.open('dart_ffi.dll');+ throw UnsupportedError('This platform is not supported.');+ }}/// C function `async_event`.diff --git a/frontend/app_flowy/pubspec.lock b/frontend/app_flowy/pubspec.lockindex 0a8aaf79d7..f8d24d0552 100644--- a/frontend/app_flowy/pubspec.lock+++ b/frontend/app_flowy/pubspec.lock@@ -43,6 +43,13 @@ packages:url: "https://pub.dartlang.org"source: hostedversion: "8.0.2"+ bloc_test:+ dependency: "direct dev"+ description:+ name: bloc_test+ url: "https://pub.dartlang.org"+ source: hosted+ version: "9.0.2"boolean_selector:dependency: transitivedescription:@@ -211,6 +218,13 @@ packages:url: "https://pub.dartlang.org"source: hostedversion: "3.0.1"+ coverage:+ dependency: transitive+ description:+ name: coverage+ url: "https://pub.dartlang.org"+ source: hosted+ version: "1.0.3"cross_file:dependency: transitivedescription:@@ -702,6 +716,13 @@ packages:url: "https://pub.dartlang.org"source: hostedversion: "1.0.1"+ mocktail:+ dependency: transitive+ description:+ name: mocktail+ url: "https://pub.dartlang.org"+ source: hosted+ version: "0.2.0"nested:dependency: transitivedescription:@@ -716,6 +737,13 @@ packages:url: "https://pub.dartlang.org"source: hostedversion: "0.4.2"+ node_preamble:+ dependency: transitive+ description:+ name: node_preamble+ url: "https://pub.dartlang.org"+ source: hosted+ version: "2.0.1"package_config:dependency: transitivedescription:@@ -982,6 +1010,20 @@ packages:url: "https://pub.dartlang.org"source: hostedversion: "1.2.0"+ shelf_packages_handler:+ dependency: transitive+ description:+ name: shelf_packages_handler+ url: "https://pub.dartlang.org"+ source: hosted+ version: "3.0.0"+ shelf_static:+ dependency: transitive+ description:+ name: shelf_static+ url: "https://pub.dartlang.org"+ source: hosted+ version: "1.1.0"shelf_web_socket:dependency: transitivedescription:@@ -1008,6 +1050,20 @@ packages:url: "https://pub.dartlang.org"source: hostedversion: "1.2.1"+ source_map_stack_trace:+ dependency: transitive+ description:+ name: source_map_stack_trace+ url: "https://pub.dartlang.org"+ source: hosted+ version: "2.1.0"+ source_maps:+ dependency: transitive+ description:+ name: source_maps+ url: "https://pub.dartlang.org"+ source: hosted+ version: "0.10.10"source_span:dependency: transitivedescription:@@ -1071,6 +1127,13 @@ packages:url: "https://pub.dartlang.org"source: hostedversion: "1.2.0"+ test:+ dependency: transitive+ description:+ name: test+ url: "https://pub.dartlang.org"+ source: hosted+ version: "1.19.5"test_api:dependency: transitivedescription:@@ -1078,6 +1141,13 @@ packages:url: "https://pub.dartlang.org"source: hostedversion: "0.4.8"+ test_core:+ dependency: transitive+ description:+ name: test_core+ url: "https://pub.dartlang.org"+ source: hosted+ version: "0.4.9"textstyle_extensions:dependency: transitivedescription:@@ -1211,6 +1281,13 @@ packages:url: "https://pub.dartlang.org"source: hostedversion: "2.0.6"+ vm_service:+ dependency: transitive+ description:+ name: vm_service+ url: "https://pub.dartlang.org"+ source: hosted+ version: "7.5.0"watcher:dependency: transitivedescription:@@ -1225,6 +1302,13 @@ packages:url: "https://pub.dartlang.org"source: hostedversion: "2.1.0"+ webkit_inspection_protocol:+ dependency: transitive+ description:+ name: webkit_inspection_protocol+ url: "https://pub.dartlang.org"+ source: hosted+ version: "1.0.0"win32:dependency: transitivedescription:diff --git a/frontend/app_flowy/pubspec.yaml b/frontend/app_flowy/pubspec.yamlindex 54155390a5..31721eb5d1 100644--- a/frontend/app_flowy/pubspec.yaml+++ b/frontend/app_flowy/pubspec.yaml@@ -80,6 +80,7 @@ dev_dependencies:sdk: flutterbuild_runner:freezed: "^0.14.2"+ bloc_test: ^9.0.2# The "flutter_lints" package below contains a set of recommended lints to# encourage good coding practices. The lint set provided by the package isdiff --git a/frontend/app_flowy/test/util/test_env.dart b/frontend/app_flowy/test/util/test_env.dartnew file mode 100644index 0000000000..34070894c8--- /dev/null+++ b/frontend/app_flowy/test/util/test_env.dart@@ -0,0 +1,42 @@+import 'package:app_flowy/startup/startup.dart';+import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart';+import 'package:easy_localization/easy_localization.dart';+import 'package:flowy_infra/uuid.dart';+import 'package:flowy_sdk/log.dart';+import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart';+import 'package:flutter/material.dart';++class FlowyTest {+ static Future<FlowyTest> setup() async {+ WidgetsFlutterBinding.ensureInitialized();+ // await EasyLocalization.ensureInitialized();++ System.run(FlowyTestApp());+ return FlowyTest();+ }++ Future<UserProfile> signIn() async {+ final authRepo = getIt<AuthRepository>();+ const password = "AppFlowy123@";+ final uid = uuid();+ final userEmail = "[email protected]";+ final result = await authRepo.signUp(+ name: "FlowyTestUser",+ password: password,+ email: userEmail,+ );+ return result.fold(+ (user) => user,+ (error) {+ throw StateError("$error");+ },+ );+ }+}++class FlowyTestApp implements EntryPoint {+ @override+ Widget create() {+ return Container();+ }+}diff --git a/frontend/app_flowy/test/widget_test.dart b/frontend/app_flowy/test/widget_test.dartdeleted file mode 100644index 8b13789179..0000000000--- a/frontend/app_flowy/test/widget_test.dart+++ /dev/null@@ -1 +0,0 @@-diff --git a/frontend/app_flowy/test/workspace_bloc_test.dart b/frontend/app_flowy/test/workspace_bloc_test.dartnew file mode 100644index 0000000000..ef19874593--- /dev/null+++ b/frontend/app_flowy/test/workspace_bloc_test.dart@@ -0,0 +1,30 @@+import 'package:app_flowy/startup/startup.dart';+import 'package:app_flowy/workspace/application/workspace/welcome_bloc.dart';+import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:bloc_test/bloc_test.dart';++import 'util/test_env.dart';++void main() {+ UserProfile? userInfo;+ setUpAll(() async {+ final flowyTest = await FlowyTest.setup();+ userInfo = await flowyTest.signIn();+ });++ group('WelcomeBloc', () {+ blocTest<WelcomeBloc, WelcomeState>(+ "create workspace",+ build: () => getIt<WelcomeBloc>(param1: userInfo),+ act: (bloc) {+ bloc.add(const WelcomeEvent.initial());+ },+ wait: const Duration(seconds: 2),+ verify: (bloc) {+ assert(bloc.state.isLoading == false);+ assert((bloc.state.workspaces.length) == 1);+ },+ );+ });+}diff --git a/frontend/scripts/makefile/desktop.toml b/frontend/scripts/makefile/desktop.tomlindex 3b4f8aed4e..06b41fe68b 100644--- a/frontend/scripts/makefile/desktop.toml+++ b/frontend/scripts/makefile/desktop.toml@@ -16,17 +16,17 @@ linux_alias = "flowy-sdk-dev-linux"[tasks.flowy-sdk-dev-macos]category = "Build"dependencies = ["env_check"]-run_task = { name = ["setup-crate-type","sdk-build", "post-desktop", "restore-crate-type"] }+run_task = { name = ["setup-crate-type","sdk-build", "post-desktop", "restore-crate-type", "copy-to-sys-tmpdir"] }[tasks.flowy-sdk-dev-windows]category = "Build"dependencies = ["env_check"]-run_task = { name = ["setup-crate-type","sdk-build", "post-desktop", "restore-crate-type"] }+run_task = { name = ["setup-crate-type","sdk-build", "post-desktop", "restore-crate-type", "copy-to-sys-tmpdir"] }[tasks.flowy-sdk-dev-linux]category = "Build"dependencies = ["env_check"]-run_task = { name = ["setup-crate-type","sdk-build", "post-desktop", "restore-crate-type"] }+run_task = { name = ["setup-crate-type","sdk-build", "post-desktop", "restore-crate-type", "copy-to-sys-tmpdir"] }#[tasks.sdk-build]@@ -82,27 +82,29 @@ private = truescript = ["""echo "π π π Flowy-SDK(macOS) build success"+ dart_ffi_dir= set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/packages/flowy_sdk/${TARGET_OS}+ lib = set lib${LIB_NAME}.${SDK_EXT}- cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/lib${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT} \- ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/packages/flowy_sdk/${TARGET_OS}/lib${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT}+ cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/${lib} \+ ${dart_ffi_dir}/${lib}cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/binding.h \- ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/packages/flowy_sdk/${TARGET_OS}/Classes/binding.h+ ${dart_ffi_dir}/Classes/binding.h""",]script_runner = "@duckscript"-[tasks.post-desktop-windows]private = truescript = ["""echo "π π π Flowy-SDK(windows) build success"dart_ffi_dir= set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/windows/flutter/dart_ffi+ lib = set ${LIB_NAME}.${SDK_EXT}# copy dll- cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT} \- ${dart_ffi_dir}/${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT}+ cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/${lib} \+ ${dart_ffi_dir}/${lib}# copy binding.hcp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/binding.h \@@ -117,10 +119,11 @@ script = ["""echo "π π π Flowy-SDK(linux) build success"dart_ffi_dir= set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/linux/flutter/dart_ffi+ lib = set lib${LIB_NAME}.${SDK_EXT}# copy dll- cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/lib${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT} \- ${dart_ffi_dir}/lib${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT}+ cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/${lib} \+ ${dart_ffi_dir}/${lib}# copy binding.hcp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/binding.h \@@ -129,29 +132,28 @@ script = []script_runner = "@duckscript"-#[tasks.copy-to-sys-tmpdir]private = true-condition = { profiles = [ "development-mac" ], platforms = ["mac"] }script = ["""- # post the dylib target_path that use for flutter unit test- target_path = set ${TMPDIR}/appflowy/lib${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT}- rm ${target_path}- cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/lib${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT} ${target_path}+ # Copy the flowy_sdk lib to system temp directory for flutter unit test.+ lib = set lib${LIB_NAME}.${SDK_EXT}+ dest = set ${TMPDIR}/appflowy/${lib}+ echo ${dest}+ rm ${dest}+++ cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/${lib} \+ ${dest}""",]script_runner = "@duckscript"-[tasks.check_protoc_cmd]+[tasks.copy-to-sys-tmpdir.windows]+private = truescript = ["""- ret = which protoc- if is_empty ${ret}- echo Please make sure <protoc_installation_folder>/bin/ is in PATH env var- echo See BUILD_ON_{LINUX|WINDOWS}.md for how to get protoc- exit -1- end+ # Doesn't work on windows""",]-script_runner = "@duckscript"+script_runner = "@duckscript"\ No newline at end of filediff --git a/frontend/scripts/makefile/protobuf.toml b/frontend/scripts/makefile/protobuf.tomlindex 82084bd3e9..f507b7aba6 100644--- a/frontend/scripts/makefile/protobuf.toml+++ b/frontend/scripts/makefile/protobuf.toml@@ -52,19 +52,6 @@ dart pub global activate protoc_pluginscript_runner = "@shell"-[tasks.check_protoc_cmd]-script = [- """- ret = which protoc- if is_empty ${ret}- echo Please make sure <protoc_installation_folder>/bin/ is in PATH env var- echo See BUILD_ON_{LINUX|WINDOWS}.md for how to get protoc- exit -1- end- """,-]-script_runner = "@duckscript"-[tasks.gen_pb_file]script = ["""