This repository has been archived by the owner on Feb 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for History View user script and fix reloading history (…
…#3855) Task/Issue URL: https://app.asana.com/0/72649045549333/1209365356928711 Description: This change adds missing unit tests, adds event handling to History View (together with 2 pixels) and fixes reloading history.
- Loading branch information
Showing
20 changed files
with
583 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// HistoryViewCoordinator.swift | ||
// | ||
// Copyright © 2025 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Combine | ||
import Foundation | ||
import HistoryView | ||
import Persistence | ||
import PixelKit | ||
|
||
final class HistoryViewCoordinator { | ||
let actionsManager: HistoryViewActionsManager | ||
|
||
init( | ||
historyCoordinator: HistoryGroupingDataSource, | ||
notificationCenter: NotificationCenter = .default, | ||
fireDailyPixel: @escaping (PixelKitEvent) -> Void = { PixelKit.fire($0, frequency: .daily) } | ||
) { | ||
actionsManager = HistoryViewActionsManager(historyCoordinator: historyCoordinator) | ||
|
||
notificationCenter.publisher(for: .historyWebViewDidAppear) | ||
.prefix(1) | ||
.sink { _ in | ||
fireDailyPixel(HistoryViewPixel.historyPageShown) | ||
} | ||
.store(in: &cancellables) | ||
} | ||
|
||
private var cancellables: Set<AnyCancellable> = [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// HistoryViewErrorHandler.swift | ||
// | ||
// Copyright © 2025 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Common | ||
import HistoryView | ||
import PixelKit | ||
|
||
final class HistoryViewErrorHandler: EventMapping<HistoryViewEvent> { | ||
|
||
init() { | ||
super.init { event, _, _, _ in | ||
switch event { | ||
case .historyViewError(let message): | ||
PixelKit.fire(DebugEvent(HistoryViewPixel.historyPageExceptionReported(message: message)), frequency: .dailyAndStandard) | ||
} | ||
} | ||
} | ||
|
||
override init(mapping: @escaping EventMapping<HistoryViewEvent>.Mapping) { | ||
fatalError("Use init()") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// HistoryViewPixel.swift | ||
// | ||
// Copyright © 2025 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import PixelKit | ||
|
||
/** | ||
* This enum keeps pixels related to HTML History View. | ||
*/ | ||
enum HistoryViewPixel: PixelKitEventV2 { | ||
|
||
/** | ||
* Event Trigger: History View is displayed to user. | ||
* | ||
* > Note: This is a daily pixel. | ||
* | ||
* > Related links: | ||
* [Privacy Triage TBD]() | ||
* [Detailed Pixels description](https://app.asana.com/0/0/1209364382402737/f) | ||
* | ||
* Anomaly Investigation: | ||
* - Anomaly in this pixel may mean an increase/drop in app use. | ||
*/ | ||
case historyPageShown | ||
|
||
// MARK: - Debug | ||
|
||
/** | ||
* Event Trigger: History View reports a JavaScript exception. | ||
* | ||
* > Note: This is a daily + standard pixel. | ||
* | ||
* > Related links: | ||
* [Privacy Triage TBD]() | ||
* [Detailed Pixels description](https://app.asana.com/0/0/1209364382402737/f) | ||
* | ||
* Anomaly Investigation: | ||
* - Anomaly in this pixel may mean a critical breakage in the History View. | ||
*/ | ||
case historyPageExceptionReported(message: String) | ||
|
||
var name: String { | ||
switch self { | ||
case .historyPageShown: return "history-page_shown" | ||
case .historyPageExceptionReported: return "history-page_exception-reported" | ||
} | ||
} | ||
|
||
var parameters: [String: String]? { | ||
switch self { | ||
case .historyPageShown: | ||
return nil | ||
case .historyPageExceptionReported(let message): | ||
return [PixelKit.Parameters.assertionMessage: message] | ||
} | ||
} | ||
|
||
var error: (any Error)? { | ||
nil | ||
} | ||
} |
Oops, something went wrong.