Skip to content

Commit e482ac7

Browse files
authored
test: edit a field in kanban board (#1428)
1 parent 42c2c47 commit e482ac7

File tree

5 files changed

+139
-14
lines changed

5 files changed

+139
-14
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import 'package:app_flowy/plugins/board/application/board_bloc.dart';
2+
import 'package:app_flowy/plugins/grid/application/field/field_editor_bloc.dart';
3+
import 'package:app_flowy/plugins/grid/application/field/type_option/type_option_context.dart';
4+
import 'package:bloc_test/bloc_test.dart';
5+
import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
6+
import 'package:flutter_test/flutter_test.dart';
7+
import 'util.dart';
8+
9+
void main() {
10+
late AppFlowyBoardTest boardTest;
11+
12+
setUpAll(() async {
13+
boardTest = await AppFlowyBoardTest.ensureInitialized();
14+
});
15+
16+
group('The grouped field is not changed after editing a field:', () {
17+
late BoardBloc boardBloc;
18+
late FieldEditorBloc editorBloc;
19+
setUpAll(() async {
20+
await boardTest.context.createTestBoard();
21+
});
22+
23+
setUp(() async {
24+
boardBloc = BoardBloc(view: boardTest.context.gridView)
25+
..add(const BoardEvent.initial());
26+
27+
final fieldContext = boardTest.context.singleSelectFieldContext();
28+
final loader = FieldTypeOptionLoader(
29+
gridId: boardTest.context.gridView.id,
30+
field: fieldContext.field,
31+
);
32+
33+
editorBloc = FieldEditorBloc(
34+
gridId: boardTest.context.gridView.id,
35+
fieldName: fieldContext.name,
36+
isGroupField: fieldContext.isGroupField,
37+
loader: loader,
38+
)..add(const FieldEditorEvent.initial());
39+
40+
await boardResponseFuture();
41+
});
42+
43+
blocTest<BoardBloc, BoardState>(
44+
"initial",
45+
build: () => boardBloc,
46+
wait: boardResponseDuration(),
47+
verify: (bloc) {
48+
assert(bloc.groupControllers.values.length == 4);
49+
assert(boardTest.context.fieldContexts.length == 2);
50+
},
51+
);
52+
53+
blocTest<FieldEditorBloc, FieldEditorState>(
54+
"edit a field",
55+
build: () => editorBloc,
56+
act: (bloc) async {
57+
editorBloc.add(const FieldEditorEvent.updateName('Hello world'));
58+
},
59+
wait: boardResponseDuration(),
60+
verify: (bloc) {
61+
bloc.state.field.fold(
62+
() => throw Exception("The field should not be none"),
63+
(field) {
64+
assert(field.name == 'Hello world');
65+
},
66+
);
67+
},
68+
);
69+
70+
blocTest<BoardBloc, BoardState>(
71+
"assert the groups were not changed",
72+
build: () => boardBloc,
73+
wait: boardResponseDuration(),
74+
verify: (bloc) {
75+
assert(bloc.groupControllers.values.length == 4,
76+
"Expected 4, but receive ${bloc.groupControllers.values.length}");
77+
78+
assert(boardTest.context.fieldContexts.length == 2,
79+
"Expected 2, but receive ${boardTest.context.fieldContexts.length}");
80+
},
81+
);
82+
});
83+
group('The grouped field is not changed after creating a new field:', () {
84+
late BoardBloc boardBloc;
85+
setUpAll(() async {
86+
await boardTest.context.createTestBoard();
87+
});
88+
89+
setUp(() async {
90+
boardBloc = BoardBloc(view: boardTest.context.gridView)
91+
..add(const BoardEvent.initial());
92+
await boardResponseFuture();
93+
});
94+
95+
blocTest<BoardBloc, BoardState>(
96+
"initial",
97+
build: () => boardBloc,
98+
wait: boardResponseDuration(),
99+
verify: (bloc) {
100+
assert(bloc.groupControllers.values.length == 4);
101+
assert(boardTest.context.fieldContexts.length == 2);
102+
},
103+
);
104+
105+
test('create a field', () async {
106+
await boardTest.context.createField(FieldType.Checkbox);
107+
await boardResponseFuture();
108+
final checkboxField = boardTest.context.fieldContexts.last.field;
109+
assert(checkboxField.fieldType == FieldType.Checkbox);
110+
});
111+
112+
blocTest<BoardBloc, BoardState>(
113+
"assert the groups were not changed",
114+
build: () => boardBloc,
115+
wait: boardResponseDuration(),
116+
verify: (bloc) {
117+
assert(bloc.groupControllers.values.length == 4,
118+
"Expected 4, but receive ${bloc.groupControllers.values.length}");
119+
120+
assert(boardTest.context.fieldContexts.length == 3,
121+
"Expected 3, but receive ${boardTest.context.fieldContexts.length}");
122+
},
123+
);
124+
});
125+
}

frontend/app_flowy/test/bloc_test/board_test/group_by_field_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void main() {
3737
});
3838

3939
blocTest<GridGroupBloc, GridGroupState>(
40-
"set grouped by multi-select field",
40+
"set grouped by the new multi-select field",
4141
build: () => GridGroupBloc(
4242
viewId: boardTest.context.gridView.id,
4343
fieldController: boardTest.context.fieldController,

frontend/app_flowy/test/bloc_test/grid_test/grid_bloc_test.dart

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ void main() {
1010
await gridTest.createTestGrid();
1111
});
1212

13-
group('GridBloc', () {
13+
group('Create a new row in Grid', () {
1414
blocTest<GridBloc, GridState>(
15-
"Create row",
15+
"Create a row",
1616
build: () =>
1717
GridBloc(view: gridTest.gridView)..add(const GridEvent.initial()),
1818
act: (bloc) => bloc.add(const GridEvent.createRow()),
@@ -23,23 +23,18 @@ void main() {
2323
);
2424
});
2525

26-
group('GridBloc', () {
26+
group('Delete a row in the grid', () {
2727
late GridBloc gridBloc;
2828
setUpAll(() async {
2929
gridBloc = GridBloc(view: gridTest.gridView)
3030
..add(const GridEvent.initial());
3131
await gridResponseFuture();
3232
});
3333

34-
// The initial number of rows is three
35-
test('', () async {
36-
assert(gridBloc.state.rowInfos.length == 3);
37-
});
38-
39-
test('delete row', () async {
34+
test('delete the last row', () async {
4035
gridBloc.add(GridEvent.deleteRow(gridBloc.state.rowInfos.last));
4136
await gridResponseFuture();
42-
assert(gridBloc.state.rowInfos.length == 2);
37+
assert(gridBloc.state.rowInfos.length == 3);
4338
});
4439
});
4540
}

frontend/rust-lib/flowy-grid/src/services/grid_view_editor.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,13 @@ impl GridViewRevisionEditor {
291291
.await
292292
}
293293
#[tracing::instrument(level = "trace", skip_all, err)]
294-
pub(crate) async fn did_update_view_field(&self, _field_id: &str) -> FlowyResult<()> {
295-
// Do nothing
294+
pub(crate) async fn did_update_view_field(&self, field_id: &str) -> FlowyResult<()> {
295+
let grouped_field_id = self.group_controller.read().await.field_id().to_owned();
296+
if grouped_field_id == field_id {
297+
let _ = self.group_by_view_field(field_id).await?;
298+
} else {
299+
// Do nothing
300+
}
296301
Ok(())
297302
}
298303

frontend/rust-lib/flowy-grid/src/services/grid_view_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl GridViewManager {
193193
#[tracing::instrument(level = "trace", skip(self), err)]
194194
pub(crate) async fn did_update_view_field_type_option(&self, field_id: &str) -> FlowyResult<()> {
195195
let view_editor = self.get_default_view_editor().await?;
196-
let _ = view_editor.group_by_view_field(field_id).await?;
196+
let _ = view_editor.did_update_view_field(field_id).await?;
197197
Ok(())
198198
}
199199

0 commit comments

Comments
 (0)