Skip to content

Commit d358e18

Browse files
authored
fix: add card at the beginning (#3835)
1 parent dd9b1fb commit d358e18

File tree

5 files changed

+115
-2
lines changed

5 files changed

+115
-2
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import 'package:appflowy/generated/flowy_svgs.g.dart';
2+
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
3+
import 'package:appflowy_board/appflowy_board.dart';
4+
import 'package:flowy_infra_ui/style_widget/text.dart';
5+
import 'package:flutter/material.dart';
6+
import 'package:flutter_test/flutter_test.dart';
7+
import 'package:integration_test/integration_test.dart';
8+
9+
import '../util/util.dart';
10+
11+
const defaultFirstCardName = 'Card 1';
12+
const defaultLastCardName = 'Card 3';
13+
14+
void main() {
15+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
16+
17+
group('board add row test', () {
18+
testWidgets('Add card from header', (tester) async {
19+
await tester.initializeAppFlowy();
20+
await tester.tapGoButton();
21+
22+
await tester.createNewPageWithName(layout: ViewLayoutPB.Board);
23+
24+
final findFirstCard = find.descendant(
25+
of: find.byType(AppFlowyGroupCard),
26+
matching: find.byType(FlowyText),
27+
);
28+
29+
FlowyText firstCardText = tester.firstWidget(findFirstCard);
30+
expect(firstCardText.text, defaultFirstCardName);
31+
32+
await tester.tap(
33+
find
34+
.descendant(
35+
of: find.byType(AppFlowyGroupHeader),
36+
matching: find.byType(FlowySvg),
37+
)
38+
.first,
39+
);
40+
await tester.pumpAndSettle();
41+
42+
const newCardName = 'Card 4';
43+
await tester.enterText(
44+
find.descendant(
45+
of: find.byType(IntrinsicHeight),
46+
matching: find.byType(TextField),
47+
),
48+
newCardName,
49+
);
50+
await tester.pumpAndSettle();
51+
52+
await tester.tap(find.byType(AppFlowyBoard));
53+
await tester.pumpAndSettle();
54+
55+
firstCardText = tester.firstWidget(findFirstCard);
56+
expect(firstCardText.text, newCardName);
57+
});
58+
59+
testWidgets('Add card from footer', (tester) async {
60+
await tester.initializeAppFlowy();
61+
await tester.tapGoButton();
62+
63+
await tester.createNewPageWithName(layout: ViewLayoutPB.Board);
64+
65+
final findLastCard = find.descendant(
66+
of: find.byType(AppFlowyGroupCard),
67+
matching: find.byType(FlowyText),
68+
);
69+
70+
FlowyText? lastCardText =
71+
tester.widgetList(findLastCard).last as FlowyText;
72+
expect(lastCardText.text, defaultLastCardName);
73+
74+
await tester.tap(
75+
find
76+
.descendant(
77+
of: find.byType(AppFlowyGroupFooter),
78+
matching: find.byType(FlowySvg),
79+
)
80+
.first,
81+
);
82+
await tester.pumpAndSettle();
83+
84+
const newCardName = 'Card 4';
85+
await tester.enterText(
86+
find.descendant(
87+
of: find.byType(IntrinsicHeight),
88+
matching: find.byType(TextField),
89+
),
90+
newCardName,
91+
);
92+
await tester.pumpAndSettle();
93+
94+
await tester.tap(find.byType(AppFlowyBoard));
95+
await tester.pumpAndSettle();
96+
97+
lastCardText = tester.widgetList(findLastCard).last as FlowyText;
98+
expect(lastCardText.text, newCardName);
99+
});
100+
});
101+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import 'package:integration_test/integration_test.dart';
22

33
import 'board_row_test.dart' as board_row_test;
4+
import 'board_add_row_test.dart' as board_add_row_test;
45

56
void startTesting() {
67
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
78

89
// Board integration tests
910
board_row_test.main();
11+
board_add_row_test.main();
1012
}

frontend/appflowy_flutter/lib/plugins/database_view/application/database_controller.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class DatabaseController {
177177
Future<Either<RowMetaPB, FlowyError>> createRow({
178178
RowId? startRowId,
179179
String? groupId,
180+
bool fromBeginning = false,
180181
void Function(RowDataBuilder builder)? withCells,
181182
}) {
182183
Map<String, String>? cellDataByFieldId;
@@ -191,6 +192,7 @@ class DatabaseController {
191192
startRowId: startRowId,
192193
groupId: groupId,
193194
cellDataByFieldId: cellDataByFieldId,
195+
fromBeginning: fromBeginning,
194196
);
195197
}
196198

frontend/appflowy_flutter/lib/plugins/database_view/application/database_view_service.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ class DatabaseViewBackendService {
3535
RowId? startRowId,
3636
String? groupId,
3737
Map<String, String>? cellDataByFieldId,
38+
bool fromBeginning = false,
3839
}) {
3940
final payload = CreateRowPayloadPB.create()..viewId = viewId;
40-
payload.startRowId = startRowId ?? "";
41+
42+
if (!fromBeginning || startRowId != null) {
43+
payload.startRowId = startRowId ?? "";
44+
}
4145

4246
if (groupId != null) {
4347
payload.groupId = groupId;

frontend/appflowy_flutter/lib/plugins/database_view/board/application/board_bloc.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
9090
);
9191
},
9292
createHeaderRow: (String groupId) async {
93-
final result = await databaseController.createRow(groupId: groupId);
93+
final result = await databaseController.createRow(
94+
groupId: groupId,
95+
fromBeginning: true,
96+
);
97+
9498
result.fold(
9599
(_) {},
96100
(err) => Log.error(err),

0 commit comments

Comments
 (0)