diff --git a/GliaWidgets/Public/Glia/Glia+StartEngagement.swift b/GliaWidgets/Public/Glia/Glia+StartEngagement.swift index d37f65e1c..fa51952e3 100644 --- a/GliaWidgets/Public/Glia/Glia+StartEngagement.swift +++ b/GliaWidgets/Public/Glia/Glia+StartEngagement.swift @@ -48,12 +48,12 @@ extension Glia { theme.chat.connect.queue.firstText = companyName( using: interactor, - currentName: theme.chat.connect.queue.firstText + themeCompanyName: theme.chat.connect.queue.firstText ) theme.call.connect.queue.firstText = companyName( using: interactor, - currentName: theme.call.connect.queue.firstText + themeCompanyName: theme.call.connect.queue.firstText ) let viewFactory = ViewFactory( @@ -81,20 +81,23 @@ extension Glia { func companyName( using interactor: Interactor, - currentName: String? + themeCompanyName: String? ) -> String { - // As the default value is empty, it means that the integrator - // has set a value on the theme itself. Return that same value. - if let currentName, !currentName.isEmpty { - return currentName - } - let companyNameStringKey = "general.company_name" - // Company name has been set on the custom locale. - if let remoteCompanyName = stringProviding?.getRemoteString(companyNameStringKey) { + // Company name has been set on the custom locale and is not empty. + if + let remoteCompanyName = stringProviding?.getRemoteString(companyNameStringKey), + !remoteCompanyName.isEmpty + { return remoteCompanyName } + // As the default value in the theme is not empty, it means that + // the integrator has set a value on the theme itself. Return that + // same value. + else if let themeCompanyName, !themeCompanyName.isEmpty { + return themeCompanyName + } // Integrator has not set a company name in the custom locale, // but has set it on the configuration. else if !interactor.configuration.companyName.isEmpty { diff --git a/GliaWidgetsTests/Sources/Glia/GliaTests+StartEngagement.swift b/GliaWidgetsTests/Sources/Glia/GliaTests+StartEngagement.swift index 573aa7e1b..0bcafdf2a 100644 --- a/GliaWidgetsTests/Sources/Glia/GliaTests+StartEngagement.swift +++ b/GliaWidgetsTests/Sources/Glia/GliaTests+StartEngagement.swift @@ -111,8 +111,13 @@ extension GliaTests { let sdk = Glia(environment: environment) + // Even if theme is set, the remote string takes priority. + let theme = Theme() + theme.call.connect.queue.firstText = "Glia 1" + theme.chat.connect.queue.firstText = "Glia 2" + try sdk.configure(with: .mock()) { } - try sdk.startEngagement(engagementKind: .chat, in: ["queueId"]) + try sdk.startEngagement(engagementKind: .chat, in: ["queueId"], theme: theme) let configuredSdkTheme = resultingViewFactory?.theme XCTAssertEqual(configuredSdkTheme?.call.connect.queue.firstText, "Glia") @@ -174,4 +179,43 @@ extension GliaTests { XCTAssertEqual(configuredSdkTheme?.call.connect.queue.firstText, "Company Name") XCTAssertEqual(configuredSdkTheme?.chat.connect.queue.firstText, "Company Name") } + + func testCompanyNameIsReceivedFromThemeIfCustomLocalesIsEmpty() throws { + var environment = Glia.Environment.failing + var resultingViewFactory: ViewFactory? + + environment.createRootCoordinator = { _, viewFactory, _, _, _, _, _ in + resultingViewFactory = viewFactory + + return .mock( + interactor: .mock(environment: .failing), + viewFactory: viewFactory, + sceneProvider: nil, + engagementKind: .none, + screenShareHandler: .mock, + features: [], + environment: .failing + ) + } + + environment.coreSdk.localeProvider.getRemoteString = { _ in "" } + environment.coreSdk.configureWithInteractor = { _ in } + environment.coreSdk.configureWithConfiguration = { _, completion in + completion?() + } + environment.coreSdk.getCurrentEngagement = { nil } + + let sdk = Glia(environment: environment) + + let theme = Theme() + theme.call.connect.queue.firstText = "Glia 1" + theme.chat.connect.queue.firstText = "Glia 2" + + try sdk.configure(with: .mock()) + try sdk.startEngagement(engagementKind: .chat, in: ["queueId"], theme: theme) + + let configuredSdkTheme = resultingViewFactory?.theme + XCTAssertEqual(configuredSdkTheme?.call.connect.queue.firstText, "Glia 1") + XCTAssertEqual(configuredSdkTheme?.chat.connect.queue.firstText, "Glia 2") + } }