Skip to content

Commit

Permalink
Change priority of company name algorithm
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gersonnoboa committed Oct 10, 2023
1 parent f766393 commit d482c1d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 12 deletions.
25 changes: 14 additions & 11 deletions GliaWidgets/Public/Glia/Glia+StartEngagement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down
46 changes: 45 additions & 1 deletion GliaWidgetsTests/Sources/Glia/GliaTests+StartEngagement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
}
}

0 comments on commit d482c1d

Please sign in to comment.