Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contextual improvements #3105

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 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 @@ -445,12 +451,10 @@ final class DaxDialogs: NewTabDialogSpecProvider, ContextualOnboardingLogic {
return .subsequent
}

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

return nil
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ struct OnboardingSuggestedSitesProvider: OnboardingSuggestionsItemsProviding {
case .germany: site = "https://www.duden.de/rechtschreibung/Ente"
case .netherlands: site = "https://www.woorden.org/woord/eend"
case .sweden: site = "https://www.synonymer.se/sv-syn/anka"
default: site = "britannica.com/animal/duck"
default: site = "https:britannica.com/animal/duck"
}
return ContextualOnboardingListItem.surprise(title: site)
}
Expand Down
9 changes: 7 additions & 2 deletions DuckDuckGo/TabSwitcherViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,16 @@ class TabSwitcherViewController: UIViewController {

@IBAction func onFirePressed(sender: AnyObject) {
Pixel.fire(pixel: .forgetAllPressedTabSwitching)

if DaxDialogs.shared.shouldShowFireButtonPulse {
let isNewOnboarding = DefaultVariantManager().isSupported(feature: .newOnboardingIntro)

if !isNewOnboarding
&& DaxDialogs.shared.shouldShowFireButtonPulse {
let spec = DaxDialogs.shared.fireButtonEducationMessage()
performSegue(withIdentifier: "ActionSheetDaxDialog", sender: spec)
} else {
if isNewOnboarding {
ViewHighlighter.hideAll()
}
let alert = ForgetDataAlert.buildAlert(forgetTabsAndDataHandler: { [weak self] in
self?.forgetAll()
})
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
32 changes: 23 additions & 9 deletions DuckDuckGoTests/DaxDialogsNewTabTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ final class DaxDialogsNewTabTests: XCTestCase {

override func setUp() {
settings = MockDaxDialogsSettings()
daxDialogs = DaxDialogs(settings: settings, entityProviding: MockEntityProvider())
let mockVariantManager = MockVariantManager(isSupportedReturns: true)
daxDialogs = DaxDialogs(settings: settings, entityProviding: MockEntityProvider(), variantManager: mockVariantManager)
}

override func tearDown() {
Expand Down Expand Up @@ -70,44 +71,57 @@ final class DaxDialogsNewTabTests: XCTestCase {
// GIVEN
settings.browsingAfterSearchShown = true
settings.browsingMajorTrackingSiteShown = true
XCTAssertFalse(settings.browsingFinalDialogShown)
settings.fireButtonEducationShownOrExpired = true

// WHEN
let homeScreenMessage = daxDialogs.nextHomeScreenMessageNew()

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

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

// WHEN
let homeScreenMessage = daxDialogs.nextHomeScreenMessageNew()

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

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

// WHEN
let homeScreenMessage = daxDialogs.nextHomeScreenMessageNew()

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

func testIfBrowsingAfterSearchShown_andTrackersDialogsShown_andFirreButtonFialogNotShown_OnNextHomeScreenMessageNew_ReturnsNil() {
// GIVEN
settings.browsingAfterSearchShown = true
settings.browsingWithoutTrackersShown = true
settings.browsingMajorTrackingSiteShown = true
settings.browsingWithTrackersShown = true

// WHEN
let homeScreenMessage = daxDialogs.nextHomeScreenMessageNew()

// THEN
XCTAssertNil(homeScreenMessage)
XCTAssertFalse(settings.browsingFinalDialogShown)
}


func testIfBrowsingAfterSearchShown_andBrowsingMajorTrackingSiteShown_andFinalDialogAlreadyShown_OnNextHomeScreenMessageNew_ReturnsNil() {
// GIVEN
settings.browsingAfterSearchShown = true
Expand Down
14 changes: 7 additions & 7 deletions DuckDuckGoTests/OnboardingSuggestedSitesProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class OnboardingSuggestedSitesProviderTests: XCTestCase {
XCTAssertEqual(sitesList[0], ContextualOnboardingListItem.site(title: scheme + "bolasport.com"))
XCTAssertEqual(sitesList[1], ContextualOnboardingListItem.site(title: scheme + "kompas.com"))
XCTAssertEqual(sitesList[2], ContextualOnboardingListItem.site(title: scheme + "tokopedia.com"))
XCTAssertEqual(sitesList[3], ContextualOnboardingListItem.surprise(title: "britannica.com/animal/duck"))
XCTAssertEqual(sitesList[3], ContextualOnboardingListItem.surprise(title: scheme + "britannica.com/animal/duck"))
}

func testSuggestedSitesForGB() {
Expand All @@ -50,7 +50,7 @@ class OnboardingSuggestedSitesProviderTests: XCTestCase {
XCTAssertEqual(sitesList[0], ContextualOnboardingListItem.site(title: scheme + "skysports.com"))
XCTAssertEqual(sitesList[1], ContextualOnboardingListItem.site(title: scheme + "bbc.co.uk"))
XCTAssertEqual(sitesList[2], ContextualOnboardingListItem.site(title: scheme + "eBay.com"))
XCTAssertEqual(sitesList[3], ContextualOnboardingListItem.surprise(title: "britannica.com/animal/duck"))
XCTAssertEqual(sitesList[3], ContextualOnboardingListItem.surprise(title: scheme + "britannica.com/animal/duck"))
}

func testSuggestedSitesForGermany() {
Expand Down Expand Up @@ -80,7 +80,7 @@ class OnboardingSuggestedSitesProviderTests: XCTestCase {
XCTAssertEqual(sitesList[0], ContextualOnboardingListItem.site(title: scheme + "tsn.ca"))
XCTAssertEqual(sitesList[1], ContextualOnboardingListItem.site(title: scheme + "cbc.ca"))
XCTAssertEqual(sitesList[2], ContextualOnboardingListItem.site(title: scheme + "canadiantire.ca"))
XCTAssertEqual(sitesList[3], ContextualOnboardingListItem.surprise(title: "britannica.com/animal/duck"))
XCTAssertEqual(sitesList[3], ContextualOnboardingListItem.surprise(title: scheme + "britannica.com/animal/duck"))
}

func testSuggestedSitesForNetherlands() {
Expand Down Expand Up @@ -110,7 +110,7 @@ class OnboardingSuggestedSitesProviderTests: XCTestCase {
XCTAssertEqual(sitesList[0], ContextualOnboardingListItem.site(title: scheme + "afl.com.au"))
XCTAssertEqual(sitesList[1], ContextualOnboardingListItem.site(title: scheme + "abc.net.au"))
XCTAssertEqual(sitesList[2], ContextualOnboardingListItem.site(title: scheme + "eBay.com"))
XCTAssertEqual(sitesList[3], ContextualOnboardingListItem.surprise(title: "britannica.com/animal/duck"))
XCTAssertEqual(sitesList[3], ContextualOnboardingListItem.surprise(title: scheme + "britannica.com/animal/duck"))
}

func testSuggestedSitesForSweden() {
Expand Down Expand Up @@ -140,7 +140,7 @@ class OnboardingSuggestedSitesProviderTests: XCTestCase {
XCTAssertEqual(sitesList[0], ContextualOnboardingListItem.site(title: scheme + "skysports.com"))
XCTAssertEqual(sitesList[1], ContextualOnboardingListItem.site(title: scheme + "bbc.co.uk"))
XCTAssertEqual(sitesList[2], ContextualOnboardingListItem.site(title: scheme + "eBay.com"))
XCTAssertEqual(sitesList[3], ContextualOnboardingListItem.surprise(title: "britannica.com/animal/duck"))
XCTAssertEqual(sitesList[3], ContextualOnboardingListItem.surprise(title: scheme + "britannica.com/animal/duck"))
}

func testSuggestedSitesForUS() {
Expand All @@ -155,7 +155,7 @@ class OnboardingSuggestedSitesProviderTests: XCTestCase {
XCTAssertEqual(sitesList[0], ContextualOnboardingListItem.site(title: scheme + "ESPN.com"))
XCTAssertEqual(sitesList[1], ContextualOnboardingListItem.site(title: scheme + "yahoo.com"))
XCTAssertEqual(sitesList[2], ContextualOnboardingListItem.site(title: scheme + "eBay.com"))
XCTAssertEqual(sitesList[3], ContextualOnboardingListItem.surprise(title: "britannica.com/animal/duck"))
XCTAssertEqual(sitesList[3], ContextualOnboardingListItem.surprise(title: scheme + "britannica.com/animal/duck"))
}

func testSuggestedSitesForUnknownCountry() {
Expand All @@ -170,6 +170,6 @@ class OnboardingSuggestedSitesProviderTests: XCTestCase {
XCTAssertEqual(sitesList[0], ContextualOnboardingListItem.site(title: scheme + "ESPN.com"))
XCTAssertEqual(sitesList[1], ContextualOnboardingListItem.site(title: scheme + "yahoo.com"))
XCTAssertEqual(sitesList[2], ContextualOnboardingListItem.site(title: scheme + "eBay.com"))
XCTAssertEqual(sitesList[3], ContextualOnboardingListItem.surprise(title: "britannica.com/animal/duck"))
XCTAssertEqual(sitesList[3], ContextualOnboardingListItem.surprise(title: scheme + "britannica.com/animal/duck"))
}
}
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()
}

}
Loading