| 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:flutter_riverpod/flutter_riverpod.dart'; |
| 3 | import 'package:flutter_test/flutter_test.dart'; |
| 4 | import 'package:localmind/core/theme/app_theme.dart'; |
| 5 | import 'package:localmind/features/onboarding/screens/onboarding_server_type_screen.dart'; |
| 6 | import 'package:localmind/features/servers/views/components/https_scheme_hint.dart'; |
| 7 | import 'package:localmind/l10n/app_localizations.dart'; |
| 8 | import 'package:shadcn_ui/shadcn_ui.dart'; |
| 9 | |
| 10 | Widget _wrapWithApp(Widget child) { |
| 11 | return ProviderScope( |
| 12 | child: ShadTheme( |
| 13 | data: AppTheme.lightShadTheme, |
| 14 | child: MaterialApp( |
| 15 | locale: const Locale('en'), |
| 16 | localizationsDelegates: AppLocalizations.localizationsDelegates, |
| 17 | supportedLocales: AppLocalizations.supportedLocales, |
| 18 | home: child, |
| 19 | ), |
| 20 | ), |
| 21 | ); |
| 22 | } |
| 23 | |
| 24 | void main() { |
| 25 | testWidgets('shows OpenAI Compatible on the onboarding server picker', ( |
| 26 | tester, |
| 27 | ) async { |
| 28 | await tester.pumpWidget(_wrapWithApp(const OnboardingServerTypeScreen())); |
| 29 | await tester.pumpAndSettle(); |
| 30 | |
| 31 | expect(find.text('OpenAI Compatible'), findsWidgets); |
| 32 | expect(find.text('Add more'), findsOneWidget); |
| 33 | expect(find.text('on GitHub'), findsOneWidget); |
| 34 | }); |
| 35 | |
| 36 | testWidgets('shows the HTTPS hint only for https hosts', (tester) async { |
| 37 | final controller = TextEditingController(); |
| 38 | addTearDown(controller.dispose); |
| 39 | |
| 40 | await tester.pumpWidget( |
| 41 | _wrapWithApp(Material(child: HttpsSchemeHint(controller: controller))), |
| 42 | ); |
| 43 | |
| 44 | expect(find.text('HTTPS requires SSL'), findsNothing); |
| 45 | expect(find.text('Most local setups use http://'), findsNothing); |
| 46 | |
| 47 | controller.text = 'https://localhost:1234'; |
| 48 | await tester.pump(); |
| 49 | |
| 50 | expect(find.text('HTTPS requires SSL'), findsOneWidget); |
| 51 | expect(find.text('Most local setups use http://'), findsOneWidget); |
| 52 | |
| 53 | controller.text = 'http://localhost:1234'; |
| 54 | await tester.pump(); |
| 55 | |
| 56 | expect(find.text('HTTPS requires SSL'), findsNothing); |
| 57 | expect(find.text('Most local setups use http://'), findsNothing); |
| 58 | }); |
| 59 | } |