mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: add select option bloc test (#1291)
Co-authored-by: nathan <nathan@appflowy.io>
This commit is contained in:
parent
df91e00985
commit
7edc4fd76e
@ -27,7 +27,7 @@ void main() {
|
|||||||
setUpAll(() async {
|
setUpAll(() async {
|
||||||
gridBloc = GridBloc(view: gridTest.gridView)
|
gridBloc = GridBloc(view: gridTest.gridView)
|
||||||
..add(const GridEvent.initial());
|
..add(const GridEvent.initial());
|
||||||
await gridBlocResponseFuture();
|
await gridResponseFuture();
|
||||||
});
|
});
|
||||||
|
|
||||||
// The initial number of rows is three
|
// The initial number of rows is three
|
||||||
@ -37,7 +37,7 @@ void main() {
|
|||||||
|
|
||||||
test('delete row', () async {
|
test('delete row', () async {
|
||||||
gridBloc.add(GridEvent.deleteRow(gridBloc.state.rowInfos.last));
|
gridBloc.add(GridEvent.deleteRow(gridBloc.state.rowInfos.last));
|
||||||
await gridBlocResponseFuture();
|
await gridResponseFuture();
|
||||||
assert(gridBloc.state.rowInfos.length == 2);
|
assert(gridBloc.state.rowInfos.length == 2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart';
|
||||||
|
import 'package:app_flowy/plugins/grid/application/cell/select_option_editor_bloc.dart';
|
||||||
|
import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:bloc_test/bloc_test.dart';
|
||||||
|
import 'util.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
late AppFlowyGridSelectOptionCellTest cellTest;
|
||||||
|
setUpAll(() async {
|
||||||
|
cellTest = await AppFlowyGridSelectOptionCellTest.ensureInitialized();
|
||||||
|
});
|
||||||
|
|
||||||
|
group('SingleSelectOptionBloc', () {
|
||||||
|
late GridSelectOptionCellController cellController;
|
||||||
|
setUp(() async {
|
||||||
|
cellController =
|
||||||
|
await cellTest.makeCellController(FieldType.SingleSelect);
|
||||||
|
});
|
||||||
|
|
||||||
|
blocTest<SelectOptionCellEditorBloc, SelectOptionEditorState>(
|
||||||
|
"create option",
|
||||||
|
build: () {
|
||||||
|
final bloc = SelectOptionCellEditorBloc(cellController: cellController);
|
||||||
|
bloc.add(const SelectOptionEditorEvent.initial());
|
||||||
|
return bloc;
|
||||||
|
},
|
||||||
|
act: (bloc) => bloc.add(const SelectOptionEditorEvent.newOption("A")),
|
||||||
|
wait: gridResponseDuration(),
|
||||||
|
verify: (bloc) {
|
||||||
|
assert(bloc.state.options.length == 1);
|
||||||
|
assert(bloc.state.options[0].name == "A");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
@ -1,6 +1,12 @@
|
|||||||
|
import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_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';
|
||||||
|
import 'package:app_flowy/plugins/grid/application/row/row_data_controller.dart';
|
||||||
import 'package:app_flowy/plugins/grid/grid.dart';
|
import 'package:app_flowy/plugins/grid/grid.dart';
|
||||||
import 'package:app_flowy/workspace/application/app/app_service.dart';
|
import 'package:app_flowy/workspace/application/app/app_service.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
|
||||||
|
import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
|
||||||
|
|
||||||
import '../../util.dart';
|
import '../../util.dart';
|
||||||
|
|
||||||
@ -35,10 +41,84 @@ class AppFlowyGridTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> gridBlocResponseFuture({int millseconds = 100}) {
|
class AppFlowyGridSelectOptionCellTest {
|
||||||
return Future.delayed(gridBlocResponseDuration(millseconds: millseconds));
|
final AppFlowyGridCellTest _cellTest;
|
||||||
|
|
||||||
|
AppFlowyGridSelectOptionCellTest(AppFlowyGridCellTest cellTest)
|
||||||
|
: _cellTest = cellTest;
|
||||||
|
|
||||||
|
static Future<AppFlowyGridSelectOptionCellTest> ensureInitialized() async {
|
||||||
|
final cellTest = await AppFlowyGridCellTest.ensureInitialized();
|
||||||
|
final test = AppFlowyGridSelectOptionCellTest(cellTest);
|
||||||
|
return test;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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;
|
||||||
|
final field =
|
||||||
|
fieldContexts.firstWhere((element) => element.fieldType == fieldType);
|
||||||
|
final builder = await _cellTest.cellControllerBuilder(0, field.id);
|
||||||
|
final cellController = builder.build() as GridSelectOptionCellController;
|
||||||
|
return cellController;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Duration gridBlocResponseDuration({int millseconds = 100}) {
|
class AppFlowyGridCellTest {
|
||||||
return Duration(milliseconds: millseconds);
|
// ignore: unused_field
|
||||||
|
final AppFlowyGridTest _gridTest;
|
||||||
|
final GridDataController _dataController;
|
||||||
|
AppFlowyGridCellTest(AppFlowyGridTest gridTest)
|
||||||
|
: _gridTest = gridTest,
|
||||||
|
_dataController = GridDataController(view: gridTest.gridView);
|
||||||
|
|
||||||
|
static Future<AppFlowyGridCellTest> ensureInitialized() async {
|
||||||
|
final gridTest = await AppFlowyGridTest.ensureInitialized();
|
||||||
|
final test = AppFlowyGridCellTest(gridTest);
|
||||||
|
await test._loadGridData();
|
||||||
|
return test;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _loadGridData() async {
|
||||||
|
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];
|
||||||
|
final blockCache = _dataController.blocks[rowInfo.rowPB.blockId];
|
||||||
|
final rowCache = blockCache?.rowCache;
|
||||||
|
|
||||||
|
final rowDataController = GridRowDataController(
|
||||||
|
rowInfo: rowInfo,
|
||||||
|
fieldController: _dataController.fieldController,
|
||||||
|
rowCache: rowCache!,
|
||||||
|
);
|
||||||
|
|
||||||
|
final rowBloc = RowBloc(
|
||||||
|
rowInfo: rowInfo,
|
||||||
|
dataController: rowDataController,
|
||||||
|
)..add(const RowEvent.initial());
|
||||||
|
await gridResponseFuture(milliseconds: 300);
|
||||||
|
|
||||||
|
return GridCellControllerBuilder(
|
||||||
|
cellId: rowBloc.state.gridCellMap[fieldId]!,
|
||||||
|
cellCache: rowCache.cellCache,
|
||||||
|
delegate: rowDataController,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> gridResponseFuture({int milliseconds = 200}) {
|
||||||
|
return Future.delayed(gridResponseDuration(milliseconds: milliseconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
Duration gridResponseDuration({int milliseconds = 200}) {
|
||||||
|
return Duration(milliseconds: milliseconds);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user