import 'package:cutdex/app/editor_theme.dart'; import 'package:cutdex/l10n/app_localizations.dart'; import 'package:cutdex_ui/widgets.dart'; import 'package:cutdex/shared/widgets/drop_to_add_overlay.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { testWidgets( 'theme switches preserve combobox query, focus and control styles', (tester) async { var selected = 0; Future mount(ThemeData theme) async { await tester.pumpWidget( MaterialApp( theme: theme, localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, home: Scaffold( body: SizedBox( width: 300, child: Column( children: [ AppTabs( tabs: const [AppTab(0, 'General'), AppTab(1, 'Other')], value: 0, onChanged: (_) {}, ), AppCombobox( emptyLabel: 'No matching options', searchHint: 'Search options', label: 'Choice', value: selected, options: const [ AppSelectOption(0, 'Alpha'), AppSelectOption(1, 'Beta'), ], onChanged: (value) => selected = value, ), AppSwitch(value: false, onChanged: (_) {}), const ResourceDownloadProgress( downloadedBytes: 0, totalBytes: 1000, status: '', ), const SizedBox(height: 40, child: DropToAddOverlay()), ], ), ), ), ), ); await tester.pumpAndSettle(); } await mount(EditorTheme.penLight); final combo = find.byType(AppCombobox); final initialState = tester.state(combo); final input = find.descendant( of: combo, matching: find.byType(TextField), ); await tester.tap(input); await tester.enterText(input, 'Bet'); await tester.pumpAndSettle(); for (final (theme, background, border, label, scrim, track, thumb) in [ ( EditorTheme.penDark, const Color(0xFF3F3F46).withValues(alpha: .3), const Color(0xFFFCFCFC).withValues(alpha: .084), const Color(0xFFFCFCFC).withValues(alpha: .55), Colors.black.withValues(alpha: .62), const Color(0x1AC8C8C8), const Color(0xFFFCFCFC), ), ( EditorTheme.penLight, Colors.transparent, Colors.transparent, const Color(0xFF71717A), Colors.black.withValues(alpha: .38), const Color(0x0A020202), const Color(0xFF020202), ), ]) { await mount(theme); expect(tester.state(combo), same(initialState)); final field = tester.widget(input); expect(field.controller!.text, 'Bet'); expect(field.focusNode!.hasFocus, isTrue); expect(find.text('Beta'), findsOneWidget); final container = tester.widget( find.descendant(of: combo, matching: find.byType(Container)).first, ); expect((container.decoration! as BoxDecoration).color, background); final tab = tester.widget( find.widgetWithText(TextButton, 'General'), ); expect(tab.style!.side!.resolve({})!.color, border); final progressLabel = tester.widget( find.descendant( of: find.byType(ResourceDownloadProgress), matching: find.byType(Text), ), ); expect(progressLabel.style!.color, label); final overlay = tester.widget( find.descendant( of: find.byType(DropToAddOverlay), matching: find.byType(ColoredBox), ), ); expect(overlay.color, scrim); final switchTrack = tester.widget( find .descendant( of: find.byType(AppSwitch), matching: find.byType(AnimatedContainer), ) .first, ); expect((switchTrack.decoration! as BoxDecoration).color, track); final switchThumb = tester .widgetList( find.descendant( of: find.byType(AppSwitch), matching: find.byType(DecoratedBox), ), ) .firstWhere( (box) => (box.decoration as BoxDecoration).shape == BoxShape.circle, ); expect((switchThumb.decoration as BoxDecoration).color, thumb); expect(tester.takeException(), isNull); } await tester.sendKeyEvent(LogicalKeyboardKey.enter); await tester.pumpAndSettle(); expect(selected, 1); }, ); }