Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add URLOpener protocol for mocking UIApplication.shared #1148

Merged
merged 4 commits into from
Dec 8, 2023

Conversation

scannillo
Copy link
Contributor

@scannillo scannillo commented Dec 6, 2023

Summary of changes

  • Move to protocol & extension to mock UIApplication.shared
    • This let's us remove the logic that lived in BTVenmoClient source code which only existed for mocking
  • Update FakeApplication to conform to new protocol

References

http://swiftyjimmy.com/mock-uiapplication-swift/

Checklist

  • Added a changelog entry

Authors

@scannillo

@scannillo scannillo requested a review from a team as a code owner December 6, 2023 21:49
} else {
application.open(appStoreURL)
}
application.open(appStoreURL, options: [:], completionHandler: nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

Take it or leave it, but if we want to provide defaults like open in UIApplication we can provide it in a protocol extension to URLOpener:

public extension URLOpener {

    func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any] = [:], completionHandler completion: ((Bool) -> Void)? = nil) {
        open(url, options: options, completionHandler: completion)
    }
}

Would allow us to update this and the call to open in performAppSwitch to:

application.open(appStoreURL) // openVenmoAppPageInAppStore
application.open(appSwitchURL) { success in // performAppSwitch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeh this crossed my mind - but I thought the purpose of the protocol extension was confusing to read/deduce. I don't mind the passing of the empty dict and nil completion, but will defer to what folks think is more clear!

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the cleaner callsite but I 100% just think that's a personal preference. Lol. I am fine with either so will leave it up to you to decide!


@objc public override func open(_ URL: URL, completionHandler: (@Sendable (Bool) -> Void)? = nil) {
lastOpenURL = URL
public func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey : Any], completionHandler: ((Bool) -> Void)?) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥

@scannillo scannillo merged commit 1528d60 into main Dec 8, 2023
6 checks passed
@scannillo scannillo deleted the mock-uiapplication-protocol branch December 8, 2023 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants