Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lishaduck committed Sep 16, 2024
1 parent f95a2eb commit 818cfd4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ class MapInfoPage extends StatelessWidget {
);
}

// coverage:ignore-start
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DoubleProperty('x', latitude))
..add(DoubleProperty('y', longitude));
}
// coverage:ignore-start
}
69 changes: 56 additions & 13 deletions packages/app/test/src/app/router_test.dart
Original file line number Diff line number Diff line change
@@ -1,45 +1,88 @@
import 'package:auto_route/auto_route.dart';
import 'package:checks/checks.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nexus/src/app/router.dart';
import 'package:nexus/src/app/router.gr.dart';
import 'package:nexus/src/app/wrapper_page.dart';
import 'package:nexus/src/utils/router.dart';

import '../../helpers/pump_app.dart';
import '../../helpers/riverpod.dart';

Future<BuildContext> _getContext<W extends Widget>(
WidgetTester tester,
ProviderContainer container,
AppRouter router,
) async {
await tester.pumpApp(
UncontrolledProviderScope(
container: container,
child: MaterialApp.router(
routerConfig: router.config(),
),
),
);
return tester.element(find.byType(W));
}

// class MockRouteData extends Mock implements RouteData {}

void main() {
group('router', () {
final tested = AppRouter();

group('config', () {
test(
'defaultRouteType is a RouteType.material.',
() {
check(tested.defaultRouteType).isA<MaterialRouteType>();
},
);

test('should contain the correct number of routes.', () {
test('defaultRouteType is a RouteType.material.', () {
final tested = AppRouter();
check(tested.defaultRouteType).isA<MaterialRouteType>();
});

test('should contain the correct number of top level routes.', () {
final tested = AppRouter();

// WrapperRoute and 404 redirect.
check(tested.routes.length).equals(2);
});
});

group('path', () {
test('should be correct for WrapperRoute.', () {
final wrapperRoute = tested.routes[0];
check(wrapperRoute.path).equals('/');
testWidgets('should be correct for WrapperRoute.', (tester) async {
final container = createContainer();
final routerSubscription = container.listen(routerProvider, (_, __) {});
final router = routerSubscription.read();
final context = await _getContext<WrapperPage>(
tester,
container,
router,
);

// FIXME: Hangs! Yay!
await context.router.push(const WrapperRoute());
await tester.pumpAndSettle();

check(router)
..has((router) => router.urlState.url, 'url').equals('/')
..has((router) => router.topRoute.title(context), 'title').equals('');
});
test('should be correct for MapRoute.', () {
final tested = AppRouter();
final sampleItemListRoute =
tested.routes[0].children?.routes.toList()[0];
check(sampleItemListRoute?.path).equals('');
});
test('should be correct for MapInfoRoute.', () {
final tested = AppRouter();
final sampleItemDetailsRoute =
tested.routes[0].children?.routes.toList()[1];
check(sampleItemDetailsRoute?.path).equals('info');
});
test('should be correct for SettingsRoute.', () {
final tested = AppRouter();
final settingsRoute = tested.routes[0].children?.routes.toList()[2];
check(settingsRoute?.path).equals('settings');
});
test('should redirect on 404', () {
final tested = AppRouter();
final redirectRoute = tested.routes[1];
check(redirectRoute.path).equals('/*');
});
Expand Down
4 changes: 1 addition & 3 deletions packages/app/test/src/app/wrapper_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import '../../helpers/riverpod.dart';

extension _WidgetTesterX on WidgetTester {
Future<void> pumpWidgetPage() async {
final container = createContainer(
overrides: [],
);
final container = createContainer();
final routerSubscription = container.listen(routerProvider, (_, __) {});
final router = routerSubscription.read();

Expand Down

0 comments on commit 818cfd4

Please sign in to comment.