mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
test: add context menu test
This commit is contained in:
parent
9e40b7f992
commit
793d3808ec
@ -1,4 +1,6 @@
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:appflowy_editor/src/service/context_menu/context_menu.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import '../infra/test_editor.dart';
|
||||
|
||||
@ -79,5 +81,50 @@ void main() async {
|
||||
Selection.single(path: [1], startOffset: 0, endOffset: text.length),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Test secondary tap', (tester) async {
|
||||
const text = 'Welcome to Appflowy 😁';
|
||||
final editor = tester.editor
|
||||
..insertTextNode(text)
|
||||
..insertTextNode(text)
|
||||
..insertTextNode(text);
|
||||
await editor.startTesting();
|
||||
|
||||
final secondTextNode = editor.nodeAtPath([1]) as TextNode;
|
||||
final finder = find.byKey(secondTextNode.key!);
|
||||
|
||||
final rect = tester.getRect(finder);
|
||||
// secondary tap
|
||||
await tester.tapAt(
|
||||
rect.centerLeft + const Offset(10.0, 0.0),
|
||||
buttons: kSecondaryButton,
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
const welcome = 'Welcome';
|
||||
expect(
|
||||
editor.documentSelection,
|
||||
Selection.single(
|
||||
path: [1],
|
||||
startOffset: 0,
|
||||
endOffset: welcome.length,
|
||||
), // Welcome
|
||||
);
|
||||
|
||||
final contextMenu = find.byType(ContextMenu);
|
||||
expect(contextMenu, findsOneWidget);
|
||||
|
||||
// test built in context menu items
|
||||
|
||||
// cut
|
||||
await tester.tap(find.text('Cut'));
|
||||
await tester.pump();
|
||||
expect(
|
||||
secondTextNode.toPlainText(),
|
||||
text.replaceAll(welcome, ''),
|
||||
);
|
||||
|
||||
// TODO: the copy and paste test is not working during test env.
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user