import 'package:cutdex_ui/theme.dart'; import 'package:cutdex_ui/widgets.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { testWidgets( 'dialog fits small screens and restores trigger focus on escape', (tester) async { tester.view.physicalSize = const Size(320, 400); tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); final focus = FocusNode(); addTearDown(focus.dispose); for (final theme in [AppTheme.penLight, AppTheme.penDark]) { await tester.pumpWidget( MaterialApp( theme: theme, home: Scaffold( body: Builder( builder: (context) => TextButton( focusNode: focus, onPressed: () => showAppDialog( context: context, builder: (_) => AppDialog( title: 'Settings', width: 1040, height: 680, actions: [ TextButton(onPressed: () {}, child: const Text('Save')), ], child: Column( children: List.generate( 12, (index) => AppField( label: 'Field $index', error: index == 0 ? 'Invalid' : null, orientation: AppFieldOrientation.horizontal, child: const TextField(), ), ), ), ), ), child: const Text('Open'), ), ), ), ), ); focus.requestFocus(); await tester.pump(); await tester.sendKeyEvent(LogicalKeyboardKey.enter); await tester.pumpAndSettle(); expect(find.text('Settings'), findsOneWidget); expect( tester.getRect(find.byType(Dialog)).right, lessThanOrEqualTo(320), ); expect(tester.takeException(), isNull); await tester.sendKeyEvent(LogicalKeyboardKey.escape); await tester.pumpAndSettle(); expect(find.text('Settings'), findsNothing); expect(focus.hasFocus, isTrue); } }, ); testWidgets('tabs navigate enabled options and switch supports keyboard', ( tester, ) async { var tab = 0; var enabled = false; final focus = FocusNode(); addTearDown(focus.dispose); await tester.pumpWidget( MaterialApp( theme: AppTheme.penDark, home: Scaffold( body: StatefulBuilder( builder: (context, update) => Column( children: [ AppTabs( tabs: const [ AppTab(0, 'General'), AppTab(1, 'Disabled', enabled: false), AppTab(2, 'MCP'), ], value: tab, onChanged: (value) => update(() => tab = value), ), AppSwitch( value: enabled, focusNode: focus, semanticLabel: 'Service', onChanged: (value) => update(() => enabled = value), ), ], ), ), ), ), ); await tester.tap(find.text('General')); await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); await tester.pump(); expect(tab, 2); await tester.sendKeyEvent(LogicalKeyboardKey.home); await tester.pump(); expect(tab, 0); focus.requestFocus(); await tester.pump(); await tester.sendKeyEvent(LogicalKeyboardKey.space); await tester.pumpAndSettle(); expect(enabled, isTrue); expect(tester.takeException(), isNull); }); }