From 39709e5c4214ccdc0237850a5c780c7e4a97a9f5 Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Tue, 26 May 2026 23:00:44 +0200 Subject: [PATCH] test(tv): update keyboard focus expectations --- .../add_local_profile_screen_test.dart | 22 ++++++++++---- .../profile/profile_detail_screen_test.dart | 7 +++++ .../settings/add_jellyfin_screen_test.dart | 29 ++++++++----------- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/test/screens/profile/add_local_profile_screen_test.dart b/test/screens/profile/add_local_profile_screen_test.dart index 477bb20b..3d388192 100644 --- a/test/screens/profile/add_local_profile_screen_test.dart +++ b/test/screens/profile/add_local_profile_screen_test.dart @@ -30,6 +30,12 @@ void main() { ); await tester.pumpAndSettle(); + expect(FocusManager.instance.primaryFocus?.debugLabel, 'TvVirtualKeyboard'); + expect(find.byKey(const Key('tv_virtual_keyboard_panel')), findsOneWidget); + + await tester.sendKeyEvent(LogicalKeyboardKey.gameButtonB); + await tester.pumpAndSettle(); + expect(FocusManager.instance.primaryFocus?.debugLabel, 'AddLocalProfile:Name'); await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); @@ -45,7 +51,7 @@ void main() { expect(FocusManager.instance.primaryFocus?.debugLabel, 'AddLocalProfile:Cancel'); }); - testWidgets('Android TV native keyboard done leaves profile name input', (tester) async { + testWidgets('Android TV virtual keyboard done leaves profile name input', (tester) async { TvDetectionService.debugSetAppleTVOverride(null); await TvDetectionService.getInstance(forceTv: true); TvDetectionService.setForceTVSync(true); @@ -57,11 +63,10 @@ void main() { ); await tester.pumpAndSettle(); - expect(FocusManager.instance.primaryFocus?.debugLabel, 'AddLocalProfile:Name'); + expect(FocusManager.instance.primaryFocus?.debugLabel, 'TvVirtualKeyboard'); - await tester.showKeyboard(find.byType(TextField)); - await tester.testTextInput.receiveAction(TextInputAction.done); - await tester.pump(); + await tester.tap(find.byIcon(Icons.check_rounded)); + await tester.pumpAndSettle(); expect(FocusManager.instance.primaryFocus?.debugLabel, 'AddLocalProfile:SetPin'); }); @@ -90,6 +95,13 @@ void main() { await tester.tap(find.text('Open new profile')); await tester.pumpAndSettle(); expect(find.text(t.profiles.newProfile), findsOneWidget); + expect(find.byKey(const Key('tv_virtual_keyboard_panel')), findsOneWidget); + + await tester.sendKeyEvent(LogicalKeyboardKey.gameButtonB); + await tester.pumpAndSettle(); + + expect(find.text(t.profiles.newProfile), findsOneWidget); + expect(find.byKey(const Key('tv_virtual_keyboard_panel')), findsNothing); await tester.sendKeyEvent(LogicalKeyboardKey.gameButtonB); await tester.pumpAndSettle(); diff --git a/test/screens/profile/profile_detail_screen_test.dart b/test/screens/profile/profile_detail_screen_test.dart index 4b6fd8c0..e7fb0f33 100644 --- a/test/screens/profile/profile_detail_screen_test.dart +++ b/test/screens/profile/profile_detail_screen_test.dart @@ -85,6 +85,13 @@ void main() { await tester.tap(find.text('Open profile')); await tester.pumpAndSettle(); expect(find.text(t.profiles.connectionsLabel), findsOneWidget); + expect(find.byKey(const Key('tv_virtual_keyboard_panel')), findsOneWidget); + + await tester.sendKeyEvent(LogicalKeyboardKey.gameButtonB); + await tester.pumpAndSettle(); + + expect(find.text(t.profiles.connectionsLabel), findsOneWidget); + expect(find.byKey(const Key('tv_virtual_keyboard_panel')), findsNothing); await tester.sendKeyEvent(LogicalKeyboardKey.gameButtonB); await tester.pumpAndSettle(); diff --git a/test/screens/settings/add_jellyfin_screen_test.dart b/test/screens/settings/add_jellyfin_screen_test.dart index f4b4dd95..3870225e 100644 --- a/test/screens/settings/add_jellyfin_screen_test.dart +++ b/test/screens/settings/add_jellyfin_screen_test.dart @@ -1,5 +1,3 @@ -import 'dart:ui' as ui; - import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -26,16 +24,17 @@ void main() { expect(field.autofocus, isTrue); }); - testWidgets('TV initial focus stays on the server URL field', (tester) async { + testWidgets('TV initial focus opens the server URL keyboard', (tester) async { TvDetectionService.debugSetAppleTVOverride(true); await tester.pumpWidget(const InputModeTracker(child: MaterialApp(home: AddJellyfinScreen()))); await tester.pumpAndSettle(); - expect(FocusManager.instance.primaryFocus?.debugLabel, 'AddJellyfin:Url'); + expect(FocusManager.instance.primaryFocus?.debugLabel, 'TvVirtualKeyboard'); + expect(find.byKey(const Key('tv_virtual_keyboard_panel')), findsOneWidget); }); - testWidgets('Android TV remote navigation stays with native URL keyboard', (tester) async { + testWidgets('Android TV remote navigation stays with virtual URL keyboard', (tester) async { TvDetectionService.debugSetAppleTVOverride(null); await TvDetectionService.getInstance(forceTv: true); TvDetectionService.setForceTVSync(true); @@ -43,21 +42,17 @@ void main() { await tester.pumpWidget(const InputModeTracker(child: MaterialApp(home: AddJellyfinScreen()))); await tester.pumpAndSettle(); - final urlFocus = FocusManager.instance.primaryFocus!; - expect(urlFocus.debugLabel, 'AddJellyfin:Url'); + expect(FocusManager.instance.primaryFocus?.debugLabel, 'TvVirtualKeyboard'); - final result = urlFocus.onKeyEvent!( - urlFocus, - const KeyDownEvent( - physicalKey: PhysicalKeyboardKey.arrowDown, - logicalKey: LogicalKeyboardKey.arrowDown, - timeStamp: Duration.zero, - deviceType: ui.KeyEventDeviceType.directionalPad, - ), - ); + await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); await tester.pump(); - expect(result, KeyEventResult.skipRemainingHandlers); + expect(FocusManager.instance.primaryFocus?.debugLabel, 'TvVirtualKeyboard'); + expect(find.byKey(const Key('tv_virtual_keyboard_panel')), findsOneWidget); + + await tester.sendKeyEvent(LogicalKeyboardKey.gameButtonB); + await tester.pumpAndSettle(); + expect(FocusManager.instance.primaryFocus?.debugLabel, 'AddJellyfin:Url'); });