mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-04 08:10:55 +00:00
44 lines
1.8 KiB
Dart
44 lines
1.8 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:gopeed/app/router/app_router.dart';
|
|
import 'package:gopeed/features/auth/application/web_auth_controller.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
for (final platform in TargetPlatform.values) {
|
|
test('$platform preserves the expected section route stacks', () {
|
|
debugDefaultTargetPlatformOverride = platform;
|
|
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
|
final auth = WebAuthController();
|
|
final router = AppRouter.build(auth);
|
|
addTearDown(router.dispose);
|
|
addTearDown(auth.dispose);
|
|
final isMobile = !kIsWeb && (platform == TargetPlatform.android || platform == TargetPlatform.iOS);
|
|
|
|
for (final entry in {
|
|
'/': ['/'],
|
|
'/extensions': isMobile ? ['/', 'extensions'] : ['/extensions'],
|
|
'/extensions/example': isMobile ? ['/', 'extensions', ':id'] : ['/extensions', ':id'],
|
|
'/settings': isMobile ? ['/', 'settings'] : ['/settings'],
|
|
'/settings/general': isMobile ? ['/', 'settings', ':section'] : ['/settings', ':section'],
|
|
'/tasks/example': ['/', 'tasks/:id'],
|
|
'/create': ['/', 'create'],
|
|
}.entries) {
|
|
final match = router.configuration.findMatch(Uri.parse(entry.key));
|
|
expect(match.isError, isFalse);
|
|
final shell = match.matches.first as ShellRouteMatch;
|
|
final routes = [
|
|
...shell.matches.map((match) => match.route as GoRoute),
|
|
...match.matches.skip(1).map((match) => match.route as GoRoute),
|
|
];
|
|
expect(routes.map((route) => route.path), entry.value);
|
|
if (entry.key == '/create') {
|
|
expect(routes.last.parentNavigatorKey, same(AppRouter.rootNavigatorKey));
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|