-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathFeatureFlagManagerTests.swift
67 lines (57 loc) · 3.12 KB
/
FeatureFlagManagerTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// 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
import Shared
import XCTest
@testable import Client
class FeatureFlagManagerTests: XCTestCase, FeatureFlaggable {
// MARK: - Test Lifecycle
override func setUp() {
super.setUp()
let mockProfile = MockProfile(databasePrefix: "FeatureFlagsManagerTests_")
mockProfile.prefs.clearAll()
LegacyFeatureFlagsManager.shared.initializeDeveloperFeatures(with: mockProfile)
}
// MARK: - Tests
func testExpectedCoreFeatures() {
let adjustSetting = featureFlags.isCoreFeatureEnabled(.adjustEnvironmentProd)
let mockDataSetting = featureFlags.isCoreFeatureEnabled(.useMockData)
let contileAPISetting = featureFlags.isCoreFeatureEnabled(.useStagingContileAPI)
XCTAssertFalse(adjustSetting)
XCTAssertTrue(mockDataSetting)
XCTAssertTrue(contileAPISetting)
}
func testDefaultNimbusBoolFlags() {
// Tests for default settings should be performed on both build and user
// prefs separately to ensure that we are getting the expected results on both.
// Technically, at this stage, these should be the same.
XCTAssertTrue(featureFlags.isFeatureEnabled(.bottomSearchBar, checking: .buildOnly))
XCTAssertTrue(featureFlags.isFeatureEnabled(.bottomSearchBar, checking: .userOnly))
XCTAssertTrue(featureFlags.isFeatureEnabled(.inactiveTabs, checking: .buildOnly))
XCTAssertTrue(featureFlags.isFeatureEnabled(.inactiveTabs, checking: .userOnly))
XCTAssertTrue(featureFlags.isFeatureEnabled(.reportSiteIssue, checking: .buildOnly))
XCTAssertTrue(featureFlags.isFeatureEnabled(.reportSiteIssue, checking: .userOnly))
}
func testDefaultNimbusCustomFlags() {
XCTAssertEqual(featureFlags.getCustomState(for: .searchBarPosition), SearchBarPosition.top)
}
// Changing the prefs manually, to make sure settings are respected through
// the FFMs interface
func testManagerRespectsProfileChangesForCustomSettings() {
let mockProfile = MockProfile(databasePrefix: "FeatureFlagsManagerTests_")
mockProfile.prefs.clearAll()
LegacyFeatureFlagsManager.shared.initializeDeveloperFeatures(with: mockProfile)
// Search Bar position
XCTAssertEqual(featureFlags.getCustomState(for: .searchBarPosition), SearchBarPosition.top)
mockProfile.prefs.setString(SearchBarPosition.bottom.rawValue,
forKey: PrefsKeys.FeatureFlags.SearchBarPosition)
XCTAssertEqual(featureFlags.getCustomState(for: .searchBarPosition), SearchBarPosition.bottom)
}
func testManagerInterfaceForUpdatingCustomFlags() {
// Search Bar
XCTAssertEqual(featureFlags.getCustomState(for: .searchBarPosition), SearchBarPosition.top)
featureFlags.set(feature: .searchBarPosition, to: SearchBarPosition.bottom)
XCTAssertEqual(featureFlags.getCustomState(for: .searchBarPosition), SearchBarPosition.bottom)
}
}