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.

chore: refactor grid test directory

nathan60267e674ec6
diff --git a/frontend/app_flowy/test/bloc_test/grid_test/create_filter_test.dart b/frontend/app_flowy/test/bloc_test/grid_test/create_filter_test.dart
deleted file mode 100644
index 374c60faac..0000000000
--- a/frontend/app_flowy/test/bloc_test/grid_test/create_filter_test.dart
+++ /dev/null
@@ -1,146 +0,0 @@
-import 'package:app_flowy/plugins/grid/application/filter/filter_service.dart';
-import 'package:app_flowy/plugins/grid/application/grid_bloc.dart';
-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';
-
-void main() {
- late AppFlowyGridTest gridTest;
- setUpAll(() async {
- gridTest = await AppFlowyGridTest.ensureInitialized();
- });
-
- test('create a text filter)', () async {
- final context = await gridTest.createTestGrid();
- final service = FilterFFIService(viewId: context.gridView.id);
- final textField = context.textFieldContext();
- service.insertTextFilter(
- fieldId: textField.id,
- condition: TextFilterCondition.TextIsEmpty,
- content: "");
- await gridResponseFuture();
- assert(context.fieldController.filterInfos.length == 1);
- });
-
- test('delete a text filter)', () async {
- final context = await gridTest.createTestGrid();
- final service = FilterFFIService(viewId: context.gridView.id);
- final textField = context.textFieldContext();
- service.insertTextFilter(
- fieldId: textField.id,
- condition: TextFilterCondition.TextIsEmpty,
- content: "");
- await gridResponseFuture();
-
- final filterInfo = context.fieldController.filterInfos.first;
- service.deleteFilter(
- fieldId: textField.id,
- filterId: filterInfo.filter.id,
- fieldType: textField.fieldType,
- );
- await gridResponseFuture();
-
- assert(context.fieldController.filterInfos.isEmpty);
- });
-
- test('filter rows with condition: text is empty', () async {
- final context = await gridTest.createTestGrid();
- final service = FilterFFIService(viewId: context.gridView.id);
- final gridController = GridController(view: context.gridView);
- final gridBloc = GridBloc(
- view: context.gridView,
- gridController: gridController,
- )..add(const GridEvent.initial());
- await gridResponseFuture();
-
- final textField = context.textFieldContext();
- service.insertTextFilter(
- fieldId: textField.id,
- condition: TextFilterCondition.TextIsEmpty,
- content: "");
- await gridResponseFuture();
-
- assert(gridBloc.state.rowInfos.length == 3);
- });
-
- test('filter rows with condition: text is empty(After edit the row)',
- () async {
- final context = await gridTest.createTestGrid();
- final service = FilterFFIService(viewId: context.gridView.id);
- final gridController = GridController(view: context.gridView);
- final gridBloc = GridBloc(
- view: context.gridView,
- gridController: gridController,
- )..add(const GridEvent.initial());
- await gridResponseFuture();
-
- final textField = context.textFieldContext();
- service.insertTextFilter(
- fieldId: textField.id,
- condition: TextFilterCondition.TextIsEmpty,
- content: "");
- await gridResponseFuture();
-
- final controller = await context.makeTextCellController();
- controller.saveCellData("edit text cell content");
- await gridResponseFuture();
- assert(gridBloc.state.rowInfos.length == 2);
-
- controller.saveCellData("");
- await gridResponseFuture();
- assert(gridBloc.state.rowInfos.length == 3);
- });
-
- test('filter rows with condition: text is not empty', () async {
- final context = await gridTest.createTestGrid();
- final service = FilterFFIService(viewId: context.gridView.id);
- final textField = context.textFieldContext();
- await gridResponseFuture();
- service.insertTextFilter(
- fieldId: textField.id,
- condition: TextFilterCondition.TextIsNotEmpty,
- content: "");
- await gridResponseFuture();
- assert(context.rowInfos.isEmpty);
- });
-
- test('filter rows with condition: checkbox uncheck', () async {
- final context = await gridTest.createTestGrid();
- final checkboxField = context.checkboxFieldContext();
- final service = FilterFFIService(viewId: context.gridView.id);
- final gridController = GridController(view: context.gridView);
- final gridBloc = GridBloc(
- view: context.gridView,
- gridController: gridController,
- )..add(const GridEvent.initial());
-
- await gridResponseFuture();
- service.insertCheckboxFilter(
- fieldId: checkboxField.id,
- condition: CheckboxFilterCondition.IsUnChecked,
- );
- await gridResponseFuture();
- assert(gridBloc.state.rowInfos.length == 3);
- });
-
- test('filter rows with condition: checkbox check', () async {
- final context = await gridTest.createTestGrid();
- final checkboxField = context.checkboxFieldContext();
- final service = FilterFFIService(viewId: context.gridView.id);
- final gridController = GridController(view: context.gridView);
- final gridBloc = GridBloc(
- view: context.gridView,
- gridController: gridController,
- )..add(const GridEvent.initial());
-
- await gridResponseFuture();
- service.insertCheckboxFilter(
- fieldId: checkboxField.id,
- condition: CheckboxFilterCondition.IsChecked,
- );
- await gridResponseFuture();
- assert(gridBloc.state.rowInfos.isEmpty);
- });
-}
diff --git a/frontend/app_flowy/test/bloc_test/grid_test/edit_field_change_filter_test.dart b/frontend/app_flowy/test/bloc_test/grid_test/edit_field_change_filter_test.dart
deleted file mode 100644
index 1a8c3edf06..0000000000
--- a/frontend/app_flowy/test/bloc_test/grid_test/edit_field_change_filter_test.dart
+++ /dev/null
@@ -1,56 +0,0 @@
-import 'package:app_flowy/plugins/grid/application/field/field_editor_bloc.dart';
-import 'package:app_flowy/plugins/grid/application/field/type_option/type_option_context.dart';
-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/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';
-
-void main() {
- late AppFlowyGridTest gridTest;
- setUpAll(() async {
- gridTest = await AppFlowyGridTest.ensureInitialized();
- });
-
- test("create a text filter and then alter the filter's field)", () async {
- final context = await gridTest.createTestGrid();
- final service = FilterFFIService(viewId: context.gridView.id);
- final textField = context.textFieldContext();
-
- // Create the filter menu bloc
- final menuBloc = GridFilterMenuBloc(
- fieldController: context.fieldController,
- viewId: context.gridView.id,
- )..add(const GridFilterMenuEvent.initial());
-
- // Insert filter for the text field
- service.insertTextFilter(
- fieldId: textField.id,
- condition: TextFilterCondition.TextIsEmpty,
- content: "");
- await gridResponseFuture();
- assert(menuBloc.state.filters.length == 1);
-
- // Edit the text field
- final loader = FieldTypeOptionLoader(
- gridId: context.gridView.id,
- field: textField.field,
- );
-
- final editorBloc = FieldEditorBloc(
- gridId: context.gridView.id,
- fieldName: textField.field.name,
- isGroupField: false,
- loader: loader,
- )..add(const FieldEditorEvent.initial());
- await gridResponseFuture();
-
- // Alter the field type to Number
- editorBloc.add(const FieldEditorEvent.switchToField(FieldType.Number));
- await gridResponseFuture();
-
- // Check the number of filters
- assert(menuBloc.state.filters.isEmpty);
- });
-}
diff --git a/frontend/app_flowy/test/bloc_test/grid_test/edit_field_edit_test.dart b/frontend/app_flowy/test/bloc_test/grid_test/edit_field_edit_test.dart
deleted file mode 100644
index 5a8173b7bd..0000000000
--- a/frontend/app_flowy/test/bloc_test/grid_test/edit_field_edit_test.dart
+++ /dev/null
@@ -1,102 +0,0 @@
-import 'package:app_flowy/plugins/grid/application/field/type_option/type_option_context.dart';
-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';
-
-Future<FieldEditorBloc> createEditorBloc(AppFlowyGridTest gridTest) async {
- final context = await gridTest.createTestGrid();
- final fieldInfo = context.singleSelectFieldContext();
- final loader = FieldTypeOptionLoader(
- gridId: context.gridView.id,
- field: fieldInfo.field,
- );
-
- return FieldEditorBloc(
- gridId: context.gridView.id,
- fieldName: fieldInfo.name,
- isGroupField: fieldInfo.isGroupField,
- loader: loader,
- )..add(const FieldEditorEvent.initial());
-}
-
-void main() {
- late AppFlowyGridTest gridTest;
-
- setUpAll(() async {
- gridTest = await AppFlowyGridTest.ensureInitialized();
- });
-
- group('$FieldEditorBloc', () {
- late FieldEditorBloc editorBloc;
-
- setUp(() async {
- final context = await gridTest.createTestGrid();
- final fieldInfo = context.singleSelectFieldContext();
- final loader = FieldTypeOptionLoader(
- gridId: context.gridView.id,
- field: fieldInfo.field,
- );
-
- editorBloc = FieldEditorBloc(
- gridId: context.gridView.id,
- fieldName: fieldInfo.name,
- isGroupField: fieldInfo.isGroupField,
- loader: loader,
- )..add(const FieldEditorEvent.initial());
-
- await gridResponseFuture();
- });
-
- blocTest<FieldEditorBloc, FieldEditorState>(
- "rename field",
- build: () => editorBloc,
- act: (bloc) async {
- editorBloc.add(const FieldEditorEvent.updateName('Hello world'));
- },
- wait: gridResponseDuration(),
- verify: (bloc) {
- bloc.state.field.fold(
- () => throw Exception("The field should not be none"),
- (field) {
- assert(field.name == 'Hello world');
- },
- );
- },
- );
-
- blocTest<FieldEditorBloc, FieldEditorState>(
- "switch to text field",
- build: () => editorBloc,
- act: (bloc) async {
- editorBloc
- .add(const FieldEditorEvent.switchToField(FieldType.RichText));
- },
- wait: gridResponseDuration(),
- verify: (bloc) {
- bloc.state.field.fold(
- () => throw Exception("The field should not be none"),
- (field) {
- // The default length of the fields is 3. The length of the fields
- // should not change after switching to other field type
- // assert(gridTest.fieldContexts.length == 3);
- assert(field.fieldType == FieldType.RichText);
- },
- );
- },
- );
-
- blocTest<FieldEditorBloc, FieldEditorState>(
- "delete field",
- build: () => editorBloc,
- act: (bloc) async {
- editorBloc.add(const FieldEditorEvent.deleteField());
- },
- wait: gridResponseDuration(),
- verify: (bloc) {
- // assert(gridTest.fieldContexts.length == 2);
- },
- );
- });
-}
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
deleted file mode 100644
index fef80e2181..0000000000
--- a/frontend/app_flowy/test/bloc_test/grid_test/select_option_bloc_test.dart
+++ /dev/null
@@ -1,201 +0,0 @@
-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:app_flowy/plugins/grid/application/prelude.dart';
-import 'package:dartz/dartz.dart';
-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';
-
-void main() {
- late AppFlowyGridCellTest cellTest;
- setUpAll(() async {
- cellTest = await AppFlowyGridCellTest.ensureInitialized();
- });
-
- group('SingleSelectOptionBloc', () {
- late GridSelectOptionCellController cellController;
- setUp(() async {
- await cellTest.createTestGrid();
- await cellTest.createTestRow();
- cellController = await cellTest.makeCellController(
- FieldType.SingleSelect,
- );
- });
-
- blocTest<SelectOptionCellEditorBloc, SelectOptionEditorState>(
- "delete options",
- build: () {
- final bloc = SelectOptionCellEditorBloc(cellController: cellController);
- bloc.add(const SelectOptionEditorEvent.initial());
- return bloc;
- },
- act: (bloc) async {
- bloc.add(const SelectOptionEditorEvent.newOption("A"));
- await Future.delayed(gridResponseDuration());
- bloc.add(const SelectOptionEditorEvent.newOption("B"));
- await Future.delayed(gridResponseDuration());
- bloc.add(const SelectOptionEditorEvent.newOption("C"));
- await Future.delayed(gridResponseDuration());
- bloc.add(const SelectOptionEditorEvent.deleteAllOptions());
- },
- wait: gridResponseDuration(),
- verify: (bloc) {
- assert(bloc.state.options.isEmpty);
- },
- );
-
- blocTest<SelectOptionCellEditorBloc, SelectOptionEditorState>(
- "create option",
- build: () {
- final bloc = SelectOptionCellEditorBloc(cellController: cellController);
- bloc.add(const SelectOptionEditorEvent.initial());
- return bloc;
- },
- act: (bloc) async {
- bloc.add(const SelectOptionEditorEvent.newOption("A"));
- },
- wait: gridResponseDuration(),
- verify: (bloc) {
- expect(bloc.state.options.length, 1);
- expect(bloc.state.options[0].name, "A");
- },
- );
-
- blocTest<SelectOptionCellEditorBloc, SelectOptionEditorState>(
- "delete option",
- build: () {
- final bloc = SelectOptionCellEditorBloc(cellController: cellController);
- bloc.add(const SelectOptionEditorEvent.initial());
- return bloc;
- },
- act: (bloc) async {
- bloc.add(const SelectOptionEditorEvent.newOption("A"));
- await Future.delayed(gridResponseDuration());
- bloc.add(SelectOptionEditorEvent.deleteOption(bloc.state.options[0]));
- },
- wait: gridResponseDuration(),
- verify: (bloc) {
- assert(bloc.state.options.isEmpty);
- },
- );
-
- blocTest<SelectOptionCellEditorBloc, SelectOptionEditorState>(
- "update option",
- build: () {
- final bloc = SelectOptionCellEditorBloc(cellController: cellController);
- bloc.add(const SelectOptionEditorEvent.initial());
- return bloc;
- },
- act: (bloc) async {
- bloc.add(const SelectOptionEditorEvent.newOption("A"));
- await Future.delayed(gridResponseDuration());
- SelectOptionPB optionUpdate = bloc.state.options[0]
- ..color = SelectOptionColorPB.Aqua
- ..name = "B";
- bloc.add(SelectOptionEditorEvent.updateOption(optionUpdate));
- },
- wait: gridResponseDuration(),
- verify: (bloc) {
- assert(bloc.state.options.length == 1);
- expect(bloc.state.options[0].color, SelectOptionColorPB.Aqua);
- expect(bloc.state.options[0].name, "B");
- },
- );
-
- blocTest<SelectOptionCellEditorBloc, SelectOptionEditorState>(
- "select/unselect option",
- build: () {
- final bloc = SelectOptionCellEditorBloc(cellController: cellController);
- bloc.add(const SelectOptionEditorEvent.initial());
- return bloc;
- },
- act: (bloc) async {
- bloc.add(const SelectOptionEditorEvent.newOption("A"));
- await Future.delayed(gridResponseDuration());
- expect(bloc.state.selectedOptions.length, 1);
- final optionId = bloc.state.options[0].id;
- bloc.add(SelectOptionEditorEvent.unSelectOption(optionId));
- await Future.delayed(gridResponseDuration());
- assert(bloc.state.selectedOptions.isEmpty);
- bloc.add(SelectOptionEditorEvent.selectOption(optionId));
- },
- wait: gridResponseDuration(),
- verify: (bloc) {
- assert(bloc.state.selectedOptions.length == 1);
- expect(bloc.state.selectedOptions[0].name, "A");
- },
- );
-
- blocTest<SelectOptionCellEditorBloc, SelectOptionEditorState>(
- "select an option or create one",
- build: () {
- final bloc = SelectOptionCellEditorBloc(cellController: cellController);
- bloc.add(const SelectOptionEditorEvent.initial());
- return bloc;
- },
- act: (bloc) async {
- bloc.add(const SelectOptionEditorEvent.newOption("A"));
- await Future.delayed(gridResponseDuration());
- bloc.add(const SelectOptionEditorEvent.trySelectOption("B"));
- await Future.delayed(gridResponseDuration());
- bloc.add(const SelectOptionEditorEvent.trySelectOption("A"));
- },
- wait: gridResponseDuration(),
- verify: (bloc) {
- assert(bloc.state.selectedOptions.length == 1);
- assert(bloc.state.options.length == 2);
- expect(bloc.state.selectedOptions[0].name, "A");
- },
- );
-
- blocTest<SelectOptionCellEditorBloc, SelectOptionEditorState>(
- "select multiple options",
- build: () {
- final bloc = SelectOptionCellEditorBloc(cellController: cellController);
- bloc.add(const SelectOptionEditorEvent.initial());
- return bloc;
- },
- act: (bloc) async {
- bloc.add(const SelectOptionEditorEvent.newOption("A"));
- await Future.delayed(gridResponseDuration());
- bloc.add(const SelectOptionEditorEvent.newOption("B"));
- await Future.delayed(gridResponseDuration());
- bloc.add(const SelectOptionEditorEvent.selectMultipleOptions(
- ["A", "B", "C"], "x"));
- },
- wait: gridResponseDuration(),
- verify: (bloc) {
- assert(bloc.state.selectedOptions.length == 1);
- expect(bloc.state.selectedOptions[0].name, "A");
- expect(bloc.state.filter, const Some("x"));
- },
- );
-
- blocTest<SelectOptionCellEditorBloc, SelectOptionEditorState>(
- "filter options",
- build: () {
- final bloc = SelectOptionCellEditorBloc(cellController: cellController);
- bloc.add(const SelectOptionEditorEvent.initial());
- return bloc;
- },
- act: (bloc) async {
- bloc.add(const SelectOptionEditorEvent.newOption("abcd"));
- await Future.delayed(gridResponseDuration());
- bloc.add(const SelectOptionEditorEvent.newOption("aaaa"));
- await Future.delayed(gridResponseDuration());
- bloc.add(const SelectOptionEditorEvent.newOption("defg"));
- await Future.delayed(gridResponseDuration());
- bloc.add(const SelectOptionEditorEvent.filterOption("a"));
- },
- wait: gridResponseDuration(),
- verify: (bloc) {
- expect(bloc.state.options.length, 2);
- expect(bloc.state.allOptions.length, 3);
- expect(bloc.state.createOption, const Some("a"));
- expect(bloc.state.filter, const Some("a"));
- },
- );
- });
-}
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 8e9dd16fec..27c111a8f3 100644
--- a/frontend/app_flowy/test/bloc_test/grid_test/util.dart
+++ b/frontend/app_flowy/test/bloc_test/grid_test/util.dart
@@ -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({
@@ -71,7 +71,7 @@ class GridTestContext {
final RowInfo rowInfo = rowInfos.last;
final blockCache = blocks[rowInfo.rowPB.blockId];
final rowCache = blockCache?.rowCache;
- final fieldController = _gridController.fieldController;
+ final fieldController = gridController.fieldController;
final rowDataController = GridRowDataController(
rowInfo: rowInfo,
@@ -171,7 +171,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;
},