2026-06-07 15:44:48 -04:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
|
import 'package:frontend/navigation.dart';
|
|
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
// The app's real [router] is configured so that switching between top-level
|
|
|
|
|
// destinations crossfades (a [CustomTransitionPage]) instead of using the
|
|
|
|
|
// default platform slide, which would otherwise leave the outgoing screen
|
2026-06-07 18:29:57 -04:00
|
|
|
// visible behind the incoming one. Drilling into a detail screen uses its own
|
|
|
|
|
// custom page builder (an opaque iOS-style slide), not the default builder.
|
2026-06-07 15:44:48 -04:00
|
|
|
List<GoRoute> topLevelRoutes() {
|
|
|
|
|
final shell = router.configuration.routes.single as ShellRoute;
|
|
|
|
|
return shell.routes.cast<GoRoute>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GoRoute routeByName(String name) =>
|
|
|
|
|
topLevelRoutes().firstWhere((r) => r.name == name);
|
|
|
|
|
|
|
|
|
|
group('navigation transitions', () {
|
|
|
|
|
test('top-level destinations use a page builder (crossfade)', () {
|
|
|
|
|
for (final name in ['home', 'devices', 'status', 'settings', 'about']) {
|
|
|
|
|
final route = routeByName(name);
|
|
|
|
|
expect(
|
|
|
|
|
route.pageBuilder,
|
|
|
|
|
isNotNull,
|
|
|
|
|
reason: '"$name" should crossfade via a custom page builder',
|
|
|
|
|
);
|
|
|
|
|
expect(route.builder, isNull, reason: '"$name" should not also build');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-07 18:29:57 -04:00
|
|
|
test('the device detail drill-in uses a custom page builder (slide)', () {
|
2026-06-07 15:44:48 -04:00
|
|
|
final devices = routeByName('devices');
|
|
|
|
|
final detail = devices.routes.single as GoRoute;
|
|
|
|
|
|
|
|
|
|
expect(detail.name, 'deviceDetail');
|
|
|
|
|
expect(
|
2026-06-07 18:29:57 -04:00
|
|
|
detail.pageBuilder,
|
2026-06-07 15:44:48 -04:00
|
|
|
isNotNull,
|
2026-06-07 18:29:57 -04:00
|
|
|
reason: 'the detail push should use the opaque drill-in slide page',
|
2026-06-07 15:44:48 -04:00
|
|
|
);
|
2026-06-07 18:29:57 -04:00
|
|
|
expect(detail.builder, isNull, reason: 'the detail should not also build');
|
2026-06-07 15:44:48 -04:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|