Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
370a279
Refactor internal classes and methods
johnpryan Jul 1, 2022
aaec44a
format
johnpryan Jul 12, 2022
61fbc2d
Sort imports
johnpryan Jul 12, 2022
632b012
Update changelog
johnpryan Jul 12, 2022
40e2c61
Address code review comments
johnpryan Jul 13, 2022
61da05d
remove routing library
johnpryan Jul 14, 2022
1c2577c
Move classes in go_router.dart into separate libraries
johnpryan Jul 14, 2022
db91f56
Move Configuration.validate() into constructor
johnpryan Jul 14, 2022
1eaf6c3
Remove comment
johnpryan Jul 14, 2022
ea01665
use continue in redirect loop
johnpryan Jul 14, 2022
d4c2ff9
Fix comments
johnpryan Jul 14, 2022
199c353
Sort imports
johnpryan Jul 14, 2022
b8a65af
Fix logging in configuration
johnpryan Jul 14, 2022
85fe41d
add visibleForTesting annotation
johnpryan Jul 14, 2022
ccb8097
Merge branch 'main' into refactor
johnpryan Jul 14, 2022
e0bb4f4
Updates from merge with main
johnpryan Jul 14, 2022
4c17bba
Format
johnpryan Jul 15, 2022
8449014
Add TODOs to make Router implementation classes private
johnpryan Jul 15, 2022
9b40f1e
Add copyright headers
johnpryan Jul 15, 2022
0e14a04
Fix tests
johnpryan Jul 15, 2022
73feaa8
Merge branch 'main' into refactor
johnpryan Jul 20, 2022
e3458e6
format
johnpryan Jul 20, 2022
13bc273
fix comment
johnpryan Jul 20, 2022
2a350ad
Update packages/go_router/lib/src/parser.dart
johnpryan Jul 21, 2022
fc82dbb
add whitespace
johnpryan Jul 21, 2022
86c8961
format
johnpryan Jul 21, 2022
7f8954c
Hide typedefs that weren't previously exported
johnpryan Jul 21, 2022
fdcf0ed
Delete empty file
johnpryan Jul 21, 2022
78e60a6
add missing import
johnpryan Jul 21, 2022
26b4c12
Specify version 4.1.2 in pubspec.yaml
johnpryan Jul 21, 2022
0c5436e
Update packages/go_router/lib/src/builder.dart
johnpryan Jul 21, 2022
348697b
Fix comment
johnpryan Jul 21, 2022
77f2244
Add isError and error getters to RouteMatchList
johnpryan Jul 21, 2022
820162d
Add issue links to TODO comments
johnpryan Jul 21, 2022
07f7ada
Add link to issue for TODO
johnpryan Jul 22, 2022
686d315
Merge branch 'main' into refactor
johnpryan Jul 22, 2022
5e282d3
Re-apply code from #2306 due to merge conflicts
johnpryan Jul 22, 2022
714e682
Add issue references
johnpryan Jul 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into refactor
  • Loading branch information
johnpryan committed Jul 14, 2022
commit ccb80972044163d73eb3be658a9f8b0a7fc172b3
341 changes: 3 additions & 338 deletions packages/go_router/test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
import 'package:logging/logging.dart';
import 'package:go_router/src/delegate.dart';
import 'package:go_router/src/match.dart';
import 'package:go_router/src/misc/error_screen.dart';
import 'package:logging/logging.dart';

import 'test_helpers.dart';

Expand All @@ -32,8 +31,8 @@ void main() {
const HomeScreen()),
];

final GoRouter router = await _router(routes, tester);
final List<RouteMatch> matches = router.routerDelegate.matches.matches;
final GoRouter router = await createRouter(routes, tester);
final List<GoRouteMatch> matches = router.routerDelegate.matches;
expect(matches, hasLength(1));
expect(matches.first.fullpath, '/');
expect(router.screenFor(matches.first).runtimeType, HomeScreen);
Expand Down Expand Up @@ -1811,337 +1810,3 @@ void main() {
);
});
}

Future<GoRouter> createGoRouter(
WidgetTester tester, {
GoRouterNavigatorBuilder? navigatorBuilder,
}) async {
final GoRouter goRouter = GoRouter(
initialLocation: '/',
routes: <GoRoute>[
GoRoute(path: '/', builder: (_, __) => const DummyStatefulWidget()),
GoRoute(
path: '/error',
builder: (_, __) => const ErrorScreen(null),
),
],
navigatorBuilder: navigatorBuilder,
);
await tester.pumpWidget(MaterialApp.router(
routeInformationProvider: goRouter.routeInformationProvider,
routeInformationParser: goRouter.routeInformationParser,
routerDelegate: goRouter.routerDelegate));
return goRouter;
}

Widget fakeNavigationBuilder(
BuildContext context,
GoRouterState state,
Widget child,
) =>
child;

class GoRouterNamedLocationSpy extends GoRouter {
GoRouterNamedLocationSpy({required List<GoRoute> routes})
: super(routes: routes);

String? name;
Map<String, String>? params;
Map<String, String>? queryParams;

@override
String namedLocation(
String name, {
Map<String, String> params = const <String, String>{},
Map<String, String> queryParams = const <String, String>{},
}) {
this.name = name;
this.params = params;
this.queryParams = queryParams;
return '';
}
}

class GoRouterGoSpy extends GoRouter {
GoRouterGoSpy({required List<GoRoute> routes}) : super(routes: routes);

String? myLocation;
Object? extra;

@override
void go(String location, {Object? extra}) {
myLocation = location;
this.extra = extra;
}
}

class GoRouterGoNamedSpy extends GoRouter {
GoRouterGoNamedSpy({required List<GoRoute> routes}) : super(routes: routes);

String? name;
Map<String, String>? params;
Map<String, String>? queryParams;
Object? extra;

@override
void goNamed(
String name, {
Map<String, String> params = const <String, String>{},
Map<String, String> queryParams = const <String, String>{},
Object? extra,
}) {
this.name = name;
this.params = params;
this.queryParams = queryParams;
this.extra = extra;
}
}

class GoRouterPushSpy extends GoRouter {
GoRouterPushSpy({required List<GoRoute> routes}) : super(routes: routes);

String? myLocation;
Object? extra;

@override
void push(String location, {Object? extra}) {
myLocation = location;
this.extra = extra;
}
}

class GoRouterPushNamedSpy extends GoRouter {
GoRouterPushNamedSpy({required List<GoRoute> routes}) : super(routes: routes);

String? name;
Map<String, String>? params;
Map<String, String>? queryParams;
Object? extra;

@override
void pushNamed(
String name, {
Map<String, String> params = const <String, String>{},
Map<String, String> queryParams = const <String, String>{},
Object? extra,
}) {
this.name = name;
this.params = params;
this.queryParams = queryParams;
this.extra = extra;
}
}

class GoRouterPopSpy extends GoRouter {
GoRouterPopSpy({required List<GoRoute> routes}) : super(routes: routes);

bool popped = false;

@override
void pop() {
popped = true;
}
}

class GoRouterRefreshStreamSpy extends GoRouterRefreshStream {
GoRouterRefreshStreamSpy(
Stream<dynamic> stream,
) : notifyCount = 0,
super(stream);

late int notifyCount;

@override
void notifyListeners() {
notifyCount++;
super.notifyListeners();
}
}

Future<GoRouter> _router(
List<GoRoute> routes,
WidgetTester tester, {
GoRouterRedirect? redirect,
String initialLocation = '/',
int redirectLimit = 5,
}) async {
final GoRouter goRouter = GoRouter(
routes: routes,
redirect: redirect,
initialLocation: initialLocation,
redirectLimit: redirectLimit,
errorBuilder: (BuildContext context, GoRouterState state) =>
TestErrorScreen(state.error!),
debugLogDiagnostics: false,
);
await tester.pumpWidget(
MaterialApp.router(
routeInformationProvider: goRouter.routeInformationProvider,
routeInformationParser: goRouter.routeInformationParser,
routerDelegate: goRouter.routerDelegate,
),
);
return goRouter;
}

class TestErrorScreen extends DummyScreen {
const TestErrorScreen(this.ex, {Key? key}) : super(key: key);
final Exception ex;
}

class HomeScreen extends DummyScreen {
const HomeScreen({Key? key}) : super(key: key);
}

class Page1Screen extends DummyScreen {
const Page1Screen({Key? key}) : super(key: key);
}

class Page2Screen extends DummyScreen {
const Page2Screen({Key? key}) : super(key: key);
}

class LoginScreen extends DummyScreen {
const LoginScreen({Key? key}) : super(key: key);
}

class FamilyScreen extends DummyScreen {
const FamilyScreen(this.fid, {Key? key}) : super(key: key);
final String fid;
}

class FamiliesScreen extends DummyScreen {
const FamiliesScreen({required this.selectedFid, Key? key}) : super(key: key);
final String selectedFid;
}

class PersonScreen extends DummyScreen {
const PersonScreen(this.fid, this.pid, {Key? key}) : super(key: key);
final String fid;
final String pid;
}

class DummyScreen extends StatelessWidget {
const DummyScreen({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) => const Placeholder();
}

Widget _dummy(BuildContext context, GoRouterState state) => const DummyScreen();

extension on GoRouter {
Page<dynamic> _pageFor(RouteMatch match) {
final List<RouteMatch> matches = routerDelegate.matches.matches;
final int i = matches.indexOf(match);
final List<Page<dynamic>> pages =
routerDelegate.builder.getPages(DummyBuildContext(), matches).toList();
return pages[i];
}

Widget screenFor(RouteMatch match) =>
(_pageFor(match) as MaterialPage<void>).child;
}

class DummyBuildContext implements BuildContext {
@override
bool get debugDoingBuild => throw UnimplementedError();

@override
InheritedWidget dependOnInheritedElement(InheritedElement ancestor,
{Object aspect = 1}) {
throw UnimplementedError();
}

@override
T? dependOnInheritedWidgetOfExactType<T extends InheritedWidget>(
{Object? aspect}) {
throw UnimplementedError();
}

@override
DiagnosticsNode describeElement(String name,
{DiagnosticsTreeStyle style = DiagnosticsTreeStyle.errorProperty}) {
throw UnimplementedError();
}

@override
List<DiagnosticsNode> describeMissingAncestor(
{required Type expectedAncestorType}) {
throw UnimplementedError();
}

@override
DiagnosticsNode describeOwnershipChain(String name) {
throw UnimplementedError();
}

@override
DiagnosticsNode describeWidget(String name,
{DiagnosticsTreeStyle style = DiagnosticsTreeStyle.errorProperty}) {
throw UnimplementedError();
}

@override
void dispatchNotification(Notification notification) {
throw UnimplementedError();
}

@override
T? findAncestorRenderObjectOfType<T extends RenderObject>() {
throw UnimplementedError();
}

@override
T? findAncestorStateOfType<T extends State<StatefulWidget>>() {
throw UnimplementedError();
}

@override
T? findAncestorWidgetOfExactType<T extends Widget>() {
throw UnimplementedError();
}

@override
RenderObject? findRenderObject() {
throw UnimplementedError();
}

@override
T? findRootAncestorStateOfType<T extends State<StatefulWidget>>() {
throw UnimplementedError();
}

@override
InheritedElement?
getElementForInheritedWidgetOfExactType<T extends InheritedWidget>() {
throw UnimplementedError();
}

@override
BuildOwner? get owner => throw UnimplementedError();

@override
Size? get size => throw UnimplementedError();

@override
void visitAncestorElements(bool Function(Element element) visitor) {}

@override
void visitChildElements(ElementVisitor visitor) {}

@override
Widget get widget => throw UnimplementedError();
}

class DummyStatefulWidget extends StatefulWidget {
const DummyStatefulWidget({Key? key}) : super(key: key);

@override
State<DummyStatefulWidget> createState() => _DummyStatefulWidgetState();
}

class _DummyStatefulWidgetState extends State<DummyStatefulWidget> {
@override
Widget build(BuildContext context) => Container();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';

import '../go_router_test.dart';
import '../test_helpers.dart';

WidgetTesterCallback testPageNotFound({required Widget widget}) {
return (WidgetTester tester) async {
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.