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

Request: Check if route is valid/mapped #70

Closed
Kalzem opened this issue Sep 11, 2017 · 9 comments
Closed

Request: Check if route is valid/mapped #70

Kalzem opened this issue Sep 11, 2017 · 9 comments

Comments

@Kalzem
Copy link

Kalzem commented Sep 11, 2017

It would be nice to test a route "foo://bar" so we know it is has been mapped:

Maybe?

// In URLNavigator.swift
// Return true if route is found
open func map(_ urlPattern: URLConvertible) -> Bool {
    let URLString = URLMatcher.default.normalized(urlPattern, scheme: self.scheme).urlStringValue
    return self.urlMap[URLString] != nil ? true : (self.urlOpenHandlers[URLString] != nil ? true : false)
}
@devxoul
Copy link
Owner

devxoul commented Sep 14, 2017

You may want to use:

let isMapped = Navigator.viewController(for: "foo://bar") != nil

@Kalzem
Copy link
Author

Kalzem commented Sep 14, 2017

I wouldn't recommend this method to check if a route is mapped for 3 reasons:

  • It relies on a failable init which can return nil even though the map did exist.
  • It does init a controller which can create a lot of overhead if the controller is big and has a plethora of variables.
  • It doesn't check against openURLHandlers.

@devxoul
Copy link
Owner

devxoul commented Sep 15, 2017

When do you need this feature?

@Kalzem
Copy link
Author

Kalzem commented Sep 15, 2017

Ideally with URLNavigator 2 which I hope is for this year :)
Let me know if you want me to make a PR with the Unit Tests.

@devxoul
Copy link
Owner

devxoul commented Sep 15, 2017

Oh, I mean 'why do you need?'

@Kalzem
Copy link
Author

Kalzem commented Sep 15, 2017

Example:

  • Unit Testing my app. I try a list of static strings, I want to know if it will be caught by my app. Some routes, when being triggered, will do some contextual processing which will always fail in Unit Tests even though the routes do exist.

If you have other ways, let me know.

@devxoul devxoul added this to the URLNavigator 2 milestone Sep 18, 2017
@devxoul
Copy link
Owner

devxoul commented Sep 18, 2017

Oh I see. Actually current version of URLNavigator is not really test-friendly. It would be great if it can be included in URLNavigator 2.

@Kalzem
Copy link
Author

Kalzem commented Sep 20, 2017

I would gladly contribute to URLNavigator2 to include Unit Tests

@devxoul devxoul mentioned this issue Oct 9, 2017
3 tasks
@devxoul
Copy link
Owner

devxoul commented Oct 19, 2017

This is implemented in URLNavigator 2. You may use view controller factory to achieve this. Thanks!

@devxoul devxoul closed this as completed Oct 19, 2017
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

No branches or pull requests

2 participants