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.

fix: bloc test errors

nathan1af6c5eadcba
diff --git a/.github/workflows/dart_lint.yml b/.github/workflows/dart_lint.yml
index 6ce8630b8d..68b0a94350 100644
--- a/.github/workflows/dart_lint.yml
+++ b/.github/workflows/dart_lint.yml
@@ -73,7 +73,7 @@ jobs:
run: |
cargo make --profile development-linux-x86_64 flowy-sdk-dev
- - name: Code Generation
+ - name: Flutter Code Generation
working-directory: frontend/app_flowy
run: |
flutter packages pub run easy_localization:generate -f keys -o locale_keys.g.dart -S assets/translations -s en.json
diff --git a/.github/workflows/dart_test.yml b/.github/workflows/dart_test.yml
index 465c8a09b9..55efb0e7e1 100644
--- a/.github/workflows/dart_test.yml
+++ b/.github/workflows/dart_test.yml
@@ -1,4 +1,4 @@
-name: Unit test(Flutter)
+name: Frontend test
on:
push:
@@ -21,7 +21,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
-
- uses: actions-rs/toolchain@v1
with:
toolchain: "stable-2022-04-07"
@@ -53,10 +52,6 @@ jobs:
working-directory: frontend
run: |
cargo install cargo-make
-
- - name: Cargo make flowy dev
- working-directory: frontend
- run: |
cargo make flowy_dev
- name: Flutter Deps
@@ -64,12 +59,12 @@ jobs:
run: |
flutter config --enable-linux-desktop
- - name: Build FlowySDK
+ - name: Build Test lib
working-directory: frontend
run: |
cargo make --profile test-linux build-test-lib
- - name: Code Generation
+ - name: Flutter Code Generation
working-directory: frontend/app_flowy
run: |
flutter packages pub get
diff --git a/.github/workflows/rust_test.yml b/.github/workflows/rust_test.yml
index 3a42f9074f..78763e7f10 100644
--- a/.github/workflows/rust_test.yml
+++ b/.github/workflows/rust_test.yml
@@ -1,4 +1,4 @@
-name: Unit test(Rust)
+name: Backend test
on:
push:
diff --git a/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_data_controller.dart b/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_data_controller.dart
index bcb308c20f..d11a35e764 100644
--- a/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_data_controller.dart
+++ b/frontend/app_flowy/lib/plugins/grid/application/field/type_option/type_option_data_controller.dart
@@ -1,6 +1,5 @@
import 'package:app_flowy/plugins/grid/application/field/field_controller.dart';
import 'package:flowy_infra/notifier.dart';
-import 'package:flowy_sdk/dispatch/dispatch.dart';
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
import 'package:app_flowy/plugins/grid/application/field/field_service.dart';
diff --git a/frontend/app_flowy/lib/plugins/grid/application/grid_data_controller.dart b/frontend/app_flowy/lib/plugins/grid/application/grid_data_controller.dart
index aafaeb3774..ba9dc05b83 100644
--- a/frontend/app_flowy/lib/plugins/grid/application/grid_data_controller.dart
+++ b/frontend/app_flowy/lib/plugins/grid/application/grid_data_controller.dart
@@ -79,8 +79,8 @@ class GridDataController {
);
}
- void createRow() {
- _gridFFIService.createRow();
+ Future<void> createRow() async {
+ await _gridFFIService.createRow();
}
Future<void> dispose() async {
diff --git a/frontend/app_flowy/test/bloc_test/grid_test/grid_bloc_test.dart b/frontend/app_flowy/test/bloc_test/grid_test/grid_bloc_test.dart
index b2bfa6996f..a703cbe330 100644
--- a/frontend/app_flowy/test/bloc_test/grid_test/grid_bloc_test.dart
+++ b/frontend/app_flowy/test/bloc_test/grid_test/grid_bloc_test.dart
@@ -7,6 +7,7 @@ void main() {
late AppFlowyGridTest gridTest;
setUpAll(() async {
gridTest = await AppFlowyGridTest.ensureInitialized();
+ await gridTest.createTestGrid();
});
group('GridBloc', () {
diff --git a/frontend/app_flowy/test/bloc_test/grid_test/select_option_bloc_test.dart b/frontend/app_flowy/test/bloc_test/grid_test/select_option_bloc_test.dart
index 5aad5c9420..520c76a4ab 100644
--- a/frontend/app_flowy/test/bloc_test/grid_test/select_option_bloc_test.dart
+++ b/frontend/app_flowy/test/bloc_test/grid_test/select_option_bloc_test.dart
@@ -17,8 +17,11 @@ void main() {
group('SingleSelectOptionBloc', () {
late GridSelectOptionCellController cellController;
setUp(() async {
- cellController =
- await cellTest.makeCellController(FieldType.SingleSelect);
+ await cellTest.createTestGrid();
+ await cellTest.createTestRow();
+ cellController = await cellTest.makeCellController(
+ FieldType.SingleSelect,
+ );
});
blocTest<SelectOptionCellEditorBloc, SelectOptionEditorState>(
diff --git a/frontend/app_flowy/test/bloc_test/grid_test/util.dart b/frontend/app_flowy/test/bloc_test/grid_test/util.dart
index 16809dcfe9..0f97fb5ba7 100644
--- a/frontend/app_flowy/test/bloc_test/grid_test/util.dart
+++ b/frontend/app_flowy/test/bloc_test/grid_test/util.dart
@@ -19,12 +19,10 @@ class AppFlowyGridTest {
static Future<AppFlowyGridTest> ensureInitialized() async {
final inner = await AppFlowyUnitTest.ensureInitialized();
- final test = AppFlowyGridTest(inner);
- await test._createTestGrid();
- return test;
+ return AppFlowyGridTest(inner);
}
- Future<void> _createTestGrid() async {
+ Future<void> createTestGrid() async {
final app = await _inner.createTestApp();
final builder = GridPluginBuilder();
final result = await AppService().createView(
@@ -42,56 +40,65 @@ class AppFlowyGridTest {
}
class AppFlowyGridSelectOptionCellTest {
- final AppFlowyGridCellTest _cellTest;
+ final AppFlowyGridCellTest _gridCellTest;
AppFlowyGridSelectOptionCellTest(AppFlowyGridCellTest cellTest)
- : _cellTest = cellTest;
+ : _gridCellTest = cellTest;
static Future<AppFlowyGridSelectOptionCellTest> ensureInitialized() async {
- final cellTest = await AppFlowyGridCellTest.ensureInitialized();
- final test = AppFlowyGridSelectOptionCellTest(cellTest);
- return test;
+ final gridTest = await AppFlowyGridCellTest.ensureInitialized();
+ return AppFlowyGridSelectOptionCellTest(gridTest);
+ }
+
+ Future<void> createTestGrid() async {
+ await _gridCellTest.createTestGrid();
+ }
+
+ Future<void> createTestRow() async {
+ await _gridCellTest.createTestRow();
}
- /// For the moment, just edit the first row of the grid.
Future<GridSelectOptionCellController> makeCellController(
FieldType fieldType) async {
assert(fieldType == FieldType.SingleSelect ||
fieldType == FieldType.MultiSelect);
final fieldContexts =
- _cellTest._dataController.fieldController.fieldContexts;
+ _gridCellTest._dataController.fieldController.fieldContexts;
final field =
fieldContexts.firstWhere((element) => element.fieldType == fieldType);
- final builder = await _cellTest.cellControllerBuilder(0, field.id);
+ final builder = await _gridCellTest.cellControllerBuilder(field.id);
final cellController = builder.build() as GridSelectOptionCellController;
return cellController;
}
}
+/// Create a new Grid for cell test
class AppFlowyGridCellTest {
- // ignore: unused_field
final AppFlowyGridTest _gridTest;
- final GridDataController _dataController;
- AppFlowyGridCellTest(AppFlowyGridTest gridTest)
- : _gridTest = gridTest,
- _dataController = GridDataController(view: gridTest.gridView);
+ late GridDataController _dataController;
+ AppFlowyGridCellTest(AppFlowyGridTest gridTest) : _gridTest = gridTest;
static Future<AppFlowyGridCellTest> ensureInitialized() async {
final gridTest = await AppFlowyGridTest.ensureInitialized();
- final test = AppFlowyGridCellTest(gridTest);
- await test._loadGridData();
- return test;
+ return AppFlowyGridCellTest(gridTest);
+ }
+
+ Future<void> createTestRow() async {
+ await _dataController.createRow();
}
- Future<void> _loadGridData() async {
+ Future<void> createTestGrid() async {
+ await _gridTest.createTestGrid();
+ _dataController = GridDataController(view: _gridTest.gridView);
final result = await _dataController.loadData();
result.fold((l) => null, (r) => throw Exception(r));
}
Future<GridCellControllerBuilder> cellControllerBuilder(
- int rowIndex, String fieldId) async {
- final RowInfo rowInfo = _dataController.rowInfos[rowIndex];
+ String fieldId,
+ ) async {
+ final RowInfo rowInfo = _dataController.rowInfos.last;
final blockCache = _dataController.blocks[rowInfo.rowPB.blockId];
final rowCache = blockCache?.rowCache;
@@ -116,9 +123,9 @@ class AppFlowyGridCellTest {
}
Future<void> gridResponseFuture() {
- return Future.delayed(gridResponseDuration(milliseconds: 500));
+ return Future.delayed(gridResponseDuration(milliseconds: 200));
}
-Duration gridResponseDuration({int milliseconds = 500}) {
+Duration gridResponseDuration({int milliseconds = 200}) {
return Duration(milliseconds: milliseconds);
}