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
Add unit tests for History View user script and fix reloading history #3855
Merged
+583
−22
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ef0997a
Add initial tests for History Data Client
ayoy 7b51fa7
Add remaining tests for Data Client
ayoy 271b218
ActionsHandler -> ActionsHandling
ayoy c986bce
Add ArrayExtensionTests
ayoy a45647a
Add HistoryViewCoordinatorTests
ayoy 387691a
Fix deciding policy for history web view
ayoy 7d8bf1b
Use localizedCaseInsensitiveContains in history search
ayoy 0a85249
Fix SwiftLint violation
ayoy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Did we have calls to the
chunk
method with negative values onlimit
andoffset
, is it something we should be worried about?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only if accidentally called with a negative value, which shouldn't be the case, but this function is ultimately called from JS, so better safe than sorry :)