Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#F Change priority of company name algorithm #793

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 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,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 {
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")
}
}