Skip to content

Commit

Permalink
Add DeeplinkTests
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlidakis committed Sep 26, 2023
1 parent 23288bf commit dd34c06
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DemoApp/Sources/Components/AppEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ extension AppEnvironment {
case .debug:
return [.staging, .pronto, .production]
case .test:
return [.staging]
return [.staging, .pronto, .production]
case .release:
return [.production]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct DetailedCallingView: View {
self.callId = callId
viewModel.joinCall(callType: .default, callId: callId)
}
.onChange(of: appState.deeplinkInfo) { deeplinkInfo in
.onReceive(appState.$deeplinkInfo) { deeplinkInfo in
self.callId = deeplinkInfo.callId
joinCallIfNeeded(with: deeplinkInfo.callId, callType: deeplinkInfo.callType)
}
Expand Down
106 changes: 102 additions & 4 deletions SwiftUIDemoAppUITests/Tests/DeeplinkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,42 @@ import XCTest

final class DeeplinkTests: StreamTestCase {

static override func setUp() {
super.setUp()

// We are launching and terminating the app to ensure the executable
// has been installed.
app.launch()
app.terminate()
}

override func setUpWithError() throws {
launchApp = false
try super.setUpWithError()
}

private enum MockDeeplink {
static let production: URL = .init(string: "https://getstream.io/video/demos?id=test-call")!
static let pronto: URL = .init(string: "https://pronto.getstream.io/video/demos?id=test-call")!
static let staging: URL = .init(string: "https://staging.getstream.io/video/demos?id=test-call")!
static let customScheme: URL = .init(string: "streamvideo://video/demos?id=test-call")!
}

func test_customSchemeURL_joinsTheSpecifiedCall() {
func test_universalLink_production_joinsExpectedCall() {
WHEN("") {
Safari.openUniversalLinkFromSmartBanner(MockDeeplink.production)
}
THEN("user joins the the specified call") {
userRobot
.assertCallControls()
.assertParticipantsAreVisible(count: 1)
}
}

func test_customSchemeURL_joinsExpectedCall() {
GIVEN("") {
app.terminate()
}
WHEN("User opens a URL that contains a custom scheme") {
XCUIDevice.shared.open(MockDeeplink.customScheme)
Safari.openApp(MockDeeplink.customScheme)
}
THEN("user joins the the specified call") {
userRobot
Expand All @@ -38,3 +64,75 @@ extension XCUIDevice {
}
}
}

enum Safari {

private static let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")

fileprivate static func go(to url: URL) {
safari.textFields["Address"].tap()
safari.typeText(url.absoluteString)
let goButton = safari.buttons["Go"]
if goButton.waitForExistence(timeout: 5) {
safari.tapKeyboardKey("Go")
}
}

fileprivate static func open(_ url: URL) {
safari.launch()

_ = safari.wait(for: .runningForeground, timeout: 5)

// Type the deeplink and execute it
let firstLaunchContinueButton = safari.buttons["Continue"]
if firstLaunchContinueButton.exists {
firstLaunchContinueButton.tap()
}

go(to: url)
}

fileprivate static func openApp(_ url: URL) {
open(url)

let openButton = safari.buttons["Open"]
if openButton.waitForExistence(timeout: 5) {
openButton.tap()
}
}

fileprivate static func openUniversalLinkFromSmartBanner(_ url: URL) {
open(url)

let allowButton1 = safari.alerts.buttons["Allow"]
if allowButton1.waitForExistence(timeout: 5) {
allowButton1.tap()
let allowButton2 = safari.alerts.buttons["Allow"]
if allowButton2.waitForExistence(timeout: 5) {
allowButton2.tap()
}
}

let openButton = safari.buttons["OPEN"]
if openButton.waitForExistence(timeout: 5) {
openButton.tap()
}
}
}

extension XCUIApplication {
/// Taps the specified keyboard key while handling the
/// keyboard onboarding interruption, if it exists.
/// - Parameter key: The keyboard key to tap.
fileprivate func tapKeyboardKey(_ key: String) {
let key = self.keyboards.buttons[key]

if key.isHittable == false {
// Attempt to find and tap the Continue button
// of the keyboard onboarding screen.
self.buttons["Continue"].tap()
}

key.tap()
}
}

0 comments on commit dd34c06

Please sign in to comment.