mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
Merge pull request #1490 from AppFlowy-IO/filter_bloc_test
chore: add filter test
This commit is contained in:
commit
8c7e2d341d
@ -66,7 +66,6 @@ class BoardCardBloc extends Bloc<BoardCardEvent, BoardCardState> {
|
||||
state.cells.map((cell) => cell.identifier.fieldInfo).toList(),
|
||||
),
|
||||
rowPB: state.rowPB,
|
||||
visible: true,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -287,7 +287,6 @@ class _BoardContentState extends State<BoardContent> {
|
||||
gridId: gridId,
|
||||
fields: UnmodifiableListView(fieldController.fieldInfos),
|
||||
rowPB: rowPB,
|
||||
visible: true,
|
||||
);
|
||||
|
||||
final dataController = GridRowDataController(
|
||||
|
@ -39,7 +39,6 @@ class GridRowCache {
|
||||
|
||||
UnmodifiableListView<RowInfo> get visibleRows {
|
||||
var visibleRows = [..._rowList.rows];
|
||||
visibleRows.retainWhere((element) => element.visible);
|
||||
return UnmodifiableListView(visibleRows);
|
||||
}
|
||||
|
||||
@ -236,7 +235,6 @@ class GridRowCache {
|
||||
gridId: gridId,
|
||||
fields: _fieldNotifier.fields,
|
||||
rowPB: rowPB,
|
||||
visible: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -264,7 +262,6 @@ class RowInfo with _$RowInfo {
|
||||
required String gridId,
|
||||
required UnmodifiableListView<FieldInfo> fields,
|
||||
required RowPB rowPB,
|
||||
required bool visible,
|
||||
}) = _RowInfo;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/select_type_option.pb.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:bloc_test/bloc_test.dart';
|
||||
import 'util.dart';
|
||||
import '../util.dart';
|
||||
|
||||
void main() {
|
||||
late AppFlowyGridCellTest cellTest;
|
||||
@ -19,9 +19,8 @@ void main() {
|
||||
setUp(() async {
|
||||
await cellTest.createTestGrid();
|
||||
await cellTest.createTestRow();
|
||||
cellController = await cellTest.makeCellController(
|
||||
FieldType.SingleSelect,
|
||||
);
|
||||
cellController =
|
||||
await cellTest.makeCellController(FieldType.SingleSelect, 0);
|
||||
});
|
||||
|
||||
blocTest<SelectOptionCellEditorBloc, SelectOptionEditorState>(
|
@ -3,7 +3,7 @@ import 'package:app_flowy/plugins/grid/application/prelude.dart';
|
||||
import 'package:bloc_test/bloc_test.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'util.dart';
|
||||
import '../util.dart';
|
||||
|
||||
Future<FieldEditorBloc> createEditorBloc(AppFlowyGridTest gridTest) async {
|
||||
final context = await gridTest.createTestGrid();
|
@ -4,7 +4,8 @@ import 'package:app_flowy/plugins/grid/application/grid_data_controller.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/checkbox_filter.pbenum.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/text_filter.pb.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'util.dart';
|
||||
|
||||
import '../util.dart';
|
||||
|
||||
void main() {
|
||||
late AppFlowyGridTest gridTest;
|
||||
@ -16,11 +17,12 @@ void main() {
|
||||
final context = await gridTest.createTestGrid();
|
||||
final service = FilterFFIService(viewId: context.gridView.id);
|
||||
final textField = context.textFieldContext();
|
||||
service.insertTextFilter(
|
||||
await service.insertTextFilter(
|
||||
fieldId: textField.id,
|
||||
condition: TextFilterCondition.TextIsEmpty,
|
||||
content: "");
|
||||
await gridResponseFuture();
|
||||
|
||||
assert(context.fieldController.filterInfos.length == 1);
|
||||
});
|
||||
|
||||
@ -28,14 +30,14 @@ void main() {
|
||||
final context = await gridTest.createTestGrid();
|
||||
final service = FilterFFIService(viewId: context.gridView.id);
|
||||
final textField = context.textFieldContext();
|
||||
service.insertTextFilter(
|
||||
await service.insertTextFilter(
|
||||
fieldId: textField.id,
|
||||
condition: TextFilterCondition.TextIsEmpty,
|
||||
content: "");
|
||||
await gridResponseFuture();
|
||||
|
||||
final filterInfo = context.fieldController.filterInfos.first;
|
||||
service.deleteFilter(
|
||||
await service.deleteFilter(
|
||||
fieldId: textField.id,
|
||||
filterId: filterInfo.filter.id,
|
||||
fieldType: textField.fieldType,
|
||||
@ -77,13 +79,13 @@ void main() {
|
||||
await gridResponseFuture();
|
||||
|
||||
final textField = context.textFieldContext();
|
||||
service.insertTextFilter(
|
||||
await service.insertTextFilter(
|
||||
fieldId: textField.id,
|
||||
condition: TextFilterCondition.TextIsEmpty,
|
||||
content: "");
|
||||
await gridResponseFuture();
|
||||
|
||||
final controller = await context.makeTextCellController();
|
||||
final controller = await context.makeTextCellController(0);
|
||||
controller.saveCellData("edit text cell content");
|
||||
await gridResponseFuture();
|
||||
assert(gridBloc.state.rowInfos.length == 2);
|
||||
@ -98,7 +100,7 @@ void main() {
|
||||
final service = FilterFFIService(viewId: context.gridView.id);
|
||||
final textField = context.textFieldContext();
|
||||
await gridResponseFuture();
|
||||
service.insertTextFilter(
|
||||
await service.insertTextFilter(
|
||||
fieldId: textField.id,
|
||||
condition: TextFilterCondition.TextIsNotEmpty,
|
||||
content: "");
|
||||
@ -117,7 +119,7 @@ void main() {
|
||||
)..add(const GridEvent.initial());
|
||||
|
||||
await gridResponseFuture();
|
||||
service.insertCheckboxFilter(
|
||||
await service.insertCheckboxFilter(
|
||||
fieldId: checkboxField.id,
|
||||
condition: CheckboxFilterCondition.IsUnChecked,
|
||||
);
|
||||
@ -136,7 +138,7 @@ void main() {
|
||||
)..add(const GridEvent.initial());
|
||||
|
||||
await gridResponseFuture();
|
||||
service.insertCheckboxFilter(
|
||||
await service.insertCheckboxFilter(
|
||||
fieldId: checkboxField.id,
|
||||
condition: CheckboxFilterCondition.IsChecked,
|
||||
);
|
@ -5,7 +5,8 @@ import 'package:app_flowy/plugins/grid/application/filter/filter_service.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/text_filter.pb.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'util.dart';
|
||||
|
||||
import '../util.dart';
|
||||
|
||||
void main() {
|
||||
late AppFlowyGridTest gridTest;
|
||||
@ -25,7 +26,7 @@ void main() {
|
||||
)..add(const GridFilterMenuEvent.initial());
|
||||
|
||||
// Insert filter for the text field
|
||||
service.insertTextFilter(
|
||||
await service.insertTextFilter(
|
||||
fieldId: textField.id,
|
||||
condition: TextFilterCondition.TextIsEmpty,
|
||||
content: "");
|
@ -0,0 +1,61 @@
|
||||
import 'package:app_flowy/plugins/grid/application/filter/filter_menu_bloc.dart';
|
||||
import 'package:app_flowy/plugins/grid/application/filter/filter_service.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/text_filter.pb.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../util.dart';
|
||||
|
||||
void main() {
|
||||
late AppFlowyGridTest gridTest;
|
||||
setUpAll(() async {
|
||||
gridTest = await AppFlowyGridTest.ensureInitialized();
|
||||
});
|
||||
|
||||
test('test filter menu after create a text filter)', () async {
|
||||
final context = await gridTest.createTestGrid();
|
||||
final menuBloc = GridFilterMenuBloc(
|
||||
viewId: context.gridView.id, fieldController: context.fieldController)
|
||||
..add(const GridFilterMenuEvent.initial());
|
||||
await gridResponseFuture();
|
||||
assert(menuBloc.state.creatableFields.length == 1);
|
||||
|
||||
final service = FilterFFIService(viewId: context.gridView.id);
|
||||
final textField = context.textFieldContext();
|
||||
await service.insertTextFilter(
|
||||
fieldId: textField.id,
|
||||
condition: TextFilterCondition.TextIsEmpty,
|
||||
content: "");
|
||||
await gridResponseFuture();
|
||||
assert(menuBloc.state.creatableFields.isEmpty);
|
||||
});
|
||||
|
||||
test('test filter menu after update existing text filter)', () async {
|
||||
final context = await gridTest.createTestGrid();
|
||||
final menuBloc = GridFilterMenuBloc(
|
||||
viewId: context.gridView.id, fieldController: context.fieldController)
|
||||
..add(const GridFilterMenuEvent.initial());
|
||||
await gridResponseFuture();
|
||||
|
||||
final service = FilterFFIService(viewId: context.gridView.id);
|
||||
final textField = context.textFieldContext();
|
||||
|
||||
// Create filter
|
||||
await service.insertTextFilter(
|
||||
fieldId: textField.id,
|
||||
condition: TextFilterCondition.TextIsEmpty,
|
||||
content: "");
|
||||
await gridResponseFuture();
|
||||
|
||||
final textFilter = context.fieldController.filterInfos.first;
|
||||
// Update the existing filter
|
||||
await service.insertTextFilter(
|
||||
fieldId: textField.id,
|
||||
filterId: textFilter.filter.id,
|
||||
condition: TextFilterCondition.Is,
|
||||
content: "ABC");
|
||||
await gridResponseFuture();
|
||||
assert(menuBloc.state.filters.first.textFilter()!.condition ==
|
||||
TextFilterCondition.Is);
|
||||
assert(menuBloc.state.filters.first.textFilter()!.content == "ABC");
|
||||
});
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
import 'package:app_flowy/plugins/grid/application/filter/filter_service.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/text_filter.pb.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../util.dart';
|
||||
import 'filter_util.dart';
|
||||
|
||||
void main() {
|
||||
late AppFlowyGridTest gridTest;
|
||||
setUpAll(() async {
|
||||
gridTest = await AppFlowyGridTest.ensureInitialized();
|
||||
});
|
||||
|
||||
test('filter rows by text is empty or is not empty condition)', () async {
|
||||
final context = await createTestFilterGrid(gridTest);
|
||||
|
||||
final service = FilterFFIService(viewId: context.gridView.id);
|
||||
final textField = context.textFieldContext();
|
||||
// create a new filter
|
||||
await service.insertTextFilter(
|
||||
fieldId: textField.id,
|
||||
condition: TextFilterCondition.TextIsEmpty,
|
||||
content: "");
|
||||
await gridResponseFuture();
|
||||
assert(context.fieldController.filterInfos.length == 1,
|
||||
"expect 1 but receive ${context.fieldController.filterInfos.length}");
|
||||
assert(context.rowInfos.length == 1,
|
||||
"expect 1 but receive ${context.rowInfos.length}");
|
||||
|
||||
// Update the existing filter
|
||||
final textFilter = context.fieldController.filterInfos.first;
|
||||
await service.insertTextFilter(
|
||||
fieldId: textField.id,
|
||||
filterId: textFilter.filter.id,
|
||||
condition: TextFilterCondition.TextIsNotEmpty,
|
||||
content: "");
|
||||
await gridResponseFuture();
|
||||
assert(context.rowInfos.length == 2);
|
||||
|
||||
// delete the filter
|
||||
await service.deleteFilter(
|
||||
fieldId: textField.id,
|
||||
filterId: textFilter.filter.id,
|
||||
fieldType: textField.fieldType,
|
||||
);
|
||||
await gridResponseFuture();
|
||||
assert(context.rowInfos.length == 3);
|
||||
});
|
||||
|
||||
test('filter rows by text is condition)', () async {
|
||||
final context = await createTestFilterGrid(gridTest);
|
||||
|
||||
final service = FilterFFIService(viewId: context.gridView.id);
|
||||
final textField = context.textFieldContext();
|
||||
// create a new filter
|
||||
await service.insertTextFilter(
|
||||
fieldId: textField.id, condition: TextFilterCondition.Is, content: "A");
|
||||
await gridResponseFuture();
|
||||
assert(context.rowInfos.length == 1,
|
||||
"expect 1 but receive ${context.rowInfos.length}");
|
||||
|
||||
// Update the existing filter's content from 'A' to 'B'
|
||||
final textFilter = context.fieldController.filterInfos.first;
|
||||
await service.insertTextFilter(
|
||||
fieldId: textField.id,
|
||||
filterId: textFilter.filter.id,
|
||||
condition: TextFilterCondition.Is,
|
||||
content: "B");
|
||||
await gridResponseFuture();
|
||||
assert(context.rowInfos.length == 1);
|
||||
|
||||
// Update the existing filter's content from 'B' to 'b'
|
||||
await service.insertTextFilter(
|
||||
fieldId: textField.id,
|
||||
filterId: textFilter.filter.id,
|
||||
condition: TextFilterCondition.Is,
|
||||
content: "b");
|
||||
await gridResponseFuture();
|
||||
assert(context.rowInfos.length == 1);
|
||||
|
||||
// Update the existing filter with content 'C'
|
||||
await service.insertTextFilter(
|
||||
fieldId: textField.id,
|
||||
filterId: textFilter.filter.id,
|
||||
condition: TextFilterCondition.Is,
|
||||
content: "C");
|
||||
await gridResponseFuture();
|
||||
assert(context.rowInfos.isEmpty);
|
||||
|
||||
// delete the filter
|
||||
await service.deleteFilter(
|
||||
fieldId: textField.id,
|
||||
filterId: textFilter.filter.id,
|
||||
fieldType: textField.fieldType,
|
||||
);
|
||||
await gridResponseFuture();
|
||||
assert(context.rowInfos.length == 3);
|
||||
});
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
import 'package:app_flowy/plugins/grid/application/grid_data_controller.dart';
|
||||
import 'package:app_flowy/plugins/grid/grid.dart';
|
||||
import 'package:app_flowy/workspace/application/app/app_service.dart';
|
||||
|
||||
import '../util.dart';
|
||||
|
||||
Future<GridTestContext> createTestFilterGrid(AppFlowyGridTest gridTest) async {
|
||||
final app = await gridTest.unitTest.createTestApp();
|
||||
final builder = GridPluginBuilder();
|
||||
final context = await AppService()
|
||||
.createView(
|
||||
appId: app.id,
|
||||
name: "Filter Grid",
|
||||
dataFormatType: builder.dataFormatType,
|
||||
pluginType: builder.pluginType,
|
||||
layoutType: builder.layoutType!,
|
||||
)
|
||||
.then((result) {
|
||||
return result.fold(
|
||||
(view) async {
|
||||
final context = GridTestContext(view, GridController(view: view));
|
||||
final result = await context.gridController.openGrid();
|
||||
|
||||
await editCells(context);
|
||||
await gridResponseFuture(milliseconds: 500);
|
||||
result.fold((l) => null, (r) => throw Exception(r));
|
||||
return context;
|
||||
},
|
||||
(error) => throw Exception(),
|
||||
);
|
||||
});
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
Future<void> editCells(GridTestContext context) async {
|
||||
final controller0 = await context.makeTextCellController(0);
|
||||
final controller1 = await context.makeTextCellController(1);
|
||||
|
||||
controller0.saveCellData('A');
|
||||
controller1.saveCellData('B');
|
||||
}
|
@ -18,26 +18,26 @@ import '../../util.dart';
|
||||
|
||||
class GridTestContext {
|
||||
final ViewPB gridView;
|
||||
final GridController _gridController;
|
||||
final GridController gridController;
|
||||
|
||||
GridTestContext(this.gridView, this._gridController);
|
||||
GridTestContext(this.gridView, this.gridController);
|
||||
|
||||
List<RowInfo> get rowInfos {
|
||||
return _gridController.rowInfos;
|
||||
return gridController.rowInfos;
|
||||
}
|
||||
|
||||
UnmodifiableMapView<String, GridBlockCache> get blocks {
|
||||
return _gridController.blocks;
|
||||
return gridController.blocks;
|
||||
}
|
||||
|
||||
List<FieldInfo> get fieldContexts => fieldController.fieldInfos;
|
||||
|
||||
GridFieldController get fieldController {
|
||||
return _gridController.fieldController;
|
||||
return gridController.fieldController;
|
||||
}
|
||||
|
||||
Future<void> createRow() async {
|
||||
return _gridController.createRow();
|
||||
return gridController.createRow();
|
||||
}
|
||||
|
||||
FieldEditorBloc createFieldEditor({
|
||||
@ -60,18 +60,20 @@ class GridTestContext {
|
||||
return editorBloc;
|
||||
}
|
||||
|
||||
Future<IGridCellController> makeCellController(String fieldId) async {
|
||||
final builder = await makeCellControllerBuilder(fieldId);
|
||||
Future<IGridCellController> makeCellController(
|
||||
String fieldId, int rowIndex) async {
|
||||
final builder = await makeCellControllerBuilder(fieldId, rowIndex);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
Future<GridCellControllerBuilder> makeCellControllerBuilder(
|
||||
String fieldId,
|
||||
int rowIndex,
|
||||
) async {
|
||||
final RowInfo rowInfo = rowInfos.last;
|
||||
final RowInfo rowInfo = rowInfos[rowIndex];
|
||||
final blockCache = blocks[rowInfo.rowPB.blockId];
|
||||
final rowCache = blockCache?.rowCache;
|
||||
final fieldController = _gridController.fieldController;
|
||||
final fieldController = gridController.fieldController;
|
||||
|
||||
final rowDataController = GridRowDataController(
|
||||
rowInfo: rowInfo,
|
||||
@ -125,22 +127,22 @@ class GridTestContext {
|
||||
}
|
||||
|
||||
Future<GridSelectOptionCellController> makeSelectOptionCellController(
|
||||
FieldType fieldType) async {
|
||||
FieldType fieldType, int rowIndex) async {
|
||||
assert(fieldType == FieldType.SingleSelect ||
|
||||
fieldType == FieldType.MultiSelect);
|
||||
|
||||
final field =
|
||||
fieldContexts.firstWhere((element) => element.fieldType == fieldType);
|
||||
final cellController =
|
||||
await makeCellController(field.id) as GridSelectOptionCellController;
|
||||
final cellController = await makeCellController(field.id, rowIndex)
|
||||
as GridSelectOptionCellController;
|
||||
return cellController;
|
||||
}
|
||||
|
||||
Future<GridCellController> makeTextCellController() async {
|
||||
Future<GridCellController> makeTextCellController(int rowIndex) async {
|
||||
final field = fieldContexts
|
||||
.firstWhere((element) => element.fieldType == FieldType.RichText);
|
||||
final cellController =
|
||||
await makeCellController(field.id) as GridCellController;
|
||||
await makeCellController(field.id, rowIndex) as GridCellController;
|
||||
return cellController;
|
||||
}
|
||||
}
|
||||
@ -171,7 +173,7 @@ class AppFlowyGridTest {
|
||||
return result.fold(
|
||||
(view) async {
|
||||
final context = GridTestContext(view, GridController(view: view));
|
||||
final result = await context._gridController.openGrid();
|
||||
final result = await context.gridController.openGrid();
|
||||
result.fold((l) => null, (r) => throw Exception(r));
|
||||
return context;
|
||||
},
|
||||
@ -205,12 +207,12 @@ class AppFlowyGridCellTest {
|
||||
}
|
||||
|
||||
Future<GridSelectOptionCellController> makeCellController(
|
||||
FieldType fieldType) async {
|
||||
return context.makeSelectOptionCellController(fieldType);
|
||||
FieldType fieldType, int rowIndex) async {
|
||||
return context.makeSelectOptionCellController(fieldType, rowIndex);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> gridResponseFuture({int milliseconds = 500}) {
|
||||
Future<void> gridResponseFuture({int milliseconds = 200}) {
|
||||
return Future.delayed(gridResponseDuration(milliseconds: milliseconds));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user