Files
swiftapp/swift/Tests/AppNavigationCommandTests.swift

52 lines
1.7 KiB
Swift
Raw Normal View History

import XCTest
@testable import SocialIO
final class AppNavigationCommandTests: XCTestCase {
func testFromEnvironmentPrefersJSONOverRoute() {
let environment = [
AppNavigationCommand.routeEnvironmentKey: "socialio://mailbox/inbox",
AppNavigationCommand.jsonEnvironmentKey: #"{"kind":"compose","to":"team@social.io","subject":"Hello","body":"Hi"}"#
]
let command = AppNavigationCommand.from(environment: environment)
XCTAssertEqual(
command,
.compose(draft: ComposeDraft(to: "team@social.io", subject: "Hello", body: "Hi"))
)
}
func testParseMailboxURLIncludesSearchAndUnreadOnly() {
let command = AppNavigationCommand.parse("socialio://mailbox/starred?search=roadmap&unreadOnly=true")
XCTAssertEqual(
command,
.mailbox(mailbox: .starred, search: "roadmap", unreadOnly: true)
)
}
func testParseOpenURLMapsThreadAndMessageSelection() {
let command = AppNavigationCommand.parse("socialio://open?thread=launch-copy&message=launch-copy-2&mailbox=sent")
XCTAssertEqual(
command,
.thread(
threadRouteID: "launch-copy",
mailbox: .sent,
messageRouteID: "launch-copy-2",
search: nil,
unreadOnly: nil
)
)
}
func testParseJSONWithoutKindFallsBackToComposePayload() {
let command = AppNavigationCommand.from(json: #"{"to":"grandma@example.com","subject":"Photos","body":"Hi Grandma"}"#)
XCTAssertEqual(
command,
.compose(draft: ComposeDraft(to: "grandma@example.com", subject: "Photos", body: "Hi Grandma"))
)
}
}