feat(test): updated tests to increase tests coverage

This commit is contained in:
misha
2026-05-06 14:12:34 +03:00
parent fe243965e3
commit 54c27c28cd
10 changed files with 930 additions and 9 deletions

View File

@@ -704,6 +704,144 @@ void main() {
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)'));
});
});
}