Skip to content

Commit

Permalink
fix final dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
SabrinaTardio committed Jul 19, 2024
1 parent 4bce656 commit 8909067
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
8 changes: 6 additions & 2 deletions DuckDuckGo/DaxDialogs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protocol NewTabDialogSpecProvider {

protocol ContextualOnboardingLogic {
func setFireEducationMessageSeen()
func setFinalOnboardingDialogSeen()
}

extension ContentBlockerRulesManager: EntityProviding {
Expand Down Expand Up @@ -315,6 +316,11 @@ final class DaxDialogs: NewTabDialogSpecProvider, ContextualOnboardingLogic {
settings.fireButtonEducationShownOrExpired = true
}

func setFinalOnboardingDialogSeen() {
guard isNewOnboarding else { return }
settings.browsingFinalDialogShown = true
}

func nextBrowsingMessageIfShouldShow(for privacyInfo: PrivacyInfo) -> BrowsingSpec? {
guard privacyInfo.url != lastURLDaxDialogReturnedFor else { return nil }

Expand Down Expand Up @@ -446,8 +452,6 @@ final class DaxDialogs: NewTabDialogSpecProvider, ContextualOnboardingLogic {
}

if settings.fireButtonEducationShownOrExpired && !finalDaxDialogSeen {
// Ensure we don't show the final dialog again in context when the user sees it and vice-versa.
settings.browsingFinalDialogShown = true
return .final
}

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ class MainViewController: UIViewController {
addToContentContainer(controller: controller)
viewCoordinator.logoContainer.isHidden = true
} else {
let newTabDaxDialogFactory = NewTabDaxDialogFactory(delegate: self)
let newTabDaxDialogFactory = NewTabDaxDialogFactory(delegate: self, contextualOnboardingLogic: DaxDialogs.shared)
let homePageDependencies = HomePageDependencies(homePageConfiguration: homePageConfiguration,
model: tabModel,
favoritesViewModel: favoritesViewModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ protocol NewTabDaxDialogProvider {

class NewTabDaxDialogFactory: NewTabDaxDialogProvider {
var delegate: OnboardingNavigationDelegate?
var contextualOnboardingLogic: ContextualOnboardingLogic

init(delegate: OnboardingNavigationDelegate?) {
init(delegate: OnboardingNavigationDelegate?, contextualOnboardingLogic: ContextualOnboardingLogic) {
self.delegate = delegate
self.contextualOnboardingLogic = contextualOnboardingLogic
}

@ViewBuilder
Expand Down Expand Up @@ -91,6 +93,9 @@ class NewTabDaxDialogFactory: NewTabDaxDialogProvider {
}).padding()
}
}
.onAppear { [weak self] in
self?.contextualOnboardingLogic.setFinalOnboardingDialogSeen()
}
}
}

Expand Down
17 changes: 15 additions & 2 deletions DuckDuckGoTests/ContextualOnboardingNewTabDialogFactoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,27 @@ class ContextualOnboardingNewTabDialogFactoryTests: XCTestCase {

var factory: NewTabDaxDialogFactory!
var mockDelegate: CapturingOnboardingNavigationDelegate!
var contextualOnboardingLogicMock: ContextualOnboardingLogicMock!
var onDismissCalled: Bool!
var window: UIWindow!

override func setUp() {
super.setUp()
mockDelegate = CapturingOnboardingNavigationDelegate()
contextualOnboardingLogicMock = ContextualOnboardingLogicMock()
onDismissCalled = false
factory = NewTabDaxDialogFactory(delegate: mockDelegate)
factory = NewTabDaxDialogFactory(delegate: mockDelegate, contextualOnboardingLogic: contextualOnboardingLogicMock)
window = UIWindow(frame: UIScreen.main.bounds)
window.makeKeyAndVisible()
}

override func tearDown() {
window.isHidden = true
window = nil
factory = nil
mockDelegate = nil
onDismissCalled = nil
contextualOnboardingLogicMock = nil
super.tearDown()
}

Expand Down Expand Up @@ -73,23 +81,28 @@ class ContextualOnboardingNewTabDialogFactoryTests: XCTestCase {

func testCreateFinalDialogCreatesAnOnboardingFinalDialog() {
// Given
let expectation = XCTestExpectation(description: "action triggered")
contextualOnboardingLogicMock.expectation = expectation
var onDismissedRun = false
let homeDialog = DaxDialogs.HomeScreenSpec.final
let onDimsiss = { onDismissedRun = true }

// When
let view = factory.createDaxDialog(for: homeDialog, onDismiss: onDimsiss)
let host = UIHostingController(rootView: view)
window.rootViewController = host
XCTAssertNotNil(host.view)

// Then
let finalDialog = find(OnboardingFinalDialog.self, in: host)
XCTAssertNotNil(finalDialog)
finalDialog?.highFiveAction()
XCTAssertTrue(onDismissedRun)
wait(for: [expectation], timeout: 5.0)
XCTAssertTrue(contextualOnboardingLogicMock.didCallsetFinalOnboardingDialogSeen)
}

func testCreateAddFavoriteDialogCreatesAnContextualDaxDialog() {
func testCreateAddFavoriteDialogCreatesAContextualDaxDialog() {
// Given
let homeDialog = DaxDialogs.HomeScreenSpec.addFavorite

Expand Down
12 changes: 3 additions & 9 deletions DuckDuckGoTests/DaxDialogsNewTabTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,45 +71,39 @@ final class DaxDialogsNewTabTests: XCTestCase {
// GIVEN
settings.browsingAfterSearchShown = true
settings.browsingMajorTrackingSiteShown = true
daxDialogs.fireButtonPulseStarted()
XCTAssertFalse(settings.browsingFinalDialogShown)
settings.fireButtonEducationShownOrExpired = true

// WHEN
let homeScreenMessage = daxDialogs.nextHomeScreenMessageNew()

// THEN
XCTAssertEqual(homeScreenMessage, .final)
XCTAssertTrue(settings.browsingFinalDialogShown)
}

func testIfBrowsingAfterSearchShown_andBrowsingWithTrackersShown_andFireAnimationShown_OnNextHomeScreenMessageNew_ReturnsFinal() {
// GIVEN
settings.browsingAfterSearchShown = true
settings.browsingWithTrackersShown = true
daxDialogs.fireButtonPulseStarted()
XCTAssertFalse(settings.browsingFinalDialogShown)
settings.fireButtonEducationShownOrExpired = true

// WHEN
let homeScreenMessage = daxDialogs.nextHomeScreenMessageNew()

// THEN
XCTAssertEqual(homeScreenMessage, .final)
XCTAssertTrue(settings.browsingFinalDialogShown)
}

func testIfBrowsingAfterSearchShown_andBrowsingWithoutTrackersShown_andFireAnimationShown_OnNextHomeScreenMessageNew_ReturnsFinal() {
// GIVEN
settings.browsingAfterSearchShown = true
settings.browsingWithoutTrackersShown = true
daxDialogs.fireButtonPulseStarted()
XCTAssertFalse(settings.browsingFinalDialogShown)
settings.fireButtonEducationShownOrExpired = true

// WHEN
let homeScreenMessage = daxDialogs.nextHomeScreenMessageNew()

// THEN
XCTAssertEqual(homeScreenMessage, .final)
XCTAssertTrue(settings.browsingFinalDialogShown)
}

func testIfBrowsingAfterSearchShown_andTrackersDialogsShown_andFirreButtonFialogNotShown_OnNextHomeScreenMessageNew_ReturnsNil() {
Expand Down
7 changes: 7 additions & 0 deletions DuckDuckGoTests/TabViewControllerDaxDialogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,17 @@ final class TabViewControllerDaxDialogTests: XCTestCase {
}

final class ContextualOnboardingLogicMock: ContextualOnboardingLogic {
var expectation: XCTestExpectation?
private(set) var didCallSetFireEducationMessageSeen = false
private(set) var didCallsetFinalOnboardingDialogSeen = false

func setFireEducationMessageSeen() {
didCallSetFireEducationMessageSeen = true
}

func setFinalOnboardingDialogSeen() {
didCallsetFinalOnboardingDialogSeen = true
expectation?.fulfill()
}

}

0 comments on commit 8909067

Please sign in to comment.