|
@@ -1,4 +1,8 @@
|
|
|
+import 'dart:collection';
|
|
|
+import 'package:app_flowy/plugins/grid/application/block/block_cache.dart';
|
|
|
import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart';
|
|
|
+import 'package:app_flowy/plugins/grid/application/field/field_controller.dart';
|
|
|
+import 'package:app_flowy/plugins/grid/application/field/field_service.dart';
|
|
|
import 'package:app_flowy/plugins/grid/application/grid_data_controller.dart';
|
|
|
import 'package:app_flowy/plugins/grid/application/row/row_bloc.dart';
|
|
|
import 'package:app_flowy/plugins/grid/application/row/row_cache.dart';
|
|
@@ -12,9 +16,10 @@ import '../../util.dart';
|
|
|
|
|
|
/// Create a empty Grid for test
|
|
|
class AppFlowyGridTest {
|
|
|
- // ignore: unused_field
|
|
|
final AppFlowyUnitTest _inner;
|
|
|
late ViewPB gridView;
|
|
|
+ late GridDataController _dataController;
|
|
|
+
|
|
|
AppFlowyGridTest(AppFlowyUnitTest unitTest) : _inner = unitTest;
|
|
|
|
|
|
static Future<AppFlowyGridTest> ensureInitialized() async {
|
|
@@ -22,6 +27,31 @@ class AppFlowyGridTest {
|
|
|
return AppFlowyGridTest(inner);
|
|
|
}
|
|
|
|
|
|
+ List<RowInfo> get rowInfos => _dataController.rowInfos;
|
|
|
+
|
|
|
+ UnmodifiableMapView<String, GridBlockCache> get blocks =>
|
|
|
+ _dataController.blocks;
|
|
|
+
|
|
|
+ List<GridFieldContext> get fieldContexts =>
|
|
|
+ _dataController.fieldController.fieldContexts;
|
|
|
+
|
|
|
+ GridFieldController get fieldController => _dataController.fieldController;
|
|
|
+
|
|
|
+ Future<void> createRow() async {
|
|
|
+ await _dataController.createRow();
|
|
|
+ }
|
|
|
+
|
|
|
+ GridFieldContext singleSelectFieldContext() {
|
|
|
+ final fieldContext = fieldContexts
|
|
|
+ .firstWhere((element) => element.fieldType == FieldType.SingleSelect);
|
|
|
+ return fieldContext;
|
|
|
+ }
|
|
|
+
|
|
|
+ GridFieldCellContext singleSelectFieldCellContext() {
|
|
|
+ final field = singleSelectFieldContext().field;
|
|
|
+ return GridFieldCellContext(gridId: gridView.id, field: field);
|
|
|
+ }
|
|
|
+
|
|
|
Future<void> createTestGrid() async {
|
|
|
final app = await _inner.createTestApp();
|
|
|
final builder = GridPluginBuilder();
|
|
@@ -32,51 +62,21 @@ class AppFlowyGridTest {
|
|
|
pluginType: builder.pluginType,
|
|
|
layoutType: builder.layoutType!,
|
|
|
);
|
|
|
- result.fold(
|
|
|
- (view) => gridView = view,
|
|
|
+ await result.fold(
|
|
|
+ (view) async {
|
|
|
+ gridView = view;
|
|
|
+ _dataController = GridDataController(view: view);
|
|
|
+ final result = await _dataController.loadData();
|
|
|
+ result.fold((l) => null, (r) => throw Exception(r));
|
|
|
+ },
|
|
|
(error) {},
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-class AppFlowyGridSelectOptionCellTest {
|
|
|
- final AppFlowyGridCellTest _gridCellTest;
|
|
|
-
|
|
|
- AppFlowyGridSelectOptionCellTest(AppFlowyGridCellTest cellTest)
|
|
|
- : _gridCellTest = cellTest;
|
|
|
-
|
|
|
- static Future<AppFlowyGridSelectOptionCellTest> ensureInitialized() async {
|
|
|
- final gridTest = await AppFlowyGridCellTest.ensureInitialized();
|
|
|
- return AppFlowyGridSelectOptionCellTest(gridTest);
|
|
|
- }
|
|
|
-
|
|
|
- Future<void> createTestGrid() async {
|
|
|
- await _gridCellTest.createTestGrid();
|
|
|
- }
|
|
|
-
|
|
|
- Future<void> createTestRow() async {
|
|
|
- await _gridCellTest.createTestRow();
|
|
|
- }
|
|
|
-
|
|
|
- Future<GridSelectOptionCellController> makeCellController(
|
|
|
- FieldType fieldType) async {
|
|
|
- assert(fieldType == FieldType.SingleSelect ||
|
|
|
- fieldType == FieldType.MultiSelect);
|
|
|
-
|
|
|
- final fieldContexts =
|
|
|
- _gridCellTest._dataController.fieldController.fieldContexts;
|
|
|
- final field =
|
|
|
- fieldContexts.firstWhere((element) => element.fieldType == fieldType);
|
|
|
- final builder = await _gridCellTest.cellControllerBuilder(field.id);
|
|
|
- final cellController = builder.build() as GridSelectOptionCellController;
|
|
|
- return cellController;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
/// Create a new Grid for cell test
|
|
|
class AppFlowyGridCellTest {
|
|
|
final AppFlowyGridTest _gridTest;
|
|
|
- late GridDataController _dataController;
|
|
|
AppFlowyGridCellTest(AppFlowyGridTest gridTest) : _gridTest = gridTest;
|
|
|
|
|
|
static Future<AppFlowyGridCellTest> ensureInitialized() async {
|
|
@@ -85,26 +85,23 @@ class AppFlowyGridCellTest {
|
|
|
}
|
|
|
|
|
|
Future<void> createTestRow() async {
|
|
|
- await _dataController.createRow();
|
|
|
+ await _gridTest.createRow();
|
|
|
}
|
|
|
|
|
|
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(
|
|
|
String fieldId,
|
|
|
) async {
|
|
|
- final RowInfo rowInfo = _dataController.rowInfos.last;
|
|
|
- final blockCache = _dataController.blocks[rowInfo.rowPB.blockId];
|
|
|
+ final RowInfo rowInfo = _gridTest.rowInfos.last;
|
|
|
+ final blockCache = _gridTest.blocks[rowInfo.rowPB.blockId];
|
|
|
final rowCache = blockCache?.rowCache;
|
|
|
|
|
|
final rowDataController = GridRowDataController(
|
|
|
rowInfo: rowInfo,
|
|
|
- fieldController: _dataController.fieldController,
|
|
|
+ fieldController: _gridTest._dataController.fieldController,
|
|
|
rowCache: rowCache!,
|
|
|
);
|
|
|
|
|
@@ -122,6 +119,39 @@ class AppFlowyGridCellTest {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+class AppFlowyGridSelectOptionCellTest {
|
|
|
+ final AppFlowyGridCellTest _gridCellTest;
|
|
|
+
|
|
|
+ AppFlowyGridSelectOptionCellTest(AppFlowyGridCellTest cellTest)
|
|
|
+ : _gridCellTest = cellTest;
|
|
|
+
|
|
|
+ static Future<AppFlowyGridSelectOptionCellTest> ensureInitialized() async {
|
|
|
+ final gridTest = await AppFlowyGridCellTest.ensureInitialized();
|
|
|
+ return AppFlowyGridSelectOptionCellTest(gridTest);
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<void> createTestGrid() async {
|
|
|
+ await _gridCellTest.createTestGrid();
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<void> createTestRow() async {
|
|
|
+ await _gridCellTest.createTestRow();
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<GridSelectOptionCellController> makeCellController(
|
|
|
+ FieldType fieldType) async {
|
|
|
+ assert(fieldType == FieldType.SingleSelect ||
|
|
|
+ fieldType == FieldType.MultiSelect);
|
|
|
+
|
|
|
+ final fieldContexts = _gridCellTest._gridTest.fieldContexts;
|
|
|
+ final field =
|
|
|
+ fieldContexts.firstWhere((element) => element.fieldType == fieldType);
|
|
|
+ final builder = await _gridCellTest.cellControllerBuilder(field.id);
|
|
|
+ final cellController = builder.build() as GridSelectOptionCellController;
|
|
|
+ return cellController;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
Future<void> gridResponseFuture() {
|
|
|
return Future.delayed(gridResponseDuration(milliseconds: 200));
|
|
|
}
|