|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_bloc_app_template/main.dart' as app; |
| 3 | +import 'package:flutter_test/flutter_test.dart'; |
| 4 | +import 'package:integration_test/integration_test.dart'; |
| 5 | + |
| 6 | +void main() { |
| 7 | + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); |
| 8 | + |
| 9 | + setUp(() {}); |
| 10 | + |
| 11 | + testWidgets('settings test', ( |
| 12 | + WidgetTester tester, |
| 13 | + ) async { |
| 14 | + app.main([]); |
| 15 | + await tester.pumpAndSettle(); |
| 16 | + |
| 17 | + expect(find.byKey(const Key('settings')), findsOneWidget); |
| 18 | + |
| 19 | + await tester.tap(find.byTooltip('Settings')); |
| 20 | + |
| 21 | + await tester.pumpAndSettle(); |
| 22 | + |
| 23 | + expect(find.textContaining('Appearance'), findsAtLeast(1)); |
| 24 | + |
| 25 | + await tester.tap(find.byKey(const Key('appearance'))); |
| 26 | + await tester.pumpAndSettle(); |
| 27 | + expect(find.text('Appearance'), findsOneWidget); |
| 28 | + expect(find.text('Theme mode'), findsOneWidget); |
| 29 | + |
| 30 | + await tester.tap(find.byKey(const Key('theme_mode_preference_switch'))); |
| 31 | + await tester.pumpAndSettle(); |
| 32 | + |
| 33 | + expect(find.text('Dark'), findsOneWidget); |
| 34 | + expect(find.text('Light'), findsOneWidget); |
| 35 | + expect(find.text('System default'), findsOneWidget); |
| 36 | + |
| 37 | + await tester.tap(find.byKey(const Key('Dark'))); |
| 38 | + await tester.pumpAndSettle(); |
| 39 | + |
| 40 | + final darkBackgroundFinder = find.byWidgetPredicate( |
| 41 | + (widget) { |
| 42 | + return widget.key == const Key('ThemeMode.dark'); |
| 43 | + }, |
| 44 | + ); |
| 45 | + expect(darkBackgroundFinder, findsWidgets); |
| 46 | + |
| 47 | + await tester.tap(find.byKey(const Key('Light'))); |
| 48 | + await tester.pumpAndSettle(); |
| 49 | + |
| 50 | + final lightBackgroundFinder = find.byWidgetPredicate( |
| 51 | + (widget) { |
| 52 | + return widget.key == const Key('ThemeMode.light'); |
| 53 | + }, |
| 54 | + ); |
| 55 | + expect(lightBackgroundFinder, findsWidgets); |
| 56 | + |
| 57 | + await tester.tap(find.byKey(const Key('System default'))); |
| 58 | + await tester.pumpAndSettle(); |
| 59 | + |
| 60 | + final defaultBackgroundFinder = find.byWidgetPredicate( |
| 61 | + (widget) { |
| 62 | + return widget.key == const Key('ThemeMode.system'); |
| 63 | + }, |
| 64 | + ); |
| 65 | + expect(defaultBackgroundFinder, findsWidgets); |
| 66 | + |
| 67 | + await tester.tap(find.byTooltip('Back')); |
| 68 | + await tester.pumpAndSettle(); |
| 69 | + |
| 70 | + final switchFinder = find.byKey(const Key('theme_mode_switch')); |
| 71 | + expect(switchFinder, findsOneWidget); |
| 72 | + |
| 73 | + await tester.tap(switchFinder); |
| 74 | + await tester.pumpAndSettle(); |
| 75 | + |
| 76 | + expect(darkBackgroundFinder, findsWidgets); |
| 77 | + }); |
| 78 | +} |
0 commit comments