From 82f87750b09fed3473f2999ba812081ff1fb958c Mon Sep 17 00:00:00 2001 From: Gerson Noboa Date: Tue, 10 Oct 2023 15:28:54 +0300 Subject: [PATCH] Change priority of company name algorithm Before, the UiTheme took the highest priority in the algorithm to determine the company name. Now the remote company name has the highest priority, with the added constraint that it cannot be empty, as this will be the default value on the default locale. In case it is empty, the UiTheme will come afterwards, then the SDK configuration, and finally the local fallback. MOB-2733 --- .../Public/Glia/Glia+StartEngagement.swift | 23 +++++----- .../Glia/GliaTests+StartEngagement.swift | 46 ++++++++++++++++++- 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/GliaWidgets/Public/Glia/Glia+StartEngagement.swift b/GliaWidgets/Public/Glia/Glia+StartEngagement.swift index d37f65e1c..c6e4f1566 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,21 @@ 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") + } }