Skip to content

Commit 1ed3766

Browse files
committed
[red] cover official repository branch chooser
Signed-off-by: Viwat Vchirawongkwin <viwat.v@chula.ac.th>
1 parent 0eb28f3 commit 1ed3766

4 files changed

Lines changed: 778 additions & 29 deletions

File tree

‎app/test/golden/github_import_golden_test.dart‎

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ const GithubEntry _notesEntry = GithubEntry(
6868

6969
final 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

235253
Future<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

259281
void 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);

‎app/test/integration/github_import_integration_test.dart‎

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,21 @@ final class _RestBlobFixture {
117117
final String mode;
118118
}
119119

120-
http.Response _jsonResponse(Map<String, Object?> body) => http.Response(
120+
http.Response _jsonResponse(Object? body) => http.Response(
121121
jsonEncode(body),
122122
200,
123123
headers: const <String, String>{'content-type': 'application/json'},
124124
);
125125

126-
void _expectUnauthenticatedApiRequest(http.Request request) {
126+
void _expectUnauthenticatedApiRequest(
127+
http.Request request, {
128+
Map<String, String> queryParameters = const <String, String>{},
129+
}) {
127130
expect(request.method, 'GET');
128131
expect(request.url.scheme, 'https');
129132
expect(request.url.host, 'api.github.com');
130133
expect(request.url.hasPort, isFalse);
131-
expect(request.url.query, isEmpty);
134+
expect(request.url.queryParameters, queryParameters);
132135
expect(request.followRedirects, isFalse);
133136
expect(request.maxRedirects, 0);
134137
expect(request.headers['Accept'], 'application/vnd.github+json');
@@ -271,11 +274,32 @@ void main() {
271274
int refreshCount = 0;
272275

273276
final MockClient httpClient = MockClient((http.Request request) async {
274-
_expectUnauthenticatedApiRequest(request);
275277
final String path = request.url.path;
278+
_expectUnauthenticatedApiRequest(
279+
request,
280+
queryParameters:
281+
path == '/repos/PyBLE-dev/integration-fixture/branches'
282+
? const <String, String>{'per_page': '100', 'page': '1'}
283+
: const <String, String>{},
284+
);
276285
requestedPaths.add(path);
277286
operations.add('http:$path');
278287

288+
if (path == '/repos/PyBLE-dev/integration-fixture') {
289+
return _jsonResponse(<String, Object?>{'default_branch': 'moving'});
290+
}
291+
if (path == '/repos/PyBLE-dev/integration-fixture/branches') {
292+
return _jsonResponse(<Object?>[
293+
<String, Object?>{
294+
'name': 'release/v1',
295+
'commit': <String, Object?>{'sha': _commitSha},
296+
},
297+
<String, Object?>{
298+
'name': 'moving',
299+
'commit': <String, Object?>{'sha': _commitSha},
300+
},
301+
]);
302+
}
279303
if (path == '/repos/PyBLE-dev/integration-fixture/commits/moving') {
280304
movingRefResolutions += 1;
281305
return _jsonResponse(<String, Object?>{
@@ -366,9 +390,14 @@ void main() {
366390
final RepositoryLocator locator = RepositoryLocator.parse(
367391
'https://github.com/PyBLE-dev/integration-fixture',
368392
);
393+
final GithubBranchCatalog catalog = await api.listBranches(locator);
394+
expect(catalog.locator, same(locator));
395+
expect(catalog.defaultBranch, 'moving');
396+
expect(catalog.branches, <String>['moving', 'release/v1']);
397+
369398
final PinnedRepository repository = await api.resolve(
370399
locator,
371-
ref: 'moving',
400+
ref: catalog.defaultBranch,
372401
);
373402
expect(repository.requestedRef, 'moving');
374403
expect(repository.resolvedRef, 'moving');
@@ -434,6 +463,8 @@ void main() {
434463
expect(result.failure, isNull);
435464
expect(movingRefResolutions, 1);
436465
expect(requestedPaths, <String>[
466+
'/repos/PyBLE-dev/integration-fixture',
467+
'/repos/PyBLE-dev/integration-fixture/branches',
437468
'/repos/PyBLE-dev/integration-fixture/commits/moving',
438469
'/repos/PyBLE-dev/integration-fixture/git/trees/$_rootTreeSha',
439470
'/repos/PyBLE-dev/integration-fixture/git/trees/'

0 commit comments

Comments
 (0)