146 lines
5.0 KiB
Dart
146 lines
5.0 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() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
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 steps up one level at a time', () async {
|
|
var runs = 0;
|
|
final router = AppRouterDelegate(
|
|
builder: (context, route) => const SizedBox.shrink(),
|
|
onPopToRuns: () => runs++,
|
|
onPopToChat: () {},
|
|
cupertino: false,
|
|
initial: AppRoute.run.stage(77, 'plan', visit: 0),
|
|
);
|
|
addTearDown(router.dispose);
|
|
|
|
// A stage returns to its run, then the run to the Runs list.
|
|
expect(await router.popRoute(), isTrue);
|
|
expect(router.route, AppRoute.run(77));
|
|
expect(await router.popRoute(), isTrue);
|
|
expect(runs, 1);
|
|
|
|
// A pipeline stage returns to its pipeline, then to the list, and the
|
|
// list leaves Back to the platform.
|
|
router.goTo(AppRoute.pipelineStage(4, 'plan', version: 2));
|
|
expect(await router.popRoute(), isTrue);
|
|
expect(router.route, AppRoute.pipeline(4, version: 2));
|
|
expect(await router.popRoute(), isTrue);
|
|
expect(router.route, AppRoute.pipelines);
|
|
expect(await router.popRoute(), isFalse);
|
|
});
|
|
|
|
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(),
|
|
'/',
|
|
);
|
|
});
|
|
|
|
test('the native notification link opens its run', () async {
|
|
const parser = AppRouteParser();
|
|
final run = await parser.parseRouteInformation(
|
|
RouteInformation(uri: Uri.parse('pipelines://run/42')),
|
|
);
|
|
expect(run, AppRoute.run(42));
|
|
final decide = await parser.parseRouteInformation(
|
|
RouteInformation(uri: Uri.parse('pipelines://run/42?action=decide')),
|
|
);
|
|
expect(decide.path, '/runs/42?action=decide');
|
|
// Another scheme or host is not a run link.
|
|
expect(routeLocation(Uri.parse('pipelines://other/42')), '/42');
|
|
});
|
|
}
|