Skip to content

Commit

Permalink
Fix an issue that cause showing again the Dax dialog for last visited…
Browse files Browse the repository at this point in the history
… website when opening a new tab and visit again the website
  • Loading branch information
alessandroboron committed Sep 24, 2024
1 parent 0dd603c commit 218d74d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
17 changes: 11 additions & 6 deletions DuckDuckGo/DaxDialogs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ final class DaxDialogs: NewTabDialogSpecProvider, ContextualOnboardingLogic {
func dismiss() {
settings.isDismissed = true
// Reset last shown dialog as we don't have to show it anymore.
removeLastShownDaxDialog()
removeLastVisitedOnboardingWebsite()
clearOnboardingBrowsingData()
}

func primeForUse() {
Expand Down Expand Up @@ -462,8 +461,7 @@ final class DaxDialogs: NewTabDialogSpecProvider, ContextualOnboardingLogic {

func setDaxDialogDismiss() {
guard isNewOnboarding else { return }
removeLastShownDaxDialog()
removeLastVisitedOnboardingWebsite()
clearOnboardingBrowsingData()
}

func setFinalOnboardingDialogSeen() {
Expand Down Expand Up @@ -556,8 +554,7 @@ final class DaxDialogs: NewTabDialogSpecProvider, ContextualOnboardingLogic {
saveLastShownDaxDialog(specType: spec.type)
saveLastVisitedOnboardingWebsite(url: privacyInfo.url)
} else {
removeLastVisitedOnboardingWebsite()
removeLastShownDaxDialog()
clearOnboardingBrowsingData()
}

return spec
Expand All @@ -574,6 +571,9 @@ final class DaxDialogs: NewTabDialogSpecProvider, ContextualOnboardingLogic {
}

func nextHomeScreenMessageNew() -> HomeScreenSpec? {
// Reset the last browsing information when opening a new tab so loading the previous website won't show again the Dax dialog
clearedBrowserData()

guard let homeScreenSpec = peekNextHomeScreenMessageExperiment() else {
currentHomeSpec = nil
return nil
Expand Down Expand Up @@ -729,6 +729,11 @@ final class DaxDialogs: NewTabDialogSpecProvider, ContextualOnboardingLogic {

return url1.isSameDuckDuckGoSearchURL(other: url2)
}

private func clearOnboardingBrowsingData() {
removeLastShownDaxDialog()
removeLastVisitedOnboardingWebsite()
}
}

extension URL {
Expand Down
17 changes: 17 additions & 0 deletions DuckDuckGoTests/DaxDialogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,23 @@ final class DaxDialog: XCTestCase {
XCTAssertEqual(result, .final)
}

func testWhenExperimentGroup_AndNextHomeScreenMessageNewIsCalled_ThenLastVisitedOnboardingWebsiteAndLastShownDaxDialogAreSetToNil() {
// GIVEN
let settings = InMemoryDaxDialogsSettings()
settings.lastShownContextualOnboardingDialogType = DaxDialogs.BrowsingSpec.fire.type.rawValue
settings.lastVisitedOnboardingWebsiteURLPath = "https://www.example.com"
let sut = makeExperimentSUT(settings: settings)
XCTAssertNotNil(settings.lastShownContextualOnboardingDialogType)
XCTAssertNotNil(settings.lastVisitedOnboardingWebsiteURLPath)

// WHEN
_ = sut.nextHomeScreenMessageNew()

// THEN
XCTAssertNil(settings.lastShownContextualOnboardingDialogType)
XCTAssertNil(settings.lastVisitedOnboardingWebsiteURLPath)
}

func testWhenExperimentGroup_AndCanEnableAddFavoritesFlowIsCalled_ThenReturnFalse() {
// GIVEN
let sut = makeExperimentSUT(settings: InMemoryDaxDialogsSettings())
Expand Down

0 comments on commit 218d74d

Please sign in to comment.