Skip to content
This repository was archived by the owner on Feb 24, 2020. It is now read-only.

[WIP] Add support to UINavigationController#2

Open
barbosa wants to merge 7 commits intomarcelofabri:masterfrom
barbosa:feature/navigation-controller
Open

[WIP] Add support to UINavigationController#2
barbosa wants to merge 7 commits intomarcelofabri:masterfrom
barbosa:feature/navigation-controller

Conversation

@barbosa
Copy link

@barbosa barbosa commented Aug 1, 2016

This is still a work in progress.

Its idea is to have a similar implementation of the verifier for UINavigationControllers.

Tasks are listed below:

  • create structure with STGNavigationControllerVerifier and UINavigationController category
  • swizzle pushViewController:animated:
  • swizzle popViewControllerAnimated:
  • swizzle popToRootViewControllerAnimated:
  • swizzle popToViewController:animated:
  • swizzle setViewControllers:animated:
  • update documentation

@codecov-io
Copy link

codecov-io commented Aug 1, 2016

Current coverage is 98.27% (diff: 97.54%)

Merging #2 into master will decrease coverage by 1.72%

@@           master         #2   diff @@
========================================
  Files           2          5     +3   
  Lines          56        174   +118   
  Methods         0          0          
  Messages        0          0          
  Branches        0          0          
========================================
+ Hits           56        171   +115   
- Misses          0          3     +3   
  Partials        0          0          

Powered by Codecov. Last update 4a300a2...66a1f6f

[nc postNotificationName:STGViewControllerWasPoppedNotificationName
object:self.topViewController
userInfo:@{STGViewControllerPoppingAnimatedKey: @(flag)}];
return nil;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't these methods return the view controller that would be popped? It's not a big issue since I've never seen any code using the return code, but who knows ¯_(ツ)_/¯

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought about that. Wasn't sure if necessary. But it makes sense. I'll do it.

@marcelofabri
Copy link
Owner

marcelofabri commented Aug 8, 2016

I know that it's not probably the main use case in unit tests, but what if there's more than one navigation controller? Should we have a property in STGNavigationControllerVerifier that can be used to test which navigation controller was used?

I also thought about init'ing it with a UINavigationController, so only changes to that object would be reflected in the verifier, but I think this might turn it harder to use, because you may not have a reference to the navigation controller in the unit tests (and you'd have to refactor your app to get it).

[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (UIViewController * _Nullable )topViewController {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nullable UIViewController *) instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean (nonnull UIViewController *)?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah 😅

@barbosa barbosa force-pushed the feature/navigation-controller branch from af97739 to 66a1f6f Compare August 9, 2016 18:40
@barbosa
Copy link
Author

barbosa commented Aug 9, 2016

Code coverage went down due to the new return statements. I'll add some unit tests to cover it.

@barbosa
Copy link
Author

barbosa commented Oct 7, 2016

Hey @marcelofabri,

I've finally had some time to have a look at it again.

Based on your comment...

shouldn't these methods return the view controller that would be popped? It's not a big issue since I've never seen any code using the return code, but who knows ¯_(ツ)_/¯

... I was thinking:

Although we swizzle the implementations to send all the notifications we need and capture them, we don't follow the real implementation of the methods. Eg.:

- (void)stg_pushViewController:(UIViewController *)viewControllerToPush
                      animated:(BOOL)flag {
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    [nc postNotificationName:STGViewControllerWasPushedNotificationName
                      object:viewControllerToPush
                    userInfo:@{STGViewControllerPushingAnimatedKey: @(flag)}];
}

In the case above, we're just posting the notification but we're not including the given viewController onto the navigation stack. The same logic applies to present/dismiss.

Because of that, methods returning viewControllers as part of the pop action, would have to know which viewControllers are already in the stack so it can pop the last one.

Maybe if we just ignore those values, returning nil or @[], we could make this easier to implement. I don't see this as a problem given that the main purpose of the library is to test the navigation behavior (which we are already doing through a verifier).

This would allow me to remove the if statement from some methods, bringing the coverage back to 100%.

Thoughts?

@marcelofabri
Copy link
Owner

@barbosa Sorry for taking so long, but I agree we can just return nil and @[], documenting that. Also verifying that in tests to make it clear that it's the intended behavior.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants