Skip to content

Commit

Permalink
Merge pull request #2314 from CruGlobal/GT-2469-disable-firebase-mess…
Browse files Browse the repository at this point in the history
…aging-in-ui-tests

GT-2469 disable firebase messaging in UI tests
  • Loading branch information
levieggertcru authored Oct 31, 2024
2 parents ad5d94f + f407cb4 commit 5f333ab
Show file tree
Hide file tree
Showing 18 changed files with 289 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SPEC REPOS:
- GodToolsShared

SPEC CHECKSUMS:
GodToolsShared: 0b717d26f71b2eb7748b6999ad3d2d6fe7a8c401
GodToolsShared: 404a619e53dc1890091397ac4e1da69afb5eabcd

PODFILE CHECKSUM: 1816453b60fe876696e3cc9b1da49602bb07e16b

Expand Down
121 changes: 109 additions & 12 deletions godtools.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions godtools/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
InfoPlist()
}()

private lazy var launchEnvironmentReader: LaunchEnvironmentReader = {
return LaunchEnvironmentReader.createFromProcessInfo()
}()

private lazy var realmDatabase: RealmDatabase = {
RealmDatabase(databaseConfiguration: RealmDatabaseProductionConfiguration())
}()
Expand All @@ -35,11 +39,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}()

private lazy var appDiContainer: AppDiContainer = {
AppDiContainer(appBuild: appBuild, appConfig: appConfig, infoPlist: infoPlist, realmDatabase: realmDatabase)
AppDiContainer(
appBuild: appBuild,
appConfig: appConfig,
infoPlist: infoPlist,
realmDatabase: realmDatabase,
appMessagingEnabled: launchEnvironmentReader.getAppMessagingIsEnabled() ?? true
)
}()

private lazy var appFlow: AppFlow = {
AppFlow(appDiContainer: appDiContainer, appDeepLinkingService: appDeepLinkingService)
AppFlow(
appDiContainer: appDiContainer,
appDeepLinkingService: appDeepLinkingService
)
}()

private var toolShortcutLinks: ToolShortcutLinksView?
Expand Down Expand Up @@ -89,7 +102,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

application.registerForRemoteNotifications()

let uiTestsDeepLinkString: String? = ProcessInfo.processInfo.environment[LaunchEnvironmentKey.urlDeeplink.value]
let uiTestsDeepLinkString: String? = launchEnvironmentReader.getUrlDeepLink()

if let uiTestsDeepLinkString = uiTestsDeepLinkString, !uiTestsDeepLinkString.isEmpty, let url = URL(string: uiTestsDeepLinkString) {
_ = appDeepLinkingService.parseDeepLinkAndNotify(incomingDeepLink: .url(incomingUrl: IncomingDeepLinkUrl(url: url)))
Expand Down
17 changes: 12 additions & 5 deletions godtools/App/DependencyContainer/AppDataLayerDependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ class AppDataLayerDependencies {
private let sharedIgnoreCacheSession: IgnoreCacheSession = IgnoreCacheSession()
private let sharedUserDefaultsCache: SharedUserDefaultsCache = SharedUserDefaultsCache()
private let sharedAnalytics: AnalyticsContainer
private let appMessagingEnabled: Bool

init(appBuild: AppBuild, appConfig: AppConfig, infoPlist: InfoPlist, realmDatabase: RealmDatabase) {
init(appBuild: AppBuild, appConfig: AppConfig, infoPlist: InfoPlist, realmDatabase: RealmDatabase, appMessagingEnabled: Bool) {

sharedAppBuild = appBuild
sharedAppConfig = appConfig
sharedInfoPlist = infoPlist
sharedRealmDatabase = realmDatabase
self.appMessagingEnabled = appMessagingEnabled

sharedAnalytics = AnalyticsContainer(
appsFlyerAnalytics: AppsFlyerAnalytics(appsFlyer: AppsFlyer.shared, loggingEnabled: appBuild.configuration == .analyticsLogging),
Expand Down Expand Up @@ -53,6 +55,15 @@ class AppDataLayerDependencies {
return sharedAppConfig
}

func getAppMessaging() -> AppMessagingInterface {

guard appMessagingEnabled else {
return DisabledInAppMessaging()
}

return FirebaseInAppMessaging.shared
}

func getArticleAemRepository() -> ArticleAemRepository {
return ArticleAemRepository(
downloader: ArticleAemDownloader(
Expand Down Expand Up @@ -122,10 +133,6 @@ class AppDataLayerDependencies {
return FavoritingToolMessageCache(userDefaultsCache: sharedUserDefaultsCache)
}

func getFirebaseInAppMessaing() -> FirebaseInAppMessaging {
return FirebaseInAppMessaging.shared
}

func getFollowUpsService() -> FollowUpsService {

let api = FollowUpsApi(
Expand Down
11 changes: 9 additions & 2 deletions godtools/App/DependencyContainer/AppDiContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ class AppDiContainer {
let domainLayer: AppDomainLayerDependencies
let feature: AppFeatureDiContainer

init(appBuild: AppBuild, appConfig: AppConfig, infoPlist: InfoPlist, realmDatabase: RealmDatabase) {
init(appBuild: AppBuild, appConfig: AppConfig, infoPlist: InfoPlist, realmDatabase: RealmDatabase, appMessagingEnabled: Bool) {

self.appBuild = appBuild
self.realmDatabase = realmDatabase

dataLayer = AppDataLayerDependencies(appBuild: appBuild, appConfig: appConfig, infoPlist: infoPlist, realmDatabase: realmDatabase)
dataLayer = AppDataLayerDependencies(
appBuild: appBuild,
appConfig: appConfig,
infoPlist: infoPlist,
realmDatabase: realmDatabase,
appMessagingEnabled: appMessagingEnabled
)

domainLayer = AppDomainLayerDependencies(dataLayer: dataLayer)

let accountDiContainer = AccountDiContainer(coreDataLayer: dataLayer)
Expand Down
16 changes: 8 additions & 8 deletions godtools/App/Flows/App/AppFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AppFlow: NSObject, ToolNavigationFlow, Flow {
private let followUpsService: FollowUpsService
private let resourceViewsService: ResourceViewsService
private let deepLinkingService: DeepLinkingService
private let inAppMessaging: FirebaseInAppMessaging
private let appMessaging: AppMessagingInterface
private let dashboardTabObserver = CurrentValueSubject<DashboardTabTypeDomainModel, Never>(AppFlow.defaultStartingDashboardTab)

private var onboardingFlow: OnboardingFlow?
Expand Down Expand Up @@ -66,7 +66,7 @@ class AppFlow: NSObject, ToolNavigationFlow, Flow {
self.followUpsService = appDiContainer.dataLayer.getFollowUpsService()
self.resourceViewsService = appDiContainer.dataLayer.getResourceViewsService()
self.deepLinkingService = appDeepLinkingService
self.inAppMessaging = appDiContainer.dataLayer.getFirebaseInAppMessaing()
self.appMessaging = appDiContainer.dataLayer.getAppMessaging()

super.init()

Expand All @@ -81,7 +81,7 @@ class AppFlow: NSObject, ToolNavigationFlow, Flow {
addUIApplicationLifeCycleObservers()
addDeepLinkingObservers()

inAppMessaging.setDelegate(delegate: self)
appMessaging.setMessagingDelegate(messagingDelegate: self)

appDiContainer.feature.appLanguage.domainLayer
.getCurrentAppLanguageUseCase()
Expand Down Expand Up @@ -402,7 +402,7 @@ class AppFlow: NSObject, ToolNavigationFlow, Flow {
case .languageSettingsFlowCompleted( _):
closeLanguageSettings()

case .buttonWithUrlTappedFromFirebaseInAppMessage(let url):
case .buttonWithUrlTappedFromAppMessage(let url):

let didParseDeepLinkFromUrl: Bool = deepLinkingService.parseDeepLinkAndNotify(incomingDeepLink: .url(incomingUrl: IncomingDeepLinkUrl(url: url)))

Expand Down Expand Up @@ -1385,11 +1385,11 @@ extension AppFlow {
}
}

// MARK: - FirebaseInAppMessagingDelegate
// MARK: - AppMessagingDelegate

extension AppFlow: FirebaseInAppMessagingDelegate {
extension AppFlow: AppMessagingDelegate {

func firebaseInAppMessageActionTappedWithUrl(url: URL) {
navigate(step: .buttonWithUrlTappedFromFirebaseInAppMessage(url: url))
func actionTappedWithUrl(url: URL) {
navigate(step: .buttonWithUrlTappedFromAppMessage(url: url))
}
}
2 changes: 1 addition & 1 deletion godtools/App/Flows/Flow/FlowStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum FlowStep {
case deepLink(deepLinkType: ParsedDeepLinkType)
case showOnboardingTutorial(animated: Bool)
case onboardingFlowCompleted(onboardingFlowCompletedState: OnboardingFlowCompletedState?)
case buttonWithUrlTappedFromFirebaseInAppMessage(url: URL)
case buttonWithUrlTappedFromAppMessage(url: URL)
case menuTappedFromTools
case openTutorialTappedFromTools

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class SwiftUIPreviewDiContainer {
appBuild: appBuild,
appConfig: AppConfig(appBuild: appBuild),
infoPlist: InfoPlist(),
realmDatabase: SwiftUIPreviewDiContainer.previewDatabase
realmDatabase: SwiftUIPreviewDiContainer.previewDatabase,
appMessagingEnabled: false
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ enum LaunchEnvironmentKey: String {
return rawValue
}

case appMessagingIsEnabled
case urlDeeplink
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// LaunchEnvironmentReader.swift
// godtools
//
// Created by Levi Eggert on 10/31/24.
// Copyright © 2024 Cru. All rights reserved.
//

import Foundation

class LaunchEnvironmentReader {

private let launchEnvironment: [String: String]

init(launchEnvironment: [String: String]) {

self.launchEnvironment = launchEnvironment
}

static func createFromProcessInfo() -> LaunchEnvironmentReader {
return LaunchEnvironmentReader(launchEnvironment: ProcessInfo.processInfo.environment)
}

func getAppMessagingIsEnabled() -> Bool? {

guard let stringBool = launchEnvironment[LaunchEnvironmentKey.appMessagingIsEnabled.value] else {
return nil
}

return Bool(stringBool)
}

func getUrlDeepLink() -> String? {
return launchEnvironment[LaunchEnvironmentKey.urlDeeplink.value]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// LaunchEnvironmentWriter.swift
// godtools
//
// Created by Levi Eggert on 10/31/24.
// Copyright © 2024 Cru. All rights reserved.
//

import Foundation

class LaunchEnvironmentWriter {

init() {

}

func setAppMessagingIsEnabled(launchEnvironment: inout [String: String], enabled: Bool) {
launchEnvironment[LaunchEnvironmentKey.appMessagingIsEnabled.value] = String(enabled)
}

func setUrlDeepLink(launchEnvironment: inout [String: String], url: String) {
launchEnvironment[LaunchEnvironmentKey.urlDeeplink.value] = url
}
}
14 changes: 14 additions & 0 deletions godtools/App/Share/Data/AppMessaging/AppMessagingDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// AppMessagingDelegate.swift
// godtools
//
// Created by Levi Eggert on 10/30/24.
// Copyright © 2024 Cru. All rights reserved.
//

import Foundation

protocol AppMessagingDelegate: AnyObject {

func actionTappedWithUrl(url: URL)
}
16 changes: 16 additions & 0 deletions godtools/App/Share/Data/AppMessaging/AppMessagingInterface.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// AppMessagingInterface.swift
// godtools
//
// Created by Levi Eggert on 10/30/24.
// Copyright © 2024 Cru. All rights reserved.
//

import Foundation

protocol AppMessagingInterface {

var messagingDelegate: AppMessagingDelegate? { get }

func setMessagingDelegate(messagingDelegate: AppMessagingDelegate?)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// DisabledInAppMessaging.swift
// godtools
//
// Created by Levi Eggert on 10/31/24.
// Copyright © 2024 Cru. All rights reserved.
//

class DisabledInAppMessaging: AppMessagingInterface {

private(set) weak var messagingDelegate: AppMessagingDelegate?

init() {

}

func setMessagingDelegate(messagingDelegate: AppMessagingDelegate?) {

// Won't do anything here. The purpose of this class is to provide a disabled in app messaging that does nothing. ~Levi
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,22 @@
import Foundation
import FirebaseInAppMessaging

protocol FirebaseInAppMessagingDelegate: AnyObject {

func firebaseInAppMessageActionTappedWithUrl(url: URL)
}

class FirebaseInAppMessaging: NSObject {
class FirebaseInAppMessaging: NSObject, AppMessagingInterface {

static let shared: FirebaseInAppMessaging = FirebaseInAppMessaging()

private let sharedInAppMessaging: InAppMessaging = InAppMessaging.inAppMessaging()

private weak var delegate: FirebaseInAppMessagingDelegate?

private(set) weak var messagingDelegate: AppMessagingDelegate?
private override init() {

super.init()
}

func setDelegate(delegate: FirebaseInAppMessagingDelegate?) {

if self.delegate != nil && delegate != nil {
assertionFailure("\nWARNING: Attempting to set delegate that has already been set on \(String(describing: self.delegate)). Is this intended?\n")
}

sharedInAppMessaging.delegate = self
self.delegate = delegate
}

func triggerInAppMessage(eventName: String) {
func setMessagingDelegate(messagingDelegate: AppMessagingDelegate?) {

sharedInAppMessaging.triggerEvent(eventName)
self.messagingDelegate = messagingDelegate
}
}

Expand All @@ -50,7 +35,7 @@ extension FirebaseInAppMessaging: InAppMessagingDisplayDelegate {
func messageClicked(_ inAppMessage: InAppMessagingDisplayMessage, with action: InAppMessagingAction) {

if let url = action.actionURL {
delegate?.firebaseInAppMessageActionTappedWithUrl(url: url)
messagingDelegate?.actionTappedWithUrl(url: url)
}
}

Expand Down
3 changes: 2 additions & 1 deletion godtoolsTests/App/DependencyContainer/TestsDiContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class TestsDiContainer: AppDiContainer {
appBuild: appBuild,
appConfig: appConfig,
infoPlist: InfoPlist(),
realmDatabase: realmDatabase
realmDatabase: realmDatabase,
appMessagingEnabled: false
)
}
}
Loading

0 comments on commit 5f333ab

Please sign in to comment.