Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SabrinaTardio committed Jul 16, 2024
1 parent 1921533 commit f32831e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 85 deletions.
5 changes: 3 additions & 2 deletions DuckDuckGo/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ class HomeViewController: UIViewController, NewTabPage {
object: nil)

registerForBookmarksChanges()
presentNextDaxDialog()
}

private func registerForBookmarksChanges() {
Expand Down Expand Up @@ -230,7 +229,9 @@ class HomeViewController: UIViewController, NewTabPage {

Pixel.fire(pixel: .homeScreenShown)
sendDailyDisplayPixel()


presentNextDaxDialog()

collectionView.didAppear()

viewHasAppeared = true
Expand Down

This file was deleted.

18 changes: 14 additions & 4 deletions DuckDuckGoTests/HomeViewControllerDaxDialogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ final class HomeViewControllerDaxDialogTests: XCTestCase {
favoritesDisplayModeStorage: MockFavoritesDisplayModeStoring(),
syncErrorHandler: SyncErrorHandler()
)
let remoteMessagingClient = RemoteMessagingClient(
bookmarksDatabase: db,
appSettings: AppSettingsMock(),
internalUserDecider: DefaultInternalUserDecider(),
configurationStore: MockConfigurationStoring(),
database: db,
errorEvents: nil,
remoteMessagingAvailabilityProvider: MockRemoteMessagingAvailabilityProviding())
let homePageConfiguration = HomePageConfiguration(remoteMessagingClient: remoteMessagingClient)
let dependencies = HomePageDependencies(
homePageConfiguration: homePageConfiguration,
model: Tab(),
favoritesViewModel: MockFavoritesListInteracting(),
appSettings: AppSettingsMock(),
Expand Down Expand Up @@ -81,14 +91,14 @@ final class HomeViewControllerDaxDialogTests: XCTestCase {
hvc = nil
}

func testWhenNewOnboarding_OnViewDidLoad_CorrectTypePassedToDialogFactory() throws {
func testWhenNewOnboarding_OnDidAppear_CorrectTypePassedToDialogFactory() throws {
// GIVEN
variantManager.isSupported = true
let expectedSpec = randomDialogType()
specProvider.specToReturn = expectedSpec

// WHEN
hvc.viewDidLoad()
hvc.viewDidAppear(false)

// THEN
XCTAssertEqual(self.variantManager.capturedFeatureName?.rawValue, FeatureName.newOnboardingIntro.rawValue)
Expand All @@ -98,12 +108,12 @@ final class HomeViewControllerDaxDialogTests: XCTestCase {
XCTAssertNotNil(self.dialogFactory.onDismiss)
}

func testWhenOldOnboarding_OnViewDidLoad_NothingPassedDialogFactory() throws {
func testWhenOldOnboarding_OnDidAppear_NothingPassedDialogFactory() throws {
// GIVEN
variantManager.isSupported = false

// WHEN
hvc.viewDidLoad()
hvc.viewDidAppear(false)

// THEN
XCTAssertTrue(specProvider.nextHomeScreenMessageCalled)
Expand Down
51 changes: 44 additions & 7 deletions DuckDuckGoTests/OnboardingNavigationDelegateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import Bookmarks
import DDGSync
import History
import BrowserServicesKit
import RemoteMessaging
import Configuration
import Combine
@testable import DuckDuckGo
@testable import Core

Expand All @@ -35,12 +38,6 @@ final class OnboardingNavigationDelegateTests: XCTestCase {
let db = CoreDataDatabase(name: "Test", containerLocation: tempDBDir(), model: model)
db.loadStore()
let bookmarkDatabaseCleaner = BookmarkDatabaseCleaner(bookmarkDatabase: db, errorEvents: nil)
let historyManager = HistoryManager(
privacyConfigManager: MockPrivacyConfigurationManager(),
variantManager: MockVariantManager(),
database: db,
internalUserDecider: DefaultInternalUserDecider(),
isEnabledByUser: false)
let dataProviders = SyncDataProviders(
bookmarksDatabase: db,
secureVaultFactory: AutofillSecureVaultFactory,
Expand All @@ -49,11 +46,22 @@ final class OnboardingNavigationDelegateTests: XCTestCase {
favoritesDisplayModeStorage: MockFavoritesDisplayModeStoring(),
syncErrorHandler: SyncErrorHandler()
)

let remoteMessagingClient = RemoteMessagingClient(
bookmarksDatabase: db,
appSettings: AppSettingsMock(),
internalUserDecider: DefaultInternalUserDecider(),
configurationStore: MockConfigurationStoring(),
database: db,
errorEvents: nil,
remoteMessagingAvailabilityProvider: MockRemoteMessagingAvailabilityProviding())
let homePageConfiguration = HomePageConfiguration(remoteMessagingClient: remoteMessagingClient)
let tabsModel = TabsModel(desktop: true)
mainVC = MainViewController(
bookmarksDatabase: db,
bookmarksDatabaseCleaner: bookmarkDatabaseCleaner,
historyManager: historyManager,
historyManager: MockHistoryManager(historyCoordinator: MockHistoryCoordinator(), isEnabledByUser: true, historyFeatureEnabled: true),
homePageConfiguration: homePageConfiguration,
syncService: MockDDGSyncing(authState: .active, isSyncInProgress: false),
syncDataProviders: dataProviders,
appSettings: AppSettingsMock(),
Expand Down Expand Up @@ -108,3 +116,32 @@ final class OnboardingNavigationDelegateTests: XCTestCase {
}

}

class MockConfigurationStoring: ConfigurationStoring {
func loadData(for configuration: Configuration) -> Data? {
return nil
}

func loadEtag(for configuration: Configuration) -> String? {
return nil
}

func loadEmbeddedEtag(for configuration: Configuration) -> String? {
return nil
}

func saveData(_ data: Data, for configuration: Configuration) throws {
}

func saveEtag(_ etag: String, for configuration: Configuration) throws {
}

}

class MockRemoteMessagingAvailabilityProviding: RemoteMessagingAvailabilityProviding {
var isRemoteMessagingAvailable: Bool = false

var isRemoteMessagingAvailablePublisher: AnyPublisher<Bool, Never> = Just(false)
.eraseToAnyPublisher()

}

0 comments on commit f32831e

Please sign in to comment.