|
9 | 9 |
|
10 | 10 | import 'dart:async'; |
11 | 11 | import 'dart:convert'; |
12 | | -import 'dart:typed_data'; |
13 | 12 |
|
14 | 13 | import 'package:flutter/material.dart'; |
15 | 14 | import 'package:flutter_riverpod/flutter_riverpod.dart'; |
| 15 | +import 'package:flutter/services.dart'; |
16 | 16 | import 'package:flutter_test/flutter_test.dart'; |
17 | 17 |
|
18 | 18 | import 'package:pyble/files/files.dart'; |
@@ -245,6 +245,17 @@ Future<void> _browse( |
245 | 245 | await tester.pumpAndSettle(); |
246 | 246 | } |
247 | 247 |
|
| 248 | +Future<void> _activateButtonWithEnter(WidgetTester tester, Key key) async { |
| 249 | + final Finder button = find.byKey(key); |
| 250 | + final Finder label = find.descendant(of: button, matching: find.byType(Text)); |
| 251 | + final FocusNode focusNode = Focus.of(tester.element(label)); |
| 252 | + focusNode.requestFocus(); |
| 253 | + await tester.pump(); |
| 254 | + expect(focusNode.hasFocus, isTrue); |
| 255 | + await tester.sendKeyEvent(LogicalKeyboardKey.enter); |
| 256 | + await tester.pumpAndSettle(); |
| 257 | +} |
| 258 | + |
248 | 259 | void main() { |
249 | 260 | group('A-33 GitHub import — adaptive connected Files workflow', () { |
250 | 261 | testWidgets( |
@@ -331,6 +342,34 @@ void main() { |
331 | 342 | expect(find.byKey(kGithubRefFieldKey), findsOneWidget); |
332 | 343 | }); |
333 | 344 |
|
| 345 | + testWidgets('hardware Enter activates Browse and Review', ( |
| 346 | + WidgetTester tester, |
| 347 | + ) async { |
| 348 | + final RecordingConnection connection = RecordingConnection( |
| 349 | + initial: ConnState.ready, |
| 350 | + ); |
| 351 | + final _FakeGithubApi api = _FakeGithubApi( |
| 352 | + entries: const <GithubEntry>[_helloEntry], |
| 353 | + ); |
| 354 | + addTearDown(connection.dispose); |
| 355 | + |
| 356 | + await _openImport(tester, connection, api); |
| 357 | + await tester.enterText( |
| 358 | + find.byKey(kGithubRepositoryFieldKey), |
| 359 | + 'https://github.com/PyBLE-dev/examples', |
| 360 | + ); |
| 361 | + await _activateButtonWithEnter(tester, kGithubBrowseButtonKey); |
| 362 | + |
| 363 | + expect(api.resolveCalls, hasLength(1)); |
| 364 | + expect(api.listedRemotePaths, <String>['']); |
| 365 | + await tester.tap(find.byKey(_selectionKey('hello.py'))); |
| 366 | + await tester.pump(); |
| 367 | + await _activateButtonWithEnter(tester, kGithubReviewButtonKey); |
| 368 | + |
| 369 | + expect(find.text(l10nOf(tester).githubImportReviewTitle), findsOneWidget); |
| 370 | + expect(connection.putFileCalls, isEmpty); |
| 371 | + }); |
| 372 | + |
334 | 373 | testWidgets( |
335 | 374 | 'an existing target needs a separate localized confirmation; Cancel writes nothing', |
336 | 375 | (WidgetTester tester) async { |
@@ -450,6 +489,20 @@ void main() { |
450 | 489 | hasFocusAction: true, |
451 | 490 | ), |
452 | 491 | ); |
| 492 | + Finder failureLiveRegions() => find.descendant( |
| 493 | + of: failure, |
| 494 | + matching: find.byWidgetPredicate( |
| 495 | + (Widget widget) => |
| 496 | + widget is Semantics && widget.properties.liveRegion == true, |
| 497 | + ), |
| 498 | + ); |
| 499 | + expect(failureLiveRegions(), findsOneWidget); |
| 500 | + final int failureNodeId = tester.getSemantics(failureLiveRegions()).id; |
| 501 | + tester.platformDispatcher.textScaleFactorTestValue = 1.1; |
| 502 | + addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue); |
| 503 | + await tester.pump(); |
| 504 | + expect(failureLiveRegions(), findsOneWidget); |
| 505 | + expect(tester.getSemantics(failureLiveRegions()).id, failureNodeId); |
453 | 506 | expect(find.text(l10nOf(tester).githubImportRetry), findsNothing); |
454 | 507 | expect( |
455 | 508 | tester |
@@ -571,10 +624,23 @@ void main() { |
571 | 624 | const ValueKey<String>('githubImportResult'), |
572 | 625 | ); |
573 | 626 | expect(result, findsOneWidget); |
| 627 | + Finder resultLiveRegions() => find.byWidgetPredicate( |
| 628 | + (Widget widget) => |
| 629 | + widget is Semantics && |
| 630 | + widget.key == const ValueKey<String>('githubImportResult') && |
| 631 | + widget.properties.liveRegion == true, |
| 632 | + ); |
| 633 | + expect(resultLiveRegions(), findsOneWidget); |
574 | 634 | expect( |
575 | 635 | tester.getSemantics(result), |
576 | 636 | matchesSemantics(isLiveRegion: true), |
577 | 637 | ); |
| 638 | + final int resultNodeId = tester.getSemantics(resultLiveRegions()).id; |
| 639 | + tester.platformDispatcher.textScaleFactorTestValue = 1.1; |
| 640 | + addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue); |
| 641 | + await tester.pumpAndSettle(); |
| 642 | + expect(resultLiveRegions(), findsOneWidget); |
| 643 | + expect(tester.getSemantics(resultLiveRegions()).id, resultNodeId); |
578 | 644 | }, |
579 | 645 | ); |
580 | 646 |
|
@@ -712,6 +778,42 @@ void main() { |
712 | 778 | ); |
713 | 779 | }); |
714 | 780 |
|
| 781 | + testWidgets('a size failure identifies its safe repository path', ( |
| 782 | + WidgetTester tester, |
| 783 | + ) async { |
| 784 | + const GithubEntry oversized = GithubEntry( |
| 785 | + name: 'oversized.py', |
| 786 | + remotePath: 'examples/oversized.py', |
| 787 | + kind: GithubEntryKind.regularFile, |
| 788 | + objectSha: _helloBlobSha, |
| 789 | + declaredSize: 21, |
| 790 | + ); |
| 791 | + final RecordingConnection connection = RecordingConnection( |
| 792 | + initial: ConnState.ready, |
| 793 | + ); |
| 794 | + final _FakeGithubApi api = _FakeGithubApi( |
| 795 | + entries: const <GithubEntry>[oversized], |
| 796 | + fetchFailuresRemaining: 1, |
| 797 | + fetchFailure: const GithubFailure( |
| 798 | + GithubFailureKind.fileTooLarge, |
| 799 | + path: 'examples/oversized.py', |
| 800 | + ), |
| 801 | + ); |
| 802 | + addTearDown(connection.dispose); |
| 803 | + |
| 804 | + await _openImport(tester, connection, api); |
| 805 | + await _browse(tester); |
| 806 | + await tester.tap(find.byKey(_selectionKey('examples/oversized.py'))); |
| 807 | + await tester.pump(); |
| 808 | + await tester.tap(find.byKey(kGithubReviewButtonKey)); |
| 809 | + await tester.pumpAndSettle(); |
| 810 | + await tester.tap(find.byKey(kGithubCommitButtonKey)); |
| 811 | + await tester.pumpAndSettle(); |
| 812 | + |
| 813 | + expect(connection.putFileCalls, isEmpty); |
| 814 | + expect(find.textContaining('examples/oversized.py'), findsOneWidget); |
| 815 | + }); |
| 816 | + |
715 | 817 | testWidgets('a rate-limited blob retry waits without writing', ( |
716 | 818 | WidgetTester tester, |
717 | 819 | ) async { |
|
0 commit comments