Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Jun 20, 2023
1 parent 37a9f38 commit 44806f0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
2 changes: 0 additions & 2 deletions lib/src/editor/toolbar/desktop/floating_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ class _FloatingToolbarState extends State<FloatingToolbar>
}

final rect = _findSuitableRect(rects);
print(rect);
final (top, left, right) = calculateToolbarOffset(rect);
print((top, left, right));
_toolbarContainer = OverlayEntry(
builder: (context) {
return Positioned(
Expand Down
26 changes: 25 additions & 1 deletion test/new/infra/testable_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,40 @@ class TestableEditor {
bool autoFocus = false,
bool editable = true,
bool shrinkWrap = false,
bool withFloatingToolbar = false,
ScrollController? scrollController,
Widget Function(Widget child)? wrapper,
}) async {
final editor = AppFlowyEditor.standard(
await AppFlowyEditorLocalizations.load(locale);

if (withFloatingToolbar) {
scrollController ??= ScrollController();
}
Widget editor = AppFlowyEditor.standard(
editorState: editorState,
editable: editable,
autoFocus: autoFocus,
shrinkWrap: shrinkWrap,
scrollController: scrollController,
);
if (withFloatingToolbar) {
editor = FloatingToolbar(
items: [
paragraphItem,
...headingItems,
...markdownFormatItems,
quoteItem,
bulletedListItem,
numberedListItem,
linkItem,
textColorItem,
highlightColorItem
],
editorState: editorState,
scrollController: scrollController!,
child: editor,
);
}
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: const [
Expand Down
36 changes: 36 additions & 0 deletions test/new/toolbar/desktop/floating_toolbar_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';

import '../../util/util.dart';
import '../../infra/testable_editor.dart';

void main() async {
group('floating toolbar', () {
const text = 'Welcome to AppFlowy Editor 🔥!';

testWidgets(
'select the first line of the document, the toolbar should not be blocked',
(tester) async {
final editor = tester.editor..addParagraphs(3, initialText: text);
await editor.startTesting(
withFloatingToolbar: true,
);

final selection = Selection.single(
path: [0],
startOffset: 0,
endOffset: text.length,
);
await editor.updateSelection(selection);
await tester.pumpAndSettle();

final floatingToolbar = find.byType(FloatingToolbarWidget);
expect(floatingToolbar, findsOneWidget);
expect(tester.getTopLeft(floatingToolbar).dy >= 0, true);
await editor.dispose();
});
});
}

0 comments on commit 44806f0

Please sign in to comment.