mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 19:05:20 +00:00
Expand coverage for transport, chat, and media flows (#1056)
* Expand coverage for transport, chat, and media flows * Stabilize transport and media coverage tests --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable import bitchat
|
||||
|
||||
@Suite("AutocompleteService Tests")
|
||||
struct AutocompleteServiceTests {
|
||||
|
||||
@Test("Mention suggestions are sorted, capped, and include replacement range")
|
||||
func mentionSuggestionsAreSortedAndCapped() {
|
||||
let service = AutocompleteService()
|
||||
let text = "hi @al"
|
||||
|
||||
let result = service.getSuggestions(
|
||||
for: text,
|
||||
peers: ["zoe", "alice", "albert", "bob", "alex", "ally", "alpha"],
|
||||
cursorPosition: text.count
|
||||
)
|
||||
|
||||
#expect(result.suggestions == ["@albert", "@alex", "@alice", "@ally", "@alpha"])
|
||||
#expect(result.range == NSRange(location: 3, length: 3))
|
||||
}
|
||||
|
||||
@Test("Suggestions are empty when cursor is not at a trailing mention")
|
||||
func suggestionsRequireTrailingMentionContext() {
|
||||
let service = AutocompleteService()
|
||||
let text = "hi @al there"
|
||||
|
||||
let result = service.getSuggestions(
|
||||
for: text,
|
||||
peers: ["alice", "albert"],
|
||||
cursorPosition: text.count
|
||||
)
|
||||
|
||||
#expect(result.suggestions.isEmpty)
|
||||
#expect(result.range == nil)
|
||||
}
|
||||
|
||||
@Test("Applying suggestions replaces the range and adds command spacing only when needed")
|
||||
func applySuggestionReplacesRangeAndHandlesCommandSpacing() {
|
||||
let service = AutocompleteService()
|
||||
|
||||
let mentionResult = service.applySuggestion("@alice", to: "hi @al", range: NSRange(location: 3, length: 3))
|
||||
let msgCommand = service.applySuggestion("/msg", to: "/m", range: NSRange(location: 0, length: 2))
|
||||
let clearCommand = service.applySuggestion("/clear", to: "/c", range: NSRange(location: 0, length: 2))
|
||||
|
||||
#expect(mentionResult == "hi @alice")
|
||||
#expect(msgCommand == "/msg ")
|
||||
#expect(clearCommand == "/clear")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user