marcglasberg / async_redux

Flutter Package: A Redux version tailored for Flutter, which is easy to learn, to use, to test, and has no boilerplate. Allows for both sync and async reducers.
Other
234 stars 40 forks source link

Can't test route redirects from actions in version 6.0 #92

Closed dluksza closed 4 years ago

dluksza commented 4 years ago

Before 6.0 release it was possible to assert route names used in navigation actions. This gave a possibility to test screen redirects from actions.

Code like this would compile and test that action was emitted and verify the routeName

final navigateAction = actions.get(NavigateAction).action as NavigateAction;

expect(navigateAction.routeName, HomeScreen.routeName);

Now in 6.0 this is not possible, because routeName was removed from NavigateAction.

Is there a new way to verify dispatched action?

I've found previous implementation really useful, especially verifying app flow in unit test instead of widget or driver tests. Would be great to get this possibility back.

marcglasberg commented 4 years ago

Problem is, routeName was good for that simple case, but each Navigation method gets different parameters. Some of them had routes which I improperly called routeName.

This is better:

1) I added a NavigateAction.type which you can use if you just want to check the type of the navigation (NavigateType.pop, NavigateType.push etc).

2) As for the other action details, check the NavigateAction.details:

expect(navigateAction.details as NavigatorDetails_PushNamed).routeName, "myRoute");

This gives you more than just the routeName, depending on the NavigatorDetails exact class. For example:

expect((navigateAction.details as NavigatorDetails_Replace).newRoute, "someRoute");
expect((navigateAction.details as NavigatorDetails_Replace).newRoute, "otherRoute");

Please see version [6.0.1], and tell me if it solves the problem.

dluksza commented 4 years ago

Thanks, this worked!

btw. NavigatorDetails_Replace or NavigatorDetails_PushNamedAndRemoveUntil is descriptive, but also a bit of a mouthful, would it be possible to have something shorter?

marcglasberg commented 4 years ago

I can't really, since I am just copying the Navigator method names: https://api.flutter.dev/flutter/widgets/Navigator/pushNamedAndRemoveUntil.html