Skip to content

Commit

Permalink
Merge branch 'main' into dominik/rmf-store
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Oct 10, 2024
2 parents 5cfda4f + c642e92 commit 9c82f9c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Sources/Suggestions/SuggestionResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ public struct SuggestionResult: Equatable {
}

public var canBeAutocompleted: Bool {
!topHits.isEmpty
guard let firstTopHit = topHits.first else {
return false
}

// Disable autocompletion for website suggestions
if case .website = firstTopHit {
return false
}

return true
}

}
18 changes: 18 additions & 0 deletions Tests/SuggestionsTests/SuggestionResultTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,22 @@ final class SuggestionResultTests: XCTestCase {
XCTAssertEqual(emptyResult.duckduckgoSuggestions.count, 0)
}

func testWhenResultContainsWebsiteSuggestionAsFirstSuggestion_ThenCanNotBeAutocompleted() {
let suggestions = [Suggestion.website(url: URL(string: "duckduckgo.com")!), Suggestion.website(url: URL(string: "spreadprivacy.com")!)]
let result = SuggestionResult(topHits: suggestions, duckduckgoSuggestions: [], localSuggestions: [])

XCTAssertFalse(result.canBeAutocompleted)
}

func testWhenResultContainsHistoryOrBookmarkSuggestionAsFirstSuggestion_ThenCanBeAutocompleted() {
let suggestions = [Suggestion.bookmark(title: "", url: URL(string: "duckduckgo.com")!, isFavorite: false, allowedInTopHits: true), Suggestion.bookmark(title: "", url: URL(string: "spreadprivacy.com")!, isFavorite: false, allowedInTopHits: true)]
let result = SuggestionResult(topHits: suggestions, duckduckgoSuggestions: [], localSuggestions: [])

XCTAssert(result.canBeAutocompleted)

let suggestions2 = [Suggestion.historyEntry(title: nil, url: URL(string: "duckduckgo.com")!, allowedInTopHits: true), Suggestion.historyEntry(title: nil, url: URL(string: "spreadprivacy.com")!, allowedInTopHits: true)]
let result2 = SuggestionResult(topHits: suggestions2, duckduckgoSuggestions: [], localSuggestions: [])
XCTAssert(result2.canBeAutocompleted)
}

}

0 comments on commit 9c82f9c

Please sign in to comment.