From 8584abe0c7dd86470d24a7df884e9368fd96ebd2 Mon Sep 17 00:00:00 2001 From: Sam Symons Date: Fri, 18 Oct 2024 09:02:21 -0700 Subject: [PATCH] Remove `voiceSearchHelper` from `AppDependencyProvider` (#3452) Task/Issue URL: https://app.asana.com/0/414235014887631/1208574561964832/f Tech Design URL: CC: Description: This PR removes voiceSearchHelper from AppDependencyProvider and updates the test suite to no longer mutate the dependency provider singleton. Tests that use this pattern have been prone to occasional crashes, so I'm simplifying them and working towards removing makeTestingInstance() entirely. --- DuckDuckGo/AppDelegate.swift | 12 +- DuckDuckGo/AppDependencyProvider.swift | 2 - DuckDuckGo/BlankSnapshotViewController.swift | 6 +- DuckDuckGo/LargeOmniBarState.swift | 98 ++++---- DuckDuckGo/MainView.swift | 10 +- DuckDuckGo/MainViewController+Segues.swift | 1 + DuckDuckGo/MainViewController.swift | 12 +- DuckDuckGo/OmniBar.swift | 22 +- DuckDuckGo/SettingsViewModel.swift | 6 +- DuckDuckGo/SmallOmniBarState.swift | 112 +++++---- DuckDuckGo/SwipeTabsCoordinator.swift | 9 +- DuckDuckGoTests/BarsAnimatorTests.swift | 3 +- DuckDuckGoTests/LargeOmniBarStateTests.swift | 216 ++++++++---------- DuckDuckGoTests/MockDependencyProvider.swift | 2 - .../OnboardingDaxFavouritesTests.swift | 3 +- .../OnboardingNavigationDelegateTests.swift | 3 +- DuckDuckGoTests/QuerySubmittedTests.swift | 2 +- DuckDuckGoTests/SmallOmniBarStateTests.swift | 214 ++++++++--------- 18 files changed, 364 insertions(+), 369 deletions(-) diff --git a/DuckDuckGo/AppDelegate.swift b/DuckDuckGo/AppDelegate.swift index 2863f90b3c..3d009fd4ba 100644 --- a/DuckDuckGo/AppDelegate.swift +++ b/DuckDuckGo/AppDelegate.swift @@ -105,6 +105,8 @@ import os.log private let launchOptionsHandler = LaunchOptionsHandler() private let onboardingPixelReporter = OnboardingPixelReporter() + private let voiceSearchHelper = VoiceSearchHelper() + private let marketplaceAdPostbackManager = MarketplaceAdPostbackManager() override init() { super.init() @@ -320,7 +322,8 @@ import os.log if shouldPresentInsufficientDiskSpaceAlertAndCrash { window = UIWindow(frame: UIScreen.main.bounds) - window?.rootViewController = BlankSnapshotViewController(appSettings: AppDependencyProvider.shared.appSettings) + window?.rootViewController = BlankSnapshotViewController(appSettings: AppDependencyProvider.shared.appSettings, + voiceSearchHelper: voiceSearchHelper) window?.makeKeyAndVisible() presentInsufficientDiskSpaceAlert() @@ -342,7 +345,8 @@ import os.log contextualOnboardingPresenter: contextualOnboardingPresenter, contextualOnboardingLogic: daxDialogs, contextualOnboardingPixelReporter: onboardingPixelReporter, - subscriptionFeatureAvailability: subscriptionFeatureAvailability) + subscriptionFeatureAvailability: subscriptionFeatureAvailability, + voiceSearchHelper: voiceSearchHelper) main.loadViewIfNeeded() syncErrorHandler.alertPresenter = main @@ -359,7 +363,7 @@ import os.log } } - AppDependencyProvider.shared.voiceSearchHelper.migrateSettingsFlagIfNecessary() + self.voiceSearchHelper.migrateSettingsFlagIfNecessary() // Task handler registration needs to happen before the end of `didFinishLaunching`, otherwise submitting a task can throw an exception. // Having both in `didBecomeActive` can sometimes cause the exception when running on a physical device, so registration happens here. @@ -828,7 +832,7 @@ import os.log overlayWindow = UIWindow(frame: frame) overlayWindow?.windowLevel = UIWindow.Level.alert - let overlay = BlankSnapshotViewController(appSettings: AppDependencyProvider.shared.appSettings) + let overlay = BlankSnapshotViewController(appSettings: AppDependencyProvider.shared.appSettings, voiceSearchHelper: voiceSearchHelper) overlay.delegate = self overlayWindow?.rootViewController = overlay diff --git a/DuckDuckGo/AppDependencyProvider.swift b/DuckDuckGo/AppDependencyProvider.swift index 196ded5082..4f87b08207 100644 --- a/DuckDuckGo/AppDependencyProvider.swift +++ b/DuckDuckGo/AppDependencyProvider.swift @@ -34,7 +34,6 @@ protocol DependencyProvider { var internalUserDecider: InternalUserDecider { get } var featureFlagger: FeatureFlagger { get } var storageCache: StorageCache { get } - var voiceSearchHelper: VoiceSearchHelperProtocol { get } var downloadManager: DownloadManager { get } var autofillLoginSession: AutofillLoginSession { get } var autofillNeverPromptWebsitesManager: AutofillNeverPromptWebsitesManager { get } @@ -64,7 +63,6 @@ final class AppDependencyProvider: DependencyProvider { let featureFlagger: FeatureFlagger let storageCache = StorageCache() - let voiceSearchHelper: VoiceSearchHelperProtocol = VoiceSearchHelper() let downloadManager = DownloadManager() let autofillLoginSession = AutofillLoginSession() lazy var autofillNeverPromptWebsitesManager = AutofillNeverPromptWebsitesManager() diff --git a/DuckDuckGo/BlankSnapshotViewController.swift b/DuckDuckGo/BlankSnapshotViewController.swift index ab4c6b2471..9c55649c0d 100644 --- a/DuckDuckGo/BlankSnapshotViewController.swift +++ b/DuckDuckGo/BlankSnapshotViewController.swift @@ -37,13 +37,15 @@ class BlankSnapshotViewController: UIViewController { var tabSwitcherButton: TabSwitcherButton! let appSettings: AppSettings + let voiceSearchHelper: VoiceSearchHelperProtocol var viewCoordinator: MainViewCoordinator! weak var delegate: BlankSnapshotViewRecoveringDelegate? - init(appSettings: AppSettings) { + init(appSettings: AppSettings, voiceSearchHelper: VoiceSearchHelperProtocol) { self.appSettings = appSettings + self.voiceSearchHelper = voiceSearchHelper super.init(nibName: nil, bundle: nil) } @@ -56,7 +58,7 @@ class BlankSnapshotViewController: UIViewController { tabSwitcherButton = TabSwitcherButton() - viewCoordinator = MainViewFactory.createViewHierarchy(view) + viewCoordinator = MainViewFactory.createViewHierarchy(view, voiceSearchHelper: voiceSearchHelper) if appSettings.currentAddressBarPosition.isBottom { viewCoordinator.moveAddressBarToPosition(.bottom) viewCoordinator.hideToolbarSeparator() diff --git a/DuckDuckGo/LargeOmniBarState.swift b/DuckDuckGo/LargeOmniBarState.swift index 6c4fb32904..eb543f9f96 100644 --- a/DuckDuckGo/LargeOmniBarState.swift +++ b/DuckDuckGo/LargeOmniBarState.swift @@ -30,7 +30,6 @@ struct LargeOmniBarState { let showShareButton: Bool = false let clearTextOnStart = true let allowsTrackersAnimation = false - let showSearchLoupe = !AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled let showPrivacyIcon = false let showBackground = false let showClear = false @@ -38,17 +37,20 @@ struct LargeOmniBarState { let showMenu = false let showSettings = true let showCancel: Bool = false - let showVoiceSearch = AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled var name: String { return "Pad" + Type.name(self) } - var onEditingStoppedState: OmniBarState { return HomeNonEditingState() } + var onEditingStoppedState: OmniBarState { return HomeNonEditingState(voiceSearchHelper: voiceSearchHelper) } var onEditingStartedState: OmniBarState { return self } var onTextClearedState: OmniBarState { return self } - var onTextEnteredState: OmniBarState { return HomeTextEditingState() } - var onBrowsingStartedState: OmniBarState { return BrowsingNonEditingState() } + var onTextEnteredState: OmniBarState { return HomeTextEditingState(voiceSearchHelper: voiceSearchHelper) } + var onBrowsingStartedState: OmniBarState { return BrowsingNonEditingState(voiceSearchHelper: voiceSearchHelper) } var onBrowsingStoppedState: OmniBarState { return self } var onEnterPadState: OmniBarState { return self } - var onEnterPhoneState: OmniBarState { return SmallOmniBarState.HomeEmptyEditingState() } - var onReloadState: OmniBarState { return BrowsingNonEditingState() } + var onEnterPhoneState: OmniBarState { return SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } + var onReloadState: OmniBarState { return BrowsingNonEditingState(voiceSearchHelper: voiceSearchHelper) } + var showSearchLoupe: Bool { !voiceSearchHelper.isVoiceSearchEnabled } + var showVoiceSearch: Bool { voiceSearchHelper.isVoiceSearchEnabled } + + let voiceSearchHelper: VoiceSearchHelperProtocol } struct HomeTextEditingState: OmniBarState { @@ -59,7 +61,6 @@ struct LargeOmniBarState { let showShareButton: Bool = false let clearTextOnStart = false let allowsTrackersAnimation = false - let showSearchLoupe = !AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled let showPrivacyIcon = false let showBackground = false let showClear = true @@ -67,17 +68,20 @@ struct LargeOmniBarState { let showMenu = false let showSettings = true let showCancel: Bool = false - let showVoiceSearch = AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled var name: String { return "Pad" + Type.name(self) } - var onEditingStoppedState: OmniBarState { return HomeNonEditingState() } + var onEditingStoppedState: OmniBarState { return HomeNonEditingState(voiceSearchHelper: voiceSearchHelper) } var onEditingStartedState: OmniBarState { return self } - var onTextClearedState: OmniBarState { return HomeEmptyEditingState() } + var onTextClearedState: OmniBarState { return HomeEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } var onTextEnteredState: OmniBarState { return self } - var onBrowsingStartedState: OmniBarState { return BrowsingNonEditingState() } - var onBrowsingStoppedState: OmniBarState { return HomeEmptyEditingState() } + var onBrowsingStartedState: OmniBarState { return BrowsingNonEditingState(voiceSearchHelper: voiceSearchHelper) } + var onBrowsingStoppedState: OmniBarState { return HomeEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } var onEnterPadState: OmniBarState { return self } - var onEnterPhoneState: OmniBarState { return SmallOmniBarState.HomeTextEditingState() } - var onReloadState: OmniBarState { return HomeTextEditingState() } + var onEnterPhoneState: OmniBarState { return SmallOmniBarState.HomeTextEditingState(voiceSearchHelper: voiceSearchHelper) } + var onReloadState: OmniBarState { return HomeTextEditingState(voiceSearchHelper: voiceSearchHelper) } + var showSearchLoupe: Bool { !voiceSearchHelper.isVoiceSearchEnabled } + var showVoiceSearch: Bool { voiceSearchHelper.isVoiceSearchEnabled } + + let voiceSearchHelper: VoiceSearchHelperProtocol } struct HomeNonEditingState: OmniBarState { @@ -96,17 +100,19 @@ struct LargeOmniBarState { let showMenu = false let showSettings = true let showCancel: Bool = false - let showVoiceSearch = AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled var name: String { return "Pad" + Type.name(self) } var onEditingStoppedState: OmniBarState { return self } - var onEditingStartedState: OmniBarState { return HomeEmptyEditingState() } - var onTextClearedState: OmniBarState { return HomeEmptyEditingState() } - var onTextEnteredState: OmniBarState { return HomeTextEditingState() } - var onBrowsingStartedState: OmniBarState { return BrowsingNonEditingState() } - var onBrowsingStoppedState: OmniBarState { return HomeNonEditingState() } + var onEditingStartedState: OmniBarState { return HomeEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } + var onTextClearedState: OmniBarState { return HomeEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } + var onTextEnteredState: OmniBarState { return HomeTextEditingState(voiceSearchHelper: voiceSearchHelper) } + var onBrowsingStartedState: OmniBarState { return BrowsingNonEditingState(voiceSearchHelper: voiceSearchHelper) } + var onBrowsingStoppedState: OmniBarState { return HomeNonEditingState(voiceSearchHelper: voiceSearchHelper) } var onEnterPadState: OmniBarState { return self } - var onEnterPhoneState: OmniBarState { return SmallOmniBarState.HomeNonEditingState() } - var onReloadState: OmniBarState { return HomeNonEditingState() } + var onEnterPhoneState: OmniBarState { return SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: voiceSearchHelper) } + var onReloadState: OmniBarState { return HomeNonEditingState(voiceSearchHelper: voiceSearchHelper) } + var showVoiceSearch: Bool { voiceSearchHelper.isVoiceSearchEnabled } + + let voiceSearchHelper: VoiceSearchHelperProtocol } struct BrowsingEmptyEditingState: OmniBarState { @@ -117,7 +123,6 @@ struct LargeOmniBarState { let showShareButton: Bool = true let clearTextOnStart = true let allowsTrackersAnimation = false - let showSearchLoupe = !AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled let showPrivacyIcon = false let showBackground = false let showClear = false @@ -125,17 +130,20 @@ struct LargeOmniBarState { let showMenu = true let showSettings = false let showCancel: Bool = false - let showVoiceSearch = AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled var name: String { return "Pad" + Type.name(self) } - var onEditingStoppedState: OmniBarState { return BrowsingNonEditingState() } + var onEditingStoppedState: OmniBarState { return BrowsingNonEditingState(voiceSearchHelper: voiceSearchHelper) } var onEditingStartedState: OmniBarState { return self } var onTextClearedState: OmniBarState { return self } - var onTextEnteredState: OmniBarState { return BrowsingTextEditingState() } + var onTextEnteredState: OmniBarState { return BrowsingTextEditingState(voiceSearchHelper: voiceSearchHelper) } var onBrowsingStartedState: OmniBarState { return self } - var onBrowsingStoppedState: OmniBarState { return HomeEmptyEditingState() } + var onBrowsingStoppedState: OmniBarState { return HomeEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } var onEnterPadState: OmniBarState { return self } - var onEnterPhoneState: OmniBarState { return SmallOmniBarState.BrowsingEmptyEditingState() } - var onReloadState: OmniBarState { return BrowsingEmptyEditingState() } + var onEnterPhoneState: OmniBarState { return SmallOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } + var onReloadState: OmniBarState { return BrowsingEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } + var showSearchLoupe: Bool { !voiceSearchHelper.isVoiceSearchEnabled } + var showVoiceSearch: Bool { voiceSearchHelper.isVoiceSearchEnabled } + + let voiceSearchHelper: VoiceSearchHelperProtocol } struct BrowsingTextEditingState: OmniBarState { @@ -146,7 +154,6 @@ struct LargeOmniBarState { let showShareButton: Bool = true let clearTextOnStart = false let allowsTrackersAnimation = false - let showSearchLoupe = !AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled let showPrivacyIcon = false let showBackground = false let showClear = true @@ -154,17 +161,20 @@ struct LargeOmniBarState { let showMenu = true let showSettings = false let showCancel: Bool = false - let showVoiceSearch = AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled var name: String { return "Pad" + Type.name(self) } - var onEditingStoppedState: OmniBarState { return BrowsingNonEditingState() } + var onEditingStoppedState: OmniBarState { return BrowsingNonEditingState(voiceSearchHelper: voiceSearchHelper) } var onEditingStartedState: OmniBarState { return self } - var onTextClearedState: OmniBarState { return BrowsingEmptyEditingState() } + var onTextClearedState: OmniBarState { return BrowsingEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } var onTextEnteredState: OmniBarState { return self } var onBrowsingStartedState: OmniBarState { return self } - var onBrowsingStoppedState: OmniBarState { return HomeEmptyEditingState() } + var onBrowsingStoppedState: OmniBarState { return HomeEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } var onEnterPadState: OmniBarState { return self } - var onEnterPhoneState: OmniBarState { return SmallOmniBarState.BrowsingTextEditingState() } - var onReloadState: OmniBarState { return BrowsingTextEditingState() } + var onEnterPhoneState: OmniBarState { return SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: voiceSearchHelper) } + var onReloadState: OmniBarState { return BrowsingTextEditingState(voiceSearchHelper: voiceSearchHelper) } + var showSearchLoupe: Bool { !voiceSearchHelper.isVoiceSearchEnabled } + var showVoiceSearch: Bool { voiceSearchHelper.isVoiceSearchEnabled } + + let voiceSearchHelper: VoiceSearchHelperProtocol } struct BrowsingNonEditingState: OmniBarState { @@ -186,14 +196,16 @@ struct LargeOmniBarState { let showVoiceSearch = false var name: String { return "Pad" + Type.name(self) } var onEditingStoppedState: OmniBarState { return self } - var onEditingStartedState: OmniBarState { return BrowsingTextEditingState() } - var onTextClearedState: OmniBarState { return BrowsingEmptyEditingState() } - var onTextEnteredState: OmniBarState { return BrowsingTextEditingState() } + var onEditingStartedState: OmniBarState { return BrowsingTextEditingState(voiceSearchHelper: voiceSearchHelper) } + var onTextClearedState: OmniBarState { return BrowsingEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } + var onTextEnteredState: OmniBarState { return BrowsingTextEditingState(voiceSearchHelper: voiceSearchHelper) } var onBrowsingStartedState: OmniBarState { return self } - var onBrowsingStoppedState: OmniBarState { return HomeNonEditingState() } + var onBrowsingStoppedState: OmniBarState { return HomeNonEditingState(voiceSearchHelper: voiceSearchHelper) } var onEnterPadState: OmniBarState { return self } - var onEnterPhoneState: OmniBarState { return SmallOmniBarState.BrowsingNonEditingState() } - var onReloadState: OmniBarState { return BrowsingNonEditingState() } + var onEnterPhoneState: OmniBarState { return SmallOmniBarState.BrowsingNonEditingState(voiceSearchHelper: voiceSearchHelper) } + var onReloadState: OmniBarState { return BrowsingNonEditingState(voiceSearchHelper: voiceSearchHelper) } + + let voiceSearchHelper: VoiceSearchHelperProtocol } } diff --git a/DuckDuckGo/MainView.swift b/DuckDuckGo/MainView.swift index 87b22aa6ad..d11658736c 100644 --- a/DuckDuckGo/MainView.swift +++ b/DuckDuckGo/MainView.swift @@ -22,17 +22,19 @@ import UIKit class MainViewFactory { private let coordinator: MainViewCoordinator + private let voiceSearchHelper: VoiceSearchHelperProtocol var superview: UIView { coordinator.superview } - private init(_ superview: UIView) { + private init(superview: UIView, voiceSearchHelper: VoiceSearchHelperProtocol) { coordinator = MainViewCoordinator(superview: superview) + self.voiceSearchHelper = voiceSearchHelper } - static func createViewHierarchy(_ superview: UIView) -> MainViewCoordinator { - let factory = MainViewFactory(superview) + static func createViewHierarchy(_ superview: UIView, voiceSearchHelper: VoiceSearchHelperProtocol) -> MainViewCoordinator { + let factory = MainViewFactory(superview: superview, voiceSearchHelper: voiceSearchHelper) factory.createViews() factory.disableAutoresizingOnImmediateSubviews(superview) factory.constrainViews() @@ -70,7 +72,7 @@ extension MainViewFactory { } private func createOmniBar() { - coordinator.omniBar = OmniBar.loadFromXib() + coordinator.omniBar = OmniBar.loadFromXib(voiceSearchHelper: voiceSearchHelper) coordinator.omniBar.translatesAutoresizingMaskIntoConstraints = false } diff --git a/DuckDuckGo/MainViewController+Segues.swift b/DuckDuckGo/MainViewController+Segues.swift index 6ac0a7cadc..bca512800e 100644 --- a/DuckDuckGo/MainViewController+Segues.swift +++ b/DuckDuckGo/MainViewController+Segues.swift @@ -308,6 +308,7 @@ extension MainViewController { let settingsViewModel = SettingsViewModel(legacyViewProvider: legacyViewProvider, subscriptionManager: AppDependencyProvider.shared.subscriptionManager, subscriptionFeatureAvailability: subscriptionFeatureAvailability, + voiceSearchHelper: voiceSearchHelper, deepLink: deepLinkTarget, historyManager: historyManager, syncPausedStateManager: syncPausedStateManager, diff --git a/DuckDuckGo/MainViewController.swift b/DuckDuckGo/MainViewController.swift index a916d8320a..7e90bf0129 100644 --- a/DuckDuckGo/MainViewController.swift +++ b/DuckDuckGo/MainViewController.swift @@ -110,6 +110,7 @@ class MainViewController: UIViewController { private let contextualOnboardingLogic: ContextualOnboardingLogic let contextualOnboardingPixelReporter: OnboardingPixelReporting private let statisticsStore: StatisticsStore + let voiceSearchHelper: VoiceSearchHelperProtocol @UserDefaultsWrapper(key: .syncDidShowSyncPausedByFeatureFlagAlert, defaultValue: false) private var syncDidShowSyncPausedByFeatureFlagAlert: Bool @@ -197,7 +198,8 @@ class MainViewController: UIViewController { contextualOnboardingPixelReporter: OnboardingPixelReporting, tutorialSettings: TutorialSettings = DefaultTutorialSettings(), statisticsStore: StatisticsStore = StatisticsUserDefaults(), - subscriptionFeatureAvailability: SubscriptionFeatureAvailability + subscriptionFeatureAvailability: SubscriptionFeatureAvailability, + voiceSearchHelper: VoiceSearchHelperProtocol ) { self.bookmarksDatabase = bookmarksDatabase self.bookmarksDatabaseCleaner = bookmarksDatabaseCleaner @@ -229,6 +231,7 @@ class MainViewController: UIViewController { self.contextualOnboardingPixelReporter = contextualOnboardingPixelReporter self.statisticsStore = statisticsStore self.subscriptionFeatureAvailability = subscriptionFeatureAvailability + self.voiceSearchHelper = voiceSearchHelper super.init(nibName: nil, bundle: nil) @@ -264,7 +267,7 @@ class MainViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - viewCoordinator = MainViewFactory.createViewHierarchy(self.view) + viewCoordinator = MainViewFactory.createViewHierarchy(self.view, voiceSearchHelper: voiceSearchHelper) viewCoordinator.moveAddressBarToPosition(appSettings.currentAddressBarPosition) viewCoordinator.toolbarBackButton.action = #selector(onBackPressed) @@ -346,8 +349,9 @@ class MainViewController: UIViewController { swipeTabsCoordinator = SwipeTabsCoordinator(coordinator: viewCoordinator, tabPreviewsSource: previewsSource, - appSettings: appSettings) { [weak self] in - + appSettings: appSettings, + voiceSearchHelper: voiceSearchHelper) { [weak self] in + guard $0 != self?.tabManager.model.currentIndex else { return } DailyPixel.fire(pixel: .swipeTabsUsedDaily) diff --git a/DuckDuckGo/OmniBar.swift b/DuckDuckGo/OmniBar.swift index 09e4935a5f..d12d00d8e9 100644 --- a/DuckDuckGo/OmniBar.swift +++ b/DuckDuckGo/OmniBar.swift @@ -32,7 +32,7 @@ public enum OmniBarIcon: String { } class OmniBar: UIView { - + public static let didLayoutNotification = Notification.Name("com.duckduckgo.app.OmniBarDidLayout") @IBOutlet weak var searchLoupe: UIView! @@ -69,8 +69,8 @@ class OmniBar: UIView { @IBOutlet var separatorToBottom: NSLayoutConstraint! weak var omniDelegate: OmniBarDelegate? - fileprivate var state: OmniBarState = SmallOmniBarState.HomeNonEditingState() - + fileprivate var state: OmniBarState! + private var privacyIconAndTrackersAnimator = PrivacyIconAndTrackersAnimator() private var notificationAnimator = OmniBarNotificationAnimator() private let privacyIconContextualOnboardingAnimator = PrivacyIconContextualOnboardingAnimator() @@ -78,20 +78,21 @@ class OmniBar: UIView { // Set up a view to add a custom icon to the Omnibar private var customIconView: UIImageView = UIImageView(frame: CGRect(x: 4, y: 8, width: 26, height: 26)) - static func loadFromXib() -> OmniBar { - return OmniBar.load(nibName: "OmniBar") - } + static func loadFromXib(voiceSearchHelper: VoiceSearchHelperProtocol) -> OmniBar { + let omniBar = OmniBar.load(nibName: "OmniBar") + omniBar.state = SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: voiceSearchHelper) + omniBar.refreshState(omniBar.state) - private let appSettings: AppSettings + return omniBar + } required init?(coder: NSCoder) { - appSettings = AppDependencyProvider.shared.appSettings super.init(coder: coder) } // Tests require this - override init(frame: CGRect) { - appSettings = AppDependencyProvider.shared.appSettings + init(voiceSearchHelper: VoiceSearchHelperProtocol, frame: CGRect) { + self.state = SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: voiceSearchHelper) super.init(frame: frame) } @@ -105,7 +106,6 @@ class OmniBar: UIView { configureSeparator() configureEditingMenu() - refreshState(state) enableInteractionsWithPointer() privacyInfoContainer.isHidden = true diff --git a/DuckDuckGo/SettingsViewModel.swift b/DuckDuckGo/SettingsViewModel.swift index eb984187ff..e008a34ab6 100644 --- a/DuckDuckGo/SettingsViewModel.swift +++ b/DuckDuckGo/SettingsViewModel.swift @@ -363,7 +363,7 @@ final class SettingsViewModel: ObservableObject { legacyViewProvider: SettingsLegacyViewProvider, subscriptionManager: SubscriptionManager, subscriptionFeatureAvailability: SubscriptionFeatureAvailability, - voiceSearchHelper: VoiceSearchHelperProtocol = AppDependencyProvider.shared.voiceSearchHelper, + voiceSearchHelper: VoiceSearchHelperProtocol, variantManager: VariantManager = AppDependencyProvider.shared.variantManager, deepLink: SettingsDeepLinkSection? = nil, historyManager: HistoryManaging, @@ -417,8 +417,8 @@ extension SettingsViewModel { version: versionProvider.versionAndBuildNumber, crashCollectionOptInStatus: appSettings.crashCollectionOptInStatus, debugModeEnabled: featureFlagger.isFeatureOn(.debugMenu) || isDebugBuild, - voiceSearchEnabled: AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled, - speechRecognitionAvailable: AppDependencyProvider.shared.voiceSearchHelper.isSpeechRecognizerAvailable, + voiceSearchEnabled: voiceSearchHelper.isVoiceSearchEnabled, + speechRecognitionAvailable: voiceSearchHelper.isSpeechRecognizerAvailable, loginsEnabled: featureFlagger.isFeatureOn(.autofillAccessCredentialManagement), networkProtectionConnected: false, subscription: SettingsState.defaults.subscription, diff --git a/DuckDuckGo/SmallOmniBarState.swift b/DuckDuckGo/SmallOmniBarState.swift index e66aa50d17..ee47e1af6d 100644 --- a/DuckDuckGo/SmallOmniBarState.swift +++ b/DuckDuckGo/SmallOmniBarState.swift @@ -30,7 +30,6 @@ struct SmallOmniBarState { let showShareButton: Bool = false let clearTextOnStart = true let allowsTrackersAnimation = false - let showSearchLoupe = !AppDependencyProvider.shared.voiceSearchHelper.isSpeechRecognizerAvailable let showPrivacyIcon = false let showBackground = false let showClear = false @@ -38,17 +37,20 @@ struct SmallOmniBarState { let showMenu = false let showSettings = false let showCancel: Bool = true - let showVoiceSearch = AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled var name: String { return "Phone" + Type.name(self) } - var onEditingStoppedState: OmniBarState { return HomeNonEditingState() } + var onEditingStoppedState: OmniBarState { return HomeNonEditingState(voiceSearchHelper: voiceSearchHelper) } var onEditingStartedState: OmniBarState { return self } var onTextClearedState: OmniBarState { return self } - var onTextEnteredState: OmniBarState { return HomeTextEditingState() } - var onBrowsingStartedState: OmniBarState { return BrowsingNonEditingState() } + var onTextEnteredState: OmniBarState { return HomeTextEditingState(voiceSearchHelper: voiceSearchHelper) } + var onBrowsingStartedState: OmniBarState { return BrowsingNonEditingState(voiceSearchHelper: voiceSearchHelper) } var onBrowsingStoppedState: OmniBarState { return self } - var onEnterPadState: OmniBarState { return LargeOmniBarState.HomeEmptyEditingState() } + var onEnterPadState: OmniBarState { return LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } var onEnterPhoneState: OmniBarState { return self } - var onReloadState: OmniBarState { return HomeEmptyEditingState() } + var onReloadState: OmniBarState { return HomeEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } + var showSearchLoupe: Bool { !voiceSearchHelper.isSpeechRecognizerAvailable } + var showVoiceSearch: Bool { voiceSearchHelper.isVoiceSearchEnabled } + + let voiceSearchHelper: VoiceSearchHelperProtocol } struct HomeTextEditingState: OmniBarState { @@ -59,7 +61,6 @@ struct SmallOmniBarState { let showShareButton: Bool = false let clearTextOnStart = false let allowsTrackersAnimation = false - let showSearchLoupe = !AppDependencyProvider.shared.voiceSearchHelper.isSpeechRecognizerAvailable let showPrivacyIcon = false let showBackground = false let showClear = true @@ -69,15 +70,18 @@ struct SmallOmniBarState { let showCancel: Bool = true let showVoiceSearch = false var name: String { return "Phone" + Type.name(self) } - var onEditingStoppedState: OmniBarState { return HomeNonEditingState() } + var onEditingStoppedState: OmniBarState { return HomeNonEditingState(voiceSearchHelper: voiceSearchHelper) } var onEditingStartedState: OmniBarState { return self } - var onTextClearedState: OmniBarState { return HomeEmptyEditingState() } + var onTextClearedState: OmniBarState { return HomeEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } var onTextEnteredState: OmniBarState { return self } - var onBrowsingStartedState: OmniBarState { return BrowsingNonEditingState() } - var onBrowsingStoppedState: OmniBarState { return HomeEmptyEditingState() } - var onEnterPadState: OmniBarState { return LargeOmniBarState.HomeTextEditingState() } + var onBrowsingStartedState: OmniBarState { return BrowsingNonEditingState(voiceSearchHelper: voiceSearchHelper) } + var onBrowsingStoppedState: OmniBarState { return HomeEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } + var onEnterPadState: OmniBarState { return LargeOmniBarState.HomeTextEditingState(voiceSearchHelper: voiceSearchHelper) } var onEnterPhoneState: OmniBarState { return self } - var onReloadState: OmniBarState { return HomeTextEditingState() } + var onReloadState: OmniBarState { return HomeTextEditingState(voiceSearchHelper: voiceSearchHelper) } + var showSearchLoupe: Bool { !voiceSearchHelper.isSpeechRecognizerAvailable } + + let voiceSearchHelper: VoiceSearchHelperProtocol } struct HomeNonEditingState: OmniBarState { @@ -96,17 +100,19 @@ struct SmallOmniBarState { let showMenu = false let showSettings = true let showCancel: Bool = false - let showVoiceSearch = AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled var name: String { return "Phone" + Type.name(self) } var onEditingStoppedState: OmniBarState { return self } - var onEditingStartedState: OmniBarState { return HomeEmptyEditingState() } - var onTextClearedState: OmniBarState { return HomeEmptyEditingState() } - var onTextEnteredState: OmniBarState { return HomeTextEditingState() } - var onBrowsingStartedState: OmniBarState { return BrowsingNonEditingState() } - var onBrowsingStoppedState: OmniBarState { return HomeNonEditingState() } - var onEnterPadState: OmniBarState { return LargeOmniBarState.HomeNonEditingState() } + var onEditingStartedState: OmniBarState { return HomeEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } + var onTextClearedState: OmniBarState { return HomeEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } + var onTextEnteredState: OmniBarState { return HomeTextEditingState(voiceSearchHelper: voiceSearchHelper) } + var onBrowsingStartedState: OmniBarState { return BrowsingNonEditingState(voiceSearchHelper: voiceSearchHelper) } + var onBrowsingStoppedState: OmniBarState { return HomeNonEditingState(voiceSearchHelper: voiceSearchHelper) } + var onEnterPadState: OmniBarState { return LargeOmniBarState.HomeNonEditingState(voiceSearchHelper: voiceSearchHelper) } var onEnterPhoneState: OmniBarState { return self } - var onReloadState: OmniBarState { return HomeNonEditingState() } + var onReloadState: OmniBarState { return HomeNonEditingState(voiceSearchHelper: voiceSearchHelper) } + var showVoiceSearch: Bool { voiceSearchHelper.isVoiceSearchEnabled } + + let voiceSearchHelper: VoiceSearchHelperProtocol } struct BrowsingEmptyEditingState: OmniBarState { @@ -117,7 +123,6 @@ struct SmallOmniBarState { let showShareButton: Bool = false let clearTextOnStart = true let allowsTrackersAnimation = false - let showSearchLoupe = !AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled let showPrivacyIcon = false let showBackground = false let showClear = false @@ -125,17 +130,20 @@ struct SmallOmniBarState { let showMenu = false let showSettings = false let showCancel: Bool = true - let showVoiceSearch = AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled var name: String { return "Phone" + Type.name(self) } - var onEditingStoppedState: OmniBarState { return BrowsingNonEditingState() } + var onEditingStoppedState: OmniBarState { return BrowsingNonEditingState(voiceSearchHelper: voiceSearchHelper) } var onEditingStartedState: OmniBarState { return self } var onTextClearedState: OmniBarState { return self } - var onTextEnteredState: OmniBarState { return BrowsingTextEditingState() } + var onTextEnteredState: OmniBarState { return BrowsingTextEditingState(voiceSearchHelper: voiceSearchHelper) } var onBrowsingStartedState: OmniBarState { return self } - var onBrowsingStoppedState: OmniBarState { return HomeEmptyEditingState() } - var onEnterPadState: OmniBarState { return LargeOmniBarState.BrowsingEmptyEditingState() } + var onBrowsingStoppedState: OmniBarState { return HomeEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } + var onEnterPadState: OmniBarState { return LargeOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } var onEnterPhoneState: OmniBarState { return self } - var onReloadState: OmniBarState { return BrowsingEmptyEditingState() } + var onReloadState: OmniBarState { return BrowsingEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } + var showSearchLoupe: Bool { !voiceSearchHelper.isVoiceSearchEnabled } + var showVoiceSearch: Bool { voiceSearchHelper.isVoiceSearchEnabled } + + let voiceSearchHelper: VoiceSearchHelperProtocol } struct BrowsingTextEditingState: OmniBarState { @@ -146,7 +154,6 @@ struct SmallOmniBarState { let showShareButton: Bool = false let clearTextOnStart = false let allowsTrackersAnimation = false - let showSearchLoupe = !AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled let showPrivacyIcon = false let showBackground = false let showClear = true @@ -156,15 +163,18 @@ struct SmallOmniBarState { let showCancel: Bool = true let showVoiceSearch = false var name: String { return "Phone" + Type.name(self) } - var onEditingStoppedState: OmniBarState { return BrowsingNonEditingState() } + var onEditingStoppedState: OmniBarState { return BrowsingNonEditingState(voiceSearchHelper: voiceSearchHelper) } var onEditingStartedState: OmniBarState { return self } - var onTextClearedState: OmniBarState { return BrowsingEmptyEditingState() } + var onTextClearedState: OmniBarState { return BrowsingEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } var onTextEnteredState: OmniBarState { return self } var onBrowsingStartedState: OmniBarState { return self } - var onBrowsingStoppedState: OmniBarState { return HomeEmptyEditingState() } - var onEnterPadState: OmniBarState { return LargeOmniBarState.BrowsingTextEditingState() } + var onBrowsingStoppedState: OmniBarState { return HomeEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } + var onEnterPadState: OmniBarState { return LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: voiceSearchHelper) } var onEnterPhoneState: OmniBarState { return self } - var onReloadState: OmniBarState { return BrowsingTextEditingState() } + var onReloadState: OmniBarState { return BrowsingTextEditingState(voiceSearchHelper: voiceSearchHelper) } + var showSearchLoupe: Bool { !voiceSearchHelper.isVoiceSearchEnabled } + + let voiceSearchHelper: VoiceSearchHelperProtocol } struct BrowsingNonEditingState: OmniBarState { @@ -186,14 +196,16 @@ struct SmallOmniBarState { let showVoiceSearch = false var name: String { return "Phone" + Type.name(self) } var onEditingStoppedState: OmniBarState { return self } - var onEditingStartedState: OmniBarState { return BrowsingTextEditingStartedState() } - var onTextClearedState: OmniBarState { return BrowsingEmptyEditingState() } - var onTextEnteredState: OmniBarState { return BrowsingTextEditingState() } + var onEditingStartedState: OmniBarState { return BrowsingTextEditingStartedState(voiceSearchHelper: voiceSearchHelper) } + var onTextClearedState: OmniBarState { return BrowsingEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } + var onTextEnteredState: OmniBarState { return BrowsingTextEditingState(voiceSearchHelper: voiceSearchHelper) } var onBrowsingStartedState: OmniBarState { return self } - var onBrowsingStoppedState: OmniBarState { return HomeNonEditingState() } - var onEnterPadState: OmniBarState { return LargeOmniBarState.BrowsingNonEditingState() } + var onBrowsingStoppedState: OmniBarState { return HomeNonEditingState(voiceSearchHelper: voiceSearchHelper) } + var onEnterPadState: OmniBarState { return LargeOmniBarState.BrowsingNonEditingState(voiceSearchHelper: voiceSearchHelper) } var onEnterPhoneState: OmniBarState { return self } - var onReloadState: OmniBarState { return BrowsingNonEditingState() } + var onReloadState: OmniBarState { return BrowsingNonEditingState(voiceSearchHelper: voiceSearchHelper) } + + let voiceSearchHelper: VoiceSearchHelperProtocol } struct BrowsingTextEditingStartedState: OmniBarState { @@ -204,7 +216,6 @@ struct SmallOmniBarState { let showShareButton: Bool = false let clearTextOnStart = false let allowsTrackersAnimation = false - let showSearchLoupe = !AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled let showPrivacyIcon = false let showBackground = false let showClear = true @@ -212,16 +223,19 @@ struct SmallOmniBarState { let showMenu = false let showSettings = false let showCancel: Bool = true - let showVoiceSearch = AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled var name: String { return "Phone" + Type.name(self) } - var onEditingStoppedState: OmniBarState { return BrowsingNonEditingState() } + var onEditingStoppedState: OmniBarState { return BrowsingNonEditingState(voiceSearchHelper: voiceSearchHelper) } var onEditingStartedState: OmniBarState { return self } - var onTextClearedState: OmniBarState { return BrowsingEmptyEditingState() } - var onTextEnteredState: OmniBarState { return BrowsingTextEditingState() } + var onTextClearedState: OmniBarState { return BrowsingEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } + var onTextEnteredState: OmniBarState { return BrowsingTextEditingState(voiceSearchHelper: voiceSearchHelper) } var onBrowsingStartedState: OmniBarState { return self } - var onBrowsingStoppedState: OmniBarState { return HomeEmptyEditingState() } - var onEnterPadState: OmniBarState { return LargeOmniBarState.BrowsingTextEditingState() } + var onBrowsingStoppedState: OmniBarState { return HomeEmptyEditingState(voiceSearchHelper: voiceSearchHelper) } + var onEnterPadState: OmniBarState { return LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: voiceSearchHelper) } var onEnterPhoneState: OmniBarState { return self } - var onReloadState: OmniBarState { return BrowsingTextEditingStartedState() } + var onReloadState: OmniBarState { return BrowsingTextEditingStartedState(voiceSearchHelper: voiceSearchHelper) } + var showSearchLoupe: Bool { !voiceSearchHelper.isVoiceSearchEnabled } + var showVoiceSearch: Bool { voiceSearchHelper.isVoiceSearchEnabled } + + let voiceSearchHelper: VoiceSearchHelperProtocol } } diff --git a/DuckDuckGo/SwipeTabsCoordinator.swift b/DuckDuckGo/SwipeTabsCoordinator.swift index 9e77cbd28e..ea883d3dd7 100644 --- a/DuckDuckGo/SwipeTabsCoordinator.swift +++ b/DuckDuckGo/SwipeTabsCoordinator.swift @@ -30,7 +30,8 @@ class SwipeTabsCoordinator: NSObject { weak var coordinator: MainViewCoordinator! weak var tabPreviewsSource: TabPreviewsSource! weak var appSettings: AppSettings! - + let voiceSearchHelper: VoiceSearchHelperProtocol + let selectTab: (Int) -> Void let newTab: () -> Void let onSwipeStarted: () -> Void @@ -54,6 +55,7 @@ class SwipeTabsCoordinator: NSObject { init(coordinator: MainViewCoordinator, tabPreviewsSource: TabPreviewsSource, appSettings: AppSettings, + voiceSearchHelper: VoiceSearchHelperProtocol, selectTab: @escaping (Int) -> Void, newTab: @escaping () -> Void, onSwipeStarted: @escaping () -> Void) { @@ -61,7 +63,8 @@ class SwipeTabsCoordinator: NSObject { self.coordinator = coordinator self.tabPreviewsSource = tabPreviewsSource self.appSettings = appSettings - + self.voiceSearchHelper = voiceSearchHelper + self.selectTab = selectTab self.newTab = newTab self.onSwipeStarted = onSwipeStarted @@ -307,7 +310,7 @@ extension SwipeTabsCoordinator: UICollectionViewDataSource { cell.omniBar = coordinator.omniBar } else { // Strong reference while we use the omnibar - let omniBar = OmniBar.loadFromXib() + let omniBar = OmniBar.loadFromXib(voiceSearchHelper: voiceSearchHelper) cell.omniBar = omniBar cell.omniBar?.translatesAutoresizingMaskIntoConstraints = false diff --git a/DuckDuckGoTests/BarsAnimatorTests.swift b/DuckDuckGoTests/BarsAnimatorTests.swift index 1e558c478c..566d0099aa 100644 --- a/DuckDuckGoTests/BarsAnimatorTests.swift +++ b/DuckDuckGoTests/BarsAnimatorTests.swift @@ -184,7 +184,8 @@ private class BrowserChromeDelegateMock: BrowserChromeDelegate { var barsMaxHeight: CGFloat = 30 - var omniBar: OmniBar = OmniBar(frame: CGRect(x: 0, y: 0, width: 300, height: 30)) + var omniBar: OmniBar = OmniBar(voiceSearchHelper: MockVoiceSearchHelper(isSpeechRecognizerAvailable: true, voiceSearchEnabled: true), + frame: CGRect(x: 0, y: 0, width: 300, height: 30)) var tabBarContainer: UIView = UIView() } diff --git a/DuckDuckGoTests/LargeOmniBarStateTests.swift b/DuckDuckGoTests/LargeOmniBarStateTests.swift index d237d7ff96..f65af8ec0a 100644 --- a/DuckDuckGoTests/LargeOmniBarStateTests.swift +++ b/DuckDuckGoTests/LargeOmniBarStateTests.swift @@ -24,25 +24,12 @@ import XCTest class LargeOmniBarStateTests: XCTestCase { - var mockDependencyProvider: MockDependencyProvider! - - override func setUp() { - super.setUp() - - mockDependencyProvider = MockDependencyProvider() - AppDependencyProvider.shared = mockDependencyProvider - } - - override func tearDown() { - super.tearDown() - - AppDependencyProvider.shared = AppDependencyProvider.makeTestingInstance() - } - + let enabledVoiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: true) + let disabledVoiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: false) + func testWhenInHomeEmptyEditingStateWithoutVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: false) - let testee = LargeOmniBarState.HomeEmptyEditingState() - + let testee = LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: disabledVoiceSearchHelper) + XCTAssertFalse(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertFalse(testee.showClear) @@ -60,9 +47,8 @@ class LargeOmniBarStateTests: XCTestCase { } func testWhenInHomeEmptyEditingStateWithVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: true) - let testee = LargeOmniBarState.HomeEmptyEditingState() - + let testee = LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertFalse(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertFalse(testee.showClear) @@ -80,44 +66,43 @@ class LargeOmniBarStateTests: XCTestCase { } func testWhenEnteringHomeEmptyEditingStateThenTextIsCleared() { - let testee = LargeOmniBarState.HomeEmptyEditingState() + let testee = LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertTrue(testee.clearTextOnStart) } func testWhenInHomeEmptyEditingStateThenEditingStartedMaintainsState() { - let testee = LargeOmniBarState.HomeEmptyEditingState() - XCTAssertEqual(testee.onEditingStartedState.name, LargeOmniBarState.HomeEmptyEditingState().name) + let testee = LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStartedState.name, LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeEmptyEditingStateThenEditingStoppedTrainsitionsToNonEditingState() { - let testee = LargeOmniBarState.HomeEmptyEditingState() - XCTAssertEqual(testee.onEditingStoppedState.name, LargeOmniBarState.HomeNonEditingState().name) + let testee = LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStoppedState.name, LargeOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeEmptyEditingStateThenEnteringTextTransitionsToTextEditingState() { - let testee = LargeOmniBarState.HomeEmptyEditingState() - XCTAssertEqual(testee.onTextEnteredState.name, LargeOmniBarState.HomeTextEditingState().name) + let testee = LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextEnteredState.name, LargeOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeEmptyEditingStateThenClearingTextMaintainsState() { - let testee = LargeOmniBarState.HomeEmptyEditingState() - XCTAssertEqual(testee.onTextClearedState.name, LargeOmniBarState.HomeEmptyEditingState().name) + let testee = LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextClearedState.name, LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeEmptyEditingStateThenBrowsingStartedTransitionsToBrowsingNonEditingState() { - let testee = LargeOmniBarState.HomeEmptyEditingState() - XCTAssertEqual(testee.onBrowsingStartedState.name, LargeOmniBarState.BrowsingNonEditingState().name) + let testee = LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStartedState.name, LargeOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeEmptyEditingStateThenBrowsingStoppedMaintainsState() { - let testee = LargeOmniBarState.HomeEmptyEditingState() - XCTAssertEqual(testee.onBrowsingStoppedState.name, LargeOmniBarState.HomeEmptyEditingState().name) + let testee = LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStoppedState.name, LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeTextEditingStateWithoutVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: false) - let testee = LargeOmniBarState.HomeTextEditingState() - + let testee = LargeOmniBarState.HomeTextEditingState(voiceSearchHelper: disabledVoiceSearchHelper) + XCTAssertFalse(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertTrue(testee.showClear) @@ -135,9 +120,8 @@ class LargeOmniBarStateTests: XCTestCase { } func testWhenInHomeTextEditingStateWithVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: true) - let testee = LargeOmniBarState.HomeTextEditingState() - + let testee = LargeOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertFalse(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertTrue(testee.showClear) @@ -154,44 +138,42 @@ class LargeOmniBarStateTests: XCTestCase { XCTAssertFalse(testee.showShareButton) } func testWhenEnteringHomeTextEditingStateThenTextIsNotCleared() { - let testee = LargeOmniBarState.HomeTextEditingState() + let testee = LargeOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertFalse(testee.clearTextOnStart) } func testWhenInHomeTextEditingStateThenEditingStartedMaintainsState() { - let testee = LargeOmniBarState.HomeTextEditingState() - XCTAssertEqual(testee.onEditingStartedState.name, LargeOmniBarState.HomeTextEditingState().name) + let testee = LargeOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStartedState.name, LargeOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeTextEditingStateThenEditingStoppedTrainsitionsToNonEditingState() { - let testee = LargeOmniBarState.HomeTextEditingState() - XCTAssertEqual(testee.onEditingStoppedState.name, LargeOmniBarState.HomeNonEditingState().name) + let testee = LargeOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStoppedState.name, LargeOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeTextEditingStateThenEnteringTextMaintainstState() { - let testee = LargeOmniBarState.HomeTextEditingState() - XCTAssertEqual(testee.onTextEnteredState.name, LargeOmniBarState.HomeTextEditingState().name) + let testee = LargeOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextEnteredState.name, LargeOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeTextEditingStateThenClearingTextTransitionsToEmptyEditingState() { - let testee = LargeOmniBarState.HomeTextEditingState() - XCTAssertEqual(testee.onTextClearedState.name, LargeOmniBarState.HomeEmptyEditingState().name) + let testee = LargeOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextClearedState.name, LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeTextEditingStateThenBrowsingStartedTransitionsToBrowsingNonEditingState() { - let testee = LargeOmniBarState.HomeTextEditingState() - XCTAssertEqual(testee.onBrowsingStartedState.name, LargeOmniBarState.BrowsingNonEditingState().name) + let testee = LargeOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStartedState.name, LargeOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeTextEditingStateThenBrowsingStoppedTransitionsToHomeTextEditingState() { - let testee = LargeOmniBarState.HomeTextEditingState() - XCTAssertEqual(testee.onBrowsingStoppedState.name, LargeOmniBarState.HomeEmptyEditingState().name) + let testee = LargeOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStoppedState.name, LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeNonEditingStateWithVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: true) - - let testee = LargeOmniBarState.HomeNonEditingState() + let testee = LargeOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertTrue(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertFalse(testee.showClear) @@ -209,9 +191,7 @@ class LargeOmniBarStateTests: XCTestCase { } func testWhenInHomeNonEditingStateWithoutVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: false) - - let testee = LargeOmniBarState.HomeNonEditingState() + let testee = LargeOmniBarState.HomeNonEditingState(voiceSearchHelper: disabledVoiceSearchHelper) XCTAssertTrue(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertFalse(testee.showClear) @@ -229,43 +209,42 @@ class LargeOmniBarStateTests: XCTestCase { } func testWhenEnteringHomeNonEditingStateThenTextIsCleared() { - let testee = LargeOmniBarState.HomeNonEditingState() + let testee = LargeOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertTrue(testee.clearTextOnStart) } func testWhenInHomeNonEditingStateThenEditingStartedTransitionsToEmptyEditingState() { - let testee = LargeOmniBarState.HomeNonEditingState() - XCTAssertEqual(testee.onEditingStartedState.name, LargeOmniBarState.HomeEmptyEditingState().name) + let testee = LargeOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStartedState.name, LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeNonEditingStateThenEditingStoppedMaintainsState() { - let testee = LargeOmniBarState.HomeNonEditingState() - XCTAssertEqual(testee.onEditingStoppedState.name, LargeOmniBarState.HomeNonEditingState().name) + let testee = LargeOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStoppedState.name, LargeOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeNonEditingStateThenEnteringTextTransitionsToTextEditingState() { - let testee = LargeOmniBarState.HomeNonEditingState() - XCTAssertEqual(testee.onTextEnteredState.name, LargeOmniBarState.HomeTextEditingState().name) + let testee = LargeOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextEnteredState.name, LargeOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeNonEditingStateThenClearingTextTransitionsToEmptyEditingState() { - let testee = LargeOmniBarState.HomeNonEditingState() - XCTAssertEqual(testee.onTextClearedState.name, LargeOmniBarState.HomeEmptyEditingState().name) + let testee = LargeOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextClearedState.name, LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeNonEditingStateThenBrowsingStartedTransitionsToBrowsingNonEditingState() { - let testee = LargeOmniBarState.HomeNonEditingState() - XCTAssertEqual(testee.onBrowsingStartedState.name, LargeOmniBarState.BrowsingNonEditingState().name) + let testee = LargeOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStartedState.name, LargeOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeNonEditingStateThenBrowsingStoppedTransitionsToHomeNonEditingState() { - let testee = LargeOmniBarState.HomeNonEditingState() - XCTAssertEqual(testee.onBrowsingStoppedState.name, LargeOmniBarState.HomeNonEditingState().name) + let testee = LargeOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStoppedState.name, LargeOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowserEmptyEditingStateWithoutVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: false) - let testee = LargeOmniBarState.BrowsingEmptyEditingState() + let testee = LargeOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: disabledVoiceSearchHelper) XCTAssertFalse(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertFalse(testee.showClear) @@ -283,8 +262,7 @@ class LargeOmniBarStateTests: XCTestCase { } func testWhenInBrowserEmptyEditingStateWithVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: true) - let testee = LargeOmniBarState.BrowsingEmptyEditingState() + let testee = LargeOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertFalse(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertFalse(testee.showClear) @@ -302,43 +280,42 @@ class LargeOmniBarStateTests: XCTestCase { } func testWhenEnteringBrowserEmptyEditingStateThenTextIsCleared() { - let testee = LargeOmniBarState.BrowsingEmptyEditingState() + let testee = LargeOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertTrue(testee.clearTextOnStart) } func testWhenInBrowsingEmptyEditingStateThenEditingStartedMaintainsState() { - let testee = LargeOmniBarState.BrowsingEmptyEditingState() - XCTAssertEqual(testee.onEditingStartedState.name, LargeOmniBarState.BrowsingEmptyEditingState().name) + let testee = LargeOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStartedState.name, LargeOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingEmptyEditingStateThenEditingStoppedTrainsitionsToBrowsingNonEditingState() { - let testee = LargeOmniBarState.BrowsingEmptyEditingState() - XCTAssertEqual(testee.onEditingStoppedState.name, LargeOmniBarState.BrowsingNonEditingState().name) + let testee = LargeOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStoppedState.name, LargeOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingEmptyEditingStateThenEnteringTextTransitionsToTextEditingState() { - let testee = LargeOmniBarState.BrowsingEmptyEditingState() - XCTAssertEqual(testee.onTextEnteredState.name, LargeOmniBarState.BrowsingTextEditingState().name) + let testee = LargeOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextEnteredState.name, LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingEmptyEditingStateThenClearingMaintainsState() { - let testee = LargeOmniBarState.BrowsingEmptyEditingState() - XCTAssertEqual(testee.onTextClearedState.name, LargeOmniBarState.BrowsingEmptyEditingState().name) + let testee = LargeOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextClearedState.name, LargeOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingEmptyEditingStateThenBrowsingStartedMaintainsState() { - let testee = LargeOmniBarState.BrowsingEmptyEditingState() - XCTAssertEqual(testee.onBrowsingStartedState.name, LargeOmniBarState.BrowsingEmptyEditingState().name) + let testee = LargeOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStartedState.name, LargeOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingEmptyEditingStateThenBrowsingStoppedTransitionsToHomeEmptyEditingState() { - let testee = LargeOmniBarState.BrowsingEmptyEditingState() - XCTAssertEqual(testee.onBrowsingStoppedState.name, LargeOmniBarState.HomeEmptyEditingState().name) + let testee = LargeOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStoppedState.name, LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingTextEditingStateWithVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: true) - let testee = LargeOmniBarState.BrowsingTextEditingState() + let testee = LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertFalse(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertTrue(testee.showClear) @@ -356,8 +333,7 @@ class LargeOmniBarStateTests: XCTestCase { } func testWhenInBrowsingTextEditingStateWithoutVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: false) - let testee = LargeOmniBarState.BrowsingTextEditingState() + let testee = LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: disabledVoiceSearchHelper) XCTAssertFalse(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertTrue(testee.showClear) @@ -375,42 +351,42 @@ class LargeOmniBarStateTests: XCTestCase { } func testWhenEnteringBrowsingTextEditingStateThenTextIsMaintained() { - let testee = LargeOmniBarState.BrowsingTextEditingState() + let testee = LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertFalse(testee.clearTextOnStart) } func testWhenInBrowsingTextEditingStateThenEditingStartedMaintainsState() { - let testee = LargeOmniBarState.BrowsingTextEditingState() - XCTAssertEqual(testee.onEditingStartedState.name, LargeOmniBarState.BrowsingTextEditingState().name) + let testee = LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStartedState.name, LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingTextEditingStateThenEditingStoppedTrainsitionsToNonEditingState() { - let testee = LargeOmniBarState.BrowsingTextEditingState() - XCTAssertEqual(testee.onEditingStoppedState.name, LargeOmniBarState.BrowsingNonEditingState().name) + let testee = LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStoppedState.name, LargeOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingTextEditingStateThenEnteringTextMaintainstState() { - let testee = LargeOmniBarState.BrowsingTextEditingState() - XCTAssertEqual(testee.onTextEnteredState.name, LargeOmniBarState.BrowsingTextEditingState().name) + let testee = LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextEnteredState.name, LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingTextEditingStateThenClearingTextTransitionsToEmptyEditingState() { - let testee = LargeOmniBarState.BrowsingTextEditingState() - XCTAssertEqual(testee.onTextClearedState.name, LargeOmniBarState.BrowsingEmptyEditingState().name) + let testee = LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextClearedState.name, LargeOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingTextEditingStateThenBrowsingStartedMaintainsState() { - let testee = LargeOmniBarState.BrowsingTextEditingState() - XCTAssertEqual(testee.onBrowsingStartedState.name, LargeOmniBarState.BrowsingTextEditingState().name) + let testee = LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStartedState.name, LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingTextEditingStateThenBrowsingStoppedTransitionsToHomeTextEditingState() { - let testee = LargeOmniBarState.BrowsingTextEditingState() - XCTAssertEqual(testee.onBrowsingStoppedState.name, LargeOmniBarState.HomeEmptyEditingState().name) + let testee = LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStoppedState.name, LargeOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingNonEditingStateThenCorrectButtonsAreShown() { - let testee = LargeOmniBarState.BrowsingNonEditingState() + let testee = LargeOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertTrue(testee.showBackground) XCTAssertTrue(testee.showPrivacyIcon) XCTAssertFalse(testee.showClear) @@ -427,37 +403,37 @@ class LargeOmniBarStateTests: XCTestCase { } func testWhenEnteringBrowsingNonEditingStateThenTextIsMaintained() { - let testee = LargeOmniBarState.BrowsingTextEditingState() + let testee = LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertFalse(testee.clearTextOnStart) } func testWhenInBrowsingNonEditingStateThenEditingStartedTransitionsToTextEditingState() { - let testee = LargeOmniBarState.BrowsingNonEditingState() - XCTAssertEqual(testee.onEditingStartedState.name, LargeOmniBarState.BrowsingTextEditingState().name) + let testee = LargeOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStartedState.name, LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingNonEditingStateThenEditingStoppedMaintainsState() { - let testee = LargeOmniBarState.BrowsingNonEditingState() - XCTAssertEqual(testee.onEditingStoppedState.name, LargeOmniBarState.BrowsingNonEditingState().name) + let testee = LargeOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStoppedState.name, LargeOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingNonEditingStateThenEnteringTextTransitionsToTextEditingState() { - let testee = LargeOmniBarState.BrowsingNonEditingState() - XCTAssertEqual(testee.onTextEnteredState.name, LargeOmniBarState.BrowsingTextEditingState().name) + let testee = LargeOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextEnteredState.name, LargeOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingNonEditingStateThenClearingTextTransitionsToEmptyEditingState() { - let testee = LargeOmniBarState.BrowsingNonEditingState() - XCTAssertEqual(testee.onTextClearedState.name, LargeOmniBarState.BrowsingEmptyEditingState().name) + let testee = LargeOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextClearedState.name, LargeOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingNonEditingStateThenBrowsingStartedMaintainstState() { - let testee = LargeOmniBarState.BrowsingNonEditingState() - XCTAssertEqual(testee.onBrowsingStartedState.name, LargeOmniBarState.BrowsingNonEditingState().name) + let testee = LargeOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStartedState.name, LargeOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingNonEditingStateThenBrowsingStoppedTransitionsToHomeNonEditingState() { - let testee = LargeOmniBarState.BrowsingNonEditingState() - XCTAssertEqual(testee.onBrowsingStoppedState.name, LargeOmniBarState.HomeNonEditingState().name) + let testee = LargeOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStoppedState.name, LargeOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } } diff --git a/DuckDuckGoTests/MockDependencyProvider.swift b/DuckDuckGoTests/MockDependencyProvider.swift index 7d0c316029..45265faa53 100644 --- a/DuckDuckGoTests/MockDependencyProvider.swift +++ b/DuckDuckGoTests/MockDependencyProvider.swift @@ -33,7 +33,6 @@ class MockDependencyProvider: DependencyProvider { var featureFlagger: FeatureFlagger var internalUserDecider: InternalUserDecider var storageCache: StorageCache - var voiceSearchHelper: VoiceSearchHelperProtocol var downloadManager: DownloadManager var autofillLoginSession: AutofillLoginSession var autofillNeverPromptWebsitesManager: AutofillNeverPromptWebsitesManager @@ -56,7 +55,6 @@ class MockDependencyProvider: DependencyProvider { featureFlagger = defaultProvider.featureFlagger internalUserDecider = defaultProvider.internalUserDecider storageCache = defaultProvider.storageCache - voiceSearchHelper = defaultProvider.voiceSearchHelper downloadManager = defaultProvider.downloadManager autofillLoginSession = defaultProvider.autofillLoginSession autofillNeverPromptWebsitesManager = defaultProvider.autofillNeverPromptWebsitesManager diff --git a/DuckDuckGoTests/OnboardingDaxFavouritesTests.swift b/DuckDuckGoTests/OnboardingDaxFavouritesTests.swift index 548b68f63c..ad3c3be669 100644 --- a/DuckDuckGoTests/OnboardingDaxFavouritesTests.swift +++ b/DuckDuckGoTests/OnboardingDaxFavouritesTests.swift @@ -77,7 +77,8 @@ final class OnboardingDaxFavouritesTests: XCTestCase { contextualOnboardingLogic: contextualOnboardingLogicMock, contextualOnboardingPixelReporter: OnboardingPixelReporterMock(), tutorialSettings: tutorialSettingsMock, - subscriptionFeatureAvailability: SubscriptionFeatureAvailabilityMock.enabled + subscriptionFeatureAvailability: SubscriptionFeatureAvailabilityMock.enabled, + voiceSearchHelper: MockVoiceSearchHelper(isSpeechRecognizerAvailable: true, voiceSearchEnabled: true) ) let window = UIWindow(frame: UIScreen.main.bounds) window.rootViewController = UIViewController() diff --git a/DuckDuckGoTests/OnboardingNavigationDelegateTests.swift b/DuckDuckGoTests/OnboardingNavigationDelegateTests.swift index 8f0bf70518..ca052c5717 100644 --- a/DuckDuckGoTests/OnboardingNavigationDelegateTests.swift +++ b/DuckDuckGoTests/OnboardingNavigationDelegateTests.swift @@ -75,7 +75,8 @@ final class OnboardingNavigationDelegateTests: XCTestCase { contextualOnboardingPresenter: ContextualOnboardingPresenterMock(), contextualOnboardingLogic: ContextualOnboardingLogicMock(), contextualOnboardingPixelReporter: onboardingPixelReporter, - subscriptionFeatureAvailability: SubscriptionFeatureAvailabilityMock.enabled) + subscriptionFeatureAvailability: SubscriptionFeatureAvailabilityMock.enabled, + voiceSearchHelper: MockVoiceSearchHelper(isSpeechRecognizerAvailable: true, voiceSearchEnabled: true)) let window = UIWindow(frame: UIScreen.main.bounds) window.rootViewController = UIViewController() window.makeKeyAndVisible() diff --git a/DuckDuckGoTests/QuerySubmittedTests.swift b/DuckDuckGoTests/QuerySubmittedTests.swift index e46b9fe8cc..da37da1e9f 100644 --- a/DuckDuckGoTests/QuerySubmittedTests.swift +++ b/DuckDuckGoTests/QuerySubmittedTests.swift @@ -24,7 +24,7 @@ import Suggestions class QuerySubmittedTests: XCTestCase { let mock = MockOmniBarDelegate() - let sut = OmniBar.loadFromXib() + let sut = OmniBar.loadFromXib(voiceSearchHelper: MockVoiceSearchHelper(isSpeechRecognizerAvailable: true, voiceSearchEnabled: true)) override func setUp() { super.setUp() diff --git a/DuckDuckGoTests/SmallOmniBarStateTests.swift b/DuckDuckGoTests/SmallOmniBarStateTests.swift index 8eb0ceb1ef..93941a66a2 100644 --- a/DuckDuckGoTests/SmallOmniBarStateTests.swift +++ b/DuckDuckGoTests/SmallOmniBarStateTests.swift @@ -24,25 +24,12 @@ import XCTest class SmallOmniBarStateTests: XCTestCase { - var mockDependencyProvider: MockDependencyProvider! - - override func setUp() { - super.setUp() - - mockDependencyProvider = MockDependencyProvider() - AppDependencyProvider.shared = mockDependencyProvider - } - - override func tearDown() { - super.tearDown() - - AppDependencyProvider.shared = AppDependencyProvider.makeTestingInstance() - } + let enabledVoiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: true) + let disabledVoiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: false) func testWhenInHomeEmptyEditingStateWithoutVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: false) - let testee = SmallOmniBarState.HomeEmptyEditingState() - + let testee = SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: disabledVoiceSearchHelper) + XCTAssertFalse(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertFalse(testee.showClear) @@ -60,9 +47,8 @@ class SmallOmniBarStateTests: XCTestCase { } func testWhenInHomeEmptyEditingStateWithVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: true) - let testee = SmallOmniBarState.HomeEmptyEditingState() - + let testee = SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertFalse(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertFalse(testee.showClear) @@ -80,43 +66,42 @@ class SmallOmniBarStateTests: XCTestCase { } func testWhenEnteringHomeEmptyEditingStateThenTextIsCleared() { - let testee = SmallOmniBarState.HomeEmptyEditingState() + let testee = SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertTrue(testee.clearTextOnStart) } func testWhenInHomeEmptyEditingStateThenEditingStartedMaintainsState() { - let testee = SmallOmniBarState.HomeEmptyEditingState() - XCTAssertEqual(testee.onEditingStartedState.name, SmallOmniBarState.HomeEmptyEditingState().name) + let testee = SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStartedState.name, SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeEmptyEditingStateThenEditingStoppedTrainsitionsToNonEditingState() { - let testee = SmallOmniBarState.HomeEmptyEditingState() - XCTAssertEqual(testee.onEditingStoppedState.name, SmallOmniBarState.HomeNonEditingState().name) + let testee = SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStoppedState.name, SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeEmptyEditingStateThenEnteringTextTransitionsToTextEditingState() { - let testee = SmallOmniBarState.HomeEmptyEditingState() - XCTAssertEqual(testee.onTextEnteredState.name, SmallOmniBarState.HomeTextEditingState().name) + let testee = SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextEnteredState.name, SmallOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeEmptyEditingStateThenClearingTextMaintainsState() { - let testee = SmallOmniBarState.HomeEmptyEditingState() - XCTAssertEqual(testee.onTextClearedState.name, SmallOmniBarState.HomeEmptyEditingState().name) + let testee = SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextClearedState.name, SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeEmptyEditingStateThenBrowsingStartedTransitionsToBrowsingNonEditingState() { - let testee = SmallOmniBarState.HomeEmptyEditingState() - XCTAssertEqual(testee.onBrowsingStartedState.name, SmallOmniBarState.BrowsingNonEditingState().name) + let testee = SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStartedState.name, SmallOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeEmptyEditingStateThenBrowsingStoppedMaintainsState() { - let testee = SmallOmniBarState.HomeEmptyEditingState() - XCTAssertEqual(testee.onBrowsingStoppedState.name, SmallOmniBarState.HomeEmptyEditingState().name) + let testee = SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStoppedState.name, SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeTextEditingStateWithoutVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: false) - let testee = SmallOmniBarState.HomeTextEditingState() + let testee = SmallOmniBarState.HomeTextEditingState(voiceSearchHelper: disabledVoiceSearchHelper) XCTAssertFalse(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertTrue(testee.showClear) @@ -134,8 +119,7 @@ class SmallOmniBarStateTests: XCTestCase { } func testWhenInHomeTextEditingStateWithVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: true) - let testee = SmallOmniBarState.HomeTextEditingState() + let testee = SmallOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertFalse(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertTrue(testee.showClear) @@ -153,43 +137,42 @@ class SmallOmniBarStateTests: XCTestCase { } func testWhenEnteringHomeTextEditingStateThenTextIsNotCleared() { - let testee = SmallOmniBarState.HomeTextEditingState() + let testee = SmallOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertFalse(testee.clearTextOnStart) } func testWhenInHomeTextEditingStateThenEditingStartedMaintainsState() { - let testee = SmallOmniBarState.HomeTextEditingState() - XCTAssertEqual(testee.onEditingStartedState.name, SmallOmniBarState.HomeTextEditingState().name) + let testee = SmallOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStartedState.name, SmallOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeTextEditingStateThenEditingStoppedTrainsitionsToNonEditingState() { - let testee = SmallOmniBarState.HomeTextEditingState() - XCTAssertEqual(testee.onEditingStoppedState.name, SmallOmniBarState.HomeNonEditingState().name) + let testee = SmallOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStoppedState.name, SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } - func testWhenInHomeTextEditingStateThenEnteringTextMaintainstState() { - let testee = SmallOmniBarState.HomeTextEditingState() - XCTAssertEqual(testee.onTextEnteredState.name, SmallOmniBarState.HomeTextEditingState().name) + func testWhenInHomeTextEditingStateThenEnteringTextMaintainsState() { + let testee = SmallOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextEnteredState.name, SmallOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeTextEditingStateThenClearingTextTransitionsToEmptyEditingState() { - let testee = SmallOmniBarState.HomeTextEditingState() - XCTAssertEqual(testee.onTextClearedState.name, SmallOmniBarState.HomeEmptyEditingState().name) + let testee = SmallOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextClearedState.name, SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeTextEditingStateThenBrowsingStartedTransitionsToBrowsingNonEditingState() { - let testee = SmallOmniBarState.HomeTextEditingState() - XCTAssertEqual(testee.onBrowsingStartedState.name, SmallOmniBarState.BrowsingNonEditingState().name) + let testee = SmallOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStartedState.name, SmallOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeTextEditingStateThenBrowsingStoppedTransitionsToHomeTextEditingState() { - let testee = SmallOmniBarState.HomeTextEditingState() - XCTAssertEqual(testee.onBrowsingStoppedState.name, SmallOmniBarState.HomeEmptyEditingState().name) + let testee = SmallOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStoppedState.name, SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeNonEditingStateWithoutVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: false) - let testee = SmallOmniBarState.HomeNonEditingState() + let testee = SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: disabledVoiceSearchHelper) XCTAssertTrue(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertFalse(testee.showClear) @@ -207,8 +190,7 @@ class SmallOmniBarStateTests: XCTestCase { } func testWhenInHomeNonEditingStateWithVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: true) - let testee = SmallOmniBarState.HomeNonEditingState() + let testee = SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertTrue(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertFalse(testee.showClear) @@ -226,43 +208,42 @@ class SmallOmniBarStateTests: XCTestCase { } func testWhenEnteringHomeNonEditingStateThenTextIsCleared() { - let testee = SmallOmniBarState.HomeNonEditingState() + let testee = SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertTrue(testee.clearTextOnStart) } func testWhenInHomeNonEditingStateThenEditingStartedTransitionsToEmptyEditingState() { - let testee = SmallOmniBarState.HomeNonEditingState() - XCTAssertEqual(testee.onEditingStartedState.name, SmallOmniBarState.HomeEmptyEditingState().name) + let testee = SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStartedState.name, SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeNonEditingStateThenEditingStoppedMaintainsState() { - let testee = SmallOmniBarState.HomeNonEditingState() - XCTAssertEqual(testee.onEditingStoppedState.name, SmallOmniBarState.HomeNonEditingState().name) + let testee = SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStoppedState.name, SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeNonEditingStateThenEnteringTextTransitionsToTextEditingState() { - let testee = SmallOmniBarState.HomeNonEditingState() - XCTAssertEqual(testee.onTextEnteredState.name, SmallOmniBarState.HomeTextEditingState().name) + let testee = SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextEnteredState.name, SmallOmniBarState.HomeTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeNonEditingStateThenClearingTextTransitionsToEmptyEditingState() { - let testee = SmallOmniBarState.HomeNonEditingState() - XCTAssertEqual(testee.onTextClearedState.name, SmallOmniBarState.HomeEmptyEditingState().name) + let testee = SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextClearedState.name, SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeNonEditingStateThenBrowsingStartedTransitionsToBrowsingNonEditingState() { - let testee = SmallOmniBarState.HomeNonEditingState() - XCTAssertEqual(testee.onBrowsingStartedState.name, SmallOmniBarState.BrowsingNonEditingState().name) + let testee = SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStartedState.name, SmallOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInHomeNonEditingStateThenBrowsingStoppedTransitionsToHomeNonEditingState() { - let testee = SmallOmniBarState.HomeNonEditingState() - XCTAssertEqual(testee.onBrowsingStoppedState.name, SmallOmniBarState.HomeNonEditingState().name) + let testee = SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStoppedState.name, SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowserEmptyEditingStateWithoutVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: false) - let testee = SmallOmniBarState.BrowsingEmptyEditingState() + let testee = SmallOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: disabledVoiceSearchHelper) XCTAssertFalse(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertFalse(testee.showClear) @@ -280,8 +261,7 @@ class SmallOmniBarStateTests: XCTestCase { } func testWhenInBrowserEmptyEditingStateWithVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: true) - let testee = SmallOmniBarState.BrowsingEmptyEditingState() + let testee = SmallOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertFalse(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertFalse(testee.showClear) @@ -299,43 +279,42 @@ class SmallOmniBarStateTests: XCTestCase { } func testWhenEnteringBrowserEmptyEditingStateThenTextIsCleared() { - let testee = SmallOmniBarState.BrowsingEmptyEditingState() + let testee = SmallOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertTrue(testee.clearTextOnStart) } func testWhenInBrowsingEmptyEditingStateThenEditingStartedMaintainsState() { - let testee = SmallOmniBarState.BrowsingEmptyEditingState() - XCTAssertEqual(testee.onEditingStartedState.name, SmallOmniBarState.BrowsingEmptyEditingState().name) + let testee = SmallOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStartedState.name, SmallOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingEmptyEditingStateThenEditingStoppedTrainsitionsToBrowsingNonEditingState() { - let testee = SmallOmniBarState.BrowsingEmptyEditingState() - XCTAssertEqual(testee.onEditingStoppedState.name, SmallOmniBarState.BrowsingNonEditingState().name) + let testee = SmallOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStoppedState.name, SmallOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingEmptyEditingStateThenEnteringTextTransitionsToTextEditingState() { - let testee = SmallOmniBarState.BrowsingEmptyEditingState() - XCTAssertEqual(testee.onTextEnteredState.name, SmallOmniBarState.BrowsingTextEditingState().name) + let testee = SmallOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextEnteredState.name, SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingEmptyEditingStateThenClearingMaintainsState() { - let testee = SmallOmniBarState.BrowsingEmptyEditingState() - XCTAssertEqual(testee.onTextClearedState.name, SmallOmniBarState.BrowsingEmptyEditingState().name) + let testee = SmallOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextClearedState.name, SmallOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingEmptyEditingStateThenBrowsingStartedMaintainsState() { - let testee = SmallOmniBarState.BrowsingEmptyEditingState() - XCTAssertEqual(testee.onBrowsingStartedState.name, SmallOmniBarState.BrowsingEmptyEditingState().name) + let testee = SmallOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStartedState.name, SmallOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingEmptyEditingStateThenBrowsingStoppedTransitionsToHomeEmptyEditingState() { - let testee = SmallOmniBarState.BrowsingEmptyEditingState() - XCTAssertEqual(testee.onBrowsingStoppedState.name, SmallOmniBarState.HomeEmptyEditingState().name) + let testee = SmallOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStoppedState.name, SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingTextEditingStateWithoutVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: false) - let testee = SmallOmniBarState.BrowsingTextEditingState() + let testee = SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: disabledVoiceSearchHelper) XCTAssertFalse(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertTrue(testee.showClear) @@ -353,8 +332,7 @@ class SmallOmniBarStateTests: XCTestCase { } func testWhenInBrowsingTextEditingStateWithVoiceSearchThenCorrectButtonsAreShown() { - mockDependencyProvider.voiceSearchHelper = MockVoiceSearchHelper(isSpeechRecognizerAvailable: true) - let testee = SmallOmniBarState.BrowsingTextEditingState() + let testee = SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertFalse(testee.showBackground) XCTAssertFalse(testee.showPrivacyIcon) XCTAssertTrue(testee.showClear) @@ -372,42 +350,42 @@ class SmallOmniBarStateTests: XCTestCase { } func testWhenEnteringBrowsingTextEditingStateThenTextIsMaintained() { - let testee = SmallOmniBarState.BrowsingTextEditingState() + let testee = SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertFalse(testee.clearTextOnStart) } func testWhenInBrowsingTextEditingStateThenEditingStartedMaintainsState() { - let testee = SmallOmniBarState.BrowsingTextEditingState() - XCTAssertEqual(testee.onEditingStartedState.name, SmallOmniBarState.BrowsingTextEditingState().name) + let testee = SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStartedState.name, SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingTextEditingStateThenEditingStoppedTrainsitionsToNonEditingState() { - let testee = SmallOmniBarState.BrowsingTextEditingState() - XCTAssertEqual(testee.onEditingStoppedState.name, SmallOmniBarState.BrowsingNonEditingState().name) + let testee = SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStoppedState.name, SmallOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingTextEditingStateThenEnteringTextMaintainstState() { - let testee = SmallOmniBarState.BrowsingTextEditingState() - XCTAssertEqual(testee.onTextEnteredState.name, SmallOmniBarState.BrowsingTextEditingState().name) + let testee = SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextEnteredState.name, SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingTextEditingStateThenClearingTextTransitionsToEmptyEditingState() { - let testee = SmallOmniBarState.BrowsingTextEditingState() - XCTAssertEqual(testee.onTextClearedState.name, SmallOmniBarState.BrowsingEmptyEditingState().name) + let testee = SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextClearedState.name, SmallOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingTextEditingStateThenBrowsingStartedMaintainsState() { - let testee = SmallOmniBarState.BrowsingTextEditingState() - XCTAssertEqual(testee.onBrowsingStartedState.name, SmallOmniBarState.BrowsingTextEditingState().name) + let testee = SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStartedState.name, SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingTextEditingStateThenBrowsingStoppedTransitionsToHomeTextEditingState() { - let testee = SmallOmniBarState.BrowsingTextEditingState() - XCTAssertEqual(testee.onBrowsingStoppedState.name, SmallOmniBarState.HomeEmptyEditingState().name) + let testee = SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStoppedState.name, SmallOmniBarState.HomeEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingNonEditingStateThenCorrectButtonsAreShown() { - let testee = SmallOmniBarState.BrowsingNonEditingState() + let testee = SmallOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertTrue(testee.showBackground) XCTAssertTrue(testee.showPrivacyIcon) XCTAssertFalse(testee.showClear) @@ -424,42 +402,42 @@ class SmallOmniBarStateTests: XCTestCase { } func testWhenEnteringBrowsingNonEditingStateThenTextIsMaintained() { - let testee = SmallOmniBarState.BrowsingTextEditingState() + let testee = SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper) XCTAssertFalse(testee.clearTextOnStart) } func testWhenInBrowsingNonEditingStateThenToBrowsingTextEditingStartedState() { - let testee = SmallOmniBarState.BrowsingNonEditingState() - XCTAssertEqual(testee.onEditingStartedState.name, SmallOmniBarState.BrowsingTextEditingStartedState().name) + let testee = SmallOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStartedState.name, SmallOmniBarState.BrowsingTextEditingStartedState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingEditingStartedStateThenEnteringTextTransitionsToTextEditingState() { - let testee = SmallOmniBarState.BrowsingTextEditingStartedState() - XCTAssertEqual(testee.onTextEnteredState.name, SmallOmniBarState.BrowsingTextEditingState().name) + let testee = SmallOmniBarState.BrowsingTextEditingStartedState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextEnteredState.name, SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingNonEditingStateThenEditingStoppedMaintainsState() { - let testee = SmallOmniBarState.BrowsingNonEditingState() - XCTAssertEqual(testee.onEditingStoppedState.name, SmallOmniBarState.BrowsingNonEditingState().name) + let testee = SmallOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onEditingStoppedState.name, SmallOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingNonEditingStateThenEnteringTextTransitionsToTextEditingState() { - let testee = SmallOmniBarState.BrowsingNonEditingState() - XCTAssertEqual(testee.onTextEnteredState.name, SmallOmniBarState.BrowsingTextEditingState().name) + let testee = SmallOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextEnteredState.name, SmallOmniBarState.BrowsingTextEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingNonEditingStateThenClearingTextTransitionsToEmptyEditingState() { - let testee = SmallOmniBarState.BrowsingNonEditingState() - XCTAssertEqual(testee.onTextClearedState.name, SmallOmniBarState.BrowsingEmptyEditingState().name) + let testee = SmallOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onTextClearedState.name, SmallOmniBarState.BrowsingEmptyEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingNonEditingStateThenBrowsingStartedMaintainstState() { - let testee = SmallOmniBarState.BrowsingNonEditingState() - XCTAssertEqual(testee.onBrowsingStartedState.name, SmallOmniBarState.BrowsingNonEditingState().name) + let testee = SmallOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStartedState.name, SmallOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } func testWhenInBrowsingNonEditingStateThenBrowsingStoppedTransitionsToHomeNonEditingState() { - let testee = SmallOmniBarState.BrowsingNonEditingState() - XCTAssertEqual(testee.onBrowsingStoppedState.name, SmallOmniBarState.HomeNonEditingState().name) + let testee = SmallOmniBarState.BrowsingNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper) + XCTAssertEqual(testee.onBrowsingStoppedState.name, SmallOmniBarState.HomeNonEditingState(voiceSearchHelper: enabledVoiceSearchHelper).name) } }