Skip to content

Commit

Permalink
fixup! Implement EngagementLauncher logic
Browse files Browse the repository at this point in the history
Added test for getEngagementLauncher
  • Loading branch information
ykyivskyi-gl committed Oct 2, 2024
1 parent fbf00f8 commit b9452a7
Showing 1 changed file with 81 additions and 18 deletions.
99 changes: 81 additions & 18 deletions GliaWidgetsTests/Sources/Glia/GliaTests+EngagementLauncher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,87 @@
import XCTest

extension GliaTests {
func test_getEngagementLauncher() throws {
func test_getEngagementLauncherDoesNotThrowErrorWithCorrectConfiguration() throws {
let sdk = makeConfigurableSDK()

try sdk.configure(
with: .mock(),
theme: .mock()
) { _ in }

XCTAssertNoThrow(
try sdk.getEngagementLauncher(queueIds: nil)
)
}

func test_startChatUsingEngagementLauncherWithCorrectConfiguration() throws {
let sdk = makeConfigurableSDK()

try sdk.configure(
with: .mock(),
theme: .mock()
) { _ in }

let engagementLauncher = try sdk.getEngagementLauncher(queueIds: nil)

try engagementLauncher.startChat()

XCTAssertEqual(sdk.engagement, .chat)
}

func test_startAudioCallUsingEngagementLauncherWithCorrectConfiguration() throws {
let sdk = makeConfigurableSDK()

try sdk.configure(
with: .mock(),
theme: .mock()
) { _ in }

let engagementLauncher = try sdk.getEngagementLauncher(queueIds: nil)

try engagementLauncher.startAudioCall()

XCTAssertEqual(sdk.engagement, .audioCall)
}

func test_startVideoCallUsingEngagementLauncherWithCorrectConfiguration() throws {
let sdk = makeConfigurableSDK()

try sdk.configure(
with: .mock(),
theme: .mock()
) { _ in }

let engagementLauncher = try sdk.getEngagementLauncher(queueIds: nil)

try engagementLauncher.startVideoCall()

XCTAssertEqual(sdk.engagement, .videoCall)
}

func test_startSecureConversationUsingEngagementLauncherWithCorrectConfiguration() throws {
let sdk = makeConfigurableSDK()

try sdk.configure(
with: .mock(),
theme: .mock()
) { _ in }

let engagementLauncher = try sdk.getEngagementLauncher(queueIds: nil)

try engagementLauncher.startSecureMessaging()

XCTAssertEqual(sdk.engagement, .messaging(.welcome))
}
}

private extension GliaTests {
func makeConfigurableSDK() -> Glia {
var sdkEnv = Glia.Environment.failing
sdkEnv.coreSDKConfigurator.configureWithInteractor = { _ in }
sdkEnv.coreSdk.localeProvider = .mock
let rootCoordinator = EngagementCoordinator.mock(
engagementKind: .chat,
screenShareHandler: .mock,
environment: .engagementCoordEnvironmentWithKeyWindow
)
sdkEnv.createRootCoordinator = { _, _, _, _, _, _, _ in
rootCoordinator
sdkEnv.createRootCoordinator = { _, _, _, engagementKind, _, _, _ in
.mock(engagementKind: engagementKind, environment: .engagementCoordEnvironmentWithKeyWindow)
}
sdkEnv.print.printClosure = { _, _, _ in }
var logger = CoreSdkClient.Logger.failing
Expand All @@ -25,19 +95,12 @@ extension GliaTests {
sdkEnv.coreSDKConfigurator.configureWithConfiguration = { _, completion in
completion(.success(()))
}
sdkEnv.coreSdk.getCurrentEngagement = { nil }
let window = UIWindow(frame: .zero)
window.makeKeyAndVisible()
sdkEnv.uiApplication.windows = { [window] }
let sdk = Glia(environment: sdkEnv)

sdk.rootCoordinator = rootCoordinator
try sdk.configure(
with: .mock(),
theme: .mock()
) { _ in }

XCTAssertNoThrow(
try sdk.getEngagementLauncher(queueIds: nil)
)

return sdk
}
}

0 comments on commit b9452a7

Please sign in to comment.