Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Commit

Permalink
tests repro'ing #120
Browse files Browse the repository at this point in the history
  • Loading branch information
csells committed Nov 3, 2021
1 parent c2b4944 commit 2bb5dfd
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,41 @@ void main() {
// expect((page.runtimeType as PersonPage).fid, 'f2');
// expect((page.runtimeType as PersonPage).pid, 'p1');
});

test('preserve path param spaces and slashes', () {
const param1 = 'param w/ spaces and slashes';
final routes = [
GoRoute(name: 'page1', path: '/page1/:param1', pageBuilder: _dummy),
];

final router = _router(routes);
final loc = router.namedLocation('page1', params: {'param1': param1});
print('loc= $loc');
router.go(loc);

final matches = router.routerDelegate.matches;
print('param1= ${matches[0].params['param1']}');
expect(router.pageFor(matches[0]).runtimeType, DummyPage);
expect(matches[0].params['param1'], param1);
});

test('preserve query param spaces and slashes', () {
const param1 = 'param w/ spaces and slashes';
final routes = [
GoRoute(name: 'page1', path: '/page1', pageBuilder: _dummy),
];

final router = _router(routes);
final loc =
router.namedLocation('page1', queryParams: {'param1': param1});
print('loc= $loc');
router.go(loc);

final matches = router.routerDelegate.matches;
print('param1= ${matches[0].queryParams['param1']}');
expect(router.pageFor(matches[0]).runtimeType, DummyPage);
expect(matches[0].queryParams['param1'], param1);
});
});

group('redirects', () {
Expand Down Expand Up @@ -1037,6 +1072,45 @@ void main() {
}
});

// TODO: do named routes, too
test('preserve path param spaces and slashes', () {
const param1 = 'param w/ spaces and slashes';
final routes = [
GoRoute(path: '/page1/:param1', pageBuilder: _dummy),
];

final router = _router(routes);
final loc = '/page1/${Uri.encodeQueryComponent(param1)}';
router.go(loc);

final matches = router.routerDelegate.matches;
print('param1= ${matches[0].params['param1']}');
expect(router.pageFor(matches[0]).runtimeType, DummyPage);
expect(matches[0].params['param1'], param1);
});

// TODO: do named routes, too
test('preserve query param spaces and slashes', () {
const param1 = 'param w/ spaces and slashes';
final routes = [
GoRoute(path: '/page1', pageBuilder: _dummy),
];

final router = _router(routes);
router.go('/page1?param1=$param1');

final matches = router.routerDelegate.matches;
expect(router.pageFor(matches[0]).runtimeType, DummyPage);
expect(matches[0].queryParams['param1'], param1);

final loc = '/page1?param1=${Uri.encodeQueryComponent(param1)}';
router.go(loc);

final matches2 = router.routerDelegate.matches;
expect(router.pageFor(matches2[0]).runtimeType, DummyPage);
expect(matches2[0].queryParams['param1'], param1);
});

test('error: duplicate path param', () {
try {
GoRouter(
Expand Down

0 comments on commit 2bb5dfd

Please sign in to comment.