markdown support for talk messages
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:marianum_mobile/view/pages/talk/data/talk_markdown.dart';
|
||||
|
||||
void main() {
|
||||
group('markdownToPlainText', () {
|
||||
test('strips emphasis markers', () {
|
||||
expect(
|
||||
markdownToPlainText('**bold** and _italic_ and ~~struck~~'),
|
||||
'bold and italic and struck',
|
||||
);
|
||||
});
|
||||
|
||||
test('drops heading markers', () {
|
||||
expect(markdownToPlainText('# Title'), 'Title');
|
||||
});
|
||||
|
||||
test('reduces links to their label and images to their alt text', () {
|
||||
expect(markdownToPlainText('see [the docs](https://x.y)'), 'see the docs');
|
||||
expect(markdownToPlainText(''), 'a cat');
|
||||
});
|
||||
|
||||
test('flattens lists into one space-separated line', () {
|
||||
expect(markdownToPlainText('- one\n- two\n- three'), 'one two three');
|
||||
});
|
||||
|
||||
test('unwraps inline code without the backticks', () {
|
||||
expect(markdownToPlainText('run `flutter test` now'), 'run flutter test now');
|
||||
});
|
||||
|
||||
test('keeps plain text unchanged', () {
|
||||
expect(markdownToPlainText('just a normal sentence.'), 'just a normal sentence.');
|
||||
});
|
||||
|
||||
test('leaves literal angle brackets intact (no HTML interpretation)', () {
|
||||
expect(markdownToPlainText('a <b>tag</b>'), 'a <b>tag</b>');
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:marianum_mobile/view/pages/talk/widgets/message_markdown.dart';
|
||||
|
||||
Future<void> _pump(WidgetTester tester, String data) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(body: MessageMarkdown(data: data)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('MessageMarkdown – supported subset', () {
|
||||
testWidgets('renders bold, italic and strikethrough text', (tester) async {
|
||||
await _pump(tester, '**bold** _italic_ ~~struck~~');
|
||||
expect(find.textContaining('bold', findRichText: true), findsWidgets);
|
||||
expect(find.textContaining('italic', findRichText: true), findsWidgets);
|
||||
expect(find.textContaining('struck', findRichText: true), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('renders headings without the # markers', (tester) async {
|
||||
await _pump(tester, '# Heading');
|
||||
expect(find.textContaining('Heading', findRichText: true), findsWidgets);
|
||||
expect(find.textContaining('#', findRichText: true), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('renders task-list checkboxes', (tester) async {
|
||||
await _pump(tester, '- [x] done\n- [ ] open');
|
||||
expect(find.byIcon(Icons.check_box_outlined), findsOneWidget);
|
||||
expect(find.byIcon(Icons.check_box_outline_blank), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
group('MessageMarkdown – enforced limits (Rahmen)', () {
|
||||
testWidgets('shows raw HTML literally instead of interpreting it', (
|
||||
tester,
|
||||
) async {
|
||||
await _pump(tester, 'a <b>tag</b> here');
|
||||
// The angle-bracket tags must survive as visible text, never as styling.
|
||||
expect(find.textContaining('<b>', findRichText: true), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('never fetches images, only shows their alt text', (
|
||||
tester,
|
||||
) async {
|
||||
await _pump(tester, '');
|
||||
expect(find.byType(Image), findsNothing);
|
||||
expect(find.textContaining('altText', findRichText: true), findsWidgets);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user