-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ios): Add overrideable routing for CAPBridgeViewController subcl…
…asses (#5546)
- Loading branch information
1 parent
33e9b34
commit 8875d5e
Showing
6 changed files
with
82 additions
and
8 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,27 @@ | ||
// | ||
// Router.swift | ||
// Capacitor | ||
// | ||
// Created by Steven Sherry on 3/29/22. | ||
// Copyright © 2022 Drifty Co. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol Router { | ||
func route(for path: String) -> String | ||
} | ||
|
||
// swiftlint:disable:next type_name | ||
internal struct _Router: Router { | ||
func route(for path: String) -> String { | ||
let pathUrl = URL(string: path) | ||
|
||
// if the pathUrl is null, then it is an invalid url (meaning it is empty or just plain invalid) then we want to route to /index.html | ||
if pathUrl?.pathExtension.isEmpty ?? true { | ||
return "/index.html" | ||
} | ||
|
||
return path | ||
} | ||
} |
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,30 @@ | ||
// | ||
// RouterTests.swift | ||
// CapacitorTests | ||
// | ||
// Created by Steven Sherry on 3/29/22. | ||
// Copyright © 2022 Drifty Co. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import Capacitor | ||
|
||
class RouterTests: XCTestCase { | ||
let router = _Router() | ||
|
||
func testRouterReturnsIndexWhenProvidedInvalidPath() { | ||
XCTAssertEqual(router.route(for: "/skull.💀"), "/index.html") | ||
} | ||
|
||
func testRouterReturnsIndexWhenProvidedEmptyPath() { | ||
XCTAssertEqual(router.route(for: ""), "/index.html") | ||
} | ||
|
||
func testRouterReturnsIndexWhenProviedPathWithoutExtension() { | ||
XCTAssertEqual(router.route(for: "/a/valid/path/no/ext"), "/index.html") | ||
} | ||
|
||
func testRouterReturnsPathWhenProvidedValidPath() { | ||
XCTAssertEqual(router.route(for: "/a/valid/path.ext"), "/a/valid/path.ext") | ||
} | ||
} |