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

[MBL-993] Dark Mode Feature Flag #1865

Merged
merged 3 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
switch feature {
case .consentManagementDialogEnabled:
return featureConsentManagementDialogEnabled()
case .darkModeEnabled:
return featureDarkModeEnabled()
case .facebookLoginInterstitialEnabled:
return featureFacebookLoginInterstitialEnabled()
case .reportThisProjectEnabled:
Expand All @@ -103,6 +105,9 @@
case .consentManagementDialogEnabled:
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.consentManagementDialogEnabled.rawValue]
case .darkModeEnabled:
return AppEnvironment.current.userDefaults

Check warning on line 109 in Library/ViewModels/RemoteConfigFeatureFlagToolsViewModel.swift

View check run for this annotation

Codecov / codecov/patch

Library/ViewModels/RemoteConfigFeatureFlagToolsViewModel.swift#L109

Added line #L109 was not covered by tests
.remoteConfigFeatureFlags[RemoteConfigFeature.darkModeEnabled.rawValue]
case .facebookLoginInterstitialEnabled:
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.facebookLoginInterstitialEnabled.rawValue]
Expand All @@ -122,6 +127,9 @@
case .consentManagementDialogEnabled:
AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.consentManagementDialogEnabled.rawValue] = value
case .darkModeEnabled:
AppEnvironment.current.userDefaults

Check warning on line 131 in Library/ViewModels/RemoteConfigFeatureFlagToolsViewModel.swift

View check run for this annotation

Codecov / codecov/patch

Library/ViewModels/RemoteConfigFeatureFlagToolsViewModel.swift#L131

Added line #L131 was not covered by tests
.remoteConfigFeatureFlags[RemoteConfigFeature.darkModeEnabled.rawValue] = value
case .facebookLoginInterstitialEnabled:
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.facebookLoginInterstitialEnabled.rawValue] = value
Expand Down
Original file line number Diff line number Diff line change
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