-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add FXIOS-10881 [Sent from Firefox] Add ability to override a user's preference for a nimbus feature in unit tests #23790
Changes from all commits
5c07f90
ab9b0bc
6438113
9930655
b2a34f7
e455fae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import Foundation | ||
|
||
extension UserDefaults { | ||
/// Returns `true` if this value exists, and `false` if the value is `nil`. | ||
/// | ||
/// @discussion: | ||
/// Calling `.bool(forKey:)` for a value that does NOT exist always returns false. However, sometimes we want to check | ||
/// that the value has actually been set first. | ||
func valueExists(forKey key: String) -> Bool { | ||
return object(forKey: key) != nil | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,11 +151,6 @@ struct NimbusFlaggableFeature: HasNimbusSearchBar { | |
|
||
// MARK: - Public methods | ||
public func isNimbusEnabled(using nimbusLayer: NimbusFeatureFlagLayer) -> Bool { | ||
// Provide a way to override nimbus feature enabled for tests | ||
if AppConstants.isRunningUnitTest, UserDefaults.standard.bool(forKey: PrefsKeys.NimbusFeatureTestsOverride) { | ||
return true | ||
} | ||
|
||
return nimbusLayer.checkNimbusConfigFor(featureID) | ||
} | ||
|
||
|
@@ -166,7 +161,15 @@ struct NimbusFlaggableFeature: HasNimbusSearchBar { | |
public func isUserEnabled(using nimbusLayer: NimbusFeatureFlagLayer) -> Bool { | ||
guard let optionsKey = featureKey, | ||
let option = profile.prefs.boolForKey(optionsKey) | ||
else { return isNimbusEnabled(using: nimbusLayer) } | ||
else { | ||
// In unit tests only, we provide a way to return an override value to simulate a user's preference for a feature | ||
if AppConstants.isRunningUnitTest, | ||
UserDefaults.standard.valueExists(forKey: PrefsKeys.NimbusUserEnabledFeatureTestsOverride) { | ||
return UserDefaults.standard.bool(forKey: PrefsKeys.NimbusUserEnabledFeatureTestsOverride) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I basically just hijacked some existing code and moved it down into the I had to move this code because |
||
|
||
return isNimbusEnabled(using: nimbusLayer) | ||
} | ||
|
||
return option | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed because previously using the
NimbusUserEnabledFeatureTestsOverride
always overrode the value totrue
. I wanted the value to override eithertrue
orfalse
so we can test with both the user preference enabled or disabled.