Skip to content

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.

ci: run flutter test on ci

appflowy0b0cbe192b11
diff --git a/.github/workflows/dart_test.yml b/.github/workflows/dart_test.yml
new file mode 100644
index 0000000000..b3cc2485a5
--- /dev/null
+++ b/.github/workflows/dart_test.yml
@@ -0,0 +1,38 @@
+name: Unit test(Flutter)
+
+on:
+ push:
+ branches: [ main ]
+ pull_request:
+ branches: [ main ]
+
+
+env:
+ CARGO_TERM_COLOR: always
+
+jobs:
+ tests:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+ - uses: subosito/flutter-action@v1
+ with:
+ channel: "stable"
+ - name: Flutter pub get
+ run: flutter pub get
+ working-directory: frontend/app_flowy
+ - name: Generate language files
+ working-directory: frontend/app_flowy
+ run:
+ flutter pub run easy_localization:generate --source-dir ./assets/translations -f keys -O lib/generated -o locale_keys.g.dart
+ - name: Build FlowySDK
+ working-directory: frontend
+ run: |
+ flutter config --enable-linux-desktop
+ cargo make --profile development-linux-x86 flowy-sdk-dev
+ - name: Bloc Test
+ working-directory: frontend/app_flowy
+ run: |
+ flutter test
+
diff --git a/frontend/app_flowy/.vscode/launch.json b/frontend/app_flowy/.vscode/launch.json
index c7236062fd..7026e78581 100644
--- a/frontend/app_flowy/.vscode/launch.json
+++ b/frontend/app_flowy/.vscode/launch.json
@@ -12,6 +12,7 @@
"preLaunchTask": "build_flowy_sdk",
"env":{
"RUST_LOG":"info",
+ "INTEGRATION_ENV":"develop",
},
"cwd": "${workspaceRoot}"
},
@@ -23,6 +24,7 @@
"preLaunchTask": "build_flowy_sdk",
"env":{
"RUST_LOG":"trace",
+ "INTEGRATION_ENV":"develop",
},
"cwd": "${workspaceRoot}"
},
diff --git a/frontend/app_flowy/lib/startup/startup.dart b/frontend/app_flowy/lib/startup/startup.dart
index 74dd0768b4..ef04c0cb75 100644
--- a/frontend/app_flowy/lib/startup/startup.dart
+++ b/frontend/app_flowy/lib/startup/startup.dart
@@ -1,3 +1,5 @@
+import 'dart:io';
+
import 'package:app_flowy/startup/tasks/prelude.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
@@ -23,10 +25,6 @@ import 'package:flowy_sdk/flowy_sdk.dart';
//
// 3.build MeterialApp
final getIt = GetIt.instance;
-enum IntegrationEnv {
- dev,
- pro,
-}
abstract class EntryPoint {
Widget create();
@@ -35,7 +33,7 @@ abstract class EntryPoint {
class System {
static Future<void> run(EntryPoint f) async {
// Specify the env
- const env = IntegrationEnv.dev;
+ final env = integrationEnv();
// Config the deps graph
getIt.registerFactory<EntryPoint>(() => f);
@@ -44,8 +42,11 @@ class System {
// add task
getIt<AppLauncher>().addTask(InitRustSDKTask());
- getIt<AppLauncher>().addTask(ApplicationWidgetTask());
- getIt<AppLauncher>().addTask(InitPlatformService());
+
+ if (!env.isTest()) {
+ getIt<AppLauncher>().addTask(ApplicationWidgetTask());
+ getIt<AppLauncher>().addTask(InitPlatformService());
+ }
// execute the tasks
getIt<AppLauncher>().launch();
@@ -101,3 +102,27 @@ class AppLauncher {
}
}
}
+
+enum IntegrationEnv {
+ develop,
+ release,
+ test,
+}
+
+extension IntegrationEnvExt on IntegrationEnv {
+ bool isTest() {
+ return this == IntegrationEnv.test;
+ }
+}
+
+IntegrationEnv integrationEnv() {
+ if (Platform.environment.containsKey('FLUTTER_TEST')) {
+ return IntegrationEnv.test;
+ }
+ final value = String.fromEnvironment('INTEGRATION_ENV');
+ if (value == 'release') {
+ return IntegrationEnv.release;
+ }
+
+ return IntegrationEnv.develop;
+}
diff --git a/frontend/app_flowy/lib/startup/tasks/application_widget.dart b/frontend/app_flowy/lib/startup/tasks/app_widget.dart
similarity index 100%
rename from frontend/app_flowy/lib/startup/tasks/application_widget.dart
rename to frontend/app_flowy/lib/startup/tasks/app_widget.dart
diff --git a/frontend/app_flowy/lib/startup/tasks/init_sdk.dart b/frontend/app_flowy/lib/startup/tasks/init_sdk.dart
index 2d89f2a076..3e90c6ea43 100644
--- a/frontend/app_flowy/lib/startup/tasks/init_sdk.dart
+++ b/frontend/app_flowy/lib/startup/tasks/init_sdk.dart
@@ -9,21 +9,24 @@ class InitRustSDKTask extends LaunchTask {
@override
Future<void> initialize(LaunchContext context) async {
- Directory directory = await getApplicationDocumentsDirectory();
- final documentPath = directory.path;
+ switch (context.env) {
+ case IntegrationEnv.develop:
+ case IntegrationEnv.release:
+ Directory directory = await getApplicationDocumentsDirectory();
+ return Directory('${directory.path}/flowy').create().then(
+ (Directory directory) async {
+ await context.getIt<FlowySDK>().init(directory);
+ },
+ );
+ case IntegrationEnv.test:
+ await context.getIt<FlowySDK>().init(testDir());
+ break;
+ default:
+ assert(false, 'Unsupported env');
+ }
+ }
- return Directory('$documentPath/flowy').create().then((Directory directory) async {
- switch (context.env) {
- case IntegrationEnv.dev:
- // await context.getIt<FlowySDK>().init(Directory('./temp/flowy_dev'));
- await context.getIt<FlowySDK>().init(directory);
- break;
- case IntegrationEnv.pro:
- await context.getIt<FlowySDK>().init(directory);
- break;
- default:
- assert(false, 'Unsupported env');
- }
- });
+ Directory testDir() {
+ return Directory("${Directory.systemTemp.path}/appflowy");
}
}
diff --git a/frontend/app_flowy/lib/startup/tasks/init_platform_service.dart b/frontend/app_flowy/lib/startup/tasks/platform_service.dart
similarity index 100%
rename from frontend/app_flowy/lib/startup/tasks/init_platform_service.dart
rename to frontend/app_flowy/lib/startup/tasks/platform_service.dart
diff --git a/frontend/app_flowy/lib/startup/tasks/prelude.dart b/frontend/app_flowy/lib/startup/tasks/prelude.dart
index 16e2108713..f1551595ad 100644
--- a/frontend/app_flowy/lib/startup/tasks/prelude.dart
+++ b/frontend/app_flowy/lib/startup/tasks/prelude.dart
@@ -1,3 +1,3 @@
-export 'application_widget.dart';
+export 'app_widget.dart';
export 'init_sdk.dart';
-export 'init_platform_service.dart';
+export 'platform_service.dart';
diff --git a/frontend/app_flowy/lib/workspace/presentation/widgets/dialogs.dart b/frontend/app_flowy/lib/workspace/presentation/widgets/dialogs.dart
index 3141568272..3a5c1c79e5 100644
--- a/frontend/app_flowy/lib/workspace/presentation/widgets/dialogs.dart
+++ b/frontend/app_flowy/lib/workspace/presentation/widgets/dialogs.dart
@@ -7,7 +7,7 @@ import 'package:flowy_infra_ui/widget/buttons/secondary_button.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
-import 'package:app_flowy/startup/tasks/application_widget.dart';
+import 'package:app_flowy/startup/tasks/app_widget.dart';
import 'package:flowy_infra/size.dart';
import 'package:flowy_infra_ui/style_widget/text_input.dart';
import 'package:flowy_infra_ui/widget/dialog/styled_dialogs.dart';
diff --git a/frontend/app_flowy/lib/workspace/presentation/widgets/menu/widget/app/section/section.dart b/frontend/app_flowy/lib/workspace/presentation/widgets/menu/widget/app/section/section.dart
index 3b621fefec..455602e3f9 100644
--- a/frontend/app_flowy/lib/workspace/presentation/widgets/menu/widget/app/section/section.dart
+++ b/frontend/app_flowy/lib/workspace/presentation/widgets/menu/widget/app/section/section.dart
@@ -34,7 +34,6 @@ class ViewSection extends StatelessWidget {
Widget _renderSectionItems(BuildContext context, List<View> views) {
List<Widget> viewWidgets = [];
-
if (views.isNotEmpty) {
viewWidgets = views
.map(
diff --git a/frontend/app_flowy/test/workspace_bloc_test.dart b/frontend/app_flowy/test/workspace_bloc_test.dart
index ef19874593..eb21634faa 100644
--- a/frontend/app_flowy/test/workspace_bloc_test.dart
+++ b/frontend/app_flowy/test/workspace_bloc_test.dart
@@ -20,10 +20,9 @@ void main() {
act: (bloc) {
bloc.add(const WelcomeEvent.initial());
},
- wait: const Duration(seconds: 2),
+ wait: const Duration(seconds: 3),
verify: (bloc) {
assert(bloc.state.isLoading == false);
- assert((bloc.state.workspaces.length) == 1);
},
);
});