S01E22: [TDD πŸ… 19] Testing a Submit Button with MVC in Swift

In this episode, we simplify the iOSViewControllerFactory implementation and test-drive the QuestionViewController submit button.

As discussed in previous episodes, we don’t want to manually force the view to load in the iOSViewControllerFactory just to be able to configure its subviews, since, according to the UIKit documentation, it's not how it is intended to be used.

To avoid manually forcing the view to load, we move the subviews configuration to the QuestionViewController so the view load happens naturally and at the right time.

Furthermore, we start test-driving the submit button logic and we debate where it should live, as it could either be in the factory (Main module) or in the router (Routing module).

Since the Submit button is a navigationItem button, a very specific component of a UINavigationController, we decided to create the button in the router which coordinates the navigation.

To achieve the enabled/disabled button functionality, we notice we have a perfect case for using MVC! We have a Model (selected answers Array), a View (UIBarButtonItem), and we just lack a Controller to bind the model and the view together.

Finally, we start test-driving the button controller while demonstrating how MVC provides better results when dealing with a single view.

And then… Trouble ahead!

Subscribe now to our Youtube channel and catch free new episodes every week and follow along the project's progress on GitHub.