Skip to content

Commit

Permalink
[go_router] migrates test for route information.location deprecation (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
chunhtai authored and nploi committed Jul 16, 2023
1 parent d5f3329 commit aea5059
Showing 1 changed file with 50 additions and 40 deletions.
90 changes: 50 additions & 40 deletions packages/go_router/test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1008,11 +1008,7 @@ void main() {
await tester.pumpAndSettle();
expect(log, <Object>[
isMethodCall('selectMultiEntryHistory', arguments: null),
isMethodCall('routeInformationUpdated', arguments: <String, dynamic>{
'location': '/settings',
'state': null,
'replace': false
}),
const IsRouteUpdateCall('/settings', false, null),
]);
});

Expand All @@ -1037,11 +1033,7 @@ void main() {
await tester.pumpAndSettle();
expect(log, <Object>[
isMethodCall('selectMultiEntryHistory', arguments: null),
isMethodCall('routeInformationUpdated', arguments: <String, dynamic>{
'location': '/',
'state': null,
'replace': false
}),
const IsRouteUpdateCall('/', false, null),
]);
});

Expand Down Expand Up @@ -1072,11 +1064,7 @@ void main() {
await tester.pumpAndSettle();
expect(log, <Object>[
isMethodCall('selectMultiEntryHistory', arguments: null),
isMethodCall('routeInformationUpdated', arguments: <String, dynamic>{
'location': '/',
'state': null,
'replace': false
}),
const IsRouteUpdateCall('/', false, null),
]);
});

Expand All @@ -1101,11 +1089,7 @@ void main() {
await tester.pumpAndSettle();
expect(log, <Object>[
isMethodCall('selectMultiEntryHistory', arguments: null),
isMethodCall('routeInformationUpdated', arguments: <String, dynamic>{
'location': '/',
'state': null,
'replace': false
}),
const IsRouteUpdateCall('/', false, null),
]);
});

Expand All @@ -1131,11 +1115,7 @@ void main() {
await tester.pumpAndSettle();
expect(log, <Object>[
isMethodCall('selectMultiEntryHistory', arguments: null),
isMethodCall('routeInformationUpdated', arguments: <String, dynamic>{
'location': '/',
'state': null,
'replace': false
}),
const IsRouteUpdateCall('/', false, null),
]);
});

Expand Down Expand Up @@ -1191,11 +1171,7 @@ void main() {
expect(find.text('Screen C'), findsOneWidget);
expect(log, <Object>[
isMethodCall('selectMultiEntryHistory', arguments: null),
isMethodCall('routeInformationUpdated', arguments: <String, dynamic>{
'location': '/b/c',
'state': null,
'replace': false
}),
const IsRouteUpdateCall('/b/c', false, null),
]);

log.clear();
Expand All @@ -1205,11 +1181,7 @@ void main() {
expect(find.text('Home'), findsOneWidget);
expect(log, <Object>[
isMethodCall('selectMultiEntryHistory', arguments: null),
isMethodCall('routeInformationUpdated', arguments: <String, dynamic>{
'location': '/',
'state': null,
'replace': false
}),
const IsRouteUpdateCall('/', false, null),
]);
});

Expand Down Expand Up @@ -1243,11 +1215,7 @@ void main() {
expect(tester.takeException(), isNull);
expect(log, <Object>[
isMethodCall('selectMultiEntryHistory', arguments: null),
isMethodCall('routeInformationUpdated', arguments: <String, dynamic>{
'location': '/login',
'state': null,
'replace': false
}),
const IsRouteUpdateCall('/login', false, null),
]);
});
});
Expand Down Expand Up @@ -3524,6 +3492,48 @@ class TestInheritedNotifier extends InheritedNotifier<ValueNotifier<String>> {
});
}

class IsRouteUpdateCall extends Matcher {
const IsRouteUpdateCall(this.uri, this.replace, this.state);

final String uri;
final bool replace;
final Object? state;

@override
bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
if (item is! MethodCall) {
return false;
}
if (item.method != 'routeInformationUpdated') {
return false;
}
if (item.arguments is! Map) {
return false;
}
final Map<String, dynamic> arguments =
item.arguments as Map<String, dynamic>;
// TODO(chunhtai): update this when minimum flutter version includes
// https://github.com/flutter/flutter/pull/119968.
// https://github.com/flutter/flutter/issues/124045.
if (arguments['uri'] != uri && arguments['location'] != uri) {
return false;
}
return arguments['state'] == state && arguments['replace'] == replace;
}

@override
Description describe(Description description) {
return description
.add("has method name: 'routeInformationUpdated'")
.add(' with uri: ')
.addDescriptionOf(uri)
.add(' with state: ')
.addDescriptionOf(state)
.add(' with replace: ')
.addDescriptionOf(replace);
}
}

/// This allows a value of type T or T? to be treated as a value of type T?.
///
/// We use this so that APIs that have become non-nullable can still be used
Expand Down

0 comments on commit aea5059

Please sign in to comment.