Skip to content

Commit

Permalink
[MBL-993] Dark Mode Feature Flag (#1865)
Browse files Browse the repository at this point in the history
* add new feature flag

* add install-rosetta step to deploy_alpha
  • Loading branch information
scottkicks committed Oct 11, 2023
1 parent 1475571 commit d90d518
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 0 deletions.
Expand Up @@ -23,6 +23,7 @@ final class RemoteConfigFeatureFlagToolsViewControllerTests: TestCase {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [
RemoteConfigFeature.consentManagementDialogEnabled.rawValue: false,
RemoteConfigFeature.darkModeEnabled.rawValue: false,
RemoteConfigFeature.facebookLoginInterstitialEnabled
.rawValue: false,
RemoteConfigFeature.reportThisProjectEnabled.rawValue: false
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Library/RemoteConfig/RemoteConfigFeature+Helpers.swift
Expand Up @@ -7,6 +7,13 @@ public func featureConsentManagementDialogEnabled() -> Bool {
.isFeatureEnabled(featureKey: RemoteConfigFeature.consentManagementDialogEnabled) ?? false)
}

public func featureDarkModeEnabled() -> Bool {
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.darkModeEnabled.rawValue] ??
(AppEnvironment.current.remoteConfigClient?
.isFeatureEnabled(featureKey: RemoteConfigFeature.darkModeEnabled) ?? false)
}

public func featureFacebookLoginInterstitialEnabled() -> Bool {
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.facebookLoginInterstitialEnabled.rawValue] ??
Expand Down
18 changes: 18 additions & 0 deletions Library/RemoteConfig/RemoteConfigFeature+HelpersTests.swift
Expand Up @@ -21,6 +21,24 @@ final class RemoteConfigFeatureHelpersTests: TestCase {
}
}

func testDarkMode_RemoteConfig_FeatureFlag_False() {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [RemoteConfigFeature.darkModeEnabled.rawValue: false]

withEnvironment(remoteConfigClient: mockRemoteConfigClient) {
XCTAssertFalse(featureDarkModeEnabled())
}
}

func testDarkMode_RemoteConfig_FeatureFlag_True() {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [RemoteConfigFeature.darkModeEnabled.rawValue: true]

withEnvironment(remoteConfigClient: mockRemoteConfigClient) {
XCTAssertTrue(featureDarkModeEnabled())
}
}

func testFacebookDeprecation_RemoteConfig_FeatureFlag_True() {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [RemoteConfigFeature.facebookLoginInterstitialEnabled.rawValue: true]
Expand Down
2 changes: 2 additions & 0 deletions Library/RemoteConfig/RemoteConfigFeature.swift
Expand Up @@ -2,6 +2,7 @@ import Foundation

public enum RemoteConfigFeature: String, CaseIterable {
case consentManagementDialogEnabled = "consent_management_dialog"
case darkModeEnabled = "dark_mode"
case facebookLoginInterstitialEnabled = "facebook_interstitial"
case reportThisProjectEnabled = "report_this_project"
case useOfAIProjectTab = "use_of_ai_project_tab"
Expand All @@ -11,6 +12,7 @@ extension RemoteConfigFeature: CustomStringConvertible {
public var description: String {
switch self {
case .consentManagementDialogEnabled: return "Consent Management Dialog"
case .darkModeEnabled: return "Dark Mode"
case .facebookLoginInterstitialEnabled: return "Facebook Login Interstitial"
case .reportThisProjectEnabled: return "Report This Project"
case .useOfAIProjectTab: return "Use of AI Project Tab"
Expand Down
Expand Up @@ -87,6 +87,8 @@ private func isFeatureEnabled(_ feature: RemoteConfigFeature) -> Bool {
switch feature {
case .consentManagementDialogEnabled:
return featureConsentManagementDialogEnabled()
case .darkModeEnabled:
return featureDarkModeEnabled()
case .facebookLoginInterstitialEnabled:
return featureFacebookLoginInterstitialEnabled()
case .reportThisProjectEnabled:
Expand All @@ -103,6 +105,9 @@ private func getValueFromUserDefaults(for feature: RemoteConfigFeature) -> Bool?
case .consentManagementDialogEnabled:
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.consentManagementDialogEnabled.rawValue]
case .darkModeEnabled:
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.darkModeEnabled.rawValue]
case .facebookLoginInterstitialEnabled:
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.facebookLoginInterstitialEnabled.rawValue]
Expand All @@ -122,6 +127,9 @@ private func setValueInUserDefaults(for feature: RemoteConfigFeature, and value:
case .consentManagementDialogEnabled:
AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.consentManagementDialogEnabled.rawValue] = value
case .darkModeEnabled:
AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.darkModeEnabled.rawValue] = value
case .facebookLoginInterstitialEnabled:
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.facebookLoginInterstitialEnabled.rawValue] = value
Expand Down
Expand Up @@ -23,6 +23,7 @@ final class RemoteConfigFlagToolsViewModelTests: TestCase {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [
RemoteConfigFeature.consentManagementDialogEnabled.rawValue: true,
RemoteConfigFeature.darkModeEnabled.rawValue: true,
RemoteConfigFeature.facebookLoginInterstitialEnabled.rawValue: true,
RemoteConfigFeature.reportThisProjectEnabled.rawValue: true,
RemoteConfigFeature.useOfAIProjectTab.rawValue: true
Expand All @@ -45,6 +46,7 @@ final class RemoteConfigFlagToolsViewModelTests: TestCase {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [
RemoteConfigFeature.consentManagementDialogEnabled.rawValue: true,
RemoteConfigFeature.darkModeEnabled.rawValue: false,
RemoteConfigFeature.facebookLoginInterstitialEnabled.rawValue: true,
RemoteConfigFeature.reportThisProjectEnabled.rawValue: false,
RemoteConfigFeature.useOfAIProjectTab.rawValue: false
Expand Down

0 comments on commit d90d518

Please sign in to comment.