Skip to content

Commit

Permalink
Merge 565c5d7 into 0a0b801
Browse files Browse the repository at this point in the history
  • Loading branch information
gibahjoe committed Dec 27, 2020
2 parents 0a0b801 + 565c5d7 commit 1b9e9d1
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 8 deletions.
Expand Up @@ -151,15 +151,15 @@ class ModularRouteInformationParser extends RouteInformationParser<ModularRoute>
paramPos++;
}
uri = uri.replace(path: routeNamed);
return router.copyWith(args: router.args!.copyWith(params: params), uri: uri);
return router.copyWith(args: router.args!.copyWith(params: params,uri: uri), uri: uri);
}

uri = uri.replace(path: routeNamed);
return router.copyWith(args: router.args!.copyWith(params: null), uri: uri);
return router.copyWith(args: router.args!.copyWith(params: null,uri: uri), uri: uri);
}

uri = uri.replace(path: routeNamed);
return router.copyWith(uri: uri);
return router.copyWith(uri: uri,args: router.args!.copyWith(uri: uri));
}

ModularRoute? _searchWildcard(
Expand Down Expand Up @@ -197,17 +197,17 @@ class ModularRouteInformationParser extends RouteInformationParser<ModularRoute>
var router = _searchInModule(module ?? Modular.initialModule, "", uri);

if (router != null) {
return canActivate(path, router);
return canActivate(uri.path, router);
} else {
router = _searchWildcard(path, module ?? Modular.initialModule);
router = _searchWildcard(uri.path, module ?? Modular.initialModule);
if (router != null) {
return router;
}
}
throw ModularError('Route \'$path\' not found');
throw ModularError('Route \'${uri.path}\' not found');
}



Future<ModularRoute> canActivate(String path, ModularRoute router) async {
if (router.guards?.isNotEmpty == true) {
Expand Down
Expand Up @@ -70,7 +70,7 @@ class ModularRouterDelegate extends RouterDelegate<ModularRoute>

String resolverPath(String routeName, String path) {
final uri = Uri.parse(path);
return uri.resolve(routeName).path;
return '${uri.resolve(routeName).toString()}';
}

@override
Expand Down
Expand Up @@ -33,12 +33,67 @@ main() {
expect(route.path, '/list/2');
});

test('should retrieve route /list?id=1234&type=DYN', () async {
final route = await parse.selectRoute('/list?id=1234&type=DYN', ModuleMock());
expect(route, isNotNull);
expect(route.child!(context, null), isA<ListView>());
expect(route.path, '/list?id=1234&type=DYN');
expect(route.uri?.path, '/list');
expect(route.queryParams, {'id':'1234','type':'DYN'});
expect(route.queryParamsAll, {'id':['1234'],'type':['DYN']});
expect(route.fragment, '');
expect(route.args?.uri?.path, '/list');
expect(route.args?.queryParams, {'id':'1234','type':'DYN'});
expect(route.args?.queryParamsAll, {'id':['1234'],'type':['DYN']});
expect(route.args?.fragment, '');
});

test('should retrieve route /list?id=1234&type=DYN#abcd', () async {
final route = await parse.selectRoute('/list?id=1234&type=DYN#abcd', ModuleMock());
expect(route, isNotNull);
expect(route.child!(context, null), isA<ListView>());
expect(route.path, '/list?id=1234&type=DYN#abcd');
expect(route.uri?.path, '/list');
expect(route.queryParams, {'id':'1234','type':'DYN'});
expect(route.queryParamsAll, {'id':['1234'],'type':['DYN']});
expect(route.fragment, 'abcd');
expect(route.args?.uri?.path, '/list');
expect(route.args?.queryParams, {'id':'1234','type':'DYN'});
expect(route.args?.queryParamsAll, {'id':['1234'],'type':['DYN']});
expect(route.args?.fragment, 'abcd');
});

test('should retrieve route /mock/list#abcd', () async {
final route = await parse.selectRoute('/list#abcd', ModuleMock());
expect(route, isNotNull);
expect(route.child!(context, null), isA<ListView>());
expect(route.path, '/list#abcd');
expect(route.uri?.path, '/list');
expect(route.queryParams, {});
expect(route.fragment, 'abcd');
expect(route.args?.uri?.path, '/list');
expect(route.args?.queryParams, {});
expect(route.args?.fragment, 'abcd');
});

test('should retrive Widcard route when not exist path', () async {
final route = await parse.selectRoute('/paulo', ModuleMock());
expect(route, isNotNull);
expect(route.child!(context, null), isA<FlutterLogo>());
});

test('should retrive Widcard route when path with query params doesnt exist', () async {
final route = await parse.selectRoute('/paulo?adbc=1234', ModuleMock());
expect(route, isNotNull);
expect(route.child!(context, null), isA<FlutterLogo>());
});

test('should retrive Widcard route when path with fragment doesnt exist', () async {
final route = await parse.selectRoute('/paulo#adbc=1234', ModuleMock());
expect(route, isNotNull);
expect(route.child!(context, null), isA<FlutterLogo>());
});

test('should guard route /401', () async {
expect(parse.selectRoute('/401', ModuleMock()), throwsA(isA<ModularError>()));
});
Expand Down Expand Up @@ -75,6 +130,10 @@ main() {
expect(route.queryParams, {'id':'1234','type':'DYN'});
expect(route.queryParamsAll, {'id':['1234'],'type':['DYN']});
expect(route.fragment, '');
expect(route.args?.uri?.path, '/mock/list');
expect(route.args?.queryParams, {'id':'1234','type':'DYN'});
expect(route.args?.queryParamsAll, {'id':['1234'],'type':['DYN']});
expect(route.args?.fragment, '');
});

test('should retrieve route /mock/list?id=1234&type=DYN#abcd', () async {
Expand All @@ -86,6 +145,10 @@ main() {
expect(route.queryParams, {'id':'1234','type':'DYN'});
expect(route.queryParamsAll, {'id':['1234'],'type':['DYN']});
expect(route.fragment, 'abcd');
expect(route.args?.uri?.path, '/mock/list');
expect(route.args?.queryParams, {'id':'1234','type':'DYN'});
expect(route.args?.queryParamsAll, {'id':['1234'],'type':['DYN']});
expect(route.args?.fragment, 'abcd');
});

test('should retrieve route /mock/list#abcd', () async {
Expand All @@ -96,6 +159,9 @@ main() {
expect(route.uri?.path, '/mock/list');
expect(route.queryParams, {});
expect(route.fragment, 'abcd');
expect(route.args?.uri?.path, '/mock/list');
expect(route.args?.queryParams, {});
expect(route.args?.fragment, 'abcd');
});

test('should retrive dynamic route /mock/list/:id', () async {
Expand All @@ -115,6 +181,14 @@ main() {
expect(parse.selectRoute('/mock/listguarded', ModuleMock()), throwsA(isA<ModularError>()));
});

test('should guard route /mock/listguarded with params', () async {
expect(parse.selectRoute('/mock/listguarded?abc=def', ModuleMock()), throwsA(isA<ModularError>()));
});

test('should guard route /mock/listguarded with fragment', () async {
expect(parse.selectRoute('/mock/listguarded#abc=def', ModuleMock()), throwsA(isA<ModularError>()));
});

test('should guard route /guarded/list', () async {
expect(parse.selectRoute('/guarded/list', ModuleMock()), throwsA(isA<ModularError>()));
});
Expand Down

0 comments on commit 1b9e9d1

Please sign in to comment.