import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:sharedinbox/ui/widgets/secure_email_webview.dart'; void _expectLightMode(String html) { expect(html, contains('color-scheme" content="light"')); expect(html, contains('color-scheme: light')); expect(html, contains('background-color: #ffffff')); expect(html, contains('color: #000000')); } Widget _wrap(Widget child) => MaterialApp( theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo), useMaterial3: true, ), home: Scaffold(body: child), ); void main() { group('buildEmailHtml', () { test('forces light color-scheme to prevent black-on-black in dark mode', () { _expectLightMode(buildEmailHtml('

Hello

')); }); test('includes email body content', () { final html = buildEmailHtml('

Test body

'); expect(html, contains('

Test body

')); }); test('blocks remote images by default', () { final html = buildEmailHtml('

x

'); expect(html, contains('img-src data: blob:')); expect(html, isNot(contains('img-src https:'))); }); test('allows remote images when loadRemoteImages is true', () { final html = buildEmailHtml('

x

', loadRemoteImages: true); expect(html, contains('https: http: data: blob:')); _expectLightMode(html); }); test('prevents horizontal overflow so wide HTML emails are not cut off', () { final html = buildEmailHtml('
x
'); // Body clips overflow so fixed-width email tables don't escape the viewport. expect(html, contains('overflow-x: hidden')); // Tables are forced to full viewport width so fixed pixel widths don't overflow. expect(html, contains('table { width: 100%')); // All elements are capped at viewport width via max-width. expect(html, contains('max-width: 100%')); // Pre-formatted text wraps instead of stretching the page. expect(html, contains('white-space: pre-wrap')); }); }); // On Linux (the test host) the widget falls back to plain text extracted via // htmlToPlain(). These tests exercise that path. group('SecureEmailWebView (Linux plain-text fallback)', () { testWidgets('renders extracted text from HTML', (tester) async { await tester.pumpWidget( _wrap( const SecureEmailWebView( htmlBody: '

Hello world

', ), ), ); expect(find.textContaining('Hello'), findsOneWidget); expect(find.textContaining('world'), findsOneWidget); }); testWidgets('strips HTML tags from body', (tester) async { await tester.pumpWidget( _wrap( const SecureEmailWebView( htmlBody: '

Clean text


More', ), ), ); expect(find.textContaining('<'), findsNothing); expect(find.textContaining('Clean text'), findsOneWidget); }); testWidgets('shows SelectableText widget', (tester) async { await tester.pumpWidget( _wrap(const SecureEmailWebView(htmlBody: '

Test

')), ); expect(find.byType(SelectableText), findsOneWidget); }); testWidgets('toggling loadRemoteImages rebuilds without error', (tester) async { await tester.pumpWidget( _wrap( const SecureEmailWebView(htmlBody: '

Body

'), ), ); await tester.pumpWidget( _wrap( const SecureEmailWebView( htmlBody: '

Body

', loadRemoteImages: true, ), ), ); expect(find.byType(SelectableText), findsOneWidget); }); testWidgets('handles empty HTML body', (tester) async { await tester.pumpWidget( _wrap(const SecureEmailWebView(htmlBody: '')), ); expect(find.byType(SelectableText), findsOneWidget); }); }); }