Skip to content

Commit

Permalink
add state for import
Browse files Browse the repository at this point in the history
  • Loading branch information
SabrinaTardio committed Oct 31, 2024
1 parent b226f66 commit 0c77896
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 24 deletions.
4 changes: 2 additions & 2 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14675,8 +14675,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 201.0.0;
branch = "sabrina/onboarding-import-state";
kind = branch;
};
};
9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "e5946eee6af859690cc1cc5e51daef3c8368981b",
"version" : "201.0.0"
"branch" : "sabrina/onboarding-import-state",
"revision" : "05ea8316abb7cf3ba312b749b09ea2a437aa188a"
}
},
{
"identity" : "content-scope-scripts",
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/content-scope-scripts",
"state" : {
"revision" : "b74549bd869fdecc16fad851f2f608b1724764df",
"version" : "6.25.0"
"branch" : "pr-releases/pr-1180",
"revision" : "551d15fcadecd1e8cddd0dca625358e8bf1fb3fa"
}
},
{
"identity" : "duckduckgo-autofill",
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/duckduckgo-autofill.git",
"state" : {
"revision" : "945ac09a0189dc6736db617867fde193ea984b20",
"version" : "15.0.0"
"revision" : "c992041d16ec10d790e6204dce9abf9966d1363c",
"version" : "15.1.0"
}
},
{
Expand Down
6 changes: 3 additions & 3 deletions DuckDuckGo/HomePage/Model/DataImportStatusProviding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import PixelKit

protocol DataImportStatusProviding {
var didImport: Bool { get }
func showImportWindow(completion: (() -> Void)?)
func showImportWindow(customTitle: String?, completion: (() -> Void)?)
}

final class BookmarksAndPasswordsImportStatusProvider: DataImportStatusProviding {
Expand All @@ -50,8 +50,8 @@ final class BookmarksAndPasswordsImportStatusProvider: DataImportStatusProviding
}

@MainActor
func showImportWindow(completion: (() -> Void)?) {
DataImportView().show(completion: completion)
func showImportWindow(customTitle: String?, completion: (() -> Void)?) {
DataImportView(title: customTitle ?? UserText.importDataTitle).show(completion: completion)
}

// It only cover the case in which the user has imported bookmar AFTER already having some bookmarks
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/HomePage/Model/HomePageContinueSetUpModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ extension HomePage.Models {
}

private func performImportBookmarksAndPasswordsAction() {
dataImportProvider.showImportWindow(completion: { self.refreshFeaturesMatrix() })
dataImportProvider.showImportWindow(customTitle: nil, completion: { self.refreshFeaturesMatrix() })
}

@MainActor
Expand Down
23 changes: 19 additions & 4 deletions DuckDuckGo/Onboarding/OnboardingActionsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protocol OnboardingActionsManaging {
func addToDock()

/// At user imput shows the import data flow
func importData()
func importData() async -> Bool

/// At user imput shows the system prompt to change default browser
func setAsDefault()
Expand Down Expand Up @@ -83,6 +83,7 @@ final class OnboardingActionsManager: OnboardingActionsManaging {
private let defaultBrowserProvider: DefaultBrowserProvider
private let appearancePreferences: AppearancePreferences
private let startupPreferences: StartupPreferences
private let dataImportProvider: DataImportStatusProviding
private var cancellables = Set<AnyCancellable>()

@UserDefaultsWrapper(key: .onboardingFinished, defaultValue: false)
Expand All @@ -109,12 +110,18 @@ final class OnboardingActionsManager: OnboardingActionsManaging {
return OnboardingConfiguration(stepDefinitions: stepDefinitions, exclude: [], order: order, env: env, locale: preferredLocale, platform: platform)
}()

init(navigationDelegate: OnboardingNavigating, dockCustomization: DockCustomization, defaultBrowserProvider: DefaultBrowserProvider, appearancePreferences: AppearancePreferences, startupPreferences: StartupPreferences) {
init(navigationDelegate: OnboardingNavigating,
dockCustomization: DockCustomization,
defaultBrowserProvider: DefaultBrowserProvider,
appearancePreferences: AppearancePreferences,
startupPreferences: StartupPreferences,
dataImportProvider: DataImportStatusProviding = BookmarksAndPasswordsImportStatusProvider()) {
self.navigation = navigationDelegate
self.dockCustomization = dockCustomization
self.defaultBrowserProvider = defaultBrowserProvider
self.appearancePreferences = appearancePreferences
self.startupPreferences = startupPreferences
self.dataImportProvider = dataImportProvider
}

func onboardingStarted() {
Expand Down Expand Up @@ -148,8 +155,16 @@ final class OnboardingActionsManager: OnboardingActionsManaging {
}

@MainActor
func importData() {
navigation.showImportDataView()
func importData() async -> Bool {
return await withCheckedContinuation { continuation in
dataImportProvider.showImportWindow(customTitle: UserText.importDataTitleOnboarding, completion: { [weak self] in
guard let self else {
continuation.resume(returning: false)
return
}
continuation.resume(returning: self.dataImportProvider.didImport)
})
}
}

func setAsDefault() {
Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/Onboarding/OnboardingConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ struct SystemSettings: Codable, Equatable {
struct OnboardingPlatform: Codable, Equatable {
var name: String
}

struct OnboardingImportResponse: Codable, Equatable {
var enabled: Bool
}
4 changes: 2 additions & 2 deletions DuckDuckGo/Onboarding/OnboardingUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ extension OnboardingUserScript {

@MainActor
private func requestImport(params: Any, original: WKScriptMessage) async throws -> Encodable? {
onboardingActionsManager.importData()
return Result()
let isDataImported = await onboardingActionsManager.importData()
return OnboardingImportResponse(enabled: isDataImported)
}

private func requestSetAsDefault(params: Any, original: WKScriptMessage) async throws -> Encodable? {
Expand Down
3 changes: 2 additions & 1 deletion UnitTests/HomePage/Mocks/CapturingDataImportProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import Foundation
@testable import DuckDuckGo_Privacy_Browser

class CapturingDataImportProvider: DataImportStatusProviding {

var showImportWindowCalled = false
var didImport = false

func showImportWindow(completion: (() -> Void)?) {
func showImportWindow(customTitle: String?, completion: (() -> Void)?) {
showImportWindowCalled = true
completion?()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ class CapturingOnboardingActionsManager: OnboardingActionsManaging {
addToDockCalled = true
}

func importData() {
func importData() async -> Bool {
importDataCalled = true
return true
}

func setAsDefault() {
Expand Down
14 changes: 10 additions & 4 deletions UnitTests/Onboarding/OnboardingManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class OnboardingManagerTests: XCTestCase {
var startupPreferences: StartupPreferences!
var appearancePersistor: MockAppearancePreferencesPersistor!
var startupPersistor: StartupPreferencesUserDefaultsPersistor!
var importProvider: CapturingDataImportProvider!

@MainActor override func setUp() {
super.setUp()
Expand All @@ -40,7 +41,8 @@ class OnboardingManagerTests: XCTestCase {
appearancePreferences = AppearancePreferences(persistor: appearancePersistor)
startupPersistor = StartupPreferencesUserDefaultsPersistor()
startupPreferences = StartupPreferences(appearancePreferences: appearancePreferences, persistor: startupPersistor)
manager = OnboardingActionsManager(navigationDelegate: navigationDelegate, dockCustomization: dockCustomization, defaultBrowserProvider: defaultBrowserProvider, appearancePreferences: appearancePreferences, startupPreferences: startupPreferences)
importProvider = CapturingDataImportProvider()
manager = OnboardingActionsManager(navigationDelegate: navigationDelegate, dockCustomization: dockCustomization, defaultBrowserProvider: defaultBrowserProvider, appearancePreferences: appearancePreferences, startupPreferences: startupPreferences, dataImportProvider: importProvider)
}

override func tearDown() {
Expand Down Expand Up @@ -151,12 +153,16 @@ class OnboardingManagerTests: XCTestCase {
}

@MainActor
func testOnImportData_DataImportViewShown() {
func testOnImportData_DataImportViewShown() async {
// Given
importProvider.didImport = true

// When
manager.importData()
let didImport = await manager.importData()

// Then
XCTAssertTrue(navigationDelegate.showImportDataViewCalled)
XCTAssertTrue(importProvider.showImportWindowCalled)
XCTAssertTrue(didImport)
}

func testOnAddToDock_IsAddedToDock() {
Expand Down

0 comments on commit 0c77896

Please sign in to comment.