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

add state for import #3485

Merged
merged 4 commits into from
Nov 8, 2024
Merged
Changes from 1 commit
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
Next Next commit
add state for import
SabrinaTardio committed Oct 31, 2024
commit 0c778961d346746bcd451409cb1fd4c72b7ed409
4 changes: 2 additions & 2 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -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" */ = {
Original file line number Diff line number Diff line change
@@ -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"
}
},
{
6 changes: 3 additions & 3 deletions DuckDuckGo/HomePage/Model/DataImportStatusProviding.swift
Original file line number Diff line number Diff line change
@@ -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 {
@@ -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
2 changes: 1 addition & 1 deletion DuckDuckGo/HomePage/Model/HomePageContinueSetUpModel.swift
Original file line number Diff line number Diff line change
@@ -145,7 +145,7 @@ extension HomePage.Models {
}

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

@MainActor
23 changes: 19 additions & 4 deletions DuckDuckGo/Onboarding/OnboardingActionsManager.swift
Original file line number Diff line number Diff line change
@@ -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()
@@ -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)
@@ -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() {
@@ -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() {
4 changes: 4 additions & 0 deletions DuckDuckGo/Onboarding/OnboardingConfiguration.swift
Original file line number Diff line number Diff line change
@@ -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
@@ -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? {
3 changes: 2 additions & 1 deletion UnitTests/HomePage/Mocks/CapturingDataImportProvider.swift
Original file line number Diff line number Diff line change
@@ -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?()
}
Original file line number Diff line number Diff line change
@@ -62,8 +62,9 @@ class CapturingOnboardingActionsManager: OnboardingActionsManaging {
addToDockCalled = true
}

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

func setAsDefault() {
14 changes: 10 additions & 4 deletions UnitTests/Onboarding/OnboardingManagerTests.swift
Original file line number Diff line number Diff line change
@@ -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()
@@ -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() {
@@ -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() {