outline_block_test.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import 'package:appflowy/generated/locale_keys.g.dart';
  2. import 'package:appflowy/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart';
  3. import 'package:appflowy_backend/protobuf/flowy-folder2/protobuf.dart';
  4. import 'package:easy_localization/easy_localization.dart';
  5. import 'package:flutter_test/flutter_test.dart';
  6. import 'package:integration_test/integration_test.dart';
  7. import '../util/ime.dart';
  8. import '../util/util.dart';
  9. void main() {
  10. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  11. group('outline block test', () {
  12. const location = 'outline_test';
  13. setUp(() async {
  14. await TestFolder.cleanTestLocation(location);
  15. await TestFolder.setTestLocation(location);
  16. });
  17. tearDown(() async {
  18. await TestFolder.cleanTestLocation(null);
  19. });
  20. testWidgets('insert an outline block', (tester) async {
  21. await tester.initializeAppFlowy();
  22. await tester.tapGoButton();
  23. await tester.createNewPageWithName(
  24. ViewLayoutPB.Document,
  25. 'outline_test',
  26. );
  27. await tester.editor.tapLineOfEditorAt(0);
  28. await insertOutlineInDocument(tester);
  29. // validate the outline is inserted
  30. expect(find.byType(OutlineBlockWidget), findsOneWidget);
  31. });
  32. testWidgets('insert an outline block and check if headings are visible',
  33. (tester) async {
  34. await tester.initializeAppFlowy();
  35. await tester.tapGoButton();
  36. await tester.createNewPageWithName(
  37. ViewLayoutPB.Document,
  38. 'outline_test',
  39. );
  40. await tester.editor.tapLineOfEditorAt(0);
  41. await tester.ime.insertText('# Heading 1\n');
  42. await tester.ime.insertText('## Heading 2\n');
  43. await tester.ime.insertText('### Heading 3\n');
  44. /* Results in:
  45. * # Heading 1
  46. * ## Heading 2
  47. * ### Heading 3
  48. */
  49. await tester.editor.tapLineOfEditorAt(3);
  50. await insertOutlineInDocument(tester);
  51. expect(
  52. find.descendant(
  53. of: find.byType(OutlineBlockWidget),
  54. matching: find.text('Heading 1'),
  55. ),
  56. findsOneWidget,
  57. );
  58. // Heading 2 is prefixed with a bullet
  59. expect(
  60. find.descendant(
  61. of: find.byType(OutlineBlockWidget),
  62. matching: find.text('Heading 2'),
  63. ),
  64. findsOneWidget,
  65. );
  66. // Heading 3 is prefixed with a dash
  67. expect(
  68. find.descendant(
  69. of: find.byType(OutlineBlockWidget),
  70. matching: find.text('Heading 3'),
  71. ),
  72. findsOneWidget,
  73. );
  74. // update the Heading 1 to Heading 1Hello world
  75. await tester.editor.tapLineOfEditorAt(0);
  76. await tester.ime.insertText('Hello world');
  77. expect(
  78. find.descendant(
  79. of: find.byType(OutlineBlockWidget),
  80. matching: find.text('Heading 1Hello world'),
  81. ),
  82. findsOneWidget,
  83. );
  84. });
  85. });
  86. }
  87. /// Inserts an outline block in the document
  88. Future<void> insertOutlineInDocument(WidgetTester tester) async {
  89. // open the actions menu and insert the outline block
  90. await tester.editor.showSlashMenu();
  91. await tester.editor.tapSlashMenuItemWithName(
  92. LocaleKeys.document_selectionMenu_outline.tr(),
  93. );
  94. await tester.pumpAndSettle();
  95. }