Merge branch 'main' into flutter/pipeline-stage-deeplink
This commit is contained in:
@@ -49,4 +49,55 @@ void main() {
|
||||
router.closeTemplates();
|
||||
expect(router.route, AppRoute.settings);
|
||||
});
|
||||
|
||||
test('the parser keeps a query and restores it as a query', () async {
|
||||
const parser = AppRouteParser();
|
||||
final route = await parser.parseRouteInformation(
|
||||
RouteInformation(uri: Uri.parse('/runs/77/stage/plan?visit=1')),
|
||||
);
|
||||
expect(route, AppRoute.run.stage(77, 'plan', visit: 1));
|
||||
|
||||
final restored = parser.restoreRouteInformation(route).uri;
|
||||
expect(restored.path, '/runs/77/stage/plan');
|
||||
expect(restored.query, 'visit=1');
|
||||
expect(restored.toString(), '/runs/77/stage/plan?visit=1');
|
||||
// A reload or Back/Forward feeds the restored location straight back in.
|
||||
expect(AppRoute.parse(restored.toString()), route);
|
||||
});
|
||||
|
||||
test('every query route survives a restore and reparse', () {
|
||||
const parser = AppRouteParser();
|
||||
for (final route in [
|
||||
AppRoute.runsForPipeline(7),
|
||||
AppRoute.run.decide(3),
|
||||
AppRoute.run.stage(3, 'plan', visit: 0),
|
||||
AppRoute.run.stage(5, 'build ✓', visit: 4),
|
||||
]) {
|
||||
final uri = parser.restoreRouteInformation(route).uri;
|
||||
expect(uri.toString(), route.path, reason: route.path);
|
||||
expect(uri.path, isNot(contains('%3F')), reason: route.path);
|
||||
expect(AppRoute.parse(uri.toString()), route, reason: route.path);
|
||||
}
|
||||
});
|
||||
|
||||
test('a web launch keeps the path and its query', () {
|
||||
final visit = routeInformationForLocation(
|
||||
Uri.parse('https://example.test/runs/7/stage/plan?visit=2'),
|
||||
);
|
||||
expect(visit.uri.toString(), '/runs/7/stage/plan?visit=2');
|
||||
expect(visit.uri.path, '/runs/7/stage/plan');
|
||||
expect(visit.uri.query, 'visit=2');
|
||||
|
||||
final decide = routeInformationForLocation(
|
||||
Uri.parse('https://example.test/runs/9?action=decide'),
|
||||
);
|
||||
expect(decide.uri.toString(), '/runs/9?action=decide');
|
||||
|
||||
expect(
|
||||
routeInformationForLocation(
|
||||
Uri.parse('https://example.test/'),
|
||||
).uri.toString(),
|
||||
'/',
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import 'dart:convert';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/app_route.dart';
|
||||
import 'package:pipelines_app/application/app_router.dart';
|
||||
import 'package:pipelines_app/application/pipelines_app.dart';
|
||||
import 'package:pipelines_app/application/server_endpoint.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
@@ -84,6 +86,57 @@ Future<void> replyDetail(
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
/// A run whose plan visits are deliberately not in sequence order, so a route
|
||||
/// visit index must follow the recorded sequence, not the reply's row order.
|
||||
Future<void> replyVisitDetail(
|
||||
WidgetTester tester,
|
||||
FakeChannel channel,
|
||||
num id,
|
||||
) async {
|
||||
for (
|
||||
var attempt = 0;
|
||||
attempt < 40 && requestOf(channel, 'get_run') == null;
|
||||
attempt++
|
||||
) {
|
||||
await tester.pump(const Duration(milliseconds: 5));
|
||||
}
|
||||
final request = requestOf(channel, 'get_run')!;
|
||||
expect(request['run_id'], id);
|
||||
channel.incoming.add(
|
||||
jsonEncode({
|
||||
'id': request['id'],
|
||||
'type': 'run',
|
||||
'run_detail': {
|
||||
'id': id,
|
||||
'title': 'Deep link run',
|
||||
'name': 'release',
|
||||
'status': 'succeeded',
|
||||
'graph': {
|
||||
'stages': [
|
||||
{
|
||||
'key': 'plan',
|
||||
'type': 'model',
|
||||
'edges': {'success': 'build'},
|
||||
},
|
||||
{
|
||||
'key': 'build',
|
||||
'type': 'model',
|
||||
'edges': {'success': '#success'},
|
||||
},
|
||||
],
|
||||
},
|
||||
'steps': [
|
||||
{'stage': 'plan', 'sequence': 5, 'status': 'completed'},
|
||||
{'stage': 'build', 'sequence': 2, 'status': 'completed'},
|
||||
{'stage': 'plan', 'sequence': 1, 'status': 'completed'},
|
||||
],
|
||||
},
|
||||
}),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('a /runs/1 boot link opens that run and Back returns to /runs', (
|
||||
tester,
|
||||
@@ -195,4 +248,47 @@ void main() {
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pump();
|
||||
});
|
||||
|
||||
testWidgets('a queried stage boot link opens that exact recorded visit', (
|
||||
tester,
|
||||
) async {
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(
|
||||
uri: Uri.parse('/runs/77/stage/plan?visit=0'),
|
||||
),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
|
||||
await pumpApp(tester, channel: channel, client: client, provider: provider);
|
||||
await replyList(
|
||||
tester,
|
||||
channel,
|
||||
runs: [
|
||||
{'id': 77, 'name': 'Deep link run', 'status': 'succeeded'},
|
||||
],
|
||||
);
|
||||
await replyVisitDetail(tester, channel, 77);
|
||||
|
||||
// The query reached the detail: visit 0 is the earlier plan visit (seq 1),
|
||||
// not the latest one the pane would show without a visit.
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
|
||||
expect(find.text('plan · visit 1'), findsOneWidget);
|
||||
expect(find.text('plan · visit 5'), findsNothing);
|
||||
expect(provider.value.uri.toString(), '/runs/77/stage/plan?visit=0');
|
||||
|
||||
// A history entry the app itself writes is parsed back as a query, so
|
||||
// Back/Forward (and a reload) open the visit instead of a bogus stage key.
|
||||
final restored = const AppRouteParser()
|
||||
.restoreRouteInformation(AppRoute.run.stage(77, 'plan', visit: 1))
|
||||
.uri;
|
||||
expect(restored.toString(), '/runs/77/stage/plan?visit=1');
|
||||
await provider.didPushRouteInformation(RouteInformation(uri: restored));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(find.text('plan · visit 5'), findsOneWidget);
|
||||
expect(provider.value.uri.path, '/runs/77/stage/plan');
|
||||
expect(provider.value.uri.query, 'visit=1');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user