outline_block_test.dart 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. testWidgets('insert an outline block', (tester) async {
  13. await tester.initializeAppFlowy();
  14. await tester.tapGoButton();
  15. await tester.createNewPageWithName(
  16. ViewLayoutPB.Document,
  17. 'outline_test',
  18. );
  19. await tester.editor.tapLineOfEditorAt(0);
  20. await insertOutlineInDocument(tester);
  21. // validate the outline is inserted
  22. expect(find.byType(OutlineBlockWidget), findsOneWidget);
  23. });
  24. testWidgets('insert an outline block and check if headings are visible',
  25. (tester) async {
  26. await tester.initializeAppFlowy();
  27. await tester.tapGoButton();
  28. await tester.createNewPageWithName(
  29. ViewLayoutPB.Document,
  30. 'outline_test',
  31. );
  32. await tester.editor.tapLineOfEditorAt(0);
  33. await tester.ime.insertText('# Heading 1\n');
  34. await tester.ime.insertText('## Heading 2\n');
  35. await tester.ime.insertText('### Heading 3\n');
  36. /* Results in:
  37. * # Heading 1
  38. * ## Heading 2
  39. * ### Heading 3
  40. */
  41. await tester.editor.tapLineOfEditorAt(3);
  42. await insertOutlineInDocument(tester);
  43. expect(
  44. find.descendant(
  45. of: find.byType(OutlineBlockWidget),
  46. matching: find.text('Heading 1'),
  47. ),
  48. findsOneWidget,
  49. );
  50. // Heading 2 is prefixed with a bullet
  51. expect(
  52. find.descendant(
  53. of: find.byType(OutlineBlockWidget),
  54. matching: find.text('Heading 2'),
  55. ),
  56. findsOneWidget,
  57. );
  58. // Heading 3 is prefixed with a dash
  59. expect(
  60. find.descendant(
  61. of: find.byType(OutlineBlockWidget),
  62. matching: find.text('Heading 3'),
  63. ),
  64. findsOneWidget,
  65. );
  66. // update the Heading 1 to Heading 1Hello world
  67. await tester.editor.tapLineOfEditorAt(0);
  68. await tester.ime.insertText('Hello world');
  69. expect(
  70. find.descendant(
  71. of: find.byType(OutlineBlockWidget),
  72. matching: find.text('Heading 1Hello world'),
  73. ),
  74. findsOneWidget,
  75. );
  76. });
  77. });
  78. }
  79. /// Inserts an outline block in the document
  80. Future<void> insertOutlineInDocument(WidgetTester tester) async {
  81. // open the actions menu and insert the outline block
  82. await tester.editor.showSlashMenu();
  83. await tester.editor.tapSlashMenuItemWithName(
  84. LocaleKeys.document_selectionMenu_outline.tr(),
  85. );
  86. await tester.pumpAndSettle();
  87. }