forked from eatvio/eatvio_app
syn with upstream (#985)
Co-authored-by: misha <mikhail_zakharov_15482356@mail.ru> Co-authored-by: misha <misha@noreply.localhost> Reviewed-on: eatvio/eatvio_app#985
This commit is contained in:
@@ -614,6 +614,234 @@ void main() {
|
||||
// Проверяем, что preview отображается (RichText должен быть)
|
||||
expect(find.byType(RichText), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('preview: маркер списка со звёздочкой', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: MarkdownEditor(
|
||||
initialText: '* Asterisk item',
|
||||
showInlineToolbar: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pump();
|
||||
await tester.tap(find.byIcon(Icons.visibility));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Тело пункта в RichText/TextSpan — find.textContaining не всегда его видит
|
||||
expect(find.byType(RichText), findsWidgets);
|
||||
expect(find.textContaining('•'), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('preview: нумерация из двух цифр', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: MarkdownEditor(
|
||||
initialText: '10. Tenth row',
|
||||
showInlineToolbar: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pump();
|
||||
await tester.tap(find.byIcon(Icons.visibility));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(RichText), findsWidgets);
|
||||
expect(find.textContaining('10.'), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets(' после выхода из preview выполняется отложенный requestFocus', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: MarkdownEditor(
|
||||
initialText: 'focus',
|
||||
showInlineToolbar: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pump();
|
||||
await tester.tap(find.byIcon(Icons.visibility));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byIcon(Icons.edit));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 150));
|
||||
|
||||
expect(find.byType(TextField), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(' снимает разметку ссылки когда выделен markdown-link', (WidgetTester tester) async {
|
||||
String? changed;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: MarkdownEditor(
|
||||
initialText: '[Label](https://example.com)',
|
||||
showInlineToolbar: true,
|
||||
onChanged: (v) => changed = v,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pump();
|
||||
|
||||
final field = tester.widget<TextField>(find.byType(TextField));
|
||||
final controller = field.controller!;
|
||||
controller.selection = TextSelection(baseOffset: 0, extentOffset: controller.text.length);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.link));
|
||||
await tester.pump();
|
||||
|
||||
expect(changed, contains('Label'));
|
||||
expect(changed, isNot(contains('[Label](https://example.com)')));
|
||||
});
|
||||
|
||||
testWidgets('preview: H2 heading renders larger heading style', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: MarkdownEditor(
|
||||
initialText: '## Subtitle',
|
||||
showInlineToolbar: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pump();
|
||||
await tester.tap(find.byIcon(Icons.visibility));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Subtitle'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('preview: H3 heading renders heading text', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: MarkdownEditor(
|
||||
initialText: '### Detail',
|
||||
showInlineToolbar: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pump();
|
||||
await tester.tap(find.byIcon(Icons.visibility));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Detail'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('preview: horizontal rule renders Divider', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: MarkdownEditor(
|
||||
initialText: 'Above\n---\nBelow',
|
||||
showInlineToolbar: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pump();
|
||||
await tester.tap(find.byIcon(Icons.visibility));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(Divider), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('preview: italic span renders inside RichText', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: MarkdownEditor(
|
||||
initialText: 'A *cursive* word',
|
||||
showInlineToolbar: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pump();
|
||||
await tester.tap(find.byIcon(Icons.visibility));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(RichText), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('preview: link span renders inside RichText', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: MarkdownEditor(
|
||||
initialText: 'Visit [the docs](https://example.com)',
|
||||
showInlineToolbar: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pump();
|
||||
await tester.tap(find.byIcon(Icons.visibility));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(RichText), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('toolbar buttons mutate text via onChanged when cursor is set', (WidgetTester tester) async {
|
||||
String? changed;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: MarkdownEditor(
|
||||
initialText: 'plain',
|
||||
showInlineToolbar: true,
|
||||
onChanged: (v) => changed = v,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
final field = tester.widget<TextField>(find.byType(TextField));
|
||||
final controller = field.controller!;
|
||||
controller.selection = const TextSelection.collapsed(offset: 0);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.format_bold));
|
||||
await tester.pump();
|
||||
expect(changed, contains('**'));
|
||||
|
||||
controller.text = 'plain';
|
||||
controller.selection = const TextSelection.collapsed(offset: 0);
|
||||
await tester.tap(find.byIcon(Icons.format_italic));
|
||||
await tester.pump();
|
||||
expect(changed, contains('*'));
|
||||
|
||||
controller.text = 'plain';
|
||||
controller.selection = const TextSelection.collapsed(offset: 0);
|
||||
await tester.tap(find.byIcon(Icons.horizontal_rule));
|
||||
await tester.pump();
|
||||
expect(changed, contains('---'));
|
||||
|
||||
controller.text = 'plain';
|
||||
controller.selection = const TextSelection.collapsed(offset: 0);
|
||||
await tester.tap(find.byIcon(Icons.link));
|
||||
await tester.pump();
|
||||
expect(changed, contains('](url)'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user