-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from hyperoslo/feature/comventional-routes
Feature: conventional routers & routes
- Loading branch information
Showing
5 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import UIKit | ||
|
||
public protocol Routable { | ||
|
||
func resolve(arguments: [String: String], navigationController: UINavigationController?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import UIKit | ||
|
||
public struct Router { | ||
|
||
public var routes = [String: Routable]() | ||
|
||
public init() {} | ||
|
||
public func navigate(route: String, arguments: [String: String], navigationController: UINavigationController?) { | ||
guard let route = routes[route] else { return } | ||
|
||
route.resolve(arguments, navigationController: navigationController) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Foundation | ||
import XCTest | ||
import Compass | ||
|
||
class TestRoute: Routable { | ||
|
||
var resolved = false | ||
|
||
func resolve(arguments: [String: String], navigationController: UINavigationController?) { | ||
resolved = true | ||
} | ||
} | ||
|
||
class TestRouter: XCTestCase { | ||
|
||
var router: Router! | ||
var navigationController = UINavigationController() | ||
var route: TestRoute! | ||
|
||
override func setUp() { | ||
router = Router() | ||
route = TestRoute() | ||
} | ||
|
||
func testNavigateIfRouteRegistered() { | ||
router.routes["test"] = route | ||
router.navigate("test", arguments: [:], navigationController: navigationController) | ||
|
||
XCTAssertTrue(route.resolved) | ||
} | ||
|
||
func testNavigateIfRouteNotRegistered() { | ||
router.navigate("test", arguments: [:], navigationController: navigationController) | ||
|
||
XCTAssertFalse(route.resolved) | ||
} | ||
} |