Files
pipelines/app/test/application/app_router_test.dart
T
alan f57d8eeb76 feat(app): open a recorded run visit from its URL
`/runs/:id/stage/:key?visit=N` now selects that stage's N-th recorded
visit in the run detail Timeline, matching the web client's stage-local
visit ordering. A stage key without a visit opens the latest recorded
visit, an out-of-range index clamps to the last one, and a stage with no
recorded visit selects only its Graph node instead of inventing a visit.

Route plumbing carries the query end to end: boot seeds the router from
path and query, the parser reads path plus query, and restore keeps `?`
a query separator instead of percent-encoding it. That also repairs the
existing `?action=decide` and `/runs?pipeline=` URLs.

The Graph node click and the stage route share one sequence-ordered
resolver, so both open the same latest visit.
2026-10-22 10:48:36 +01:00

104 lines
3.5 KiB
Dart

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';
AppRouterDelegate delegate(AppRoute initial, {void Function()? onChat}) =>
AppRouterDelegate(
builder: (context, route) => const SizedBox.shrink(),
onPopToRuns: () {},
onPopToChat: onChat ?? () {},
cupertino: false,
initial: initial,
);
void main() {
test('system Back leaves one chat session for the chat list', () async {
var left = 0;
final router = delegate(AppRoute.chatSession('s1'), onChat: () => left++);
addTearDown(router.dispose);
expect(await router.popRoute(), isTrue);
expect(left, 1);
});
test('system Back on a list destination stays with the platform', () async {
final router = delegate(AppRoute.chat);
addTearDown(router.dispose);
expect(await router.popRoute(), isFalse);
});
test('Templates opens above Settings and Back restores the route', () async {
final router = delegate(AppRoute.settings);
addTearDown(router.dispose);
router.openTemplates();
expect(router.route, AppRoute.templates);
expect(router.templatesOpen, isTrue);
expect(await router.popRoute(), isTrue);
expect(router.route, AppRoute.settings);
expect(router.templatesOpen, isFalse);
});
test('a /templates boot link still closes back to Settings', () async {
final router = delegate(AppRoute.templates);
addTearDown(router.dispose);
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(),
'/',
);
});
}