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 Get company name from custom locales #782

Merged
merged 1 commit into from
Sep 26, 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
8 changes: 0 additions & 8 deletions GliaWidgets.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,6 @@
isa = PBXGroup;
children = (
3146C9412AB1850A0047D8CC /* Resources */,
7552DFB22A6FBC6E0093519B /* CoreSdk */,
7552DFAF2A6FB37E0093519B /* ChatMessage */,
846A5C3729D18D220049B29F /* ScreenShareHandler */,
AFEF5C7229929A73005C3D8D /* SecureConversations */,
Expand Down Expand Up @@ -2688,13 +2687,6 @@
path = ChatMessage;
sourceTree = "<group>";
};
7552DFB22A6FBC6E0093519B /* CoreSdk */ = {
isa = PBXGroup;
children = (
);
path = CoreSdk;
sourceTree = "<group>";
};
755D186329A6A4B10009F5E8 /* WelcomeStyle */ = {
isa = PBXGroup;
children = (
Expand Down
6 changes: 4 additions & 2 deletions GliaWidgets/Public/Configuration/Configuration+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
Expand Down
41 changes: 40 additions & 1 deletion GliaWidgets/Public/Glia/Glia+StartEngagement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
)
)
Expand Down
2 changes: 1 addition & 1 deletion GliaWidgets/Sources/Theme/Theme+Call.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extension Theme {
)
)
let queue = ConnectStatusStyle(
firstText: Localization.General.companyName,
firstText: "",
firstTextFont: font.header1,
firstTextFontColor: color.baseLight,
firstTextStyle: .title1,
Expand Down
2 changes: 1 addition & 1 deletion GliaWidgets/Sources/Theme/Theme+Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extension Theme {
)
)
let queue = ConnectStatusStyle(
firstText: Localization.General.companyName,
firstText: "",
firstTextFont: font.header1,
firstTextFontColor: color.baseDark,
firstTextStyle: .title1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
123 changes: 123 additions & 0 deletions GliaWidgetsTests/Sources/Glia/GliaTests+StartEngagement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
3 changes: 1 addition & 2 deletions GliaWidgetsTests/Sources/Glia/GliaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -284,4 +284,3 @@ final class GliaTests: XCTestCase {
XCTAssertEqual(delegate.invokedEventCallParameterList, [.maximized])
}
}

Loading