Skip to content

Commit

Permalink
fix: check if header exists for footer (AppFlowy-IO#559)
Browse files Browse the repository at this point in the history
* fix: check if header exists for footer

* test: add tests and refactor if statement

---------

Co-authored-by: Mathias Mogensen <mathiasrieckm@gmail.com>
  • Loading branch information
MayurSMahajan and Xazin authored Nov 2, 2023
1 parent 9b8d855 commit 4b1a3d5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ class PageBlockComponent extends BlockComponentStatelessWidget {
child: header!,
);
}
if (footer != null && index == items.length + 1) {

if (footer != null && index == (items.length - 1) + extentCount) {
return IgnoreEditorSelectionGesture(
child: footer!,
);
}

return Padding(
padding: editorState.editorStyle.padding,
child: editorState.renderer.build(
Expand Down
60 changes: 60 additions & 0 deletions test/editor/editor_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import '../test_helper.dart';

void main() {
group("AppFlowyEditor tests", () {
testWidgets('can render', (tester) async {
await tester.buildAndPump(
AppFlowyEditor(
editorState: EditorState.blank(),
),
);
await tester.pumpAndSettle();

expect(find.byType(AppFlowyEditor), findsOneWidget);
});

testWidgets('can render with footer', (tester) async {
await tester.buildAndPump(
AppFlowyEditor(
editorState: EditorState(
document: Document(root: pageNode(children: [])),
),
footer: const Icon(Icons.abc),
),
);
await tester.pumpAndSettle();

expect(find.byIcon(Icons.abc), findsOneWidget);
});

testWidgets('can render with header', (tester) async {
await tester.buildAndPump(
AppFlowyEditor(
editorState: EditorState.blank(),
header: const Icon(Icons.abc),
),
);
await tester.pumpAndSettle();

expect(find.byIcon(Icons.abc), findsOneWidget);
});

testWidgets('can render with header and footer', (tester) async {
await tester.buildAndPump(
AppFlowyEditor(
editorState: EditorState.blank(),
header: const Icon(Icons.abc),
footer: const Icon(Icons.abc_outlined),
),
);
await tester.pumpAndSettle();

expect(find.byIcon(Icons.abc), findsOneWidget);
expect(find.byIcon(Icons.abc_outlined), findsOneWidget);
});
});
}

0 comments on commit 4b1a3d5

Please sign in to comment.