From 8784145e8d441c471a608fc912db67156b387721 Mon Sep 17 00:00:00 2001 From: Gerson Noboa Date: Fri, 22 Sep 2023 16:56:05 +0300 Subject: [PATCH] Get company name from custom locales In this commit, support for adding a company name from custom locales is added. However, if the integrator has set this name through the theme, that one is used instead of the custom locales. Also, in case the custom locale doesn't have a string for the company name, but the integrator has specified a company name through the configuration of the SDK, then that is used. Finally, if neither of the previous possibilies have been used, then the local fallbacks are used. Together, the first and the last point mean that there are no backwards compatibility issues, as if the integrator hasn't set any name, still the local fallback will be displayed, which is "CompanyName". If they have, then that is used immediately without caring about configuration or custom locales. MOB-2686 --- GliaWidgets.xcodeproj/project.pbxproj | 8 -- .../Configuration/Configuration+Mock.swift | 6 +- .../Public/Glia/Glia+StartEngagement.swift | 41 +++++- GliaWidgets/Sources/Theme/Theme+Call.swift | 2 +- GliaWidgets/Sources/Theme/Theme+Chat.swift | 2 +- .../Call/CallViewController.Mock.swift | 2 + .../Glia/GliaTests+StartEngagement.swift | 123 ++++++++++++++++++ GliaWidgetsTests/Sources/Glia/GliaTests.swift | 3 +- 8 files changed, 172 insertions(+), 15 deletions(-) diff --git a/GliaWidgets.xcodeproj/project.pbxproj b/GliaWidgets.xcodeproj/project.pbxproj index 7de205049..e795b61d6 100644 --- a/GliaWidgets.xcodeproj/project.pbxproj +++ b/GliaWidgets.xcodeproj/project.pbxproj @@ -1690,7 +1690,6 @@ isa = PBXGroup; children = ( 3146C9412AB1850A0047D8CC /* Resources */, - 7552DFB22A6FBC6E0093519B /* CoreSdk */, 7552DFAF2A6FB37E0093519B /* ChatMessage */, 846A5C3729D18D220049B29F /* ScreenShareHandler */, AFEF5C7229929A73005C3D8D /* SecureConversations */, @@ -2688,13 +2687,6 @@ path = ChatMessage; sourceTree = ""; }; - 7552DFB22A6FBC6E0093519B /* CoreSdk */ = { - isa = PBXGroup; - children = ( - ); - path = CoreSdk; - sourceTree = ""; - }; 755D186329A6A4B10009F5E8 /* WelcomeStyle */ = { isa = PBXGroup; children = ( diff --git a/GliaWidgets/Public/Configuration/Configuration+Mock.swift b/GliaWidgets/Public/Configuration/Configuration+Mock.swift index 95883ef39..409453c4a 100644 --- a/GliaWidgets/Public/Configuration/Configuration+Mock.swift +++ b/GliaWidgets/Public/Configuration/Configuration+Mock.swift @@ -7,12 +7,14 @@ extension Configuration { static func mock( authMethod: AuthorizationMethod = .siteApiKey(id: "site-api-key-id", secret: "site-api-key-secret"), environment: Environment = .beta, - site: String = "site-id" + site: String = "site-id", + companyName: String = "" ) -> Self { Configuration( authorizationMethod: authMethod, environment: environment, - site: site + site: site, + companyName: companyName ) } } diff --git a/GliaWidgets/Public/Glia/Glia+StartEngagement.swift b/GliaWidgets/Public/Glia/Glia+StartEngagement.swift index 6a5ab4f35..d37f65e1c 100644 --- a/GliaWidgets/Public/Glia/Glia+StartEngagement.swift +++ b/GliaWidgets/Public/Glia/Glia+StartEngagement.swift @@ -46,6 +46,16 @@ extension Glia { interactor.queueIds = queueIds } + theme.chat.connect.queue.firstText = companyName( + using: interactor, + currentName: theme.chat.connect.queue.firstText + ) + + theme.call.connect.queue.firstText = companyName( + using: interactor, + currentName: theme.call.connect.queue.firstText + ) + let viewFactory = ViewFactory( with: theme, messageRenderer: messageRenderer, @@ -69,6 +79,35 @@ extension Glia { ) } + func companyName( + using interactor: Interactor, + currentName: 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) { + return remoteCompanyName + } + // Integrator has not set a company name in the custom locale, + // but has set it on the configuration. + else if !interactor.configuration.companyName.isEmpty { + return interactor.configuration.companyName + } + // Integrator has not set a company name anywhere, use the default. + else { + // This will return the fallback value every time, because we have + // already determined that the remote string is empty. + return Localization.General.companyName + } + } + func startRootCoordinator( with interactor: Interactor, viewFactory: ViewFactory, @@ -124,7 +163,7 @@ extension Glia { startSocketObservation: environment.coreSdk.startSocketObservation, stopSocketObservation: environment.coreSdk.stopSocketObservation, pushNotifications: environment.coreSdk.pushNotifications, - createSendMessagePayload: environment.coreSdk.createSendMessagePayload, + createSendMessagePayload: environment.coreSdk.createSendMessagePayload, orientationManager: environment.orientationManager ) ) diff --git a/GliaWidgets/Sources/Theme/Theme+Call.swift b/GliaWidgets/Sources/Theme/Theme+Call.swift index df7d96c9b..8b07db7d2 100644 --- a/GliaWidgets/Sources/Theme/Theme+Call.swift +++ b/GliaWidgets/Sources/Theme/Theme+Call.swift @@ -68,7 +68,7 @@ extension Theme { ) ) let queue = ConnectStatusStyle( - firstText: Localization.General.companyName, + firstText: "", firstTextFont: font.header1, firstTextFontColor: color.baseLight, firstTextStyle: .title1, diff --git a/GliaWidgets/Sources/Theme/Theme+Chat.swift b/GliaWidgets/Sources/Theme/Theme+Chat.swift index 89592c4be..7f3d75f86 100644 --- a/GliaWidgets/Sources/Theme/Theme+Chat.swift +++ b/GliaWidgets/Sources/Theme/Theme+Chat.swift @@ -70,7 +70,7 @@ extension Theme { ) ) let queue = ConnectStatusStyle( - firstText: Localization.General.companyName, + firstText: "", firstTextFont: font.header1, firstTextFontColor: color.baseDark, firstTextStyle: .title1, diff --git a/GliaWidgets/Sources/ViewController/Call/CallViewController.Mock.swift b/GliaWidgets/Sources/ViewController/Call/CallViewController.Mock.swift index 4af4c20d0..f0d35516e 100644 --- a/GliaWidgets/Sources/ViewController/Call/CallViewController.Mock.swift +++ b/GliaWidgets/Sources/ViewController/Call/CallViewController.Mock.swift @@ -43,6 +43,7 @@ extension CallViewController { startWith: startAction ) let theme = Theme.mock() + theme.call.connect.queue.firstText = "CompanyName" let viewFactEnv = ViewFactory.Environment.mock let viewFactory: ViewFactory = .mock( theme: theme, @@ -217,6 +218,7 @@ extension CallViewController { startWith: startAction ) let theme = Theme.mock() + theme.call.connect.queue.firstText = "CompanyName" let viewFactEnv = ViewFactory.Environment.mock let viewFactory: ViewFactory = .mock( theme: theme, diff --git a/GliaWidgetsTests/Sources/Glia/GliaTests+StartEngagement.swift b/GliaWidgetsTests/Sources/Glia/GliaTests+StartEngagement.swift index 5410d4d5c..e8a897498 100644 --- a/GliaWidgetsTests/Sources/Glia/GliaTests+StartEngagement.swift +++ b/GliaWidgetsTests/Sources/Glia/GliaTests+StartEngagement.swift @@ -51,4 +51,127 @@ extension GliaTests { XCTAssertTrue(interactor.isConfigurationPerformed) XCTAssertEqual(calls, [.configureWithInteractor, .configureWithConfiguration]) } + + func testCompanyNameIsReceivedFromTheme() 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 + ) + } + + 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") + } + + func testCompanyNameIsReceivedFromRemoteStrings() 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 "Glia" } + environment.coreSdk.configureWithInteractor = { _ in } + environment.coreSdk.configureWithConfiguration = { _, completion in + completion?() + } + environment.coreSdk.getCurrentEngagement = { nil } + + let sdk = Glia(environment: environment) + + try sdk.configure(with: .mock()) { } + try sdk.startEngagement(engagementKind: .chat, in: ["queueId"]) + + let configuredSdkTheme = resultingViewFactory?.theme + XCTAssertEqual(configuredSdkTheme?.call.connect.queue.firstText, "Glia") + XCTAssertEqual(configuredSdkTheme?.chat.connect.queue.firstText, "Glia") + } + + func testCompanyNameIsReceivedFromConfiguration() 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 + ) + } + + let sdk = Glia(environment: environment) + + try sdk.configure(with: .mock(companyName: "Glia")) + try sdk.startEngagement(engagementKind: .chat, in: ["queueId"]) + + let configuredSdkTheme = resultingViewFactory?.theme + XCTAssertEqual(configuredSdkTheme?.call.connect.queue.firstText, "Glia") + XCTAssertEqual(configuredSdkTheme?.chat.connect.queue.firstText, "Glia") + } + + func testCompanyNameIsReceivedFromLocalStrings() 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 + ) + } + + let sdk = Glia(environment: environment) + + try sdk.configure(with: .mock()) + try sdk.startEngagement(engagementKind: .chat, in: ["queueId"]) + + let configuredSdkTheme = resultingViewFactory?.theme + XCTAssertEqual(configuredSdkTheme?.call.connect.queue.firstText, "CompanyName") + XCTAssertEqual(configuredSdkTheme?.chat.connect.queue.firstText, "CompanyName") + } } diff --git a/GliaWidgetsTests/Sources/Glia/GliaTests.swift b/GliaWidgetsTests/Sources/Glia/GliaTests.swift index 8fb2e2567..46dcde9ca 100644 --- a/GliaWidgetsTests/Sources/Glia/GliaTests.swift +++ b/GliaWidgetsTests/Sources/Glia/GliaTests.swift @@ -49,7 +49,7 @@ final class GliaTests: XCTestCase { gliaEnv.fileManager = fileManager gliaEnv.coreSdk.configureWithInteractor = { _ in } gliaEnv.createFileUploadListModel = { _ in .mock() } - + gliaEnv.coreSdk.localeProvider.getRemoteString = { _ in nil } gliaEnv.coreSdk.authentication = { _ in .mock } gliaEnv.coreSdk.configureWithConfiguration = { _, callback in callback?() } gliaEnv.coreSdk.queueForEngagement = { _, callback in @@ -284,4 +284,3 @@ final class GliaTests: XCTestCase { XCTAssertEqual(delegate.invokedEventCallParameterList, [.maximized]) } } -