| 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:flutter_localizations/flutter_localizations.dart'; |
| 3 | import 'package:flutter_test/flutter_test.dart'; |
| 4 | import 'package:localmind/features/sidebar/components/github_repo_card.dart'; |
| 5 | import 'package:localmind/l10n/app_localizations.dart'; |
| 6 | |
| 7 | void main() { |
| 8 | TestWidgetsFlutterBinding.ensureInitialized(); |
| 9 | |
| 10 | Widget createWidgetUnderTest() { |
| 11 | return const MaterialApp( |
| 12 | localizationsDelegates: [ |
| 13 | AppLocalizations.delegate, |
| 14 | GlobalMaterialLocalizations.delegate, |
| 15 | GlobalWidgetsLocalizations.delegate, |
| 16 | GlobalCupertinoLocalizations.delegate, |
| 17 | ], |
| 18 | supportedLocales: AppLocalizations.supportedLocales, |
| 19 | home: Scaffold(body: Center(child: GitHubRepoCard())), |
| 20 | ); |
| 21 | } |
| 22 | |
| 23 | testWidgets('GitHubRepoCard renders title and star prompt', (tester) async { |
| 24 | await tester.pumpWidget(createWidgetUnderTest()); |
| 25 | await tester.pumpAndSettle(); |
| 26 | |
| 27 | expect(find.text('Open Source'), findsOneWidget); |
| 28 | expect(find.text('Star on GitHub'), findsOneWidget); |
| 29 | }); |
| 30 | |
| 31 | testWidgets( |
| 32 | 'GitHubRepoCard does not throw an unhandled exception when tapped', |
| 33 | (tester) async { |
| 34 | // In the test environment there is no native URL launcher. The try/catch |
| 35 | // in _launchUrl must swallow any failure so the app does not crash. |
| 36 | await tester.pumpWidget(createWidgetUnderTest()); |
| 37 | await tester.pumpAndSettle(); |
| 38 | |
| 39 | await tester.tap(find.byType(GitHubRepoCard)); |
| 40 | await tester.pumpAndSettle(); |
| 41 | |
| 42 | // The core regression: no unhandled exception must reach the framework. |
| 43 | expect(tester.takeException(), isNull); |
| 44 | }, |
| 45 | ); |
| 46 | } |