@@ -68,11 +68,13 @@ const GithubEntry _notesEntry = GithubEntry(
6868
6969final class _GoldenGithubApi implements GithubApi {
7070 _GoldenGithubApi ({
71+ this .branchFailure,
7172 this .resolveFailure,
7273 this .childListGate,
7374 this .entries = _defaultEntries,
7475 });
7576
77+ final GithubFailure ? branchFailure;
7678 final GithubFailure ? resolveFailure;
7779 final Completer <void >? childListGate;
7880 final List <GithubEntry > entries;
@@ -91,6 +93,22 @@ final class _GoldenGithubApi implements GithubApi {
9193 'gamma.py' : Uint8List .fromList (utf8.encode ("print('gamma')\n " )),
9294 };
9395
96+ @override
97+ Future <GithubBranchCatalog > listBranches (
98+ RepositoryLocator locator, {
99+ GithubCancellation ? cancellation,
100+ }) async {
101+ if (branchFailure case final GithubFailure failure) throw failure;
102+ if (cancellation? .isCancelled ?? false ) {
103+ throw const GithubFailure (GithubFailureKind .cancelled);
104+ }
105+ return GithubBranchCatalog (
106+ locator: locator,
107+ defaultBranch: 'main' ,
108+ branches: const < String > ['main' , 'release/v1' ],
109+ );
110+ }
111+
94112 @override
95113 Future <PinnedRepository > resolve (
96114 RepositoryLocator locator, {
@@ -233,10 +251,14 @@ Future<void> _openImporter(WidgetTester tester) async {
233251}
234252
235253Future <void > _browseRepository (WidgetTester tester) async {
236- await tester.enterText (
237- find.byKey (kGithubRepositoryFieldKey),
238- 'https://github.com/PyBLE-dev/examples' ,
254+ expect (
255+ tester
256+ .widget <TextField >(find.byKey (kGithubRepositoryFieldKey))
257+ .controller
258+ ? .text,
259+ kOfficialExamplesRepositoryUrl,
239260 );
261+ expect (find.byKey (kGithubBranchDropdownKey), findsOneWidget);
240262 await tester.tap (find.byKey (kGithubBrowseButtonKey));
241263 await tester.pumpAndSettle ();
242264}
@@ -258,6 +280,44 @@ Future<void> _expectGolden(WidgetTester tester, String name) => expectLater(
258280
259281void main () {
260282 group ('A-33 GitHub import adaptive goldens' , () {
283+ testWidgets (
284+ 'wide dialog starts with the editable official repository and default branch' ,
285+ (WidgetTester tester) async {
286+ final RecordingConnection connection = RecordingConnection (
287+ initial: ConnState .ready,
288+ );
289+ final _GoldenGithubApi api = _GoldenGithubApi ();
290+ addTearDown (connection.dispose);
291+
292+ await _pumpGoldenHost (
293+ tester,
294+ connection: connection,
295+ api: api,
296+ size: const Size (1024 , 768 ),
297+ );
298+ await _openImporter (tester);
299+
300+ final TextField repositoryField = tester.widget <TextField >(
301+ find.byKey (kGithubRepositoryFieldKey),
302+ );
303+ expect (
304+ repositoryField.controller? .text,
305+ kOfficialExamplesRepositoryUrl,
306+ );
307+ expect (repositoryField.enabled, isNot (false ));
308+ expect (find.byKey (kGithubBranchDropdownKey), findsOneWidget);
309+ await tester.tap (find.byKey (kGithubBranchDropdownKey));
310+ await tester.pumpAndSettle ();
311+ expect (find.textContaining ('main' ), findsWidgets);
312+ expect (find.text ('release/v1' ), findsOneWidget);
313+ expect (connection.putFileCalls, isEmpty);
314+ expect (connection.runFileCalls, isEmpty);
315+ expect (connection.runSourceCalls, isEmpty);
316+ await _expectGolden (tester, 'github_import_wide_branch_chooser' );
317+ },
318+ tags: const < String > ['golden' ],
319+ );
320+
261321 testWidgets (
262322 'wide dialog retains context while a child folder loads' ,
263323 (WidgetTester tester) async {
@@ -394,7 +454,7 @@ void main() {
394454 initial: ConnState .ready,
395455 );
396456 final _GoldenGithubApi api = _GoldenGithubApi (
397- resolveFailure : const GithubFailure (
457+ branchFailure : const GithubFailure (
398458 GithubFailureKind .rateLimited,
399459 rateLimitRemaining: 0 ,
400460 retryAfter: Duration (seconds: 120 ),
@@ -411,12 +471,7 @@ void main() {
411471 highContrast: true ,
412472 );
413473 await _openImporter (tester);
414- await tester.enterText (
415- find.byKey (kGithubRepositoryFieldKey),
416- 'https://github.com/PyBLE-dev/examples' ,
417- );
418474 tester.view.viewInsets = const FakeViewPadding (bottom: 440 );
419- await tester.tap (find.byKey (kGithubBrowseButtonKey));
420475 await tester.pumpAndSettle ();
421476
422477 expect (find.byType (BottomSheet ), findsOneWidget);
@@ -493,7 +548,7 @@ void main() {
493548 find.byKey (kGithubRepositoryFieldKey),
494549 'https://github.com/PyBLE-dev/PyBLE/tree/main' ,
495550 );
496- await tester.tap (find.byKey (kGithubBrowseButtonKey ));
551+ await tester.tap (find.byKey (kGithubLoadBranchesButtonKey ));
497552 await tester.pumpAndSettle ();
498553
499554 expect (find.byType (BottomSheet ), findsOneWidget);
0 commit comments